Michael Daum


Various programming language notes
March 25, 2007, 8:37 pm
Filed under: geek

So for my entire time in industry, the issue of whether a particular language was better than any other lay for the most part dormant within me. Every product had already made its decisions and every problem seemed to indicate a particular solution.

Or something.

At any rate it’s been a while since I picked up a new language, or even thought in terms of the relative merits of the ones I already new.

But now that I’m safely inside of the ivory tower, these kind of rumblings are arumblin’ once again, and I find myself learning not one but two languages.

The first of these is Python, which I figured I’d learn because it’s the foundation of scons, the build system I use. Plus I need it for Software Carpentry, a course I’m taking. So what could go wrong. Well, I mean, let’s start with:

>>> a = range(5)
>>> print a
[0, 1, 2, 3, 4]
>>> b = a
>>> a[2] = 10
>>> print a
[0, 1, 10, 3, 4]
>>> print b
[0, 1, 10, 3, 4]

Yucky, no? Now the Pythonistas will tell me that I should have used

>>>b = a[:]

To get the deep copy I wanted. Clear as mud, boys. But if I play your game, then why don’t you tell me about:

>>> a = [1]
>>> a[1:1] = [2,3,4,5]
>>> print a
[1, 2, 3, 4, 5]

Now were you gonna tell me that the semantics of the ‘:’ slicing operator depend on whether they’re being applied in an lvalue or rvalue context? No, I guess not. In fact, my best guess is you haven’t really thought about it that much. Then again, how much do you really expect one guy in his basement (sorry…Google’s basement) to be able to do? It’s not like there’s an ANSI standard or committee for Python. Funny, that.

Advertisements

Leave a Comment so far
Leave a comment



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s



%d bloggers like this: