Slashdot Mirror


Learning Python, 2nd Edition

Ursus Maximus writes "Eagerly awaited by many, this book reached bookstores just after Christmas, and updates the 1999 edition. Learning Python is O'Reilly's introduction to Python programming and at 591 pages, this is a major upgrade to the 366 page original. Furthermore, the Python language has undergone extensive improvements and additions in the last five years, and the new book does a good job of covering these changes." Learning Python 2nd Edition author Mark Lutz & David Ascher pages 591 publisher O'Reilly & Associates, Inc. rating 10 reviewer Ursus Maximus ISBN 0596002815 summary An introduction to Python programming

Python is a dynamic, interpreted, object oriented language used for both scripting and systems programming. Python is known for being easy to learn and use, while also being powerful enough to be used for such projects as Zope and the Chandler project. Its growing popularity is also based on its reputation for fostering programmer productivity and program maintainability. One drawback sometime cited is its relatively slow execution speed compared to compiled languages such as C.

For myself, I have probably read too many books about Python, but that is because I am an amateur hacker who learns programming slowly, and I find that reading several books about the same topic, covering the subject matter from different angles, allows me to better absorb the material. For me, this was a good review of the core language and a welcome refresher course on the newer aspects introduced in versions 2.2 and 2.3. For anyone who is new to Python and wants to learn from the ground up, this book would be a great place to start.

Mark Lutz is an authority on Python and one if its leading teachers, with both Learning and O'Reilly's Programming Python to his credit, as well as the courses and seminars he teaches professionally. In updating the original version, which was already very good, Mark has polished the chapters on the core language to a nearly perfect level, while his co-author David Ascher has done the same on the more advanced aspects of the book. In addition, Mr Lutz has benefited from extensive feedback from students and readers, and his explanations therefore anticipate common misunderstandings. Each chapter is accompanied by a problem and exercise section and answers are included at the back of the book.

A major addition to the new edition is a chapter on "Advanced Function Topics," including list comprehensions, generators and iterators. Python is sometimes used with a functional programing style almost similar to Lisp, although to List purists that may sound like heresy. The recent versions of the language have significantly upgraded Python's support for the functional style. Functions cover three chapters in the 2nd edition instead of just one.

Another major change since the first edition is extended coverage of Modules, which now occupies four chapter instead of just one. Python modules are a high level package structure for code and data, and they help facilitate code reuse. Yet another addition is coverage of Python's "new style classes." Coverage of classes and object oriented programming has been greatly expanded and now includes five whole chapters and almost 100 pages. Coverage of exceptions now is expanded to three chapters.

If you have been considering learning Python, now would be a great time since this new book is the perfect introductory text. If you already know Python and have read the first edition of Learning Python or another introductory text, then this book may not be essential since the new language features are covered pretty well on the web in various places, and you might be better advised to read one of the other fine books on non-introductory aspects of Python. But this book is about as good an introduction to the language as you are likely to find. The book does not cover all of the Python libraries nor many other topics, but it does briefly touch on the major libraries, frameworks, gui toolkits, and community resources.

If you want to learn the core Python language quickly, this may be your best bet. Learning Python only covers the basics, but it is deep in information on what it does cover. Well written, understandable, and in a very logical arrangement, this book is densely packed with info.

I have often found myself returning to the original book, and the new book will now fill this role. It is deep in information, well written, and a joy to read. For an experienced programmer who is just learning Python, it may be possible to thoroughly learn everything about the core language in one reading of this book. For relative newbies, it will be an often-used resource.

To read more reviews of books about Python, visit the Python Learning Foundation. You can purchase the Learning Python, 2nd Ed. from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

322 comments

  1. A nice comparison of Python with other languages.. by tcopeland · · Score: 4, Informative

    ...can be found here.

    I prefer Ruby, but there seem to be a lot of healthy discussions of various language features and ideas across the scripting language community. The "Python comparison page", for example, has a link to John Ousterhout's paper on why scripting languages are useful - even thought he wrote the paper about Tcl, it's just as applicable to Python or Ruby.

  2. Python? by sparklingfruit · · Score: 5, Informative

    "Python has been an important part of Google since the beginning, and remains so as the system grows and evolves. Today dozens of Google engineers use Python, and we're looking for more people with skills in this language." said Peter Norvig, director of search quality at Google, Inc.

    Open source, expressive (very short code can achieve a lot), readable (very short expressive code is easily groked -- fewer bugs), no direct pointer manipulation (safe -- fewer bugs), integrates nicely with other languages, runs on a variety of platforms, very easy to learn.

    I, too would recommend learning python. It is a very good, language. Zeolotry is another thing though. Keep your mind open. Learn all the languages you can. This book, I can't comment, although I received it a week ago I haven't gotten around to reading it yet.

    1. Re:Python? by Just+Some+Guy · · Score: 4, Interesting
      integrates nicely with other languages

      The importance and utility of this can't be overstated. Python absolutely rocks as a rapid development environment. I have not personally experienced a language that lets me go from concept to implementation nearly so quickly. Once an application is up and running, Python provides a great toolset for profiling your project and making it easy to replace performance-critical sections with the low-level language of your choice.

      Does your crypto application need a faster random generator? Replace parts of that module with C. The rest of your project still gets the benefits of a strongly typed, object-oriented language with a robust library of string manipulation, pattern matching, and GUI interfacing functions.

      It really is a project manager's dream come true. Python has replaced Perl as my language of choice for all new development.

      --
      Dewey, what part of this looks like authorities should be involved?
    2. Re:Python? by jemfinch · · Score: 1

      Learn all the languages you can.

      No. Learn all the languages that will make you a better programmer. Learn languages that will expand your understanding of software engineering. Learn languages that will make you more productive. But for goodness' sake, don't waste your time learning every language you run across: the vast majority of languages are simply unproductive compared to a small handful of better, higher-quality languages.

      Languages can be compared based on objective criteria. You can honestly say that Perl has more libraries than Python, or that programs written in Haskell will experience fewer runtime errors than programs written in Python. Granted, every application has a different utility function for each of these criteria, but some languages do, all other things being equal (things such as "existing investment in a language"), dominate other languages. Don't learn the languages that are dominated: learn the ones that dominate others.

      Claiming that one language dominates another language isn't zealotry: it's objectivity.

      Jeremy

    3. Re:Python? by sparklingfruit · · Score: 1

      That's what I meant. I did not intend to imply that you should learn Visual Basic or Pascal. :)

    4. Re:Python? by jalet · · Score: 1, Funny

      > Python has replaced Perl as my language of choice
      > for all new development.

      Larry Wall, is that you ?

      --
      Votez ecolo : Chiez dans l'urne !
    5. Re:Python? by gtrubetskoy · · Score: 2, Interesting
      Python has been an important part of Google since the beginning

      What I'm kinda curious about is whether they use mod_python. From the looks of the URL's on Adsense and AdWords it seems likely that they are using the Publisher handler, but I've never heard any official (or even rumor) about it.

    6. Re:Python? by Decaff · · Score: 2, Informative

      integrates nicely with other languages.

      One of the best examples of this is Jython - python implemented in 100% java. This allows the flexibility of a scripting language with the security and portability of Java.

    7. Re:Python? by smallpaul · · Score: 1

      Does your crypto application need a faster random generator? Replace parts of that module with C.

      Even better: use pysco to optimize your existing Python code or Pyrex to GENERATE C code from your Python code.

    8. Re:Python? by Anonymous Coward · · Score: 0

      Nope, no mod_python. We don't write external webapps in python; it's mostly used for internal glue that you can't see from the outside.

    9. Re:Python? by Anonymous Coward · · Score: 0
      Does your crypto application need a faster random generator? Replace parts of that module with C. The rest of your project still gets the benefits of a strongly typed, object-oriented language with a robust library of string manipulation, pattern matching, and GUI interfacing functions.
      I agree with your sentiments but can't agree with your assertion that Python is strongly typed. As far as I understand, it's not typed at all.
    10. Re:Python? by Anonymous Coward · · Score: 0

      I'm the AC author of the above. Never mind, I'm just plain wrong. You are correct.

    11. Re:Python? by Anonymous Coward · · Score: 0

      Ummm, no, you're correct. Python is strongly typed, but dynamically and not statically typed. Everything has a type, but the system doesn't enforce types until runtime (versus static, where it enforces types at compiletime).

    12. Re:Python? by Anonymous Coward · · Score: 0

      As far as I understand, [Python is] not typed at all.

      You misunderstand. Python is 'dynamically' typed, in the sense that types are not checked at compile time, but at run-time.

      >>> foo = "bar"
      >>> bar = 5
      >>> foo + bar
      Traceback (most recent call last):
      File "", line 1, in ?
      TypeError: cannot concatenate 'str' and 'int' objects

      Note the exception class ... 'TypeError'. Pretty odd for an untyped language, don't you think? Now someone might point out that float types can be added to int types. This, however, is not the result of loose typing, but occurs because int and float classes 'know' (ie have methods) how to deal with each other.

    13. Re:Python? by Anonymous Coward · · Score: 0

      I did not intend to imply that you should learn Visual Basic or Pascal.

      And WTF is so bad about Pascal that you would include it with BASIC in a list of languages not to learn?!

    14. Re:Python? by Anonymous Coward · · Score: 0

      This allows the flexibility of a scripting language with the security and portability of Java.

      In what way is Java any more 'portable' than Python? You sound like a Java advertising brochure.

  3. 1st edition by JohnLi · · Score: 3, Informative

    I have the fist edition of this book. It has help me considerably, but it seemed as though I always had to use google to supplement it with code/examples. I guess I wanted to see more real world work in the book rather than what seemed to me to be generic theory explained via simplistic samples.

    Maybe its just me though.

    --
    The / in /. would be more accurate if it leaned to the left. http://www.metricnut.com
    1. Re:1st edition by Eep!_I'm_a_monkey! · · Score: 1

      *Hugs his worn to hell much loved copy of the first book*

    2. Re:1st edition by Anonymous Coward · · Score: 0

      I have the fist edition of this book.

      It was my textbook at the school of hard knocks.

  4. Re:There's one major reason I choose Python over P by carpe_noctem · · Score: 1, Interesting

    I have nothing against python, but every time you ask a python nut why they choose to code in this language, the response is always something to the effect of "it's easier than perl". I don't mean to troll here, but does python have any merit of its own, or do people only use it because they don't want to use perl?

    --
    "Quoting famous computer scientists out of context is the root of all evil (or at least most of it) in programming." - K
  5. on par with TCL except for C by mi · · Score: 2, Interesting

    While TCL remains my personal favorite, Python is really good, except for the creating-your-own-extensions part. The Python's C API needs a lot of catching up to do to match the excellence of TCL's.

    --
    In Soviet Washington the swamp drains you.
    1. Re:on par with TCL except for C by dustman · · Score: 3, Informative

      boost.python, one of the boost libraries, makes binding to python very easy.

      It uses C++ and lots of template mojo, but you don't really need to understand all that to use it.

    2. Re:on par with TCL except for C by Peaker · · Score: 1

      Try: Pyrex
      or as mentioned, try Boost's Python if you prefer C++.

    3. Re:on par with TCL except for C by Anonymous Coward · · Score: 0

      Try ctypes, it changed my life in terms of making extensions. If you use cygwin, creating modules is as simple as creating DLLs in gcc, then using ctypes to access them.

    4. Re:on par with TCL except for C by smallpaul · · Score: 1

      Why would you use the Python C API when there is Pyrex? Surely that's easier to do than the TCL API with its stubs weirdness.

    5. Re:on par with TCL except for C by mi · · Score: 1
      Why would you use the Python C API when there is Pyrex?

      Because it is not part of Python? I needed to access some functions from our own libraries and Python's C API seemed sufficient if imperfect. I did it, but was left with bad taste in my mouth.

      Surely that's easier to do than the TCL API with its stubs weirdness.

      Oh, surely? Not sure... Let's see, downloading and installing a third-party package (with unclear licensing). Learning to use it. No, thanks. May be next time. But you seem to agree with my main point -- Python's C API is wanting.

      TCL's stubs are, indeed, weird. They (aim to) solve a problem, that does not always exist. However, TCL can be built without them. And, most importantly, they are not part of the API. Your C code is unaffected by the stubs -- only the linking procedure is.

      On contrast, Python's C API generates warnings at compile time due to type misdeclarations (especially in function pointers). Another thing is the sheer size of the PyObj structure, which is ever growing from version to version. To initialize the field 15 in it, for example, you have to carefully assign 0s to 14 fields before that. So your C code is not as good...

      --
      In Soviet Washington the swamp drains you.
    6. Re:on par with TCL except for C by smallpaul · · Score: 1

      I asked: Why would you use the Python C API when there is Pyrex?

      You answered: Because it is not part of Python? I needed to access some functions from our own libraries and Python's C API seemed sufficient if imperfect. I did it, but was left with bad taste in my mouth.

      So you didn't use the best tool for the job! If I complained that Tcl has no OO wouldn't you say that I should download incr TCL? Speaking of OO, if you want to bridge to C++ instead of C, what does Tcl have anything like Boost.Python?

      Oh, surely? Not sure... Let's see, downloading and installing a third-party package (with unclear licensing).

      curl -O http://....pyrex.tar.gz tar -zxvf pyrex.tar.tar.gz python setup.py install

      That's it. The same way you install any Python package.

      Learning to use it. No, thanks. May be next time.

      So you didn't have to learn the TCL API at some point? You were born knowing it?

      But you seem to agree with my main point -- Python's C API is wanting.

      The Python C APIs are more complicated because they do more. They allow you to create fully namespaced, object-oriented, operator-overloaded modules with classes, factories and methods. There is a fair bit of boilerplate involved which you use Pyrex to avoid.

      On contrast, Python's C API generates warnings at compile time due to type misdeclarations (especially in function pointers). Another thing is the sheer size of the PyObj structure, which is ever growing from version to version. To initialize the field 15 in it, for example, you have to carefully assign 0s to 14 fields before that. So your C code is not as good...

      Use the right tool for the job. Pyrex is more powerful than TCL's API and easier to use.

  6. Python is amazing by arvindn · · Score: 5, Informative
    If you don't know python: learn it now!

    This is not a religious argument; I'm not advocating that python is the one language you should use or anything like that. In fact, not having an "ideology" is one of python's major strengths.

    If you're asking "why python", ESR has said it better than I ever could.

    I'm yet another of those who experienced extremely small turnaround times for python programs. It took me a week, working part time (I estimate about 30 hours) totally, to release 1.0 of gretools, starting from scratch. I had not written a single line of python code before that, mind you.

    Why python is great:

    Its not a religion. It doesn't force its style of thinking on you. Functional programming, excellent string manipulation tools, classes, inheritance, exceptions, polymorphism, operating system integration, they're all available. This is python's biggest advantage. Whichever background you're coming from, you can very quickly become effective at python.

    Incredibly compact code. This is largely a consequence of the previous point. Apart from that it is dynamically typed, and has lots of other cool features. Like doing away with braces for delimiting blocks. People who know nothing about the language flame it for using indentation, but I have never found it confusing, and it makes the code smaller far more readable.

    A user-friendly programming language! You aren't going to believe this until you've actually programmed in python. Its got this amazing property that if you can express a thought in constant space mentally, then you can code it in a constant number of lines, most of the time in a single line. In other words, the abstractions of the programming language match the "natural" abstractions of programmers very closely. After just a couple of days I got so used to this that I began to "predict" language features intuitively. At one point I just knew there had to be a language construct for something I was trying to do, and found that it was the reduce function.

    Simple syntax. Python manages to have all these features while retaining a very simple syntax, perhaps even simpler than C. This is a big plus, because it gets out of the way and Does What You Mean.

    Convinced? Get started now!

    1. Re:Python is amazing by Junks+Jerzey · · Score: 1

      Its not a religion. It doesn't force its style of thinking on you.

      I agree with you overall, but Python does bow down to the temple of OOP. To me, a heavy OOP style of thinking feels very dated, even though Python has a very dynamic nature to its OOPness.

    2. Re:Python is amazing by Anonymous Coward · · Score: 1, Insightful
      Its not a religion. It doesn't force its style of thinking on you.

      You mean they've fixed it so you don't have to rigidly adhere to Python's indentation conventions? 'Cause that and tab damage are the things that keep me from learning it.

    3. Re:Python is amazing by arkanes · · Score: 1
      If you pretend that an object is actually a namespace (and squint a little bit) it's pretty easy to pretend that Python isn't object oriented.

      Of course, I don't know how "object oriented" is the same as "dated" in your head, so maybe it won't work for you.

    4. Re:Python is amazing by lunenburg · · Score: 1

      I've tried several times to pick up Python - I have both Learning and Programming Python, have read through them, tried to do some stuff, but it's never clicked for me.

      Maybe I slept through too many CS classes and can't wrap my brain around OOP, maybe it's my failings as a coder, maybe I have a lot less free time nowadays than I used to, but I've been able to do a ton of useful work in Perl and haven't even been able to get started in Python.

      Maybe I'll give it an 8th try one of these days. I feel like I'm missing this moment of clarity where I'll go "A ha! So _that's_ what makes Python so good!" But I haven't found it yet.

    5. Re:Python is amazing by The+Bungi · · Score: 5, Interesting
      I love Python, though I primarily use it in Win32 environments (although it helps when I use BSD; shell glue is better done in Python, IMO). I've used it for close to four years now, and I suppose I consider myself relatively good at it. The best argument I've ever come up with as to why Python is better for web development than Perl: Zope/Plone vs. Bugzilla/SlashCode. I know they're different products, that's not the point. But just spend a few weeks examining both codebases. I can bet you good money that non-expert developers will understand a Python-based application faster than they will a Perl one.

      I guess Perl is just traditionally what you do these things with. It's not necessarily better. Perl also doesn't support Windows directly like Python does - if you want Perl in Win32 you pretty much have to go with ActiveState whereas Python.org has a Win32 specific distribution. Then again, it's difficult to compete against CPAN's sheer size.

      But anyway, it doesn't matter. We use what we want/like and it's cool that we have choices.

      However, over the past year or so I've also been looking at Ruby. Not to get into a religious argument (as you say) over which language is better, but if you like Python you should take a look at Ruby. If you're a Windows user there's an installer available, which comes with a full book (in CHM format) that can get you running in no time if you already know Python. As Perl and Python, Ruby has extensions and so on. I do like the OO features in Ruby a bit better than Python.

      And least but not least, there's Lua. I wouldn't use Lua the same way I use Python, but Lua is a joy to embed, much more so than Python.

      Ahhh, language wars. Cheers =)

    6. Re:Python is amazing by Just+Some+Guy · · Score: 1

      Note that you don't have to use OOP in Python - it just makes it easy if you want to. You're more than welcome to "def"ine a bunch of functions and call them directly.

      --
      Dewey, what part of this looks like authorities should be involved?
    7. Re:Python is amazing by lunenburg · · Score: 1

      Note that you don't have to use OOP in Python - it just makes it easy if you want to. You're more than welcome to "def"ine a bunch of functions and call them directly.

      Interesting point - most of the learning material is OOP-related, though, so I feel pretty lost trying to learn Python without knowing OOP. But that's good to know.

    8. Re:Python is amazing by Bimble · · Score: 1

      You mean they've fixed it so you don't have to rigidly adhere to Python's indentation conventions? 'Cause that and tab damage are the things that keep me from learning it.

      I know what you mean. I've avoided C because of those damned curly braces. Give me good ol' "begin" and "end" blocks from Pascal - at least with those you know where you stand!

      --
      Naked.
    9. Re:Python is amazing by Camel+Pilot · · Score: 1

      if you want Perl in Win32 you pretty much have to go with ActiveState whereas Python.org has a Win32 specific distribution.

      What is wrong with Activestate? Activestate is Perl's "Win32 specific distributition". Don't really see the difference.

    10. Re:Python is amazing by The+Bungi · · Score: 2, Interesting
      What is wrong with Activestate? Activestate is Perl's "Win32 specific distributition". Don't really see the difference.

      There's nothing wrong with ActiveState, except that they lag behind the main *nix releases and are generally slow to incorporate fixes. It also ships with a bunch of stuff you might not necessarily want. For example, the COM extensions. The fact that I'm running in Windows doesn't necessarily mean I want to use COM. It also takes way too long to install, considering what it is.

      The Win32 Python distribution on the other hand is pretty much sync'ed with the primary *nix point releases, and in my experience as a whole the folks that write Python are much more receptive to bug reports for the Windows distribution that the Perl people (well, they are not involved with the Win32 port at all). Just try to ask a question about ASPerl on one of the Perl mailing lists or newsgroups. Not a good experience. I'd dare say the Perl community would rather ActiveState not publish ASPerl at all. The attitude from the Python camp is quite different.

      Just my opinion of course.

    11. Re:Python is amazing by togofspookware · · Score: 1

      Pfft. I tried to pick up Python a couple times. We just didn't click. Had to get out the reference manual any time I wanted to do anything, because all the functions were hidden under levels of sys.net.http.HTTP.HttpRequest.request stuff (or whatever).

      I think the best way to choose a language is just to try a bunch of them and see which one makes *you* the most productive. For me that's Ruby. If Python makes you happy then good for you, but I just don't think a person can make a good judgement on what programming language they should use based on language features alone.

      Oh, yeah, and the lack of "}" or "end" annoys me ;)

      --
      Duct tape, XML, democracy: Not doing the job? Use more.
    12. Re:Python is amazing by Dan+Ost · · Score: 1

      Try Pyhon in a Nutshell.
      It does an excellent job of seperating OOP from the other parts of the language.

      I would recommend this book as the first python book for anyone. Get it, read
      it, and use the official documentation when you need greater detail.

      --

      *sigh* back to work...
    13. Re:Python is amazing by Anonymous Coward · · Score: 0

      https://moin.conectiva.com.br/LunaticPython

    14. Re:Python is amazing by BinxBolling · · Score: 1

      Spend some time working with a codebase where correct indention isn't generally respected, and you'll have much more appreciation for a language that would have enforced such a restriction on indention.

      And Python's rules aren't particularly rigid -- they're no different than what you ought to be doing, anyways. And as a bonus, they let you save the occasional line of code that would have otherwise contained only a '}'.

    15. Re:Python is amazing by mixmasta · · Score: 1

      Funny, you've just described the exact same thing that happened to me....

      Except reverse perl and python =)

      --
      #6495ED - cornflower blue
    16. Re:Python is amazing by $andeep · · Score: 1

      Hmm... i know python pretty well, have been trying to learn perl, somehow i get lost mid way thru & start learning from scratch.. may be i too slept thru CS classes.. wait a minute i'm a mech. engineer

      --
      gravity is a myth, earth sucks
    17. Re:Python is amazing by buzzcutbuddha · · Score: 1

      Perl also doesn't support Windows directly like Python does - if you want Perl in Win32 you pretty much have to go with ActiveState whereas Python.org has a Win32 specific distribution.

      FUD. Following Gary Ng's port of the source code to Win32, Gurusamy Sarathy began releasing a binary distribution of Perl, and so did ActiveState.

      At some point they realized that it would be a benefit to Perl and Windows if they merged the distributions and gave Windows users a single place to go to get Perl with an installer and the most common packages installed.

      This has been nothing but beneficial, as most IT managers of Windows shops feel better installing something with a company name attached to it, and an installer.

      I don't think that ActiveState has ever been anything but good to the Perl community, and it's a shame that you imply that they're involved in some murky shadow plot.

    18. Re:Python is amazing by The+Bungi · · Score: 1
      FUD.

      Right.

      At some point they realized that it would be a benefit to Perl and Windows if they merged the distributions and gave Windows users a single place to go to get Perl with an installer and the most common packages installed.

      Right, and most of the time those "common packages" are not what I happen to need. Most of the time they're overkill. Unlike the Python distribution. Like I said.

      This has been nothing but beneficial, as most IT managers of Windows shops feel better installing something with a company name attached to it, and an installer.

      Looks like you missed my point. Instead of crying "FUD" perhaps you should have read the post more carefully.

      it's a shame that you imply that they're involved in some murky shadow plot.

      It's a shame you think I'm somehow claiming that's the case. FUD much?

    19. Re:Python is amazing by Anonymous Coward · · Score: 0

      Traitor!!!

  7. Re:Python and Perl... by Anonymous Coward · · Score: 0

    awk, sed, grep, and nc.

    You need to be able to bind to a socket.

    (Of course, if you're really clever, you add 'gcc' to the list, and then you can use awk, sed, and grep to compile short C programs to do the socket interface for you)

  8. Re:There's one major reason I choose Python over P by Frums · · Score: 3, Informative

    Except that Python uses dynamic typing, not static typing. Variables are untyped but hold references to typed objects.

  9. Re:Python and Perl... by tcopeland · · Score: 2, Funny

    > There is nothing, and I do mean NOTHING that
    > a real Unix professional can do with Python
    > or Perl that he or she can't do with awk, sed,
    > and grep.

    Awk? Sed? Bah! There's nothing you can do in awk and sed that you can't do with plain, simple assembly language opcodes!

  10. Upgrade? by Sean80 · · Score: 1
    I'm never convinced that adding more pages to a book is an "upgrade." If I could buy a book which was 1 page long, but which taught me damn well everything I needed to know about Python, I'd much, much rather buy that, purely from an opportunity cost perspective.

    If there's anything I hate, it's these big, thick, 1000-page (or 500-odd page) books which tell me how to use the Help system in Appendix 42.

    So, I'm always wary.

    1. Re:Upgrade? by Anonymous Coward · · Score: 1, Funny

      I would think that most 1000-page books would, indeed, have 500 odd pages.

      And 500 even ones, too.

    2. Re:Upgrade? by Anonymous Coward · · Score: 0

      I'm never convinced that adding more pages to a book is an "upgrade."

      True. However the mere fact that the 1st edition only covered Python up to version 1.5, whereas the new edition covers Python 2.3, makes this a significant upgrade. Python now is quite a different language than it was back when the first edition came out. Although it is largely backwardly compatible, there are a couple of important gotchas, such as the changes to namespaces, as well as a whole lot or new features nowadays.

      IMHO with version 2.2 python came of age as a serious OO language. From there on, not only were all types objects, but built in types could be subclassed. These are features simply not covered in the 1st edition.

  11. Re:There's one major reason I choose Python over P by Waffle+Iron · · Score: 5, Informative
    Static typing.

    Python doesn't have static typing; it has dynamic typing like Lisp, Ruby, Perl, etc. The difference between Python and Perl is that Perl has rather weak dynamic typing. For example, Perl tries to treat strings and numbers as the same type (resulting in the use of strange constructs such as the value "0 but true"). Python and most other dynamically typed languages have stronger typing, with distinctions between strings, integers, floats, etc.

    Static typing means that each variable is only allowed to hold values of one type. Usually the variable types are manually declared (as in C or Java), but some languages (like Haskell, IIRC) can infer the types.

  12. O'Reilly & Python by Petronius · · Score: 2, Informative

    I don't think *all* the O'Reilly books are good but the Python books (I own several) are really excellent: they are written by people that have been involved with the language for a long time and that really *think* in Python and like the language. Glad to see Python is still doing well.

    --
    there's no place like ~
  13. Re:Python and Perl... by Anonymous Coward · · Score: 0

    Agreed, asm is the way to go!! Not only that, it's cross-platform, and high level!! (HLASM!!) Oh yeah, and did I mention how easy it is to learn asm? I have such an issue coding REXX, so I switched to HLASM now it only takes me 20 minutes to could a copy program!! Yeah!! Progress baby!

  14. Re:There's one major reason I choose Python over P by Anonymous Coward · · Score: 3, Informative

    This sums it up really:
    http://www.linuxjournal.com/article.php?s id=3882

  15. Re:There's one major reason I choose Python over P by PD · · Score: 3, Funny

    I like Python because of the line numbers and the goto statement. Why don't they add those features to Visual Basic?

  16. Still doesn't have a maintained, up-to-date by Anonymous Coward · · Score: 0

    odbc module so python will not be in my toolbox.

    And don't tell me to do it. I haven't used c in a decade.

    1. Re:Still doesn't have a maintained, up-to-date by PizzaFace · · Score: 2, Informative

      I agree, ODBC is a critical feature for a "glue" language like Python. There's mxODBC, but commercial use costs $75 per end-user or $1,250 per developer. Most of Python's other database modules are free, but ODBC is needed to fill a lot of gaps.

    2. Re:Still doesn't have a maintained, up-to-date by dowski · · Score: 1

      Try this on Windows with the Win32all package:

      import dbi,odbc

      conn = odbc.odbc("datasourcename/username/password")
      cur = conn.cursor()

      cur.execute("SELECT whateveryouwant FROM yourchoice WHERE yourcriteria = 'met'")

      data = cur.fetchall()

    3. Re:Still doesn't have a maintained, up-to-date by PizzaFace · · Score: 1

      Yes, the odbc module is in the public domain, but it isn't being maintained, and there are some known problems.

  17. For experienced programmers by Anonymous Coward · · Score: 5, Insightful

    I would recommend "Python In A Nutshell" as it cuts to the chase and doesn't teach you programming so much as giving you what you need to know in Python. If you can already program, the "Nutshell" book is pretty good, plus the author can always be found around the Python Newsgroup(s).

    1. Re:For experienced programmers by Anonymous Coward · · Score: 0

      Your python should not be in your nutshell, but hanging comfortably in front of it. See a doctor!

    2. Re:For experienced programmers by Anonymous Coward · · Score: 0

      Yes, if you have a lot of experience with other languages, _Python in a Nutshell_ is an awesome way to learn the language quickly. It is concise, but not overly so, and the explanations are extremely clear and exact.

  18. Re:Python and Perl... by Anonymous Coward · · Score: 0

    And you only need 4 opcodes! (add, branch, load, store)

  19. Re:There's one major reason I choose Python over P by jemfinch · · Score: 5, Informative

    One more time, for the majority of people who don't understand:

    Strong typing is when your language will only allow appropriate operations to be performed on values of the appropriate type.

    Weak typing is the opposite, where a language will implicitly convert between (possibly incompatible) types or will simply allow any operation to occur.

    Static typing is when a language enforces its typesystem (whether it be strong or weak) at compile time.

    Dynamic typing is the opposite, when a language enforces its typesystem at runtime.

    Python is strongly, dynamically typed. If you try to perform an integer operation on a string, it will check this at runtime and raise an exception. It will not perform the operation.

    Perl is weakly, dynamically typed. If you try to perform an integer operation on a string, it will implicitly convert that string to an integer (using 0 in the case of strings that aren't a valid representation of an integer). It does this at runtime.

    Haskell is strongly, statically typed. If the compiler cannot prove that all your operations are performed on values of the appropriate type, it will not compile your program.

    C is weakly, statically typed. It will implicitly convert beteween incompatible values (pointers and ints, for instance) but it will determine which implicit conversions will occur at compile time (as well as reject some other conversions or type errors).

    Python is not in any way statically typed. Perhaps only moderators who actually know Python should get mod points on articles such as these (yes, I know that'd be impossible, but it'd ridiculous that the parent post got modded up to 5, interesting when it's blatantly and obviously wrong).

    Jeremy

  20. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0, Funny

    WTF? Didn't you RTFA? Python is not just a scripting language, it's a systems programming language.

    LOL.

    I hear both the PS3 and the X-Box 2 will use Python as their fundamental OS platform, and also for writing vertex and pixel shaders.

  21. Re:Bad foundations. by Anonymous Coward · · Score: 5, Informative

    I'm not sure which Python you're referring to, but it doesn't sound like the www.python.org one!

    Python's intellectual ancestor was the language ABC, not Perl or TCL. Python's object system is very clean and well thought out, not accreted into the language. New style classes are an elaboration of that, merging the concept of a type and a class.

    I'm not sure which "aspects from Camel" fuck up the whole situation. You're one example about continuations and GC "occultism" doesn't really help. 99% of the wonderful Python applications out there have no need of such stuff, and if you did, maybe Stackless Python (a variant) might interest you.

    Python has all the necessary features to build very robust and maintainable systems. It's library is excellent, and it's C API is extremely clean for both embedding and extending.

    A valid criticism for *some* applications is that it's slower than C or C++. This should come as no surprise since Python is interpreted and highly dynamic. Fortunately, Python can easily be extended such that critical sections can be coded in C, although most applications won't need to bother. It's also an excellent prototyping language so that if you *did* want to rewrite it in a static language like C++, you'd have an excellent basis for it.

  22. Re:Python and Perl... by Anonymous Coward · · Score: 0

    Can I see sample code for awk, sed and grep that creates a curses interface or supports polling multiple processes (ie, the select() system call or equivalent)? The curses interface can be lived without, of course, but a tool that can run multiple processes (ie, ssh to multiple machines, connect to port 80) and collect output is quite useful. Curses helps display the output.

  23. Re:There's one major reason I choose Python over P by Abcd1234 · · Score: 3, Interesting

    Well, from the perspective of a long-time Perl developer, Python has a certain elegance in it's language design (apart from using whitespace as syntax ;) that some other languages lack (in fact, it reminds me of Smalltalk in many ways, for this very reason). It has taken many of the features from various object oriented, functional languages, and scripting languages, and tied it up in a nice, clean, consistent little package.

    OTOH, Perl as a language is unbelievably flexible and convenient to work with, but it's most definitely a more "hackish" language, in that it's grown more than it's been designed. As such, it's definitely more of a developer's language (ie, has many of the features which, while not necessarily incredibly elegant, are *really* convenient) than a theorist's language.

    So, then, why pick one over the other? Frankly, in the end, I suspect it's just personal preference (or predjudice).

  24. Re:There's one major reason I choose Python over P by Tumbleweed · · Score: 2, Informative

    Isn't that reason _enough_? Some people may not know what they want, but just about everyone knows when they DON'T like something. Perl makes me itch.

  25. Re:Bad foundations. by Anonymous Coward · · Score: 0

    The result can be seen when you try to program a caller frame instance-preserving continuation in Python

    You're right. This sort of thing is attempted all the time by inexperienced C programmers who just don't know better than to try to program a caller frame instance-preserving continuation in Python.

    All these programmers who think Python will provide all necessary features clearly need to switch to C in order to get the high-level support they need for their applications.

  26. swallowing the flamebait by ultrabot · · Score: 5, Insightful

    Python is basically an attempt to merge Perl, TCL/TK and object orientated programming.

    No way in hell. Python tries its best to avoid perlisms, and TCL/Tk doesn't even come close. Python has a strongly typed object system with one namespace.

    I don't think that we really have to discuss the problems of Perl's "object system"

    Perls object system is a hack. Python object system fits like a glove. ISTR that Larry kinda "copied" the objsystem from Python (and not vice versa), but it didn't really fit perl.

    or the shortcomings of TCL/TK.

    Shortcomings of TCL/Tk have really nothing to do with the topic. Don't try to sneak TCL/Tk into this. This has got to be the clumsiest strawman argument I've seen in a while. Chewbacca lives on Endor?

    The result can be seen when you try to program a caller frame instance-preserving continuation in Python.

    What do you mean? Closures (or "nested scopes" as they are referred to in the language docs - look them up before whining) work as expected. Can you give an example of the thing you are talking about in a language you know (assuming you know one). Are talking about what Stackless Python is trying to do?

    But when the project advances they suddenly notice that python doesn't provide all necessary features and a whole rewrite is in order.

    You don't really need "features", you can use libraries to add "features" and the core language is flexible enough for pretty much any tasks.

    --
    Save your wrists today - switch to Dvorak
  27. Free Python Books by iamdrscience · · Score: 5, Informative

    Actually, if anyone is interested in learning Python and doesn't mind reading a book on their computer, there's a bunch of free ebooks available on the Python Documentation page (as well as a comprehensive list of books that are only printed). I've read a few of them, most of them are pretty good, in particular "How to think like a Computer Scientist" is a very good text for a less experienced programmer and Bruce Eckel's "Thinking in Python" is a nicely comprehensive coverage of Python (not unlike his "Thinking in Java" and "Thinking in C++" books).

    Even if you do mind reading books on your computer screen, most of these books (actually I think all of them) are also available as physical printed books as well.

    Thinking In Python by Bruce Eckel
    An Introduction to Python by Guido van Rossum, and Fred L. Drake, Jr. (Editor)
    How To Think Like a Computer Scientist: Learning with Python by Allen Downey, Jeff Elkner and Chris Meyers
    Dive Into Python: Python for Experienced Programmers by Mark Pilgrim
    Text Processing In Python by David Mertz
    Python Language Reference Manual by Guido van Rossum

    1. Re:Free Python Books by Anonymous Coward · · Score: 0

      Another online intro to Python I recently ran across that may be worth checking out is called "Dive Into Python" at http://diveintopython.org/

    2. Re:Free Python Books by Anonymous Coward · · Score: 0

      You mean the fourth book in the parent's list?

  28. Re:Bad foundations. by Waffle+Iron · · Score: 5, Insightful
    The result can be seen when you try to program a caller frame instance-preserving continuation in Python. The only thing that works is an unportable stack smashing like ole C's longjumps with added occultism with the garbage collector. This is a bigger problem than you might think, I often see young programmer to use Python at the start of projects because it's good for fast hacking. But when the project advances they suddenly notice that python doesn't provide all necessary features and a whole rewrite is in order.

    Yeah, it's really sad how many large projects fail because they're implemented in a language that doesn't properly support continuations....

    Wait a minute, I've been in the computer industry for decades, and other than myself, I could probably count on one hand the number of people I've met who even know what a continuation is. Other than as an amusing tool to utterly confuse any but the most advanced developers, continuations are probably only useful for coroutines, and coroutines are mostly useful for iterator generators, which recent versions of Python have generators nicely packaged in an easy-to-understand syntax (the yield statement).

    Since few if any other popular languages give you even this much, it must be truly amazing that any software works at all.

  29. Re:Python and Perl... by Anonymous Coward · · Score: 0

    There is nothing, and I do mean NOTHING that a real Unix professional can do with Python or Perl that he or she can't do with awk, sed, and grep.

    Proof of concept:
    Somebody write Slashdot in one of the above :)
    (Slashdot is written in Perl)

  30. Re:Python and Perl... by FuzzyBad-Mofo · · Score: 1

    Assembly Language? Overkill!

    Real programmers directly input hexcodes using cat or copy con..

  31. python runtime by chan518 · · Score: 4, Insightful

    One drawback sometime cited is its relatively slow execution speed compared to compiled languages such as C. this is the tradeoff between interpretation languages (python) and compiled languages (c, java). you get flexiablity in your code but you lose some speed in runtime. Well, most people use python to write scripts that are smaller than what they would write in C++ or java. you are not going to write half life 2 in python, right?...

    1. Re:python runtime by SharpFang · · Score: 1

      this is the tradeoff between interpretation languages (python) and compiled languages (c, java)

      Oh well, don't drag Java into that. Especially concerning speed.

      BTW, I'm not sure about python, someone please straighten this out - I bet it's similar, but Perl isn't "interpreted language" as such. It is some kind of hybrid: From user point of view it's interpreted, the program is its own source code etc. But from the system's point of view, it's compiled, only compilation takes place right before launching the program - when you type "./hello_world.pl" first it gets compiled to memory, and then the freshly compiled code is executed (as opposed to interpreted language where each command is evaluated before execution), so it's almost as fast as similar compiled languages, with maybe a bit more "startup time" but just as much "runtime efficiency".

      --
      45 5F E1 04 22 CA 29 C4 93 3F 95 05 2B 79 2A B2
    2. Re:python runtime by kublai+kahn · · Score: 2, Interesting

      For medium- to large-scale scientific computing, I've found that a mixture of Python and C/C++ gets me the right combination of speed and flexibility. I write the main number-crunching pieces of my code as objects in C/C++, then use SWIG to generate the wrappers necessary to interface my objects with Python. The control structures are all in Python, which is where I really want the flexibility.

    3. Re:python runtime by Just+Some+Guy · · Score: 2, Informative
      Python works on a similar concept, except that the first time you execute (or import) "foo.py", the interpreter writes the compiled bytecode back out to the filesystem as "foo.pyc". If foo.py and foo.pyc both exist, and foo.py is not newer than foo.pyc, then the runtime environment loads foo.pyc instead of recompiling the human-readable version. If foo.py is newer than foo.pyc, then it recompiles foo.py, overwrites foo.pyc as if it never existed, and continues on.

      I love this setup. Your program will start slowly exactly once, and after that first time, it will load the compiled version. If you edit one of the modules, then it automatically recompiles it for you. I'd be hard pressed to imagine a better way of doing it.

      --
      Dewey, what part of this looks like authorities should be involved?
    4. Re:python runtime by fredrikj · · Score: 2, Interesting

      If speed is critical, it might be a good idea to check out Psyco, which works sort of as a JIT compiler for Python. It's extremely simple to use in your code - just import the psyco module and make a function call to enable it. From what I've seen, Psyco typically makes Python code about three times faster. With "low-level" code, e.g. code that mostly performs arithmetic on ints and could be converted line-by-line to C code, the speedup is greater than that, easily ten times in realistic cases.

    5. Re:python runtime by ultrabot · · Score: 3, Interesting

      Well, most people use python to write scripts that are smaller than what they would write in C++ or java.

      Please don't confuse performance and size. Larger systems don't require bigger performance, performance is needed in tight inmost loops. And those you can implement in C while retaining the rest of the Python code.

      --
      Save your wrists today - switch to Dvorak
    6. Re:python runtime by bluGill · · Score: 1

      Back in the early 80s, many good games for the atari 800 series (running at 1.6Mhz) were written in interprited BASIC. Today I've used computers running at 2.4Ghz, and interprited languages are less respected because they are so slow now, than back then!

      Sure you can write faster code in C. You can get faster yet if you write in pure binary (though beware that the best binary for the P4 is different from the P3 is different from the althalon, and then there are various VIA and Transmeta CPUs with different optimal binary), if you have years to learn what makes a processor tick. In the end though, computers are fast regaurdless of which language you use.

    7. Re:python runtime by __past__ · · Score: 1
      his is the tradeoff between interpretation languages (python) and compiled languages (c, java). you get flexiablity in your code but you lose some speed in runtime.
      No, it is the tradeoff between efficient and less efficient implementations of a language. There are languages that usually come with rather fast implementations while being very dynamic and flexible, like Common Lisp, which is usually compiled to native code. (Of course, there are also completely crappy and inflexible languages that are slow and/or interpreted, but they shall remain unnamed)

      Not to mention that there are no "compiled languages" or "interpreted languages". This is a property of a single implementation, not a programming language. A python compiler would of course be possible, just as there are already C interpreters.

    8. Re:python runtime by kclittle · · Score: 1

      But the .pyc file is still a byte-code of somekind, yes? A JIT-enabled JVM emits real machine code, IIRC.
      Note, however, I still chose Python over Java for my latest project...

      --
      Generally, bash is superior to python in those environments where python is not installed.
    9. Re:python runtime by Just+Some+Guy · · Score: 1
      But the .pyc file is still a byte-code of somekind, yes?

      Yes, similar to a .java file.

      A JIT-enabled JVM emits real machine code, IIRC.

      Nope. The JVM executes bytecode. The JIT compiles the bytecode into native machine code and caches the results. Before a given block of code is executed, the JVM checks its cache to see if it's still stored, and if so, it executes the pre-compiled version.

      Note that there's no strong reason (that I know of) why the Python VM couldn't also compile Python bytecode into native machine code. The Parrot project is a VM that can execute Python and Perl bytecode (and several other languages, too) - it seems like a prime candidate for JIT compiling.

      --
      Dewey, what part of this looks like authorities should be involved?
    10. Re:python runtime by chromatic · · Score: 1

      Parrot does JIT on at least x86 and PPC already and can emit native executables.

    11. Re:python runtime by kclittle · · Score: 1
      A JIT-enabled JVM emits real machine code, IIRC.

      Yes, that was poorly worded, wasn't it! :)

      So, question: Could the cached native machine code be saved into a .exe and run (assuming the entire bytecode image was processed)? I.e., if there was a JIT for Python, could this be done --

      xyz.py -> xyz.pyc -> xyz.exe

      --
      Generally, bash is superior to python in those environments where python is not installed.
    12. Re:python runtime by Just+Some+Guy · · Score: 1

      Nifty! I hadn't looked at it in a long time and it's nice to hear that it's doing well.

      --
      Dewey, what part of this looks like authorities should be involved?
    13. Re:python runtime by Just+Some+Guy · · Score: 1
      First, note that Java doesn't do that either (in case you were comparing the two).

      Second, by definition, a JIT compiler runs immediately before the bytecode in question is to be executed. A system that turned the bytecode into native machine code would just be a plain ol' compiler.

      Third, Psyco might come pretty close to what you want, except that it doesn't write out a compiled binary.

      --
      Dewey, what part of this looks like authorities should be involved?
    14. Re:python runtime by NoOneInParticular · · Score: 1
      It's not really interpreted vs. compiled you're after here. Both java and python are compiled to bytecode and ran through a virtual machine. This is not why java is usually faster than python (especcially in the loop department). Also the JIT doesn't really matter, python got its own jit (psyco)

      The reason that java is faster than python usually is because of compile-time typing. Java compilers (the ones that create the bytecode), know much more about the runtime behaviour of the code, while python compilers can only do runtime type checking (does this function that is called actually exist? if not, throw runtime error). Compiletime types does help compilers. Unfortunately some early attempts in python to mix runtime and compile time typechecking have been abandoned.

    15. Re:python runtime by NoOneInParticular · · Score: 1

      SWIG is nice, but you might also want to checkout Boost.python. This combined with Pyste truly make for some tight and clean integration.

    16. Re:python runtime by kraut · · Score: 1

      Just to second that - psyco gives you a huge performance improvement in runtime intensive code in python, making a lot more things practical. Just think of Java in the pre-JIT days compared to now!

      --
      no taxation without representation!
  32. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 1, Insightful

    I prefer Ruby as well, but I can already see that it's not going to be a language I can spend lots of time learning right now. Although I like programming languages, I don't have enough free time to spend time learning a language that won't be immediately useful. For the record, when I need a scripting language, I use Perl unless the design needs to be object oriented, at which point I drop back into Ruby.

    I seem to have a different view of what a scripting language should be than most of the people who write them. I write scripts when a sudden need for a small program comes along. I need the script to not take a long time to write, even though I might not be ``current'' with the language. To me, the most useful scripting language would be one with strict syntax and a large mass of well documented libraries to dip into. No scripting language I've seen so far has strict syntax. ``There's more than one way to do it'' seems like it'd hurt you if you weren't well versed in the language and were trying to write a script that only needs to run once. It also seems like dynamic typing would hurt the effort as well. Eliminating as many points of unsureness as possible would be a boon. Java's syntax would make a terrific scripting language.

    Anyway, that's just my opinion. I don't mention large-ish software projects because I don't have lots of experience in them.

  33. While we're on the subject of Python by Anonymous Coward · · Score: 0

    Is this still the only modern language without a do-while loop? Do you still have to do the "while 1: ... if (!condition): break" thing?

    1. Re:While we're on the subject of Python by pclminion · · Score: 3, Interesting
      do-while is rarely useful. The few times I actually find a use for it in C, I find myself thinking "Wow... I get to use do-while today!"

      It's too easy to accidentally use do-while when you should have just used while. It actually makes the language less error-prone, because in those few cases where you do have an unconditional first pass, you are forced to structure the code differently and actually think about what you're doing.

      You can always transform: do stmt while foo into stmt while foo stmt which isn't even longer (if stmt is actually many statements, it should be a function anyway). It's not worth introducing an abusable language construct just so you get to be lazy and not code a function when you should.

    2. Re:While we're on the subject of Python by Teach · · Score: 1

      do-while is rarely useful... in those few cases where you do have an unconditional first pass, you are forced to structure the code differently.

      I beg to differ. do-while is extremely useful, precisely because it's for situations when the code is structured differently.

      I think the biggest difficulty conceptually is that most of the time you don't need do-while, you really want repeat-until, which C, C++, and Java don't provide. Which is a damn shame, since repeat-until maps more naturally to the brain. (Take this from a guy who's been teaching C++ and it's do-while to beginners for seven years now.)

      --
      Graham "Teach" Mitchell, computer science teacher, Leander HS
    3. Re:While we're on the subject of Python by Anonymous Coward · · Score: 0

      Is this still the only modern language without a do-while loop?

      Do you still have to do the "while 1: ... if (!condition): break" thing?

      Not necessarily, you can always do the initial assignment before entering the loop. I do this, because I can't 1) bring myself to use 1 (or True) as a loop conditional, nor 2) bring myself to use break as the 'normal' way to exit a loop. This is of course mere aethetics and introduces the problem of separating the initial from subsequen assigments to the test variable. In other words, you are clearly correct, Python desperately needs something similar to a do ... while loop.

  34. Troll.. by Anonymous Coward · · Score: 0

    This guy's sig. is the giveaway.

    1. Re:Troll.. by Anonymous Coward · · Score: 0

      I was reading his post and thinking "Well, I guess that shows exactly how useful a Mensa membership is".

      Apparently, being in Mensa doesn't preclude your being a retard.

  35. doubtful by gemseele · · Score: 1

    I've grown a large appreciation for Python. If it would just incorporate a few syntactic conveniences from Perl I would use nothing else. I was very resistant at first but now after writing a script in python, I somehow feel clean, like I've taken a shower.

    As for this book... I have the first edition and they're programming python book. I consider them both lousy and don't deserve the same names as the perl equivalent books in the same series. Other better books are available fortunately.

    1. Re:doubtful by Anonymous Coward · · Score: 0

      ...whereas after writing a script in Perl one feels dirty - like one has just dipped into a rancid cesspool of cobbled-together outdated unix command line barf and confusing syntax.

  36. Test of a language by pclminion · · Score: 4, Insightful

    One of the things I initially judge a language by is how elegant it is to code the quicksort algorithm (yes, I'm aware Python has a built-in sort function -- that is not the point). Here's quicksort in Python:

    def quicksort(list):
    if len(list) > 1:
    pivot = list[0]
    left = [x for x in list if x < pivot]
    right = [x for x in list if x > pivot]
    pivot = [x for x in list if x == pivot]
    return quicksort(left) + pivot + quicksort(right)
    return list

    I'd say this speaks for itself. Enjoy.

    1. Re:Test of a language by Anonymous Coward · · Score: 1, Interesting

      Woah. I never 'got' quicksort even from reading pseudocode (call me stupid if you wish). Now I am enlightened. Amazing.

    2. Re:Test of a language by Frater+219 · · Score: 1

      Your quicksort traverses the list three times in those spiffy list comprehensions.
      Try:

      def quicksort(list):
      if len(list) > 1:
      pivot = list[0]
      left, middle, right = []. []. []
      for item in list:
      if item < pivot: left.append(item)
      if item == pivot: middle.append(item)
      if item > pivot: right.append(item)
      return quicksort(left) + middle + quicksort(right)
      else:
      return list

      The /pons asinorum/ is actually the list initialization. This is the newbie way:

      left = middle = right = []

      ... which makes all three names for the same structure.

    3. Re:Test of a language by Anonymous Coward · · Score: 0

      Same here. Don't feel too bad. :-)

    4. Re:Test of a language by pclminion · · Score: 1
      Your quicksort traverses the list three times in those spiffy list comprehensions.

      Yep. Another "failing" of this implementation (and yours, too) is that it doesn't do the sort in-place, so it uses n log n memory. The in-place sort implementation is what makes most really fast implementations so hairy and difficult to understand.

    5. Re:Test of a language by janbjurstrom · · Score: 1

      Yes, you really wouldn't want to traverse the bridge of asses more than once. ;)

      --
      668.5
    6. Re:Test of a language by rokicki · · Score: 2, Informative

      While it's not in-place, it most assuredly does not use n log n memory in the typical case (although for a bad initial input, it *can* use n^2 memory). This implementation, for random input, uses O(n) memory. The n^2 memory problem can be solved by choosing a random pivot element.

    7. Re:Test of a language by pclminion · · Score: 1
      it most assuredly does not use n log n memory in the typical case

      Are you sure? In the typical case, the list is split evenly in half, with n/2 items in the left side, and n/2 items in the right. Therefore at recursion frame k there are n/2+n/2=n items in memory. Since the list will split log n times, there are log n recursion frames, which means n log n memory in use at the deepest level of recursion.

      Have I missed something subtle here?

    8. Re:Test of a language by pclminion · · Score: 1
      Ahh, yes I have missed something. The left and right sides at recursion level k don't temporally co-exist.

      I guess that shows I do much more time analysis than space analysis...

    9. Re:Test of a language by slinkp · · Score: 1

      Nice, except for one syntax error and one gratuitous optimization nitpick. Try this:

      def quicksort(list):
      if len(list) > 1:
      pivot = list[0]
      left, middle, right = [], [], [] # commas!
      for item in list:
      # don't perform unnecessary tests
      if item < pivot: left.append(item)
      elif item > pivot: right.append(item)
      else: middle.append(item)
      return quicksort(left) + middle + quicksort(right)
      else:
      return list

      Of course it's silly to argue about optimization of such an impractical example ;-)
      list.sort() is a wonderful thing.

    10. Re:Test of a language by NoOneInParticular · · Score: 1

      Nice to read this. In documentation I write, for API's or products written in any programming languague, but that need to be platform agnostic, I usually revert to giving examples in python. In my view its the most programming language independent programming language. The ultimate pseudo-code, pseudo-code that actually runs.

    11. Re:Test of a language by jasoegaard · · Score: 1

      Quicksort is a bad choice of algorithm for
      sorting lists. There is less overhead in
      using mergesort.

      --
      -- A Mathematician is a machine for turning coffee into theorems. - Paul Erdös
    12. Re:Test of a language by Anonymous Coward · · Score: 0

      -- A Mathematician is a machine for turning coffee into theorems. - Paul Erdos

      ``Renyi would become one of Erdos's most important collaborators. ... Their long collaborative sessions were often fueled by endless cups of strong coffee. Caffeine is the drug of choice for most of the world's mathematicians and coffee is the preferred delivery system. Renyi, undoubtedly wired on espresso, summed this up in a famous remark almost always attributed to Erdos: "A mathematician is a machine for turning coffee into theorems." ... Turan, after scornfully drinking a cup of American coffee, invented the corollary: "Weak coffee is only fit for lemmas." ''

      (Bruce Schechter, 1998)

    13. Re:Test of a language by slinkp · · Score: 1

      so? in a vhll who actually rolls their own primitive sort function anyway?

      the point was to demo the expressive flavor of the language, not a sort algorithm.

    14. Re:Test of a language by HiggsBison · · Score: 1
      I don't totally comprehend all of your code, but I have some suggestions. From what I've read in Knuth vol. 3, you should:
      1. choose a pivot which is the middle value of: the first, middle, and last elements. This nullifies the danger of an already sorted array being your extreme worst case.
      2. resolve the smaller of the 2 subsets first, to keep from blowing your stack space. and
      3. don't sweat the small stuff. whenever you are down to less than, oh... maybe 9 elements, do an insertion sort. At the low end of size, overhead is your worst enemy.

      All of this, however, probably defeats the point of posting a short, slick, piece of code. :-)

      --
      My other car is a 1984 Nark Avenger.
    15. Re:Test of a language by int18 · · Score: 1

      Whereas in Haskell...

      quick :: Ord a => [a] -> [a] --optional type specification

      quick [] = []
      quick (h:t) = quick [ x | x <- t, x < h] ++
      h :
      quick [ x | x <- t, x > h]

      although IMHO list comprehensions make more sense in declarative languages.

    16. Re:Test of a language by Anonymous Coward · · Score: 0

      ... and the builtin list.sort() probably does all this and more, so why would you try to rewrite quicksort from scratch (except as an exercise)?

    17. Re:Test of a language by fredrikj · · Score: 1

      Quicksort is a bad choice of algorithm for
      sorting lists. There is less overhead in
      using mergesort.


      Not true. Quicksort has less overhead than mergesort and is generally faster. However, quicksort's worst-case running time is O(n^2), whereas mergesort always operates in O(n log n). Mergesort also has the desirable property of being "stable", that is: objects that compare equal end up in their original order in the sorted list.

      And guess what? Python uses mergesort for its default list.sort() method.

    18. Re:Test of a language by pclminion · · Score: 1
      Not true. Quicksort has less overhead than mergesort and is generally faster.

      I think what he's referring to is efficiency on linked lists as opposed to arrays. Quicksort is slower than mergesort on lists because for each element of the list it has to decide whether to place that element into the left-hand sublist or the right-hand sublist, then fool around with a bunch of links. Mergesort has less overhead because you can just walk down to the middle of the list, and split the link there, without having to re-link a bunch of nodes onto different lists.

      And quicksort can be made stable, if you want it to be. I believe the implementation given by somebody who replied to my original post, was a stable sort. Depending on the behavior of Python's list comprehensions (i.e., whether they traverse the list in-order), my implementation is also stable.

    19. Re:Test of a language by fredrikj · · Score: 1

      I think what he's referring to is efficiency on linked lists as opposed to arrays.

      That makes more sense. And AFAIK, Python lists aren't linked lists.

  37. Silly trolling article writer. by Anonymous Coward · · Score: 5, Informative
    One drawback sometime cited is its relatively slow execution speed compared to compiled languages such as C.

    A mention of the Psyco Python runtime compiler is in order. It's simple to use as well - all you do is put this at the top of your entry script:
    import psyco
    psyco.full()
    All routines called are then compiled from bytecode on-the-fly into native x86 code. It's not quite as fast as C - but with Psyco you can easily get close, especially if you design your algorithms properly.

    While I'm here, these are the Python packages that I find essential once I have the base installation (which includes the IDLE IDE). I've used these packages under Windows, but most work on Linux as well:
    • Win32All - Windows 32 extensions & the Pythonwin IDE
    • wxPython - A GUI library based on wxWindows. Far superior to the included TCL/TK libraries.
    • Psyco - Runtime compiler, mentioned above
    • Py2Exe - Takes in Python scripts, spits out executables (note: use in conjunction with Psyco for best effect)
    • Boa Constructor - A wxWindows GUI design tool. It's a full blown IDE as well, but I have only used it to design GUI layouts, I code in Pythonwin.
    1. Re:Silly trolling article writer. by TeachingMachines · · Score: 1


      I've found the more flexible solution to creating an executable is to use McMillan's installer with UPX. I can create a distributable wxPython app at approximately 2MB with this combination.

      Python is lacking in several important areas: Multimedia (i.e., QuickTime integration) and wxPython's lack of a decent rich text widget were enough to force me to use Tcl.

      Steve

      --

      The Death Penalty: Killing people to show others that killing people is wrong.
    2. Re:Silly trolling article writer. by Peaker · · Score: 2, Interesting
      And the mostly unknown but extremely useful:

      Pyrex

  38. Re:There's one major reason I choose Python over P by Anonymous Coward · · Score: 0

    Speaking of blatantly and obviously wrong...

    C is weakly, statically typed. It will implicitly convert beteween incompatible values (pointers and ints, for instance)

    Not without an explicit typecast, it won't.

  39. Re:There's one major reason I choose Python over P by chromatic · · Score: 1
    Perl is weakly, dynamically typed.

    Alternately, Perl cares more about container types than value types.

  40. You need a book? by h4rm0ny · · Score: 5, Funny


    You need a book to learn Python?!??!!? My god, I'm an old C++ programmer, Python is like a gift from a god!

    You just have to bang your head against the keyboard a couple of times and I bet you it compiles! ;) Never used to be like that when I learnt to program.

    --

    Aide-toi, le Ciel t'aidera - Jeanne D'Arc.
    1. Re:You need a book? by Anonymous Coward · · Score: 0

      You just have to bang your head against the keyboard a couple of times and I bet you it compiles!

      No, that's Perl.

    2. Re:You need a book? by mariox19 · · Score: 1

      When people ask me, I often tell them: "If you know English and one programming language, you already know Python."

      It really takes anywhere from an afternoon to a weekend for someone who already programs to learn.

      --

      quiquid id est, timeo puellas et oscula dantes.

    3. Re:You need a book? by arrowman · · Score: 2, Funny

      You'd have to bang your head with proper indentation though.

    4. Re:You need a book? by Peaker · · Score: 1
      They perhaps know how to use a certain subset of Python, but it is quite untrue that there is not much to learn in Python.

      Unless the language they know includes:

      Lexical scoping

      Dynamic typing

      The same reference semantics

      Notion of Immutability

      Generators

      List comprehensions

      They really have a lot to learn still :)

      Sure, most of these are well-designed and simple features that don't take more than a few minutes to learn. To learn the whole Python syntax and its basic semantics really shouldn't take more than a week or two.

      However, to "know the language" is to know when to use those features and in my experience it takes almost a year to learn that. (You should still be able to create working programs before that though :)

    5. Re:You need a book? by MrWa · · Score: 1
      You just have to bang your head against the keyboard a couple of times and I bet you it compiles! ;) Never used to be like that when I learnt to program.

      You must be confusing Python with Perl...

    6. Re:You need a book? by mariox19 · · Score: 1

      Sorry, to mislead by my comment. When I say the whole "a programming language and English" thing, I say that as encouragement -- not to suggest that Python is trivial.

      I think Python is a terrific language.

      P.S.

      I have the first edition of O'Reilly's Learning Python by the way.

      --

      quiquid id est, timeo puellas et oscula dantes.

  41. Re:There's one major reason I choose Python over P by enjo13 · · Score: 1

    The spirit of what he's saying is absolutely correct, simply substitute 'static' with 'strong' and the point still holds.

    Jeez, it's good to issue a correction, but the error was in name only, the concept he was trying to express is still perfectly valid.

    --
    Turn s60 photos into awesome videos with mScrapbook for all S60 3rd edition phones!
  42. Re:There's one major reason I choose Python over P by smittyoneeach · · Score: 2, Interesting

    Boost.Python
    I sort of hope that Parrot will help Perl overcome its introversion, and let it integrate more readily with other languages.
    I think that C++ and Python form a dynamic duo. You can put the effort into compiling items that benefit from such, and glue them together in Python most agreeably.
    The C++ standard library focused on Platonic abstractions, but Boost is pulling C++ in more mainstream directions. And that's a beautiful thing.
    While issuing random plugs, check out Leo. It's not too often you see a fresh interface on an editor.

    --
    Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
  43. Python getting to big by gunga · · Score: 1

    "... at 591 pages, this is a major upgrade to the 366 page original. Furthermore, the Python language has undergone extensive improvements and additions in the last five years..."

    Sadly, I think Python has grown to large recently. It has lost part of its cohesion because of this. The language has been getting fatter as fast as this book between editions (+60 % pages, I mean c'mon). It doesn't fit it my head like it used to.

    1. Re:Python getting to big by gadgetman · · Score: 1

      Maybe your head is getting smaller!

      --
      Artifical Intelligience is no match for natural stupidity.
    2. Re:Python getting to big by Da+VinMan · · Score: 1

      Get a bigger head. Seriously, the amount of background knowledge one needs to be productive in Python vs. C++ (or even Java) is trivial. You don't have to remember it all; just keep a reference handy.

      Criticizing Python because of the new features, modules, etc. really isn't warranted. Python hasn't lost its cohesion. You simply haven't kept up.

      And yes, I have done Python full time. And yes, it was about 3 years ago. So yes, I will need to catch up at some point too. But it's not anyone else's fault that I haven't done so yet.

      I just need another Python project. :+)

      --
      Please mod this post only if you think others should/n't read this. I have enough ego^H^H^Hkarma. Thanks!
    3. Re:Python getting to big by Anonymous Coward · · Score: 0

      You simply haven't kept up.

      This is why Python gets on my nerves. It used to be cool when there was "one way to do it". Now Python (and the Python community) is slowly mirroring Perl (everybody wants to use the latest language feature to show off .. and the language keeps sprouting new features to correct design flaws in the previous version of the language, yet still maintain backwards-compatibility).

    4. Re:Python getting to big by Da+VinMan · · Score: 1

      There is some merit to that. It does keep changing, and that can be irritating. But, most of the changes provide new functionality in the language. You don't *have* to use them. And respecting backward compatibility means you can blithely ignore new features and continue on in the usual fashion.

      BUT....

      You'd be missing out. Everyone gets bugged by how much things keep changing, and it is a problem. But what's the alternative? I've worked on VB, VB.NET, Java, and Python projects and they all keep changing at high speeds. Every project is a learning experience. Almost no project feature is cookie cutter from the get-go, it always takes some exploration.

      On the other hand, I've got a buddy for whom that is almost never a problem. Every project he works on is almost the same. But then, he's using COBOL, CICS, and JCL. He's got different problems from mine, and I'll take my bag of problems instead of his any day.

      --
      Please mod this post only if you think others should/n't read this. I have enough ego^H^H^Hkarma. Thanks!
    5. Re:Python getting to big by gunga · · Score: 1

      "Get a bigger head."

      Obviously talking about the size of my head was intentional, see http://www.cs.utexas.edu/users/EWD/ewd03xx/EWD340. PDF

      Yes, I haven't kept up, this is the point. Python's simplicity was it's single most useful feature. Judging from other comments, I'm not the only one to think the Python hackers are more keen to show their cleverness than to strive for simplicity.

      Recently, I'm finding Ruby has more conceptual integrity.

  44. Re:There's one major reason I choose Python over P by Just+Some+Guy · · Score: 1
    I love Perl. I've done more application programming in Perl than any other language. Still, when I first tried Python, I never looked back. The main thing, for me, is that Python and Perl seem to live in the same solution space; the set of problems I'd use them to solve is pretty similar. Python lets me do all of the stuff I'd been doing in Perl more easily and with fewer errors, while still providing access to all of the good stuff from Perl (Python's "re" regular expression module is essentially identical to Perl's regexp engine - I believe they reused much of Perl's code to implement it).

    Does that answer your question, or is it more of the same stuff that was confusing you?

    --
    Dewey, what part of this looks like authorities should be involved?
  45. Re:There's one major reason I choose Python over P by craigmarshall · · Score: 1
    Python is strongly, dynamically typed

    Ugh? Bruce Eckel says in his book (Thinking in Python) that Python is weakly typed:
    Python is a weakly-typed language, which means it puts the minimum possible requirements on typing. For example, you could pass and return different types from the same function.

    Now I'm really confused!

    Craig
  46. What would be nice ... by DrSkwid · · Score: 1


    Is a book review that wasn't for lavae.

    It's like going to the local bookstore and hoping for something more to buy than Learn VB in 24 Hours.

    --
    There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
  47. Re:There's one major reason I choose Python over P by Anonymous Coward · · Score: 0

    That's what conversion constructors are for.

  48. Re:There's one major reason I choose Python over P by scrytch · · Score: 1

    > but does python have any merit of its own, or do people only use it because they don't want to use perl?

    This turned me off of python for a while, and through the 1.x series of python, the answer was pretty much that python indeed did not have much over perl. I'm astonished perl still doesn't have formal parameters, but that's more a glaring lack in perl than a novel feature in python. Lack of funky "decorations" on variables ... again a perl wart most other languages don't already share.

    Now python has generators, list comprehensions (coming soon, generator comprehensions), the stackless variant (alas never to be merged into python core I suspect), cycle detection in the GC (perl will still let them dangle), extensible builtin types (you can even subclass int if you want to)... There's a raft of PEP's on track for the next revision of Python, which comes out on a pretty regular schedule, so the language development tends to iterate faster than any other I've seen.

    It still doesn't hold a candle to lisp or even scheme for sheer flexibility and potential expressiveness (with scheme I stress "potential", it takes lots of work to get comfortable with scheme), but for dynamic languages, it's currently my favorite. I still do use perl for things in CPAN that are nowhere else, e.g. Net::DNS has no credible equivalent in python.

    Ruby looks interesting in some ways, but I don't like its total lack of a naming convention or namespace protection for "builtin" methods, nor the extra-funky syntax concerning blocks and yields. It also doesn't seem to work very well on windows, the parser seems to outright choke on line ending conventions with code pasted from a browser. It's also really poorly documented -- I realize english isn't the native language for the Ruby community, but even API documentation is sorely lacking in organization.

    --
    I've finally had it: until slashdot gets article moderation, I am not coming back.
  49. Re:Python and Perl... by Bimble · · Score: 2, Insightful

    Heh. Sure, I _could_ write something with awk and sed to modify XML files a developer sends me. The question is, would anyone but me be able to understand the script well enough to modify it? Heck, could I, if I didn't have to do anything with it for a year?

    --
    Naked.
  50. I would love to use Python by shaka999 · · Score: 4, Insightful

    I'm a long time perl programmer. Recently I did some research into Python. It really does look to be a more elegant language and enforce some structure that is needed in Perl.

    That said I can't justify the switch. There are just too many good modules available in Perl (esp for the engineering work I do). When python has the bredth of packages that Perl does, and when they have a nicely organized way to access said modules, I'll be happy to switch.

    --
    One should not theorize before one has data. -Sherlock Holmes-
    1. Re:I would love to use Python by jalet · · Score: 1

      > When python has the bredth of packages that Perl
      > does, and when they have a nicely organized way to
      > access said modules, I'll be happy to switch.

      Guido van Rossum, is that you ?

      --
      Votez ecolo : Chiez dans l'urne !
    2. Re:I would love to use Python by Peaker · · Score: 1

      What functionality are you lacking from the standard library and the The Vaults of Parnassus?

    3. Re:I would love to use Python by Anonymous Coward · · Score: 0

      hey Karma Whore, you were already called on this stupid "[n], is that you?" trick once in this article. How many times are you going to repeat the same stupid trick?

    4. Re:I would love to use Python by jalet · · Score: 0, Redundant

      > How many times are you going to repeat the same
      > stupid trick?

      IBM lawyer, is that you speaking to Mc Bride ?

      --
      Votez ecolo : Chiez dans l'urne !
    5. Re:I would love to use Python by darekana · · Score: 1

      That said I can't justify the switch. There are just too many good modules available in...

      Sounds like the argument for not moving to Linux... wait I'm using Windows... but I like Python. Now I'm confused.

    6. Re:I would love to use Python by Anonymous Coward · · Score: 0

      How about the equivalent to Text::Template?

  51. Re:A nice comparison of Python with other language by Tyler+Eaves · · Score: 2, Informative

    Total agreement.

    I've used python for several years, but only 2 weeks after stumbling across "Programming Ruby" (Available free at http://www.rubycentral.com/book/), I've switched all new development to Ruby. As a language, it just clicks for me. It's like the best of all possible worlds. It brings in the cleanliness of Python (without the whitespace issues, for those who dislike that), the hack value of Perl (tightly integated regex, etc), the OO of smalltalk/java (for those that like that kind of thing), and essentially anonymous functions like a functional language. Many things are expressed in a very logical manner, and this allows you to concentrate on how to accomplice a task.

    A comparison:

    Python

    adict = {'key':'val','key2':'val2','key3':3.14}
    for k in adict.keys():
    ----print 'k -> '+str(adict[k])

    Ruby

    adict = {'key'=>'val','key2'=>'val2','key3'=>3.14}
    adict.each{|k,v| puts k,' -> ',v}

    --
    TODO: Something witty here...
  52. Re:Python and Perl... by Anonymous Coward · · Score: 0

    Right on man!! Here's my code for getting system time in os/390:

    00000E 4110 0002 00002
    000012 0A0B
    000014 5000 30EE 000F4
    000018 D100 30F1 315A 000F7 00160
    00001E D205 30F2 30F8 000F8 000FE
    000024 DE05 30F2 30EE 000F8 000F4
    00002A 41F0 30F2 000F8
    00002E F805 000F 30F2 0000F 000F8

    It works!! And look at the address range, only 32 bytes of code for the whole operation!! :D

  53. Re:There's one major reason I choose Python over P by Anonymous Coward · · Score: 0

    That's because the two people discussion the issue (poster and your author) have defined what it means to be weakly-typed differently. Without using a strict definition, this is what happens. Rigor folks, please, it's the only way to come to conclusions. No more off the cuff comments on CS topics. Prove it or shut up.

  54. Re:1st edition = PAPERWEIGHT by gabec · · Score: 3, Interesting
    The first edition helped me get my current job (y'know, the one I'm ignoring by reading slashdot *right now*). My "interview" was to create a fully-formed dynamic website in one week using only python. The idea being that if you can learn a whole new language in a week and get a real project off the ground then you're the kind of guy they're looking for.

    Anyway. I immediately ran off to the nearest bookstore and grabbed the first edition of the book. I read it once through and it--along with a lot of googling--helped me understand what I was doing, but once I had gone through it once I couldn't use it to recall the details of what I had been taught. If I wanted to look up something that I knew I had learned *from the book* I would have to look it up *on the web* (e.g. syntax or the required parameters of a function) because the index was useless. I never found anything I needed from that book once I did the initial once-through reading.

    Though let's not gloss over the fact that I obviously learned python fairly well from this book because I did get the job! So sure, if you need to learn the language, the first edition did the job, but you'd better buy a *real* python book while you're there at the bookstore because as soon as you were done with Learning... it was nothing more than a paperweight.

  55. Re:There's one major reason I choose Python over P by Anonymous Coward · · Score: 0

    Perl is great for UNIX scripting, but once you pass a certain point, it begins getting unwieldy (IMHO).

    Python is a very powerful language, but the whole concept of scope being dependent on indentation drives me nuts. I ran away screaming in frustration after a while.

    That being said, it beats the hell out of APL.

  56. Re:Python and Perl... by scrytch · · Score: 1

    > Real programmers directly input hexcodes using cat or copy con..

    Amateur. Real programmers use nothing but S, K, and apply.

    --
    I've finally had it: until slashdot gets article moderation, I am not coming back.
  57. My review by tarzan353 · · Score: 2, Insightful

    It gives a thorough description of how to use Python; which is indeed easy to learn if you already know another language. But when the authors say that not having to compile Python programs means that development time is speeded up, perhaps they are overstating. For most programmers who use compiled languages like C or C++, the biggest time is taken up in finding a method that solves a problem, coding it and subsequent debugging. These days, compilers on recent hardware are fast enough that link/compile times are simply not a bottleneck to development productivity. So it is a bit of a straw dummy that the authors put forth.

    However, they are absolutely spot on when comparing this to Perl or Tcl. Perl is powerful, but its code looks like assembler. Perl gurus tend to shrug when you point this out, usually saying they understand it, with the not-so-implicit suggestion that if you can't, it is your fault. But this leads to a real maintenance problem and a barrier to entry to others. The cleaner Python syntax can show coding intent far clearer. Plus, and more importantly, the object oriented nature of Python lets you scale up to much larger programs. This has always been a problem with scripting languages, all the way back to the various unix shell scripts and DOS bat files. Often, the most those ever gave you in terms of modular capabilities was the equivalent of subroutines. Which is strictly procedural and not OO.

    By the way, there is a small contradiction between the above claim that Python is more understandable than Perl and the claim that it has an advantage over C++ or Java because it is not as verbose as those. Typically, in increasing amount of source code, you have Perl -> Python -> (C++,Java). If you think that Python is more understandable than Perl, then by that same logic, we could conclude that C++ or Java is more understandable than Python.

    So if you are using Perl or Tcl and want something better, Python is a good choice. A good upgrade path.

    But if you are currently using C or C++, with maybe X for graphics, or Java, then I suggest you stay with those. All three languages, with their graphics, give you a far richer toolset. Python would be a retrograde choice.

    1. Re:My review by ultrabot · · Score: 1

      But if you are currently using C or C++, with maybe X for graphics, or Java, then I suggest you stay with those.

      Perhaps they might want a more Agile language, instead of clunky C++/Java they are using at the moment? Going with Python, they can retain the scalability while developing code/unit tests/prototypes much faster. Being primarily a C++ programmer, getting to program in Python is extremely liberating. It feels like being able to talk fluently again, instead of measuring every word carefully and then translating them to mandarin china with an unalphabetized dictionary.

      All three languages, with their graphics, give you a far richer toolset.

      This might be true w/ Java, but not w/ C++. Also, Python libraries are always easier to use and learn in my experience.

      --
      Save your wrists today - switch to Dvorak
    2. Re:My review by pclminion · · Score: 1
      These days, compilers on recent hardware are fast enough that link/compile times are simply not a bottleneck to development productivity.

      Apparently you've never worked on a project with a "core" header file that gets #include'd by about 5000 source modules. Make one little diddly change to that header and you have to recompile 5000 files.

      It can sure as hell be a massive waste of time. Now, whether or not it's good practice to structure your program in such a way that everything depends on a single header, is another issue entirely...

    3. Re:My review by Tikiman · · Score: 3, Informative
      Perl is powerful, but its code looks like assembler

      Important correction - Perl can look like assembler... but it doesn't have to. A Perl script can be as clean and readable as you want it to be. Ugly code is a result of lazy programmers, not the language itself.

    4. Re:My review by Anonymous Coward · · Score: 0

      So if you are using Perl or Tcl and want something better, Python is a good choice. A good upgrade path.

      And when you get tired of that, try Ruby!

      Seriously, if you're somebody that loves both OO and Perl, you'll find Python awkward. On the other hand, wait a while, and it will become much more like Ruby (it's starting to already with generators and new-style classes).

    5. Re:My review by Snebjorn · · Score: 1

      As far as I can tell a programmer's status in the Perl community is directly linked to his/her ability to write code that looks like assembler. The language doesn't enforce this, it's a cultural phenomenon.

      The Python culture, on the other hand, seems to favour clearness and apologies in the comments for weird constructs.

      Snebjorn

      --
      Faster-Harder-Louder
    6. Re:My review by empty · · Score: 1

      So you are the "Dr Wes Boudville" that posted the same review on bn.com and amazon.com? You reviewed an awful lot of books on Amazon...how are you able to afford $600 for an out-of-date semiconductor book (Defect Control in Semiconductors) or $1155 for Van Nostrand's Encyclopedia? Amazing....

    7. Re:My review by Phoukka · · Score: 1
      You wrote:
      By the way, there is a small contradiction between the above claim that Python is more understandable than Perl and the claim that it has an advantage over C++ or Java because it is not as verbose as those. Typically, in increasing amount of source code, you have Perl -> Python -> (C++,Java). If you think that Python is more understandable than Perl, then by that same logic, we could conclude that C++ or Java is more understandable than Python.


      There is no contradiction. Verbosity and ease of understanding are orthogonal. To the average reader, Shakespeare is verbose compared to modern English, and is less understandable.

      The usual contention is that Java et al. inflate source code with unnecessary type declarations, block delimiters and other punctuation, while Python avoids these bits of syntactic fluff. Python is less verbose than Java, and as a result is more easily understood.

      You also wrote:
      But if you are currently using C or C++, with maybe X for graphics, or Java, then I suggest you stay with those. All three languages, with their graphics, give you a far richer toolset. Python would be a retrograde choice.


      Python gives you no graphics toolkits at all, and as a result, is far from a retrograde choice. Instead, there are Pythonic wrappers for just about every extant graphics toolkit: Qt using PyQt, GTK using PyGTK, Tk using Tkinter, wxWindows via wxPython, Win32 via win32all, Aqua using PyObjC, Swing or AWT using Jython, Fox, and more. Using such a wrapper allows you to program your GUI in Python, with (generally) Pythonic GUI code, which then calls the toolkit. This kind of integration with other libraries is one of Python's strengths: program in Python, with Python's efficiency and readability, while making excellent use of available libraries for increases in speed and additional functionality.
    8. Re:My review by MechaStreisand · · Score: 1
      By the way, there is a small contradiction between the above claim that Python is more understandable than Perl and the claim that it has an advantage over C++ or Java because it is not as verbose as those. Typically, in increasing amount of source code, you have Perl -> Python -> (C++,Java). If you think that Python is more understandable than Perl, then by that same logic, we could conclude that C++ or Java is more understandable than Python.
      That is false logic, sir. No one said that Python is more understandable than Perl because it needs more source code to express a given idea. Those two simply happen to both be true in this case. (According to many.) It's possible to have a language that is really verbose and not any clearer than another language that's more compact. (Take Brainfuck, for instance.) And when you do, you'd call the more compact language a higher-level language than the more verbose one.
      --
      Disclaimer: IANAL. This post is, however, legal advice, and creates an attorney-client relationship.
    9. Re:My review by empty · · Score: 1

      Hmmm...upon re-reading my post, it sounds like I am being sarcastic, but actually I'm not. I'm genuinely interested.

  58. Re:There's one major reason I choose Python over P by craigmarshall · · Score: 1
    And another.
    Because Python is weakly typed, it doesn't really care about interfaces - all it cares about is applying operations to objects (in fact, Java's interface keyword would be wasted in Python).
    Craig
  59. Re:Bad foundations. by Anonymous Coward · · Score: 0

    good god ...

    "your" .... not "you're" ...

    it never ends!

    it's "lose" ... not "loose" (not in this article, just reminding. You're getting too loose with your English and you may lose your grasp.)

  60. Re:A nice comparison of Python with other language by Strike · · Score: 1

    Actually, the python version would be:


    adict = {'key': 'val', 'key2': 'val2', 'key3': 3.14}
    for key in adict:
    print 'k -> ', adict[key]

  61. Re:A nice comparison of Python with other language by Strike · · Score: 1

    Oops, I translated the error too :)

    make that last line:

    print '%s -> %s' % (key, adict[key])

  62. Good point, but the review did say.. by janbjurstrom · · Score: 1

    ..the book had a lot more information on many topics, which in this case would warrant the extra pages. Plus, I have the 1st edt. of this one (very good intro to Python, btw), and have read some other stuff by Lutz, and he is not verbose. I don't think he suddenly would change his style and pad a good first book with a couple of hundred pages of fluff.

    Wouldn't you know it, I just convinced myself to get this edition too :).

    --
    668.5
  63. Re:A nice comparison of Python with other language by Freedom+Bug · · Score: 4, Insightful

    Excellent example:

    1) I prefer the Python example. It's easier to read. And easier to write the first time. That's the reason Python is better than Ruby: when you write code, you get it right the first time more often. And that's such a huge advantage.

    Of course, you screwed up. (I assume you wanted to print the value of k rather than the letter k)

    2) You used a comprehension in Ruby but not in Python. And adict.items() would have been easier than adict.keys()

    To be more fair:

    adict = {'key':'val','key2':'val2','key3':3.14}
    [sys.stdout.write(k+'-> '+str(v)+'\n') for k,v in adict.items()]

    But if I was writing the code, I'd use a for loop rather than a comprehension.

    But for penis length competitions, we'll use the latter.

    Bryan

  64. actually... by violently_ill · · Score: 2, Interesting

    actually an enormous game has been written in "stackless" python: EVE online. the reviews of EVE have been mediocre, but most have complimented the game's graphics. it's also an enormous world with all kinds of complex rules. according to the developers, it wouldn't have been possible without python.

    i think EVE proves that python is ready for big projects, even when performance is critical.

    1. Re:actually... by Anonymous Coward · · Score: 0
      Are these the 'mediocre' reviews you are refering to:

      http://www.eve.is/community/reviews.asp

      and

      http://www.eve.is/community/awards.asp

      Looks good enough to me ;-)

      But it's true, Python seems quite feasible for such large projects.

  65. Re:Python and Perl... by Anonymous Coward · · Score: 0

    dude, don't feed the trolls

  66. Re:There's one major reason I choose Python over P by Camel+Pilot · · Score: 1

    get lost in the quagmire of lists, arrays, scalars, references, etc.

    uh? Care to differentiate between lists and arrays? Or are you trying to spread a little FUD to make it sound more complicated then it is.

    Explain how using and referencing extra dimensional data types (list and hashes) are different in Python.

  67. No, It's Just Slow by (eternal_software) · · Score: 0, Troll

    See here:

    http://osnews.com/story.php?news_id=5602

    C# is the second fastest language in their benchmarks, only trumped by C++, and it is an interpreted language. So your logic falls apart.

    Python scores some pretty abysmal benchmarks compared to all the other languages, including Java. So I'd say, it's just slow.

    1. Re:No, It's Just Slow by finkployd · · Score: 1

      They would have found C to be the fastest of all ("all the performance of assembly with all the ease of assembly" :) ) if they had actually used a decent compiler like Intel's or something. GCC is a VERY nice cross platform compiler realistically I don't know anyone who uses it in HPC.

      Finkployd

  68. Re:There's one major reason I choose Python over P by Anonymous Coward · · Score: 0

    EXCEPT when it comes to using a single character (domino) to solve simultaneous linear equations :)

    and what - is the number of characters in a program to convert roman numeral characters to arabic still something along the lines of 34-37 characters?


    Of course it beats the prunes out of APL. APL will siphon the cyles out of practically any machine it touches.

  69. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0

    List comprehensions are confusing and violate Pythons "one way to do it" philosophy, if you ask me. They are confusing because they are basically multi-argument operators:

    foo for bar in baz if quz

    also like the C ternary operator

    foo ? bar : baz

    I try and avoid things like this that take more than instant to mentally parse.

    PS: if Python is so clear and easy to write why do people constantly say "well, if *I* were writing that code in python, I'd do ...." ??

  70. Re:There's one major reason I choose Python over P by Anonymous Coward · · Score: 0

    yup, and that's exactly why a mediocre language like Python is winning against a horrible language like Perl!

    it's a shame really...

  71. Pricing by Anonymous Coward · · Score: 0

    Try one of these: AddAll, BookPool, Best Book Buys. Unfortunately, Froogle can't compete this time.

  72. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0

    Maybe I am some kind of a mutant or something but the Python example was way easier for me to understand than the Ruby example.

  73. Re:A nice comparison of Python with other language by jalet · · Score: 1

    for key,value in adict :
    print "%s -> %s" % (key, value)

    --
    Votez ecolo : Chiez dans l'urne !
  74. Re:A nice comparison of Python with other language by jalet · · Score: 1

    for key,value in adict.items() :
    print "%s -> %s" % (key, value)

    sorry

    --
    Votez ecolo : Chiez dans l'urne !
  75. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0

    Wow... Are you writing your posts with a typewriter?

  76. Re:There's one major reason I choose Python over P by __past__ · · Score: 2, Insightful
    Python is strongly, dynamically typed
    Ugh? Bruce Eckel says in his book (Thinking in Python) that Python is weakly typed:
    This has a simple explanation: Bruce Eckel uses the terms incorrectly, even if he may otherwise be smart. So do many others, hence the amount of confusion over these issues.
  77. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 1, Insightful

    Same here..

    I tried Python at first and found it much nicer than Perl. Like many others I was hungry for a non-compiled, object-oriented language which was for large projects, not just quick hacks. Someday, computers will be fast enough so that all our coding is done in these languages.

    But immediately the "object model" if you want to call it that got on my nerves. Why "len(list)" and not "list.len()"? Why "'\n'.join(array)" instead of "array.join('\n')"? What's with the simplistic scoping? Why all the underscores? Why "self" everywhere, and why is it so unpythonic to just call it "s" instead? Do I really have to type parantheses all the time? Where are the first-class regexps? Does it make sense that for many built-ins, "foo(obj)" calls "obj.__bar__", why not just use "obj._foo()" directly and eliminate "foo()" from the language.

    Lots of other people found it much nicer than Perl, and jumped on the bandwagon .. that's fine, but Python is half-baked. I'm confused why people say it is so great and elegant. Is it just because it's NotPerl(tm)? (I actually like the whitespace parsing in Python, btw).

    I guess I'm one of those weenies that believes all languages eventually become Lisp or Smalltalk, and any sharp corners that vary from those models will eventually be "filed off". I tried Ruby and discovered it was much more like Smalltalk. Very elegant and easy to write code. And coming from Perl, it has much of the power of Perl but in an object-oriented way. Unfortunately Python stole the thunder and now python has the great docs and 3rd-party libraries, while Ruby lingers and grows slowly.

    And Python has the arrogant, Perl-like community now, that thinks jamming list comprehensions and generators into everything makes you "cool". Why do they think it's so cool to reduce the number of lines in a program? I own the "Python cookbook" and find it highly irritating. Rather than solving problems in a single elegant and general way, it presents each author's particular 'leet Python skills, and usually 4-5 different solutions (in a language that claims "one way to do it"). I found it very unhelpful, and again was confused when people said it was such a great book.

    Python is moving in the right direction though. My fear is that someday it will be possible to write very elegant code in Python, yet still have to support all the Python 1.5 code out there, so the language will be a huge mess. Some may argue that it is already becoming a mess. I think Guido should come out with Python 3 and make it totally non-backwards compatible.

  78. Re:A nice comparison of Python with other language by pnatural · · Score: 1

    The poster should not have used a list comprehension to call sys.stdout.write.

    My rule of thumb: if I don't need the results of a list comprehension, it's probably best written as a regular for loop. The fact that the original poster used 'sys.stdout.write' when he wanted to print something is a dead-giveaway (print is a statement, which is why it's not valid in the list comp):

    This:

    [sys.stdout.write(k+'-> '+str(v)+'\n') for k,v in adict.items()]

    Could have just as easily been written (more clearly) as:

    for k, v in adict.items():
    print '%s -> %s' % (k, v)

  79. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0

    It took a lot of tries to get that right. Imagine now how hard it would be to debug your program if you only had a tenuous grasp of the language, and some of those incorrect forms didn't produce errors.

  80. Re:A nice comparison of Python with other language by Electrum · · Score: 1

    The Ruby version is half the length of the Python one, and much more readable. "sys.stdout.write" manages to be both verbose and full of idiosyncratic abbreviations.

    [print k+' -> '+v for k,v in adict.items()]

  81. Python vs Java by hey! · · Score: 1

    I picked it up a few years ago around the same time I was picking up Java, so I tend to compare it with Java. Initially I used them both for simple applications like XML processing and filtering.

    Generally speaking, I liked Python quite a bit, especially the identation delimeting code blocks thing quite a bit, especially the visual cleanness of the code (although this was slightly offset by the need to dereference member variables with "this->"). I found the module system a bit squirrely, especially the execution on load thing.

    In the end I ended up gravitation towards Java for larger and more complex projects, because of its larger and highly useful non-proprietary library and frameworks, although Python is no slouch in this department either.

    I can understand the parent post's enthusiasm for Python. It's an innovative and fun language. However I'm a bit skeptical about claims for its superiority in productivity. Truly, I can't see where the magic pixie dust is here.

    If a Lisp partisan tells me that Lisp is 10x more productive on some applications because of the whole program as data thing, or Lisp's language extensibility, I can understand this whether or not a I choose to agree with it. What I don't see is why an experienced and fairly expert coder should be much if any more productive in Python than Java, since they tend to promote similar garden variety OO architectures.

    --
    Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
    1. Re:Python vs Java by jnana · · Score: 2, Insightful
      Python and Java are the two languages that I know best. I've used Java considerably more than I have Python, yet I write Python applications much more quickly than Java. The key differences to my mind are 1) the interpreter, for 'dir(foo)' and 'help(foo.bar)' {so much quicker than searching the javadocs, especially when you consider non Sun java packages}; 2) the interpreter, for quickly testing code snippets and experimenting; 3) higher-level data structures (compare Python list to java.util.ArrayList), which means more bang for the buck in terms of lines of code required to do something; and 4) the lack of checked exceptions in Python (many supporters of Java's checked exceptions have changed their mind about the wisdom of this, people like Bruce Eckel, who not-coincidentally is now a very big supporter of Python and dynamic typing and non-checked exceptions (after learning python) where previously he thought static typing and checked exceptions were superior (i'm not saying that typing and exceptions are related, but they're both prominent features of java that I feel slow progress).

      I'm probably forgetting quite a few things, but probably the most important difference for me is that I remember Python very easily, because it's simpler (compare java IO to python IO for a particularly egregious example), whereas if I don't use Java for a while, then I have to consult reference material a lot. I don't think I'm particularly abnormal in this respect, as I know plenty of other people who've observed similarly.

  82. Re:There's one major reason I choose Python over P by pclminion · · Score: 1
    Hey, let's throw static/dynamic scoping into the mix just to further confuse people: Python is a strongly, dynamically typed language with static variable scoping :-)

    Not that there are a great many dynamically scoped languages around these days...

  83. And if I can learn it, so can you by Scot+W.+Stevenson · · Score: 1
    The thing that is really cool about Python is that it is so easy to learn the basics - "fits your brain" indeed. I have a non-IT day job and after years of programming nothing more demanding than our video recorder, I wanted to learn a new language. The problem: The only time I really have to study is on Berlin public transport.

    That didn't work with Java -- I couldn't even remember that long initialization thingy at the start from sitting to sitting. Freshing up C was to much of a problem, since I was never good enough for it to go subconscious and it takes forever to even say "Hallo World" -- and I have neither the time nor the problems that require such a low level language. Perl looked fun for a while, but two months later I couldn't figure out what I had been trying to do.

    So at some point I found Python, and used Learning Python, First Edition as my introduction. If the Second Edition is even close, go for it. Beautiful language, very friendly people on the Tutor list, and if I'm forced to take a few weeks off from the keyboard, I can come right back and still be productive.

    No, I will never be a real programmer, let alone a "Hacker", but I am able to get the computer to do the few simple things that I want it to do. Thanks to Guido van Rossum and his cast of thousands for a free, simple but powerful language that lets us mere mortals do just that.

  84. So, ... by Anonymous Coward · · Score: 0

    How's that "[n], is that you?" gig working for you?

    >>> import karmawhore
    >>> print karmawhore.firsttimeoffenders?
    jalet, ...

    1. Re:So, ... by Just+Some+Guy · · Score: 1

      Sublime, AC. Well done - on-topic and all. :-)

      --
      Dewey, what part of this looks like authorities should be involved?
    2. Re:So, ... by Anonymous Coward · · Score: 0

      Why thank you, glad to see ones (admittedly small) efforts not disappearing totally unnoticed below the +1 radar :).

  85. Re:1st edition = PAPERWEIGHT by Da+VinMan · · Score: 1

    Incidentally, what have you found to be the best ways to code a dynamic website in Python? I know about Zope and have used it a bit, but are there other compelling options?

    --
    Please mod this post only if you think others should/n't read this. I have enough ego^H^H^Hkarma. Thanks!
  86. Re:Bad foundations. by Electrum · · Score: 2, Informative

    Other than as an amusing tool to utterly confuse any but the most advanced developers, continuations are probably only useful for coroutines, and coroutines are mostly useful for iterator generators, which recent versions of Python have generators nicely packaged in an easy-to-understand syntax (the yield statement).

    Continuations are also incredibly useful for massively scalable network applications. They are arguably the best way to write them, in terms of code readability and performance.

  87. Re:There's one major reason I choose Python over P by amightywind · · Score: 1

    There's one major reason I use scheme instead of silly languages like Python or Perl, lack of static typing. Scheme's type predicates are much more flexible.

    --
    an ill wind that blows no good
  88. Re:A nice comparison of Python with other language by Peaker · · Score: 1

    adict = {'key':'val','key2':'val2','key3':3.14}
    for k, v in adict.iteritems():
    print k, '->', v

    I think this is actually more readable than Ruby's "each" function which is a weaker alternative to iteration.

  89. Re:A nice comparison of Python with other language by Tyler+Eaves · · Score: 2, Interesting

    Here's a program I've written in ruby, just today, in about 2 hours.

    It generates a graphical waveform from the component harmonics, as well as graphing the first 10 harmonics.

    Source Code: http://tylere.com/waveform.rb.txt

    Some Examples:

    Square Wave
    A Phased Sine Wave
    Triangular Wave
    Sawtooth Wave

    --
    TODO: Something witty here...
  90. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0

    Regrettably, Tom has chosen to go off-topic to focus on the wrong set of issues - comparing agile language A to agile language B, rather than commenting on the value of the Python book itself, or even (if any off-topic can of worms really must be opened,) commenting on common foes to all lightweight languages (LWLs,) such as the CLR or compile time typing issues that cross-cut a preference for one LWL's syntax or feature set to another

  91. puh-lease by Anonymous Coward · · Score: 0

    Well well...

    If you think Python is so great, then why didn't the Developers of Python develop Python by using Python instead of C?

    Huh? What's that? Is that the sound of a black hole sucking us all in?

    The real Programmers use C...and they ha^H^H learn to like the pain.

    1. Re:puh-lease by slinkp · · Score: 1
      why didn't the Developers of Python develop Python by using Python instead of C?

      you thought you were joking....

  92. Re:A nice comparison of Python with other language by slinkp · · Score: 1

    PS: if Python is so clear and easy to write why do people constantly say "well, if *I* were writing that code in python, I'd do ...." ??

    Where are python developers "constantly" saying this?

    Sure, I've seen it said sometimes. Are there developers of *any* language that don't habitually debate points of style and idiom?

  93. Re:There's one major reason I choose Python over P by Anonymous Coward · · Score: 0

    Perhaps you are thinking of C++?

  94. Re:A nice comparison of Python with other language by slinkp · · Score: 2

    sorry eclectum, you can't use print in a list comprehension. SyntaxError.

    The comprehension doesn't add anything to this example. Let's stick with the time-honored:

    for k, v in adict.items():
    print k+'->'+v

    (you can put it on one line if you really want)

  95. Re:There's one major reason I choose Python over P by Junks+Jerzey · · Score: 1

    Weak typing is the opposite, where a language will implicitly convert between (possibly incompatible) types or will simply allow any operation to occur.

    That's not weak typing. That's simply automatic conversion of types in some cases. Weak typing is like that of Forth, where if you add a float to an integer, the BIT PATTERNS are simply added together, as if both of them were integers.

    Python is strongly, dynamically typed. If you try to perform an integer operation on a string, it will check this at runtime and raise an exception. It will not perform the operation.

    Python will do similar conversions, just not for strings. For example, you can add integers and floating point values without explicit conversions. From a type view, 1 + 1.0 is exactly the same as 1 + "1". So Python is no more strongly typed here than Perl is, though I realize there's a popular compulsion to make out Python to be superior to Perl (which it is in many cases, though this isn't one of them).

  96. Re:A nice comparison of Python with other language by Peaker · · Score: 2, Informative

    But immediately the "object model" if you want to call it that got on my nerves. Why "len(list)" and not "list.len()"? Why "'\n'.join(array)" instead of "array.join('\n')"? What's with the simplistic scoping? Why all the underscores? Why "self" everywhere, and why is it so unpythonic to just call it "s" instead? Do I really have to type parantheses all the time? Where are the first-class regexps? Does it make sense that for many built-ins, "foo(obj)" calls "obj.__bar__", why not just use "obj._foo()" directly and eliminate "foo()" from the language.

    Lets call this the foo indirection.
    The foo indirection is useful because it releases the tight coupling between the foo(obj) call, and the obj.__bar__() call.
    For example, the int(object) call is implemented by usually calling object.__int__(), but this is not necessarily so.
    int is a type whose constructor converts objects to an integer using __int__ or other protocols/methods.
    For example, int(some_string, 16) will convert the string to an integer treating it as an ascii representation of a hexadecimal number. The string does not necessarily have __int__ and/or does not necessarily support the same arguments as int.

    The foo indirection also allows for later modifications of things like the len() function without modifying the __len__ method protocol.
    The foo indirection is exactly the same as the indirection you get when using object[subscript], where that subscript may be an index or a slice. It used to call __getitem__ or __getslice__, which is a messy protocol. Because of this indirection, the messy protocol was now cleaned to __getitem__ which may take an integer index or a slice object index, while still supporting __getslice__.

    I guess I'm one of those weenies that believes all languages eventually become Lisp or Smalltalk, and any sharp corners that vary from those models will eventually be "filed off". I tried Ruby and discovered it was much more like Smalltalk. Very elegant and easy to write code.

    Python does not try to be Smalltalk, however it is indeed very similar to Lisp in many ways. However, there is a fundumental difference in the philosophies of Lisp and Python. Lisp tries to be the "language of languages", where macros let you variate the language to your specific needs. Python tries to be the "uniform language", where macros would never get in the language because they harm uniformity.

    Unfortunately Python stole the thunder and now python has the great docs and 3rd-party libraries, while Ruby lingers and grows slowly.

    Fortunatly, if you ask me :)

    And Python has the arrogant, Perl-like community now, that thinks jamming list comprehensions and generators into everything makes you "cool".

    I simply find comprehensions more readable than .append() loops in most cases. I also love generators and find they are amazing ways to write extremely simple code that yields generic iterators. (Extremely useful for the implementation of __iter*__ methods).

    Why do they think it's so cool to reduce the number of lines in a program? I own the "Python cookbook" and find it highly irritating. Rather than solving problems in a single elegant and general way, it presents each author's particular 'leet Python skills, and usually 4-5 different solutions (in a language that claims "one way to do it").

    The number of lines is often a good (perhaps rough) indicator of the number of bugs in the code. Code that's not written does not have bugs. I find the "advanced" generator-using solutions very elegant and general.
    Python does not claim there is "one way to do it". Python claims "there should be one obvious way to do it, preferrably only one". There can be more than one obvious way, and there always is more than one way (just not obvious).

    I found it very unhelpful, and again was confused when people said it was such a great book.

  97. Re:A nice comparison of Python with other language by tcopeland · · Score: 1

    > rather than commenting on the value of the
    > Python book itself

    Hmm... I see a book review as a starting point for spawning off discussions - linking to a page discussing Pythons pros and cons seems reasonable.

    > commenting on common foes to all
    > lightweight languages

    Foe, or design choice?

  98. Half Life by TuringTest · · Score: 1

    Maybe not Half Life, but "Severance: Blade of Darkness"'s logic is written in python.

    --
    Singularity: a belief in the "God" idea with the "demiurge" relation inverted.
  99. Re:A nice comparison of Python with other language by CRCulver · · Score: 2, Informative

    Most of my development deals with internationalisation and support for many languages and scripts. For that reason, I prefer Python, because one can make all internal strings Unicode no longer have to worry about a million character sets. Ruby, on the other hand, lacks support for Unicode. I know the iniciator of Ruby comes from Japan, where because of CJK chauvinism Unicode sadly hasn't caught on yet, but this is the 21st century, and a scripting language without support for Unicode is just unacceptable.

  100. Re:Python and Perl... by WhiteDragon · · Score: 1
    And you only need 4 opcodes! (add, branch, load, store)


    errr, actually, you only need one: Subtract and Branch if Negative
    --
    Did you mount a military-grade, variable-focus MASER on an unlicensed artificial intelligence?
  101. Re:1st edition = PAPERWEIGHT by gabec · · Score: 1

    I've been using Albatross ( http://www.object-craft.com.au/projects/albatross/ ) and Albatross Extensions ( http://axe.pseudocode.net/ ) on Apache + mod_python.

  102. Re:There's one major reason I choose Python over P by Abcd1234 · · Score: 1

    Perl is great for UNIX scripting, but once you pass a certain point, it begins getting unwieldy (IMHO).

    I think this depends a lot on 1) the application and 2) the chosen architecture. I've written some rather largish Perl projects (well, not that large... ~8000 lines) with little difficulty. It really just depends on the choice of design and how well Perl's language features match that design.

  103. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0

    Example, the Python cookbook: at the beginning it waxes poetic about how, unlike Perl, in Python there is one clear way to do things.

    Then read the recipes. Usually one solution is given in the recipe, then in the discussion about 4-5 more, usually for different Python versions, with/without list comprehensions, with/without objects, nested scopes, or whatever. Maybe the authors are just showing off, who knows. Sometimes they have multiple recipes for the same thing (Singletons, for instance, never mind that you don't *need* singletons in Python, because of modules).

    And of course whenever somebody posts a Ruby example, the Pythoneers insist on reducing it to fewer lines or making it more "Ruby-like". Ruby is a more terse language than Python, as a design choice. I find Python becomes more difficult to understand when people try to squeeze lines out of the code. That's not Python style.

    What I wish is that 1) they would stop pretending that Python is more elegant than any other language, and drop the "one way to do it" stance and 2) not worry if their code has more lines than other languages. Clarity is in asset that Python seems to be forgetting about as it matures.

  104. Re:There's one major reason I choose Python over P by Peaker · · Score: 1
    The fact that:

    "Hello" + 3 will raise an exception in Python, but yield 3 (or "3") in Perl, along with the fact that:

    "3" and 3 are indistinguishable in Perl (Might be wrong about this, but for common operations at least, they are indistinguishable),
    make Python superior (at least in this specific regard).

  105. Yes, e.g. with these: by Anonymous Coward · · Score: 0

    I bet you've already seen the answer to your q in the threads here, but for anyone else who missed them:

    fredrikj's post on Psyco, and
    (another) AC's post mentioning both Psyco and Py2Exe, among other useful things.

  106. Re:Bad foundations. by Anonymous Coward · · Score: 0

    Actually what's cool is when you study a language and realize all the control structures and debugger and profiler are completely written in the language itself, or could be, without using any special hooks. That's what blows me away about Lisp (and Ruby to a degree), for instance.

    If you have continuations you can create loops, exceptions, even function calls, just with continuations and conditionals.

  107. Re:There's one major reason I choose Python over P by Peaker · · Score: 1

    C will typically convert between incompatible values (pointers and ints, for instance) without an explicit typecast, with certain warnings raised.

    In some cases, incompatible type conversions (mostly between pointers to different types) don't even yield warnings:

    char c;
    void *a;
    int *b;

    a = &c;
    b = a; /* To emphasize that this is wrong: */

    (*b) = 0; /* Undefined behaviour */

    Hell, the mere fact one can incorrectly cast in C makes it weakly typed.
    In a strongly typed language, the wrong type may never be applied to wrongly interpret memory bits. This is not true of C, and true of Python. C is weakly typed, Python is strongly typed.

  108. Re:There's one major reason I choose Python over P by Peaker · · Score: 1

    Do you mean to say that you don't indent your code? :)

    I tend to believe you ran away screaming before you tried using significant whitespace.

  109. Re:There's one major reason I choose Python over P by rob_au · · Score: 1
    apart from using whitespace as syntax


    A former colleague and I were discussing this at one stage, which inspired this hack entitled "Audible Code Separator" thereby allowing the bell character (^G) to be used for token separation in Perl scripts. I'll not have any other language stealing Perl's thunder in terms of lack of readability! :-)

  110. Re:A nice comparison of Python with other language by Jay+Carlson · · Score: 1

    How about Lua?

    Lua

    adict = {key='val', key2='val2', key3=3.14}
    for k,v in adict do
    print(k.." -> "..v)
    end


    Why is Lua relevant to this thread? For better or worse, Lua is very small, in a number of dimensions. The number of things you have to remember is small, and you can get by with even fewer. I suppose you could go functional if you wanted to:

    foreach(adict, function (k,v) print(k.." -> "..v) end)

    ...but there's more brainwork involved. As other posters have mentioned, functional iterators don't get you much if you're just running the function for side effects. "Code should be organized vertically, not horizontally."

    If you think of Python as Common Lisp, Lua is like Scheme. Except Lua's in a lot more console games than Scheme. :-)

  111. Re:A nice comparison of Python with other language by fredrikj · · Score: 1
    It should really be:
    adict = {'key': 'val', 'key2': 'val2', 'key3': 3.14}
    for key in adict:
    print key, '->', adict[key]
    Which without any doubt is more intuitive and prettier than the Ruby equivalent.
  112. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0

    Incorrect output is an error. How about just checking your output in the interpreter before adding the code to your program?

    *gasp*!

  113. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0

    People always like to use the % operator, but what's wrong with just:

    print k,'->',v

    ??

  114. Re:There's one major reason I choose Python over P by belroth · · Score: 1

    Why does this make Python superior to Perl?
    This is one of the things I like about Perl.

    --
    I hereby inform you that I have NOT been required to provide any decryption keys.
  115. Re:There's one major reason I choose Python over P by Peaker · · Score: 1

    What do you expect from "Hello world 3" + "3"?

    I certainly wouldn't expect 0, 3, or 6. I would expect it to either fail, or return "Hello world 33".

    Obviously, a language with simple predictable semantics is superior to one with ad-hoc weird semantics.

  116. Psyco by MartinB · · Score: 1

    Slight caveat - Psyco is x86 only. Which is OK if you're not needing a globally redistributable end result. Testing with Plone suggests that by Pysco compiling a few of the more expensive components, you get a 10% speedup.

    --

    The only thing you can accurately describe as "Scotch" is a sticky tape made by 3M. And it's

  117. The real reasons are pragmatic by Great_Jehovah · · Score: 1
    Python is attractive to different people for different reasons. My reasons:
    • Almost as powerful and expressive versatile as lisp
    • Libraries are powerful and well documented
    • Easy to create bindings to C/C++
    • Deployment is easy
    • Good cross-platform support
    • Syntax is easy for uninitiated to decypher
    • Large and growing "mindshare"
    The last two are related and are actually key.

    Lisp is really the gold standard of "expressive and versatile" but you just can't jump in and be productive in a day or two like you can in Python.

    Perl looks pretty ugly to the uninitiated.

    Ruby looks better in a lot of ways but it's not enough better to overcome Python's lead.

    I wish I really Dylan was ready. It's a real shame that Gwydion Dylan hasn't made it to production quality yet. It's a classic example of the losing end of worse-is-better. The design gets almost everything "right" which of course makes the initial implementation too difficult.

  118. Re:1st edition = PAPERWEIGHT by mav[LAG] · · Score: 1

    Do you get wafers with it?

    --
    --- Hot Shot City is particularly good.
  119. Re:There's one major reason I choose Python over P by Abcd1234 · · Score: 1

    The problems with significant whitespace has nothing to do with the benefits of code formatting. Everyone knows that proper block indentation improves readability. However, whitespace significance is *incredibly* annoying if things like tabs break (if you've ever edited a Makefile with a naive editor, you'll know *exactly* what I'm talking about, here).

    Moreover, it can also make an editor really irritating to use. Case in point, I type this code:

    if (condition):
    blah

    if (condition2): <-- wrong lexical level!
    blah

    This is Emacs' idea of indenting things. Because there aren't block delimiters, Emacs has no idea that I really want the second "if" statement to be at the same lexical level as the first. Consequently, I'm forced to backspace in order to get things to come out correctly. Plus if I try to auto-indent this code, it's quite possible that it could get it wrong, because there's no way to unabiguously determine the intended scope of the statements in a block.

  120. Re:There's one major reason I choose Python over P by Peaker · · Score: 1

    You get a warning/error (use python -t, ofcourse).

    Or if you forget -t, you get an IndentationError or a SyntaxError which is quickly narrowed down to the indentation problem.

  121. Re:Bad foundations. by navak · · Score: 1
    If you have continuations you can create loops, exceptions, even function calls, just with continuations and conditionals.

    Which is insanetly cool, unless you try to actually use that in an actual program. Same as the Turing-complete assembly language which has only one opcode.

  122. Re:A nice comparison of Python with other language by b17bmbr · · Score: 1

    actually, i think this is a plus. i have been programming in perl and java for several years. while i love alot of things in java, java is a "one way only" language. try opening a file. try opening a socket. try writing graphics to a control. i understand what java was intended for, but c'mon. i have just picked up python last few weeks. really easy to learn, especially with java/OOP background. probably the coolest thing about python is the toolkit integration. i have got pyGtk, pyQt, as well tkinter up on panther/X11. python cuts dev time down significantly. and it gives yo the freedom and power like perl. it doesn't constrain you. java pisses me off so much sometimes. what i love about coding (since it really isn't vocation) is the challenges to do it differently and better. java has little room for creativity. that's why. at least for me.

    --
    My problem? I was perfectly gruntled, until some numbnuts came by and dissed me.
  123. Re:There's one major reason I choose Python over P by Peaker · · Score: 1

    The problems with significant whitespace has nothing to do with the benefits of code formatting. Everyone knows that proper block indentation improves readability. However, whitespace significance is *incredibly* annoying if things like tabs break (if you've ever edited a Makefile with a naive editor, you'll know *exactly* what I'm talking about, here).

    There's a fundumental difference between Python's whitespace significance and that of Makefiles. Makefiles dictate where to use tabs, and where to use spaces. Good Python style merely dictates that whatever you use, you use it consistently. Simply don't mix tabs and spaces for indentation. Even naive editors don't have a problem with this.


    if (condition):
    blah

    if (condition2): # wrong lexical level!
    blah


    When indentation is the lexical level information, obviously you have to adjust it while you write the code. Your assertion that the editor does not indent the code automatically as in other languages is quite silly, because in other languages it knows to indent your code because of the extra information that you type (braces/etc).

    Consequently, I'm forced to backspace in order to get things to come out correctly.

    As opposed to being forced to press '}' in order to get things to come out correctly with most other languages?

    Plus if I try to auto-indent this code, it's quite possible that it could get it wrong, because there's no way to unabiguously determine the intended scope of the statements in a block.

    Again, you are trying to apply the concept of auto-indentation, which only makes sense where indentation is redundant information to the braces. Where the indentation is the information, there is no reason to auto-indent because indenting is done instead of, and at a lower cost than typing the curly braces.

    Once you stop trying to auto-indent a language where indentation is the one and only specificier of the nesting level, you see that it is quite trivial to unambiguously determine the intended level under which statements go.

  124. Virtual +1 insightful to you by GCP · · Score: 2, Insightful

    I prefer Python to Ruby, but your complaints about Python are right on, IMO.

    Your "Python stole the thunder" analysis is not quite right, though, and it relates to why I prefer Python.

    Ruby is as old as Python, but Matz wrote Ruby to do his own Japanese *nix work. He focused on his own needs, but made it available to all, so essentially he was focusing on the Japanese *nix community and their needs. The Japanese *nix community, for example, cares far more about handling legacy Japanese data than about handling new, multilingual Unicode data, so Matz's design decisions reflect this local bias, to the detriment of those of us with reverse priorities.

    Japanese *nixers are a pretty small, insular community, but that's where Ruby has always been centered. These days, the circle has grown out from that center large enough that there's more for Westerners or non-*nix users to use, but the center is still on Japanese *nix users.

    It's that focus that explains a lot of the weaknesses of Ruby as seen from the perspective of a Westerner who cares about cross-platform dev, internationalisation, good and plentiful English docs, a big English-speaking community of experienced users, etc.

    I think Matz is a smart, humble guy with real talent when it comes to language design. I like him, and I like Ruby's design more than Python's in many ways, but his focus on Japanese *nix programmers and their local priorities has been a ball and chain around Ruby's ankle that I think explains the more rapid growth of Python worldwide (and Ruby's faster growth in Japan).

    --
    "Those who have never entered upon scientific pursuits know not a tithe of the poetry by which they are surrounded."
  125. Re:A nice comparison of Python with other language by ahdeoz · · Score: 1

    What kind of job do you have where you can just switch your development language? Even on my personal projects, I have a lot of perl and PHP that I'm trying to migrate to Java (need persistent objects, and sadly, I don't see anything better than EJBs), but it just doesn't seem feasible.

  126. So what's your list? by GCP · · Score: 1

    Which languages, "objectively", are the ones to learn?

    Though I think the answer is more subjective than you seem to imply, I'm not asking to be argumentative. I'd be interested in what list you would come up with, based on your stated approach, and why you would learn each. As you point out, we don't have time to learn them all, so good advice regarding which few to pick is (potentially) useful.

    --
    "Those who have never entered upon scientific pursuits know not a tithe of the poetry by which they are surrounded."
  127. Re:There's one major reason I choose Python over P by Abcd1234 · · Score: 1

    Simply don't mix tabs and spaces for indentation. Even naive editors don't have a problem with this.

    Hah! You haven't mixed, say, Vi and Emacs, the two most common editors out there, have you? Depending on the editor settings, Emacs will use spaces, and Vi will always use Tabs. Hell, I haven't done *that* much Python development (relative to other languages I know), and even I have encountered the broken-tabs problem.

    When indentation is the lexical level information, obviously you have to adjust it while you write the code.

    This is true, it is partly a matter of adaptation. So, I will concede the point.

    However, there remains the problem that code can be incorrect, but not necessarily *appear* incorrect (to the developer), since there's no visual markers (other than whitespace) to indicate where the blocks *should* have been. Therefore, if something does get out of place for some reason (and yes, I've had this happen), it isn't always immediately obvious that something's amiss.

  128. Re:A nice comparison of Python with other language by ahdeoz · · Score: 1

    I notice everyone wants to use the '->' notation to signify the key->value relationship. Why is this? Could it be because it is less ambiguous than ':'? If so, then why not use that construct in the language, or if it is ambiguous for pointers, use '=>' (as ruby does.) Also, what's a 'def'? A function definition? Why not be more precise, especially if there is already a convention. Python tries too hard to be 'different' in the syntax for being different's sake. That's why I keep giving up on it. Too bad, because I really want something cleaner than Perl or PHP for scripting.

  129. Re:There's one major reason I choose Python over P by chromatic · · Score: 1

    Predictable is subjective. I find Perl's two rules here consistent:

    • If it looks like a number, it can be treated as a number. "Hello world 3" doesn't look like a number.
    • + is for addition, . is for concatenation.
  130. Re:A nice comparison of Python with other language by Tyler+Eaves · · Score: 1

    Mainly lots of small projects. Converting one fixed width format to another, things like that. Repetitive to a degree, but not to the point of being able to write a framework, as there is usually special logic involved. I'm also the only programmer at my place employment who writes in modern languages (IE: Not COBOL) so I'm given free reign by and large technically, as long as I can justify WHY X is a valid solution to problem Y.

    --
    TODO: Something witty here...
  131. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0

    How about just checking your output in the interpreter before adding the code to your program?

    Yeah and how about the posters above checking their output in the intepreter before posting to a public forum. Doh!

  132. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0

    People always like to use the % operator, but what's wrong with just:
    print k,'->',v

    The latter is fine, it's just because of the particular implementation of CPython the use of placeholders produces more efficient byte-code.

  133. Sig by Anonymous Coward · · Score: 0

    So, was Iraq better off with Saddam? Ask the Kurds.

    Just whatever you do, don't ask the Iraqi's!

  134. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0

    Now if we could just get rid of that 'do ... end' and replaces it with, say indentation, you'd have a nice litle language there. :P

  135. Re:There's one major reason I choose Python over P by Anonymous Coward · · Score: 0

    Emacs will use spaces, and Vi will always use Tabs.

    au FileType python set expandtab

    Nobody codes in python without that in the .vimrc (or the equivalent in .exrc), do they?

  136. Re:There's one major reason I choose Python over P by Anonymous Coward · · Score: 0

    Static typing.

    An odd reason to make the choice. Given that neither language has static typing. Hmm?

  137. Scheme vs Python comparison is biased by axxackall · · Score: 1
    Scheme has the following advantages to Python:
    1. Supports proper closures, with lexical scoping.
    2. Any function can be defined anonymously, via the lambda keyword.
    3. Is supported by a standard (R5RS, IEEE)
    4. Makes it easy to program in a functional style, i.e., without side effects.
    5. Supports macros.
    6. Mathematically oriented, rather then processor oriented, numeric model.
    7. Supports fairly optimized compilation to native code.

    As we can see most of points are serious arguments saying that Scheme is better designed as a language due to its original FP design.

    Python has the following advantages to Scheme:

    1. Standard object system (OTOH, "Any scheme programmer has written an object system, sometimes two")
    2. Many builtin or standard functions for easy programmings, such as regular expressions or Internet connectivity.
    3. Many builtin data types.
    4. Relatively main-stream syntax.
    5. One standard implementation: easy to write extension modules in a systems programming language (C/Java).
    6. Main-stream control structures (while, for).

    Dispite #1 all other points are weak and don't keep any water.

    I call it biased because it's abvious from the above (counting the weakness of the second group arguments) that Scheme is superior, but the comparison author wants Python to look as good as Scheme.

    I understand and appreciate when Python language designers bring one by one FP features to the language, but please be honest - Python is still not there yet in terms of having a real power of a FP language.

    Having said all that I can add that personally I consider Python as the most power among all other non-FP languages (Python was not originally designed as FP, it's aquired some FP features later).

    Due to traditional lack of math education among most of programmers around me I usually have a very hard time to ask them to use FP methods and a FP style. That's why I don't have any chances to ask them to use Lisp or Haskell or ML with me in the same project we work together. As for Python I have such chances: Java programmers find Python's OOP style convinient for them, while Tcl and Perl programmer love that Python is a scripting language.

    Don't ask about C and C++ programmers - they are a lost case, when they write applications. Kernel and DB and library programming is fine on C IMHO, but not application logic.

    --

    Less is more !
  138. Lisp vs Python comparison by axxackall · · Score: 3, Informative

    By the way, Lisp vs Python comparison by the famous AI hacker Peter Norvig is way better as it's more objective (less biassed) and it has very important details and very clear examples.

    --

    Less is more !
  139. Re:There's one major reason I choose Python over P by LittleDan · · Score: 0

    I hate when people throw around the term 'FUD'. Understandably, he just didn't understand Perl, since it isn't that easy for most Python programmers to understand.

    I think Perl is pretty interesting because, somehow, the creators have managed to combine the disadvantages of weak and manifest typing. First, due to weak typing within scalars (a term which is completely cryptic unless you know Perl), many things happen unlike you'd think they would (such as "0" == "0.0" returning true), requiring special operators on strings and such. This makes the language hugely overcomplicated (or "expressive", if you like to think of it that way). But then, if you have a vector or hash (also cryptic terms), you need to know that because each of the three main types, scalars, vectors, and hashes, must be prefixed on *every* reference. This is even worse than static typing in a language like C. Unnecessary variable prefixes combined with extremely weak typing make Perl a terrible language for new users.

    In Python, lists, tuples and dictionaries (terms from English) are much easier to use. Instead of requiring a prefix on every reference, the object is just created and then you can reference it without a prefix. And references are not necesary due to Python's linking model. Here are some examples of using Python's data types versus Perl's.

    dictionary = {'Hi': 1,
    'Hello': 2}
    hi_value = python_dictionary['Hi']
    reference = dictionary
    hello_value = reference['Hello']

    %dictionary = {"Hi", 1,
    "Hello", 2};
    $hi_value = $dictionary{"Hi"};
    ($reference) = %dictionary;
    $hello_value = ${$reference}{"Hello"};

    I'll let you choose which one is more legible and intuitive. In Python, you don't have to worry about whether things are scalars, hashes, references, or whatever, but if you think that's more readable, then that's fine.

    Daniel Ehrenberg

  140. Re:Python and Perl... by killthiskid · · Score: 1

    I know people like you... and you all scare me.

  141. Re:A nice comparison of Python with other language by Rick+and+Roll · · Score: 1

    MzScheme can be used as a scripting language, and damned if it doesn't have strict syntax. So can many others.

  142. Re:There's one major reason I choose Python over P by Anonymous+Coed · · Score: 1

    You are looking to slashdot for academic rigor?

  143. Re:A nice comparison of Python with other language by jadavis · · Score: 1

    It also seems like dynamic typing would hurt the effort as well.

    Python, and I believe Ruby as well (at least according to my quick test) are not dynamically typed.

    Php is dynamically typed. Python and ruby are "late-binding".

    In PHP, you can do:
    $a = "1";
    $b = "2";
    $c = $b/$a;

    In python and ruby, and you can't. You have to cast the string first. However, in python and ruby, you can bind any value of any type to any variable, hence "late-binding". In java, you can only bind a value to a variable of a differing type in some situations (i.e. inheritance).

    --
    Social scientists are inspired by theories; scientists are humbled by facts.
  144. Re:There's one major reason I choose Python over P by Anonymous+Coed · · Score: 1
    At our company the standard Python indentation is 1 tab character per lexical level. Several of the developers including myself use (X)Emacs with no problem as long as you put the appropriate lines in ~/.emacs.

    BTW an indentation consistency checker is part of our build process. It doesn't care if you use all spaces or all tabs, as long as they're not mixed within a file. Then again, this was only required after a time as one or two of the developers were rather sloppy in this respect.

    Hell, I'd love to put in a kind of spelling checker as well as those same individuals are also rather atrocious spellers.

  145. Re:A nice comparison of Python with other language by jadavis · · Score: 1

    One of the things I like best about python is its seamless integration with C. How is ruby in that department? Also, is the standard library getting more complete? I think last time I checked python was a little better there.

    But as far as the language itself, ruby is amazing.

    --
    Social scientists are inspired by theories; scientists are humbled by facts.
  146. Re:A nice comparison of Python with other language by Tyler+Eaves · · Score: 1

    Ruby's C interface is, from what I understand, similar to Python's, ie, quite functional nad integrated, although I haven't really messed with it.

    The actual standard lib is smaller, but this has the advantage that the source tarball is maybe 1/3rd the size of pythons (I'm thinking along the lines of 2.5MB vs 8 MB or so). Modules to do just about anything are available at the RAA (Ruby Application Archive) (http://raa.ruby-lang.org)

    --
    TODO: Something witty here...
  147. Also available via Safari by salimma · · Score: 1
    For those of us living in third-world countries, subscribing to Safari lets you browse and download O'Reilly books, probably cheaper than importing the books themselves.

    They do have some O'Reilly books at English-language bookshops in Indonesia, but the mark-up is anywhere from 30%-50%.

    --
    Michel
    Fedora Project Contribut
  148. FUD by ZeekWatson · · Score: 1
    There's nothing wrong with ActiveState, except that they lag behind the main *nix releases

    This is FUD. The standard release at times is far behind ActivePerl in providing bug fixes.

    The patches that made ActivePerl 635 were basically released as Perl 5.6.2 (with some portability fixes) almost a year after ActivePerl 635 was released.

    Here is a link to a p5p BOF about 5.6.2. I'll quote the interesting part:

    A lot of bugs in 5.6.X are fixed in the ActiveState release and not in the general release. This needs to be fixed.

    Feb 4, 2003: http://downloads.ActiveState.com/ActivePerl/src/5. 6/
    vs Nov 16, 2003: http://use.perl.org/article.pl?sid=03/11/16/162224 1&mode=thread&tid=6
  149. Re: The Ruby vs. Python thing. by CatGrep · · Score: 2, Insightful

    I too prefer Ruby. And as such, it's nice to see Ruby being mentioned more often. Sure the Ruby community is smaller (in the US anyway) than the Python community, but we do seem to be steadily gaining new users (even some Python refugees).

    The whole Ruby vs. Python issue is probably mostly a "different strokes for different folks thing". Either is a good choice to learn at this point. Try them both and see which one fits you better. In my case it mostly came down to the indentation- as-syntax issue with Python (often this is referred to as 'whitespace as syntax', but pretty much every language relies on whitespace somewhere, so indentation is more specific). I really strongly disliked Python's indentation-as-syntax 'feature'. I know that many Pythonistas will claim that with the right editor settings it's not problem, but for me not being able to cut&paste code is a deal-breaker (and having important pieces of your code be 'invisible' just doesn't sit well with me). I tried Python for a few days before trying Ruby and was bit a few times by the indentation-as-syntax thing - no thanks (but to each his own).

    The culture of the two language communities also seems very different. Ruby's seems more 'free' (for lack of a better word), while Python's is, uh, more, um... well, I'm not wanting to start a flamewar here, but the Python folks do seem a tad bit more, uh, anal.. err, I mean 'uptight' (for lack of a better word).

    By 'free' as applied to the Ruby community I mean that while there are some aspects of the language that some might consider 'dangerous' (the fact that classes are always open, for example) and others consider very powerful (I like the fact that classes are always open - it's a powerful feature) the attitude is that you're a grownup and you can figure out how to use these powerful features wisely, we're not going to constrain the language just because some kid might 'hurt himself'.

    All this to say that I think that each language appeals to a different sort of person. Python probably tends to appeal to the safety conscious, neat person (and we need people like that, don't get me wrong). While Ruby probably tends to appeal to the more creative "don't cramp my style" type of person. That's not to say that Ruby is 'dangerous' - I'm starting to use it on a commercial project and it's a big productivity booster - just that you probably have to exercise a bit more wisdom when using it.

  150. Re:There's one major reason I choose Python over P by slinkp · · Score: 1

    yep, mixed tabs and spaces is bad. Guido included this on his list of python regrets at Pycon 2003. FWIW, emacs python-mode is fantastic, and vim usually annoys the heck out of me until i remember to set up .vimrc properly.

  151. Functional languages are pretty but impractical by r6144 · · Score: 1
    As for language design, I find Lisp and Scheme and OCaml miles better than Perl (too "dirty") or Ruby (the "yield" statement just feels ugly compared to real first-class functions --- can any Ruby-lovers enlighten me?). Java, C# and Python are somewhere in between in terms of elegantness (good overall, but with some rough edges).

    However, when actually programming in those great functional languages, one often have a hard time deciding whether to use imperative or functional style. Programs in functional style is much prettier, but many data structures (arrays, hashtables) are inherently imperative, so in many places I just have to go the imperative way, which leads to either a mostly imperative program (might as well use Python or Java), or a mixture of functional and imperative stuff which is IMHO a bit slower and somewhat harder to maintain.

    To this day the most complex thing I have ever written in Scheme/Lisp/OCaml is an Unlambda interpreter written in OCaml, which is about 20KB of source code. I just can't make more good use of the functional features in more general-purpose code.

  152. I think you got the concepts wrong. by r6144 · · Score: 1

    PHP as in your example is "weakly typed". Python and Ruby are strongly typed but dynamically typed. "statically typed languages" refers to a language in which the type of everything is known prior to runtime, which is what you call "early-binding".

  153. Correction by r6144 · · Score: 1

    Hate to reply to my own post, but I found that Ruby does have Proc objects, &xxx parameters, etc. The syntax is still strange though.

  154. Well, not entirely by r6144 · · Score: 1
    I use do-while statements very rarely (mostly only do-while(0) hacks in macros that is going to be used in an unparenthesized if statement). However, suggesting statement duplication like your example IMHO really makes code unmaintainable, and sometimes it is hard to factor out a function for a long stmt that have well-defined meanings.

    The reason do-while() statements are rarely used by me is that a while(1) { ... break ... } statement is more straightforward for my brain, and often ehough there is stuff after the break statement. Actually, in this case I might as well use "goto" statement which can be as clean, but again goto's are easy to read but not straightforward to write.

  155. Re:Bad foundations. by maysonl · · Score: 1
    and coroutines are mostly useful for iterator generators,

    I once actually wrote an assembly language coroutine setup: it served mainly to connect the write word subroutine of one already working program to the read word subroutine of another one.

  156. Re:A nice comparison of Python with other language by blafasel · · Score: 0

    your print statement won't run (at least not with
    any version of python i'm familiar with).

    should read
    print k, '->', v

    cheers,
    b.

    --

    check your speling
  157. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0

    I meant, imagine if some of those examples didn't produce compiler errors, only incorrect output.

  158. Re:A nice comparison of Python with other language by jnana · · Score: 1
    List comprehensions are confusing and violate Pythons "one way to do it" philosophy, if you ask me. They are confusing because they are basically multi-argument operators

    I think it's meant as a guiding principle to be aimed for, rather than a strict dogma to be followed invariably. Otherwise there are plenty of exceptions, like:

    I think delimiting strings with both " and ' violates Python's "there's only one way to do it". They are confusing because they are basically both doing the same thing, so one of them is redundant, even if it's very useful to have them in some cases (which is also the case with list comprehensions).

  159. Re:There's one major reason I choose Python over P by jnana · · Score: 1

    I think that's the parent's point: "Hello world 3" doesn't look like a number, yet Perl treats it as if it were a number.

    foo@bar:~$ perl -e 'print "Hello world 3" + "3", "\n"'
    3
    foo@bar:~$

  160. Re:There's one major reason I choose Python over P by chromatic · · Score: 1

    That falls under the second rule above. The programmer asked for addition. Perl doesn't like to second guess the programmer.

    (This attitude isn't limited to Perl. See "I prefer to program as if errors and exceptions cannot occur" by Ron Jeffries on the XP mailing list for a similar view.)

  161. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0

    Don't be a dick. The original poster wanted to use -<, that's not 'everyone'. If it was me, I would've used '=', or even just a '-', and a colon would've been equally appropriate. Tryig to twist something like that just makes you look stupid, or desperate to find something to bitch about.

  162. Re:There's one major reason I choose Python over P by Peaker · · Score: 1

    You haven't mixed, say, Vi and Emacs, the two most common editors out there, have you? Depending on the editor settings, Emacs will use spaces, and Vi will always use Tabs. Hell, I haven't done *that* much Python development (relative to other languages I know), and even I have encountered the broken-tabs problem.

    Valid point. When I mix editors, I usually explicitly do search-replace on tabs/spaces to unify them all to the same form. I have been burnt once or twice on tabs problems (well, if wasting 5-10 minutes finding a spacing problem once or twice is a burn :), so I'm concious to it.

    However, there remains the problem that code can be incorrect, but not necessarily *appear* incorrect (to the developer), since there's no visual markers (other than whitespace) to indicate where the blocks *should* have been. Therefore, if something does get out of place for some reason (and yes, I've had this happen), it isn't always immediately obvious that something's amiss.

    I think you got that backwards.
    In languages where indentation is ignored by the compiler, there is a problem. Indentation is for the human readers, while the braces are for the compiler. A human reader is more likely to ignore the braces for the indentation than vice versa. Thus, in C, a human reader might think that an indented code is within some block where in fact it is not:

    if(x) {
    for(i = 0; i < 10; ++i)
    printf("Blah %d\n", i);
    x += 10;
    }

    The above is confusing, while:
    if x:
    for i in xrange(10):
    print "Blah", i
    x += 10

    does exactly what the reader would expect.

    So, that's one example where the C code appears correct but is actually incorrect. Can you show any example of Python code that appears correct but isn't? The whole point of significant indentation is that the human reader and the compiler are reading the same information, and thus code appearance is exactly what will execute.

  163. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0

    I meant, imagine if some of those examples didn't produce compiler errors, only incorrect output.

    Python, as a rule, doesn't let things pass silently. With Perl this might be more of a concern.

  164. Re:A nice comparison of Python with other language by Ian+Bicking · · Score: 1
    Many of the problems you identify -- which I agree can be problems -- are because Python is a language that people use to write real programs, and it has a history and a lot of backward compatibility to provide. So to override len you have to use the magic __len__ method. Is that such a big deal?

    Python also isn't a purely OO language, which I think is one of the really important parts of Python. It uses functions a lot, and those functions are often more clear than an OO approach would be. People in Smalltalk spend too much time creating frameworks, and not enough time getting stuff done -- because the language rewards that. Python is not a conceptually clear language like Smalltalk, but it's way more practical as a result. (Not that I don't like Smalltalk -- I really do, but ultimately Smalltalk was too insular for me)

    There are issues with Python, but really not that many. join as a string method is annoying, and magic methods seem somewhat arbitrary, but there's no perfect solution there either. Operators aren't methods, and some form of translation is necessary, in C++, Ruby, or Python. Python's translation isn't particularly bad (and once you know the names, it's very transparent).

    And Python has the arrogant, Perl-like community now, that thinks jamming list comprehensions and generators into everything makes you "cool".
    I'm sorry, but that's just not true. Sure, any group of programmers is going to make a few puzzles or playfully minimal programs, but in the Python community these are generally presented as toys or novelties. Cleverness is not worshipped, and especially not at the expense of clarity and simplicity. This isn't true in the Python standard library, most third party libraries, nor in comp.lang.python.

    Of course, people generally ask questions about hard things, because they don't need to ask about the easy things. And some hard things in Python require cleverness, or doing odd things with Python's object model (which is very flexible). Sometimes people want Python to be like whatever language they know best (e.g., C++, Java, Common Lisp, etc), and so people come up with mechanisms to do what they want (and then usually append "but that's not the Pythonic way to do it" and present a clearer way to get the same effect).

    The Python Cookbook didn't amaze me either. I'm not sure what would have -- the best documentation is not needing documentation at all, and for what the Python Cookbook covered I didn't really need documentation.

  165. Re:There's one major reason I choose Python over P by jnana · · Score: 1

    That falls under the second rule above.

    Why doesn't it fall under the first rule also? It doesn't look like a number, so operators that operate on numbers should not be able to be used with "hello world 3". The programmer asked for addition on a string, which doesn't make sense because addition is an operation on numbers. What if I try to use + to do addition on a hashtable and an ordered list? Perhaps Perl will permit this too, and gives some very strange result, but surely this is not a good practice to follow in general, though perhaps that's why people say Perl is needlessly complex and a 'write only' language?

    Perl doesn't like to second guess the programmer.

    Hmmm, I'm not sure this is such a good general principle. Ditto for the link you referenced. Don't programmers sometimes (in many cases, often) ask for stupid things and make mistakes? Woudn't it be nice if the compiler or interpreter informed the programmer of this? Basing a language on the notion that people are infallible seems a bit iffy to me. A better guiding assumption might be that people are fallible and the compiler/interpreter should be on the lookout for mistakes.

  166. Re:A nice comparison of Python with other language by Anonymous Coward · · Score: 0

    Incorrect output doesn't necessarily mean there's an error.

  167. Re:A nice comparison of Python with other language by Ian+Bicking · · Score: 1
    It was called Python 3000 -- first as a real idea, then as a haha, yeah we'll do that in Python 3000 kind of way. A sort of Shangra La.

    Anyway, now the discussion seems to have shifted a bit more toward the practical, and Guido is talking about Python 3.0 as a real release. It still looks like it's going to be fairly conservative -- which is good for all of us doing real programming in Python -- but some of the stuff like the changed division semantics look like they are going to wait until that release.

  168. Re:A nice comparison of Python with other language by boelthorn · · Score: 1
    Many things are expressed in a very logical manner, and this allows you to concentrate on how to accomplice a task.
    You need Lisp.