LWN.net Logo

Advertisement

Front, Kernel, Security, Distributions, Development. See your byline here on LWN.net.

Advertise here

Mostly Redundant for Python

Mostly Redundant for Python

Posted Oct 11, 2005 9:56 UTC (Tue) by NAR (subscriber, #1313)
In reply to: Mostly Redundant for Python by AnswerGuy
Parent article: Book Review: Perl Best Practices (NewsForge)

However, they won't be peppered with braces and semicolons and endless parsing subtleties that can occasionally bite even the immortals of Perldom.

No, they will be bitten by strange IdentationException errors during runtime. Usually the actual identation error is hundreds of lines away from the line number reported by the python interpreter. There's no free lunch...

Bye,NAR


(Log in to post comments)

Python Indentation Red Herring

Posted Oct 11, 2005 15:38 UTC (Tue) by mkc (guest, #2047) [Link]

I've been programming principally in Python for over five years, and I have never seen an IndentationException, nor seen any code (mine or anyone else's) that had a bug caused by ambiguous whitespace.

I do think that the Python spec should be changed to disallow tab characters as indentation in Python source. But given that there are multiple means to detect the problem, and that it is virtually non-existent in practice, it's a pretty academic issue.

If this seems like the thing most bothersome to you about Python, why not suspend this judgement for a while and give it a try? Speaking as a former Perl programmer, I don't regret doing so for a minute.

Python Indentation Red Herring

Posted Oct 11, 2005 16:19 UTC (Tue) by carcassonne (guest, #31569) [Link]

If this seems like the thing most bothersome to you about Python, why not "suspend this judgement for a while and give it a try? Speaking as a former Perl programmer, I don't regret doing so for a minute."

OK, sure. What's the Python equivalent to Memoization ?

Are there as much modules (or extensions or whatever) in Python that there is in Perl ?

The language is one thing. The libraries (or modules or extensions) provided with it are also very important. What would be Java without all the libraries ?

Memoization and Modules

Posted Oct 12, 2005 20:56 UTC (Wed) by AnswerGuy (subscriber, #1256) [Link]

Memoization is a programming technique (even an OO design pattern. The wikipedia article to which I've linked even shows a trivial Python implementation of a memoize function.

A more complete recipe for the technique can be found at the ActiveState ASPN Python Cookbook repository.

In response to the broader question about the availability of modules, extensions and code samples ... there are many. One could naively say that there aren't as many as for Perl. However I'm not sure that the comparison would be a wise one.

In general Python includes more in its base distribution/package. There are over 300 modules included; and the developers and maintainers carefully consider adding more with each release. The question should not be: "Are there as much [sic] modules ...?" The sensible question is: can the corpus of freely available code allow me to do as much and as easily as with Perl. It's a qualitative rather than quantified issue.

I won't render an opinion on the answer. That would be a endless debate. The best answer is for you to go to the Python web site, peruse the "Cheese Shop" (a.k.a. the Python Package Index, or PyPI) and perhaps pay particular attention to this wiki page to form your own opinion.

JimD

Memoization and Modules

Posted Oct 13, 2005 1:39 UTC (Thu) by carcassonne (guest, #31569) [Link]

"Memoization is a programming technique (even an OO design pattern."

Yes, but then it does not necessarily mean that it has to be written from scratch when needed. If needed and if available, why not use it instead of writing it ?

"The question should not be: "Are there as much [sic] modules ...?" The sensible question is: can the corpus of freely available code allow me to do as much and as easily as with Perl. It's a qualitative rather than quantified issue."

Well, even if 'corpus' is a singular word, it reflects in this context a quantity. And when there's quantity, there's choice.

About the quality aspect you mention in a way that seems to hint that on one side there's less but the quality is better, I dunno. I guess I stick with ample choice and amongst that choice, a whole bunch of tested modules.

Funny that on a thread about a new Perl book there are so many replies about Python and so many comments about where to place curly braces in Perl.

Anyhow, thanks for the URLs, I'll check them out.

Python Indentation Red Herring

Posted Oct 11, 2005 16:48 UTC (Tue) by NAR (subscriber, #1313) [Link]

If this seems like the thing most bothersome to you about Python, why not suspend this judgement for a while and give it a try?

I happen to manage some thousand lines of Python code, how else should I have met with that exception? And it didn't had to do anything with tabs - the def statement of a method was indented to 3 characters instead of 4.

Bye,NAR

Mostly Redundant for Python

Posted Oct 11, 2005 18:29 UTC (Tue) by piman (subscriber, #8957) [Link]

> No, they will be bitten by strange IdentationException errors during runtime.

Actually, it's during compiletime. For most Python programs runtime immediately follows compiletime, but it's an important distinction because it means if the program actually starts running, there are no indentation syntax errors.

(There can be indentation semantic errors, but in my experience they're not worse or more common than the equivalent kinds of problems in C. Perl avoids this by forcing you to use {}s no matter the size of the block.)

price worth paying

Posted Oct 12, 2005 9:59 UTC (Wed) by copsewood (subscriber, #199) [Link]

Happened to me once or twice when I was getting competent at Python. Took about 15 to 20 minutes to find and fix bug maximum. Hardly ever occurs now I've written a few thousand lines in the language, and when it does the fix is now fast.

Yes this is a minor cost in changing from Perl to Python, but the benefits that came with this change were much, much greater in connection with my improved ability to code more complex requirements in much less time using Python while being able to think about the problem to be solved and the solution more and having to think about the language less.

The use of the tool should not get in the way of the problem solving, and Python's minimalist and straightforward approach helps greatly in this area.

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds