Favorite non-python language trick?

GodFoca godfoca at gmail.com
Sun Jun 26 14:24:03 EDT 2005


> I'm curious -- what is everyone's favorite trick from a non-python
> language? And -- why isn't it in Python?

Hmm... I used to be quite the fan of Python, yet not long ago I met
Ruby and fell in love almost instantly. Some of the features I like the
most:

- statement modifiers:

< "return a if a.value == true"
< "database.query(q) unless database.connect == error
(etc)

- unless as "if not", since it gives nicer code to read

< unless false then print 1 # this prints 1 forever

- iterators, such as times (already mentioned)

- 'case'

< case var
<    when 3 then do_sth
<    when 4 then do_sth_else
<    # etc...
< end

- everything returns a value, so you can do:

< foo = case foo2
<    when 1 then yadda_yadda
<    when 2 then blah_blah
<    # etc
< end

And when foo2 == 2 then "blah_blah" gets executed and returned as the
'case' return value, thus assigning foo the value that results from
evaluating blah_blah

And some more, but those are the ones I like the best and python
doesn't have :-)

- greetings -
Nicolas




More information about the Python-list mailing list