B
bearophileHUGS
This post comes from a boring morning, if you are busy ignore this.
This post is only for relaxed people.
I've found this page, "Syntax Across Languages", it contains many
errors and omissions, but it's interesting.
http://merd.sourceforge.net/pixel/language-study/syntax-across-languages.html
Compared to the other languages Python comes out rather well, in quick
scan only few things look better in other languages (usually all/most
things are possible in all languages, so it's often just a matter of
brevity, elegance, etc):
- Nestable Pascal-like comments (useful): (* ... *)
- Information about the current line and file as Ruby:
__LINE__ __FILE__
Instead of the python version:
inspect.stack()[0][2] inspect.stack()[0][1]
- ~== for approximate FP equality
- comparison returns 4 values (i.e. inferior, equal, superior or not
comparable), as in Pliant:
"compare"
- identity function: "identity" as in Common Lisp (probably of little
use in Python).
- Exception retrying: after catching an exception, tell the snippet to
be re-run
"retry" as in Ruby
- object cloning: obj.copy() obj.deepcopy()
- accessing parent method:
super as in Ruby, instead as in Python:
super(Class, self).meth(args)
- recursive "flatten" as in Ruby (useful)
Probably there are some errors of mine too, there are many things I
don't know aboyt Python yet.
Bye,
bearophile
This post is only for relaxed people.
I've found this page, "Syntax Across Languages", it contains many
errors and omissions, but it's interesting.
http://merd.sourceforge.net/pixel/language-study/syntax-across-languages.html
Compared to the other languages Python comes out rather well, in quick
scan only few things look better in other languages (usually all/most
things are possible in all languages, so it's often just a matter of
brevity, elegance, etc):
- Nestable Pascal-like comments (useful): (* ... *)
- Information about the current line and file as Ruby:
__LINE__ __FILE__
Instead of the python version:
inspect.stack()[0][2] inspect.stack()[0][1]
- ~== for approximate FP equality
- comparison returns 4 values (i.e. inferior, equal, superior or not
comparable), as in Pliant:
"compare"
- identity function: "identity" as in Common Lisp (probably of little
use in Python).
- Exception retrying: after catching an exception, tell the snippet to
be re-run
"retry" as in Ruby
- object cloning: obj.copy() obj.deepcopy()
- accessing parent method:
super as in Ruby, instead as in Python:
super(Class, self).meth(args)
- recursive "flatten" as in Ruby (useful)
Probably there are some errors of mine too, there are many things I
don't know aboyt Python yet.
Bye,
bearophile