The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

I'm a Python Man

This week I finally decided to ditch Perl.

I had several prototype applications to build, to experiment with the effectiveness of a few new algorithms. Ordinary, I might write the first version of something like this in Perl. I've been using Perl for the last three years, and it's a great little language.

But I really dislike reading other people's perl code. And even my own Perl starts to look vague and confusing if I haven't looked at it for a few months.

And don't even get me started on Perl's object orientation.

Before deciding on Python, I took a look at Ruby, but I was turned off by its adoptioni of the Perl TMTOWTDI philosophy. And I was impressed by this Poem (found by typing 'import this' into the interactive Python interpreter):

"""
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
"""

So this week, I wrote my first Python scripts. And I am very impressed. The language is clear, concise, and unambiguous. The syntax is uncluttered and the standard library has a ton of useful stuff.

Though sometimes I wish miss the compile-time type-checking from languages like Java.
BenjiSmith Send private email
Saturday, September 03, 2005
 
 
Language advocacy is pointless and often counterproductive.  It's very nice that you like Python, but with the way you're talking about how you've switced from Perl, an unkinder commentator might almost think you were _trying_ to start a language flamewar.

Of course you should really be ditching all that OO crap and using an FP language like Scheme, Haskell, or ML anyway.  :P
Iago
Saturday, September 03, 2005
 
 
Ah, yes, language wars... Didn't intend to start one.

I just know there are probably lots of other people who like the ability to prototype quickly in Perl but who would prefer a more orthogonal There's Only One Way To Do Things kind of language.

For anyone who fits that type of profile, Python turns out to be a great choice. At least it was for me.
BenjiSmith Send private email
Saturday, September 03, 2005
 
 
>  Language advocacy is pointless and often counterproductive. 

As are statements as to its pointlessness and counterproductiveness.
son of parnas
Saturday, September 03, 2005
 
 
"Though sometimes I wish miss the compile-time type-checking from languages like Java."

Use unit testing. Preferably, test before you code.
Berislav Lopac Send private email
Saturday, September 03, 2005
 
 
> Use unit testing. Preferably, test before you code.

I doesn't make up for syntax checking. I'd rather not have to run code to know if the syntax is correct.

Several people I know new to ruby have said this is one the the things they miss most about java. Plus error messages aren't always that clear.

Using an IDE has helped them enough that the lack isn't fatal.
son of parnas
Saturday, September 03, 2005
 
 
I didn't take the first post as an invite to a language flame war. There's a huge different between saying "I like [language of choice]; it's cool," and pontificating on how one language is SUPERIOR to another.

Please. Any developer who's been around awhile has worked both sides of the fence. And, anyone who's been around for awhile and can think clearly would not disagree that each language has its strengths and weaknesses. Religious wars over programming languages are like listening to really bad lite beers commercials.

Except...they're not talking about beer, and...the ones doing the talking are nerds.

I think I'll try Python. Sounds cool.
Albi-Wan
Saturday, September 03, 2005
 
 
>>> Please. Any developer who's been around awhile has worked both sides of the fence. And, anyone who's been around for awhile and can think clearly would not disagree that each language has its strengths and weaknesses. <<<

The funny thing is, I find that I often appreciate contradictory features in different languages. For instance, I get a lot of use out of the flexibility of weakly typed languages. It's nice to be able to accept a wide variety of types and just check to see what's been passed in, and if it can do what I need it to. On the other hand, in my brief foray into Java (the only strongly typed language I've done anything non-trivial in), I really enjoyed the extra checking for correctness.

My first "real" language was Perl, and I loved the TMTOWTDI philosophy. It let me write code the way I thought. I'm just dipping my toes into Python, and I like having a Golden Path to follow. It means I don't have to think as much about developing a pattern for getting productive.

I've come to the conclusion that the language itself doesn't matter so much. It's how well you can accept the feel of it, and adapt to it's idioms. "Mind like water" and all that.

Some of my favorite language features:

javascript: prototyping (although I haven't quite figured out how to get the most out of it yet), and a somewhat functional feel.

perl: TMTOWTDI, all that special, implicit variable stuff. Allows you to be amazingly concise. My very favorite regex implementation.

PHP: ubiquity. Built in templating.

python: really, really easy to read. Everything is an object. Sparse. Docstrings.

Give your favorite language a hug - what do you like about it?
dwayne Send private email
Saturday, September 03, 2005
 
 
>>> Please. Any developer who's been around awhile has worked both sides of the fence. And, anyone who's been around for awhile and can think clearly would not disagree that each language has its strengths and weaknesses. <<<

Not necessarily.

I can't point out to the strengths of COBOL or PL/I.

And the strength of Java comes from the community and libraries; At any point in time, Python as a language was (and still is) signficantly better than Java at any meaningful comparison I can think of.
Ori Berger
Saturday, September 03, 2005
 
 
"At any point in time, Python as a language was (and still is) signficantly better than Java at any meaningful comparison I can think of."

That sentence alone speaks volumes towards the width and breadth of your academic and professional experience.
arg!
Saturday, September 03, 2005
 
 
I love Perl for quick "get the shit done" projects and prototypes.  It's great how Perl will just try its best to do SOMETHING in the face of a question instead of throwing yet another exception -- and the SOMETHING is almost always harmless in the face of achieving THE GOAL.

But prototypes have a funny way of becoming the critical infrastructure, and it's there that you start to wish Perl had been more strict with you.

But that's not really Perl's fault.  It's your fault.

Perl's good at letting you see what's really in your heart.  Maybe that's what people hate about it. ;)
Michael B
Saturday, September 03, 2005
 
 
arg!, your post is very informative. Care to enlighten?
Ori Berger
Sunday, September 04, 2005
 
 
Michael B, great post! :P
some guy
Sunday, September 04, 2005
 
 
"But prototypes have a funny way of becoming the critical infrastructure, and it's there that you start to wish Perl had been more strict with you."

use strict;  ???
Take a guess.
Sunday, September 04, 2005
 
 
"The Zen of Python"

Wait, I have some more:

While you can't control your rage, your rage will control you.
When you look into an abyss, the abyss also looks into you.
Never hold your cup of coffee above your keyboard.
Close the editor before playing with the cat.
Sayings without context are worthless.
A nail is better with a hammer.
When you have no hammer, a stone will do.
When you have no nail, use a screw.
A screw with a hammer makes greater holes in the wall.

Want more? Have more? ;)
hidden agenda
Sunday, September 04, 2005
 
 
Ori. Just because *you* can't point out the strengths of COBOL and PL/1 doesn't mean they do not exist.

COBOL is amazing at handling batch data- care to put python in a head to head comparison implementing a solution within that problem domain? I dare you. PL/1 contains more features than god, you'd be hard pressed not to find a strength of PL/1 over another language.

So to expand upon my last comment, the fact that you have not ever seen an instance, study, or situation where Python would be inferior to Java, well, then you are either inexperienced or unfairly biased. No offence intended.
arg!
Sunday, September 04, 2005
 
 
"COBOL is amazing at handling batch data- care to put python in a head to head comparison implementing a solution within that problem domain?"

You can't be serious can you?  COBOL is crap.  I should know, I used to do a lot of it.  It's old, it's crusty.  Batch processing is the easiest of all problem domains and it's really not surprising that COBOL is still used for that -- it's the only thing it's good for.  COBOL still exists only because old working code still needs it and it's too much effort to replace it (and the rest of the infastructure) with something better.
Almost H. Anonymous Send private email
Sunday, September 04, 2005
 
 
"it's really not surprising that COBOL is still used for that -- it's the only thing it's good for."

Context, AHA, context. Read the back and forth above... I was not suggesting that we all start writing COBOL- I was pointing out one inherent strength of the language- which you evidently somewhat agree with?
arg!
Sunday, September 04, 2005
 
 
" > Use unit testing. Preferably, test before you code.

I doesn't make up for syntax checking. I'd rather not have to run code to know if the syntax is correct. "

I'm not really sure about yoir point here. Is it "don't bother with unit testing, use a syntax-checking IDE"? Or "don't use interpreted languages as you can't check the syntax (without an IDE) before you run the code"? Or something else?
Berislav Lopac Send private email
Sunday, September 04, 2005
 
 
There are quite a few very very competent scripting languages out there. They all have their angle. Goods and bads. Benji, good to hear you've found one that fits you.
Li-fan Chen Send private email
Sunday, September 04, 2005
 
 
> you start to wish Perl had been more strict with you.

You are aware of "use strict" and the warnings flag in perl aren't you.
Sheldon Lavine
Sunday, September 04, 2005
 
 
arg!, we obviously disagree on metrics for "goodness".

PL/I has an unbelivable amount of features, most of which are unhelpful and get in your way. Machine code has even more features and less restrictions but I wouldn't count it as "powerful", and, in modern RISC/parallel architectures, (the braindead x86 architecture isn't), it is rare that a programmer can write a nontrivial assembly language program that works faster than a compiler generated one, so even speed isn't a feature. BUT IT'S LIMITLESS! Is it better?

In what way exactly is Cobol "fantastic for batch processing"? What kind of batch processing?

Re: Java vs. Python, I've had the chance to let Java and Python compete many times for projects. In the places where Java won, it was because of a library issue (e.g., library only available in Java). Comparing apples to apples, the Java code is _always_ longer, usually more complex, full of repeating boilerplate code. It is often (though not always) slower in practice as well.

Have you ever actually put Java vs. Python, the languages, to a test?

I am a little biased. For quite a while in a project I supervised, Python bought my lunch and Java ate it. Java's wonderful features proved, once and again, to be little more than marketing material, whereas Python kept surprising everyone by just delivering.

YMMV. In fact, it pleases me to no end that Java is vastly more popular than Python -- my competitive advantage is in no danger in the near future.
Ori Berger
Monday, September 05, 2005
 
 
"Re: Java vs. Python, I've had the chance to let Java and Python compete many times for projects. In the places where Java won, it was because of a library issue (e.g., library only available in Java)."

What made that you couldn't access the libraries through Jython?
Unemployed -> back to University.
Monday, September 05, 2005
 
 
In one case it was speed -- Jython still lags behind "native" Java and CPython in speed for anything that actually has to do some work. I suspect its mostly due to an inefficient dynamic dispatch on the types (int, string, ...) that native Java can avoid - though Jython does win hands down for glue logic.

In the other (older) case, Jython was still called JPython, and somewhat incomplete; The Java of the day was 1.2, perhaps not even that.

My favourite language at the moment, BTW, is K - an APL offspring, which is extremely terse (e.g., a featureful RDBMS in 14 lines of code, non of which is longer than 40 chars), interpreted yet extremely fast.
Ori Berger
Monday, September 05, 2005
 
 
In the world of hundreds (thousands?) of programming languages, it would take alot more than being "terse" to make me consider using a non-free language.
Arafangion Send private email
Tuesday, September 06, 2005
 
 
"And don't even get me started on Perl's object orientation."

Why not? Please enlighten us. I personally think Perl has an excellent set OO features. It lacks in some areas of it, but so does Python or Java.
Egor
Tuesday, September 06, 2005
 
 
Arfangion: So look at J (up to 7.0 it was free gratis+libre, now only libre) or APL (some versions are free, some not - A+ is a blazingly fast GPL implementation with some extensions - aplusdev.org).

I think K is an improvement on both, but J/APL are almost as good.
Ori Berger
Tuesday, September 06, 2005
 
 
>  I personally think Perl has an excellent set OO features.

So you don't think ISA is a hack? As are all of the other Perl OO features?
son of parnas
Tuesday, September 06, 2005
 
 
Hello.  This is being typed in a "really tall" box.  I can't see what I'm typing, but I'll try to post anyway.  Help!
AllanL5
Tuesday, September 06, 2005
 
 
To answer Egor's question, here are a few reasons why I think Perl's object orientation is ridiculous. These are all quotes from Programming Perl, the official language documentation:

----------------------

from section 4.2.5:

An object is simply a special kind of thingy that happens to know which class it's associated with. Constructors know how to create that association. They do so by taking an ordinary thingy and turning it into an object (which remains a thingy even while it's also being an object). The operator that a constructor uses to do this is called bless, so we can speak of an object as a blessed thingy. Constructors are customarily named new(), but don't have to be.

from section 5.3.3:

Within the class package, methods will typically deal with the reference as an ordinary (unblessed) reference to a thingy. Outside the class package, the reference should generally be treated as an opaque value that may only be accessed through the class's methods. (Mutually consenting classes may of course do whatever they like with each other, but even that doesn't necessarily make it right.)

from section 5.3.4:

Perl doesn't provide any special syntax for class definitions. You just use a package as a class by putting method definitions into the class.

Within each package a special array called @ISA tells Perl where else to look for a method if it can't find the method in that package. This is how Perl implements inheritance.

If neither a method nor an AUTOLOAD routine is found in @ISA, then one last, desperate try is made for the method (or an AUTOLOAD routine) in the special pre-defined class called UNIVERSAL. This package does not initially contain any definitions (although see CPAN for some), but you may place your "last-ditch" methods there. Think of it as a global base class from which all other classes implicitly derive.

----------------------

It's like a normal programming language exploded, and someone blindly put it back together again with all the pieces in all the wrong places. And if anything is ever unclear, you can be sure Perl will try to guess what you intended. Most of the time, it guesses correctly!!
BenjiSmith Send private email
Tuesday, September 06, 2005
 
 
Perl 5's OO is a bit weird. Especially if you are creating an object, as opposed to consuming one. (FYI OO is currently being redone in perl 6)

But for my mind perl actually delivers the benefits of OO more than any other language by an order of magntitude. Reusable code.

Show me another language with even a tenth of the perl modules here: http://search.cpan.org/
Sheldon Lavine
Tuesday, September 06, 2005
 
 
Python probably has just as many modules - but it has no CPAN.
Arafangion Send private email
Wednesday, September 07, 2005
 
 
No way does Python have has many. perl has ten of thousands.
Sheldon Lavine
Wednesday, September 07, 2005
 
 
I didn't see this mentioned in any of the comments, but PyChecker goes a long way in helping with the static checking of dynamic Python code, and was just the hand-holding I needed to feel very comfortable with Python after living in a static language world.

More info on PyChecker is available at http://pychecker.sourceforge.net.
David Brownell Send private email
Wednesday, September 07, 2005
 
 
Anyone seen Nemerle (nemerle.org)?  I have yet to write a full blown application in it, but it feels like someone took C# and applied the axiom "Those who don't know Lisp are doomed to reimplement it."  It includes macros, functions as first class data, variants, garbage collection (it is a .NET language) and the ability to use all the libraries that are made for .NET.  I am not voiching for it yet, but I am going to give it a try.
Joshua Volz Send private email
Wednesday, September 07, 2005
 
 
+++It's like a normal programming language exploded, and someone blindly put it back together again with all the pieces in all the wrong places. And if anything is ever unclear, you can be sure Perl will try to guess what you intended. Most of the time, it guesses correctly!!+++

This is all emotions and nothing even remotely resembling a practical comparative analysis. Something being more open and requiring you to learn more doesn't mean it's somehow flawed.

+++So you don't think ISA is a hack? As are all of the other Perl OO features?+++

It's as much a hack as are, say, pointers. Low-level mechanisms open for those who know what they are doing. It's there not because Perl creators couldn't intoduce a "class" keyword or something, but rather because it's more flexible.
Egor
Wednesday, September 07, 2005
 
 
So much for not starting a flame war...
David Burch
Wednesday, September 07, 2005
 
 
I think Ruby's semantics are simpler and more elegant than Python. Initially some of it's Perl-like syntax made me skeptical, but the Perl-isms are entirely optional and easy to avoid - you can write really clean smalltalk-esque functional-style OO code if you do everything the 'ruby way'.
Matt Send private email
Friday, September 09, 2005
 
 
Back to the subject of the OP, I like both Perl and Python. I was a Perl expert first, and then later looked at Python to see what it was all about.

Having used both, I prefer Perl for rapidly munging complex data, and I prefer Python for prototyping application structure and algorithms. It makes sense to pick a language that is best specialised for the task at hand.

As far as Perl OO is concerned, nobody could convincingly argue that OO Perl is convenient to write. On the other hand, once written, OO Perl modules as found in CPAN are very convenient to use and deploy.

Ruby is one of those intriguing things that unfortunately came along third. Is there room in my head for a third scripting language after I already know how to make Perl and Python do what I need?
Ian Boys Send private email
Sunday, September 11, 2005
 
 
> As far as Perl OO is concerned, nobody could convincingly
> argue that OO Perl is convenient to write. On the other
> hand, once written, OO Perl modules as found in CPAN are
> very convenient to use and deploy.

Good point. I've used lots of OO libraries from CPAN, and they were usually very easy and straightforward to use.

By whenever I've needed to *write* libraries in Perl, I usually start of thinking in OO terms, but then I switch to a more procedural model, just because writing the OO modules tends to be more of a pain in the ass.
BenjiSmith Send private email
Monday, September 12, 2005
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz