I'm coming from Tcl-world ...
Andreas Leitgeb
Andreas.Leitgeb at siemens.at
Mon Aug 5 11:31:05 EDT 2002
Robert Amesz <sheershion at mailexpire.com> wrote:
> As C-style goes this isn't a very pretty piece of code, especially
> since you seem bent on building a string of 2**42 '*' characters.
Yes, that was just an example, and not meant to be actually run :-)
I like the number 42, and ord("*") being 42, this is even a beautiful
example. :)
The other comments about that example have appeared similarly in
other posts, and answered in their followups.
>>> 4.) "calls by reference": def f( x ) : x=42
> _Don't_ use a one element list: that's misleading to anyone (including
> yourself) who reads that code later.
since Python seems to keep all types as "first class objects", I thought
it would not matter whether I chose an integer or any other object for
the example.
Meanwhile I've recognized Python's "call-by-ref" to be similar to
Java's (probably because object-handling is similar between these
languages) and I can live with that.
Generally:
It depends on the context on whether it is better to
make use of call-by-ref or return a result.
If the object is a list of millions of entries, it is definitely
better to have a way of modifying the list in-place than returning
even a shallow copy of it.
> The examples you give are typical ones if you try to emulate C-style in
> Python.
I see this differently:
If you had to switch from Python to C (and you didn't know C yet),
you would most likely ask, how to create a dictionary, and how
to do lists of mixed typed objects.
Maybe you'd hack together a simple dictionary in C, so you could
continue to use this powerful tool.
I wouldn't call this "emulating Python-style" then.
> I'm not quite sure how Python compares to TCL as my experience with
> that language is anything but extensive.
What really counts for me is, what useful gadgets and idioms a language
provides me, to let me express the algorithms as concisely as
possible. Some simple things become quite complicated when
writing it in Tcl, others, easy in Tcl, seem to become difficult
in Python ...
perl, e.g. offers me a genious regexp-engine and -syntax (not only the
re-syntax itself, but also how it is embedded in perl: if (/bla.*/) ... ).
If I write something that uses lots of regexps, I use perl (which I
otherwise don't like that much)
Tcl offers me a powerful event-loop, direct access to any stackframe
up to global context, lets me view the bodies of previously defined
procedures, but unfortunately also has some over-sophisticated
builtins (e.g. exec) that are hard to work around, and some level of
obfuscation is needed to pass a list as separate args to a function.
Python offers me flexible function-handling (passing a dictionary as
arguments), lambda's, generators(yield), ... (and more to be discovered
by me), but lacks a general for-loop (as in C and others), lacks
an internal event-loop, and other things I've not yet come across.
[Roberts "IMHO"'s :) ]
> The everything-is-a-string paradigm is interesting and pretty unique,
> but also limiting.
Unique, yes, interesting: not all that much, limiting: nope.
> The syntax seems to have been designed to help the interpreter
> rather than the programmer,
Initially perhaps, but Tcl has developed far enough, so I don't
necessarily notice it from programmer's point of view.
--
Newsflash: Sproingy made it to the ground !
read more ... <http://avl.enemy.org/sproingy/>
More information about the Python-list
mailing list