Python

new topic     » topic index » view thread      » older message » newer message

Every now and then, I like to scope out the 'competition'. C and C++ hold no
charms for me; Java makes my grumpy, and Perl gives me a headache. But
Python is a different matter...

Yes, I know that using indentation instead of proper delimiters is only
inviting trouble, but darn it, there are so many *nice* things about the
language, like:

   >>> 'x' + word[1:]
   'xelpA'

which is akin to the oft-requested:

   "x" & word[2..]

although I personally prefer:

   "x" & word[2..len]

There are a number of other 'clever' things that are done using negative
indexes and such, but I'll skip them here. After all, I'm not trying to
write a Python tutorial. You can always go to:

   http://www.python.org

and check out the tutorials yourself. And I'll also gloss over the fact the
Python strings are immutable.

Now, I know that a that I could just to write a nice set of string handling
routines, since these are just clever implementations of BASIC's left$,
right$ and mid$ functions. Perhaps I might even grant that 'clever' makes
unreadable code a couple weeks down the line. I almost convince myself, but
then I read:

   "Degenerate slice indices are handled gracefully: an index
   that is too large is replaced by the string size, an upper
   bound smaller than the lower bound returns an empty string."

Euphoria's handling of degenerate slices has always been one of my pet
peeves. And Python also has some neat list handling operators, especially
the item removal notation:

   >>> # Replace some items:
   ... a[0:2] = [1, 12]
   >>> a
   [1, 12, 123, 1234]
   >>> # Remove some:
   ... a[0:2] = []
   >>> a
   [123, 1234]
   >>> # Insert some:
   ... a[1:1] = ['bletch', 'xyzzy']
   >>> a
   [123, 'bletch', 'xyzzy', 1234]
   >>> a[:0] = a     # Insert (a copy of) itself at the beginning
   >>> a
   [123, 'bletch', 'xyzzy', 1234, 123, 'bletch', 'xyzzy', 1234]

Python has namespaces, so writing:

   >>> import fibo

imports a module; routines in the module are accessed through the namespace:

   >>> fibo.fib(1000)

If you intend to use a function often you can assign it to a local name:

   >>> fib = fibo.fib
   >>> fib(500)

You can import a list of functions:

   >>> from fibo import fib, fib2

Or even all the routines:

   >>> from fibo import *
   >>> fib(500)

Routines that are local to the module are specified by using an underscore.
But Robert already knows all this (and Java, and C++), so I'm sure he'll
take it into account when designing his own namespace solution. smile

I won't even go into exception handling and classes. Did I mention that it's
linked to a zillion libraries, including wxWindows? But there are a lot of
things to like about the language. Python is just looking better and better!

Ok, this isn't intended to be a Python lovefest. What's not to like about
it?

For one thing, the sheer size of it. I wanted to play around with wxPython,
so I went to download it. First, I need the (several meg large) wxPython
installer. And Winsock 2.0 and OpenGL. But wait, there's more. I need the
core Python download as well (5 meg compressed) and possibly some additional
files. My mind reels when I think about having to distribute an application.

There's also the dangerous use of indentation to delimit blocks, the slow
speed... Even so, it still looks very, very cool. I wish *my* language were
that cool...

Yeah, yeah - the feature list is always greener on the other side. Still, I
wouldn't mind a bit if Robert decided to filch a few of them from Python for
us.

-- David Cuny

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu