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.

Opinions on python

Does it make sense to learn python? Is it really good
for anything? Or it's just a buzzword?
(Learning language is much easier than figuring out
what it's good for, so I need a piece of advice)
nekto
Monday, December 20, 2004
 
 
From time to time I see programs that were written in Python that get pretty big, like BitTorrent (which has been in the news a lot lately).

If you want to learn, go for it.
www.MarkTAW.com Send private email
Monday, December 20, 2004
 
 
I think it's going to continue gaining in popularity.

1) It's not as fast as C/C++. Which is true, but very few applications need raw speed everywhere, and it's easy to write a Python extension in C where it's really needed.

2) It wasn't designed for major enterprise wide applications like J2EE. Also true, but if you don't need that much infrastructure, Python becomes very attractive.

3) It's so much easier to program in that other languages. Build the unittest, write the code. Move on. You just get more done in a day.
Tom H
Monday, December 20, 2004
 
 
It seems unlikely that learning something new would harm you.

  Flava Flav!
Flava Flav
Monday, December 20, 2004
 
 
It has less BS than most languages, more than some. Problem is you've given us nothing to compare it to. Do you want a discussion of advantages relative to you being a Java programmer?
Tayssir John Gabbour Send private email
Monday, December 20, 2004
 
 
I love Python. I used to work with Perl a lot, but I discovered Python around a year ago and I haven't looked back since. I work as a software test engineer and I've used Python in conjunction with various test frameworks, including a homegrown one, which started its life in Perl. We ported it to Ptython and rapidly started to notice the benefits, chief of which being the ability to actually understand and maintain the code months after it was written. Another area which I think will be hot is Dynamic Java, i.e. using scripting languages to exercise the JVM, for rapid development and prototyping. Jython (Python written in Java) shines in this area. Tim Bray recently posted on his blog about a workshop he conducted at Sun on Dynamic Java. See http://www.tbray.org/ongoing/When/200x/2004/12/08/DynamicJava

Shameless plug: see my blog (http://agiletesting.blogspot.com) for some tutorials on using Python in the context of software testing.
Grig Gheorghiu Send private email
Monday, December 20, 2004
 
 
I don't mean comparing it with anything. Just want to know
where people are really using it. If they use it, this speaks for itself.
nekto
Monday, December 20, 2004
 
 
Check out Bruce Eckel for some Python fanatacism. A bunch of other stuff too, but clearly he thinks Python is the second coming.

http://www.mindview.net/
NetFreak Send private email
Monday, December 20, 2004
 
 
Python requires specific levels of indention, doesn't it?  I mean, whitespace semantically affects code, right?
Aaron F Stanton Send private email
Tuesday, December 21, 2004
 
 
Yes        What you heard            is entirely correct.
www.MarkTAW.com Send private email
Tuesday, December 21, 2004
 
 
Aaron: Yes, but in the *right* way.

Java or C++ code in which indentation is inconsistent with scoping is quite rare and usually unreadable.

Python code in which indentation is inconsistent with scoping does not exist (or at least, does not compile).

It's as simple as that - whether you write Perl, Java, PHP, C++ or C#, you probably indent your code. So just remove those {useless} scope delimiters, and you get Python.

Ok, maybe if you write Perl you don't indent. But .... you get my point.
Ori Berger Send private email
Tuesday, December 21, 2004
 
 
Yes but its no worse than any other method and better than some.  Visually you can see whether something is contained within a block or not, it encourages tidiness.

The only problem arises when two or more developers are editing and they each have different editing parameters, one is clueless and uses tabs and other is intelligent but assumes everyone else lives behind his eyes and uses space filled tabs.

Like many script languages there are shortcuts and compressions that just make you go 'Ohhh' and occasionally 'Ahhh'.  However, there are a couple that make you go 'Huh' for a while.

If you've written Perl you won't have much problem with python.
Simon Lucy Send private email
Tuesday, December 21, 2004
 
 
Well, this confirms it - I have zero interest in python.  After years of Fortran 77, I simply do not care to deal with a language that bitches when I lose a space or add an extra one by mistake.  I don't want a language where you *need* a syntax highlighting editor just to get work done.
Aaron F Stanton Send private email
Tuesday, December 21, 2004
 
 
That was my original feeling and then I realised I was already obsessive compulsive about lining up code in blocks which was probably influenced by starting with coding sheets,  and at the same time came the second realisation that the thing that I was more likely to do was to miss out or comment out or otherwise screw up the delimiters of the block.

As it is I am more likely to miss out the terminal : in a block statement in python than anything else, but I'm very unlikely to get the block alignment wrong.
Simon Lucy Send private email
Tuesday, December 21, 2004
 
 
Feh.  I just type.  If I'm in a decent IDE I'll use its builtin pretty-print reformatter, but that's after the fact, before I check it into CVS.  But when I'm banging code out, I don't want the compiler yelling at me because I had a character in column 6 and it thought I was doing a line continuation.  The algorithm is right, everything is right except a single space, and it pukes on me?  Not interested in going through that again.  I'll pretty it up as I go, and before I hand it to someone else, but when I want rapid feedback on my code, I hate little things like that.
Aaron F Stanton Send private email
Tuesday, December 21, 2004
 
 
"The algorithm is right, everything is right except a single space, and it pukes on me?  Not interested in going through that again."

I hear you, dude.  Like when I do this in C or Java:

while (condition);
  do_something;

It's obvious to the HUMAN reader that the do_something was supposed to be in the body of the loop, but it wasn't obvious to the compiler because of a single character?  That's ridiculous.  You make a good argument for sticking with Python.

Oh wait...
Jeremy Stein Send private email
Tuesday, December 21, 2004
 
 
No, I'm talking about *invisible* characters screwing things up.  I should have been more explicit, obviously.  My fault for not saying it.

Does python change the meaning if it's tabs vs. spaces?  How about if your IDE does tab-spacing as 4 spaces vs. 5 spaces?

What if your font doesn't use uniform spacing?  There is so much wrong with this.
Aaron F Stanton Send private email
Tuesday, December 21, 2004
 
 
Oh, in your example - will python know that the semicolon wasn't intended and ignore it?
Aaron F Stanton Send private email
Tuesday, December 21, 2004
 
 
Python does not require semicolons at the end of a line, nor any other character, so there's no need to type one.

Python also self-adjusts to whatever number of spaces or tabs you want to use per indentation level. It just has to be consistent.

Regarding your attitude that you don't want to "have" to use an auto-indenting editor... I'm speechless. How did you get electricity and an Internet connection for your paleolithic cave?
Chris Nahr Send private email
Tuesday, December 21, 2004
 
 
It isn't like FORTRAN, there's nothing about continuation lines or forms based on 72 usable columns on an 80 column card.

Currently, you can have mixed spaces and tabs in a source file so long as when expanded they come to the same equivalence.  Python uses 4 spaces to the tab I think.

The most common solution people have is to set their editor to convert tabs to spaces on input so that it never arises. 

If this feels like an imposition and nothing to do with writing code then forget about python the language for the moment and think of, say, C++ with the following scenario.

There's a C++ source file, its in CVS and the original author used spaces and never the tab key but most of the time got it on 4 column boundaries.

A second developer comes along and uses an editor with tabs set to 4 columns.  He's made a single line fix and merged and checked back into CVS and everything, so far as he's concerned is fine.

Original author gets changed source from CVS and discovers reams of changes that make no sense the code looks the same, it runs the same when he tests it but CVS tells him there are hundreds of lines of differences.

Because the second editor, in making his one line fix, discovered that the natural alignment was out by a column in this or that section and went ahead and 'fixed' it, after all the code would still do the same job.

This can cause mayhem, way more mayhem than the python parser pointing out that a line is at the wrong level.

I know you can checkout and ignore whitespace differences but those kinds of filters always feel like horrible kludges.
Simon Lucy Send private email
Tuesday, December 21, 2004
 
 
Wake up - I didn't say that I don't use them.  I do use them.  I like them.

I don't want to *have* to.  I want to be able to use whatever tools I happen to like.  If I want to use notepad, I should be able to do so and have it just work.  If I want to use Eclipse, I should be able to.  But what I explicitly don't want is something that attaches a meaning to whitespace.

It's good that python adjusts to whatever consistent format the code it in.  I didn't know that.  Karma point to them.

So, if someone accidentally typed a (visible) semicolon at the end of a line in python, would it puke?  You can see, with the naked eye, that the semicolon is simply wrong, right?
Aaron F Stanton Send private email
Tuesday, December 21, 2004
 
 
Well, if you don't want significant whitespace, EVER, you can't use Python, since that's a major feature. Personally I think it's great, for the reasons stated above -- any readable code must use consistent indendation anyway, so why not have it enforced by the language?

As I recall, Python does accept a semicolon as a statement terminator but it's optional. Typically you only use it if you want to put short multiple statements on a single line.
Chris Nahr Send private email
Tuesday, December 21, 2004
 
 
You can separate two individual statements on the same line with a ; but I doubt if many take advantage of that.  A single ; at the end of the line is ignored.
Simon Lucy Send private email
Tuesday, December 21, 2004
 
 
The only significance I want in my whitespace is to separate statements.  I don't want it to care if I indent 4 characters, or 5 characters, or at all.

Hence, I'm not interested in python.

Good to know that python is intelligent enough to realize the semicolon at the end of a line is optional, since it appears to be.  Bonus karma point to them.
Aaron F Stanton Send private email
Tuesday, December 21, 2004
 
 
Python is not like Fortran 77. Fort77 is one part evil and two parts absurd. (And three parts fast?) Python uses whitespace reasonably. I think people are used to, and ignore, the pitfalls of {;}.

And that's not really the serious reason Python is pleasant; being interactive and dynamic are also plusses.

Learning Python is much simpler than you'd expect compared to beasts like Java. The included tutorial is fast; Python removes all that corporate garbage that makes tools so blunt and unwieldy. Yet Python has made certain decisions to favor popularity, like piggybacking on the same metaphors you're used to, so it's simple to learn.

Try it for ten minutes, I think you'll learn it very quickly.
Tayssir John Gabbour Send private email
Tuesday, December 21, 2004
 
 
I might try it out sometime - and thanks for the vote of confidence that I'd pick it up quickly, though I think that's more aimed at python's simplicity than my own competence.  :)  But, hey, python might turn out to be really really good.  The whole whitespace thing is a big turn-off for me, though, one I may not be able to get over.

Believe me, I wouldn't have used F77 if my advisor hadn't required it.  It can indeed be really fast...but modern compilers and hardware can make almost anything fast, except a bad algorithm.
Aaron F Stanton Send private email
Tuesday, December 21, 2004
 
 
After years of fixing other people's FORTRAN and one summer fixing some RPG, I have no interest in programming language where whitespace is important.

However others seem to think it a fabulous idea.
blank
Tuesday, December 21, 2004
 
 
I've also used Fortran, roughly 10 years ago. Like many others, when I saw this "feature" in Python, I was disgusted by this faute de goût in an otherwise appealing language.
And like many many others, I've found that after 3 hours I had completely forgotten the issue. Hey, you can start at whichever column you like, not at column 7.
Pakter
Tuesday, December 21, 2004
 
 
Python almost gets it right; unfortunately they chose to allow you to mix tabs and spaces. If they'd just required a tab for each indent and made a space a syntax error it would be perfect.

Still, a trivial editor setting will show you where you're going wrong anyway.
Mr Jack
Wednesday, December 22, 2004
 
 
Aaron, this is slightly off-topic, but if you don't like significant whitespace, ruby is quite like python (cleaner in my opinion) but without significant whitespace. Take a look :)
C-choox
Wednesday, December 22, 2004
 
 
Aaron, I know the whitespace sounds odd, but don't let it put you off too much - it's never caused me problems in practice.

Python is very easy to learn and use. To a great extent, this is because it uses a lot of lessons learned from an earlier language, ABC, which was aimed at "intelligent computer users who were not computer programmers or software developers in any sense". Nice clear logical syntax. It's very easy to interface C routines with too.

I use it as a replacement for perl, that is when I need to do cross-platform scripting, for instance for our daily builds using multiple languages on Unix/Win32.

I can't comment on how it compares to Ruby (a competitor that seems to aim at many of the same niches), but it's a great scripting language.
Paul Spendlove
Wednesday, December 22, 2004
 
 
To focus on the whitespace syntax is to miss the core nature of python. The whitespace put me off at first, but you get used to it. I've written python in emacs, vi, vim, and a python-IDE and never had a significant whitespace issue.

I like Python because:

Its got a good sized core library that includes a lot of stuff often left to 3rd party packages in other scripting languages. So it's great for cross platform scripting.

Its got the things I like about lisp; easy to handle lists, apply, closures.

Its got an intererpter, which I think vastly shortens the learning curve. Install, type "python" and start expirimenting with the tutorial.

Anyway, I bothered to pick it up because I was bored at my  work at the time, and I think it was worth the effort.
Rob Meyer Send private email
Wednesday, December 22, 2004
 
 
while (condition);
  do_something;

Requiring a special character at the end of each line is totally retarded.
Jungle DJ Stephen Hawking
Wednesday, December 22, 2004
 
 
Back on a topic more interesting than whitespace:

As far as I can tell, Python threading is somewhat broken: if a thread blocks on a Win32 API call, the entire application (ie all other threads) also block.

This is backed up by the book claiming that thread switches happen every <set number> of instructions. Obviously while waiting for a Win32 call to return you won't be executing python instructions.

Just an irritating detail that derailed use of Python in a project - it's easier just to do the whole thing in C++Builder, rather than work around that detail.

Working as designed? Maybe, but still irritating.

Wednesday, December 22, 2004
 
 
A language that is easy to learn but hard to use in serious projects is bad.

All the debate over ease of learning should also mention whether or not "easy to learn" is at the expense of usefulness.

Wednesday, December 22, 2004
 
 
Well, I believe, though I've not done this, that so long as your called C or C++ routine is thread aware in the python sense then it needn't block all threads.

The pdl nature of python syntax makes it both quick to write off the top of your head and powerful.  If you write what you think will work it pretty much does.
Simon Lucy Send private email
Thursday, December 23, 2004
 
 
As with any other language, read an online tutorial. Then continue to a bookstore, if you're curious, or forget it.

Personally, I think that if you're already proficient with at lest one scripting, and one OO language, investing into learning Python makes little sense. It's not in big demand in the job market, and there're languages that will teach you a lot more about programming.

I've read a book on Python cover to cover, and had no desire to try it whatsoever. It's an OK language that any skilled developer shouldn't mind using, but for resume dressing or inspiration go somewhere else.
Egor
Thursday, December 23, 2004
 
 
I beg to differ with Egor who says "It's an OK language that any skilled developer shouldn't mind using, but for resume dressing or inspiration go somewhere else". First of all, we weren't talking about resume dressing. For that, you just need to mention J2EE and .NET in the same breath. As for inspiration, it is through Python that I rediscovered the joy of programming. I started my career as a C++ programmer, then drifted towards network/security/system architecture jobs, then for the last 2 years I've been working as a tester. As I said in a previous post on this thread, I began by using Perl very intensively. It got the job done, but I didn't feel any particular joy. However, as soon as I started using Python, it was like my creativity got unleashed.

An anonymous contributor to this thread said "A language that is easy to learn but hard to use in serious projects is bad." I bet he never tried to use Python in a serious project. To me, a test framework for a complicated client-server product is a serious project. The intrinsic OO nature of Python made writing, reading and maintaining a large body of code among several people on our team an easy thing to do. The whitespace issue is what all non-Python programmers object to, but it's a non-issue, as several other people pointed out. It might look like a bad idea theoretically, but in practice I've never had problems with it, on the contrary it helped in maintaining the code by having a single indentation style.

If you're a tester and you consider using existing frameworks and extending them with your own code, I urge you to take a look at Python. There's a wealth of Python- or Jython-based frameworks out there: pyUnit, STAF/STAX, TestMaker, PyFIT (port of FitNesse server to Python), PyGUIUnit, and the list goes on. Also, if you're familiar with The Grinder (http://grinder.sourceforge.net/), the latest version 3 uses Jython instead of Java.
Grig Gheorghiu Send private email
Thursday, December 23, 2004
 
 
Just try it. 

You get over the indentation thing in half an hour, tops. If you don't, go try Ruby.

The more annoying thing the first couple of times you play with it is printing a mixture of text and numbers.

You don't do

print "Hi, $x times $y = $z";

or

printf("Hi, %d times %d = %d",x,y,z);

or

System.out.println("Hi, " + x + " times " + y + " = " + z);

you do this :

print "Hi, %d times %d = %d " % (x,y,z)

which is easy to forget if you're an infrequent user. After that ... everything is easy.

No. The number one problem with learning Python is this.

YOU NEVER WANT TO GO BACK TO ANYTHING ELSE AGAIN!!

Can you handle being so spoiled by your programming language that Perl looks like hard-work, that C++ and Java appear to be like wearing lead weights tied to your boots? :-)

It's a serious problem - there aren't many Python jobs. And you'll find yourself chafing at the language you need to use in your day-job. Sometimes the knowledge that there is something else, so much better, out there, can make you miserable.

Final thoughts by Eric Raymond : http://pythonology.org/success&story=esr
phil jones Send private email
Thursday, December 23, 2004
 
 
I started this thread, and I want to thank everybody
for feedback. I decided to give it a try, quickly
read tutorial (I had to read it twise to memorize).
I can summarize my early impressions like this:
normally, shorter programs are easier to understand;
however, some languages in pursuit of brevity introduce
cryptic ad-hoc constructs, which are hard to understand
It seems to me
that python achieves brevity by using a small
number of powerful ideas, and of all languages
I've seen so far, it has the best ratio between
brevity and clarity.
Example: prev. message mentioned peculiar format
of print statement, like
print "Hi, %d times %d = %d " % (x,y,z)

This really may look like a strange ad-hoc trick,
until you realize that '%' is a binary OPERATION
between string and a list, which returns string,
 and you can use it
not only in the context of print, but everywhere,
e.g.
myVar="Hi, %d times %d = %d " % (x,y,z)
file.write("Hi, %d times %d = %d " % (x,y,z));
etc.
Now compare this with, say, C, where several functions
had to be introduced to handle formats: printf,
fprintf, sprintf, etc. (In Java until v 1.5, it
was not possible to implement these functions at all)

And you can define YOUR OWN operations for your objects!
Of course, you can do it in C++ either, but...
there're no lists there. Lists add new dimension
to the language, and python does a pretty good job in
exploring this dimension.
Nekto
Thursday, December 23, 2004
 
 
"As for inspiration, it is through Python that I rediscovered the joy of programming. I started my career as a C++ programmer, then drifted towards network/security/system architecture jobs, then for the last 2 years I've been working as a tester."

This isn't the kind of inspiration I'm talking about. You've simply found a language that matched your  requirements and abilities.

It'm talking about inspiration by learning new approaches that help your better solve your everyday software design problems. Using tools and platforms dictated by customer requirements and problem field, and not your personal preferences. Speaking from experience, I can tell that  learning Prolog and Lisp is likely to give you that kind of inspiration. Python won't teach you anything you don't already know.
Egor
Thursday, December 23, 2004
 
 
it may not teach you what you don't know, but it'll teach you that in fewer lines of code ;-)

Um, I Like python. It's fun. Java is not. C++ is not. For me. Lisp is kinda fun. Then it's not. Python is always fun.

While java is not fun, I like the JVM. I program it with Jython, a java implementation of python. The JVM is much more fun with Jython than with java. And you get to leverage all the work that went into the java libraries. You can do mutiple ingheritance from 1 java class and multiple python classes. Too much fun!

As with any other software tool, python is the wrong tool for many things. For example, it's the wrong tool for Enterprise IT shops where MS or Java is the right answer to all software questions. It is also the wrong answer for people who remain convinced that the reason we still have quiality/productivity problems with software is that our languages/tools/VMs (meaning .net/java) are  too forgiving and need to *help* the coding resources, oops, I mean developers by assuring perfection at compile time.

Then again, I'm just a fool.
fool for python
Thursday, December 23, 2004
 
 
I think programs, apart from solving practical problems, MAY have aesthetic value. This is the same kind of value
that can be found in mathematical proofs. I personally
feel some sort of satisfaction not when my program
just meets requirements, but when it does it
elegantly. It looks like python opens the way to more elegant code. The only thing that bothers me
(other than performance) is that if you misspell
some variable name in assignment, you are in trouble.
This is a common problem of scripting languages,
and it seems there's no cure. (Also, rules of scope
may have unintended nasty effects).
nekto
Thursday, December 23, 2004
 
 
"This isn't the kind of inspiration I'm talking about ... It'm talking about inspiration by learning new approaches that help your better solve your everyday software design problems. "

Well here's something I learned in Python which I never knew about before : "generators" (aka co-routines)

They aren't new, but Python has them wheras almost none of the other languages I've used seriously ie. C++, Java, VB does. And although Perl also apparently does, I never realized (or even heard of them there)

Another thing, the new Python is adding in-language support for delegators. It has lambdas, iterators, the capacity to pass functions as arguments, nest function definitions inside others, has named-arguments and optional arguments etc. etc.

Yeah, all of these existed in dozens of other languages, but not in the day-to-day usage at the average VB / C++ / Java shop. So it has many advanced high level features, and is bringing them together in one place, and is making them available to a wider public where we might see them getting used.
phil jones Send private email
Friday, December 24, 2004
 
 
I converted from Perl to Python a few months ago and found it to be very similar philosophically, but a little ungainly at first. Python isn't much of language for clever one-liners (for instance, there are no true inline functions).

I'm very lucky to have found a full-time Python job - or rather, I found a full-time Java job and then set an intricate series of traps for my superiors which eventually led to them supporting my Python efforts.

Now that I have a little more experience of it, I understand why it initially feels clumsy compared to Perl - the tradeoff is that the complexity of your program doesn't grow exponentially with its lines of code. Perl projects tend to very quickly become incomprehensible (you can argue that this is the fault of the programmer, and to an extent that's true, but Perl definitely encourages such behaviour).
Python programs tend to start clean and stay clean, while allowing very nearly as much freedom as Perl.

As someone said above, a serious problem is that it makes the mere thought of Java programming almost unbearable.

Oh, and like everyone else I despised the meaningful whitespace for about half an hour, and then completely forgot about it.
Brendon Hogger Send private email
Monday, December 27, 2004
 
 
Perl encourages nothing but programmer responsibility. It's not its fault that not everyone is able to take it.
Egor
Tuesday, December 28, 2004
 
 
Do you mean "IRresponsbility"?
NoName
Monday, January 10, 2005
 
 

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

Other recent topics Other recent topics
 
Powered by FogBugz