Re[3]: [Tutor] Comparative code questions: Python vs. Rebol

antonmuhin на rambler.ru antonmuhin на rambler.ru
Fri Jan 17 05:13:02 2003


Hello Magnus,

ML> It's largely a matter of personal preference of course,
ML> but you might see that it *will* grow more complex soon if
ML> you do something like this. After a while you will need
ML> to set attributes in your tags, and do things like:

ML> Which path is easier to get here? Nested functions or classes?
IMHO, it depends on circumstances. If I write quick'n'dirty script
with Python as I mostly do (unfortunately, I have to use C++ and I'm
getting to hate it as long I started to use Python for my personal
tasks) lambdas, nested functions are really good. However, for big
projects like hypothetic HTML system you described your solution is
much better.

ML> It's always tricky to determine what features to use, at
ML> least when other people who are not so familiar with
ML> python will be involved in the code. I don't have any
ML> qualms about using classes though, and certainly not
ML> about using __init__... I think it's good to expose __call__
ML> to people as well. It's not very difficult to understand,
ML> is it? The sooner they get used to using classes, the
ML> better! I might well completely leave out lambdas, map,
ML> filter and reduce though. I have come to like them, but
ML> they are really redundant sugar. They introduce new concepts
ML> that needs to be learned without providing any really new
ML> features. Classes, on the other hand, really add something
ML> to Python.

Regarding your paragraph above, I'd like to suggest a topic that was
discussed many times, but I still think we might talk about it more :)

I do really like OOP, but I think that it has its shortcomings too.
One that is most important for me, bad treating of code blocks.

You see, for me lambdas and nested functions are substitution for
more general construction --- code blocks. It seems that Python moves
a little bit towards it: list comprehensions actually partly introduce
code blocks. And with comprehensions I don't use map anymore.

However, code blocks in Ruby and Rebol (if I understand Tim's article
correctly) seems really nice. For example, I like Ruby's way to work
with files.

Sure, one can wrap code blocks in classes. However, from pure
theoretical point of view it might be bad solution: code is really
different from data. BTW, wrapping functions in classes often leads to
class names like SomeFunctionCaller (at least in my code :) or alike
that are deprecated by some theorists.

And, at least for me, syntactic sugar is really important: one of the
reason I hate C++ is that I must wrap function calls in classes too
often.

And the last simple question: what about introducing a kind of
comprehensions for other predicates like reduce? Something like:

   [x + y for x, y reducing [1, 2, 3]]

that calculates 6 ([] seems bad here, sorry). What do you think about it?


-- 
Best regards,
 anton                            mailto:antonmuhin@rambler.ru