Python 2.4 Final Released 359
Eventh writes "The final release of Python 2.4 was just released. Python 2.4 is the result of almost 18 month's worth of work on top of Python 2.3. New features are, but not limited to, function decorators, generator expressions, a number of new module and more. Check out Andrew Kuchling's What's New In Python for a detailed view of some of the new features of Python 2.4. "
genexps (Score:5, Insightful)
From the AMK's excellent (as always) overview:
print sum(obj.count for obj in list_all_objects())
The important part is that no intermediate list is generated, because we are dealing with generators.
Generators in general kick so much ass it's not even funny.
Python annoyances (Score:2, Insightful)
Having said the above, there always seem to be 'issues'. Floating point numbers are one such issue. This release fixes that with 'Decimal'. The trouble is, you have to know about 'Decimal' before you can use it. This raises the difficulty of using Python.
I find that I write code quickly and then spend an hour researching some module or other. It sure slows down the process.
Re:I *want* to be enthused, but... (Score:2, Insightful)
Re:OK Trolls... (Score:2, Insightful)
coding standards make good code, not a language. I can write bad python just as easially as I can write good perl.
Re:Python is a pathetic language. (Score:0, Insightful)
Here's your example in Ruby for instance:
Re:I *want* to be enthused, but... (Score:5, Insightful)
I think one of the problems is too many people are still spreading the myth that it's essential to learn C before moving on to C++, which is totally false, C++ is a language in itself, and can be treated as such. Learning C (unless you intend to use it) is a waste of time, and I would go so far to say learning C first will make you less producive in C++, because it teaches concepts which are not applicable, or are actually bad habits when used in C++. At least that's my view on the subject.
That said, C still has its uses, but for many projects (like parent said) it's a "non-starter"
Re:I *want* to be enthused, but... (Score:3, Insightful)
I use Python extensively in my day-to-day work. It's the most versatile tool in my toolbox, and I'm continually amazed that so few people, at least around here, use it.
Good Stuff, but not enough to make me learn it yet (Score:2, Insightful)
I've always liked Python, but I don't think this update is enough to make me learn it.
In one respect, it is exactly what I've been hoping for. No more sweeping changes or vast syntactic variances, but they have eliminated some usability problems and silly errors. It's a very mature language now, and seems to be behaving as such, this makes me happy
Still, though, they seem to be competing for a niche that Perl has a deathgrip on for me. I use Bash whenever I can, Perl when I can't or it would be ugly, and C when I feel like I haven't had my eyeballs gouged out with hot pokers enough lately -- er, I mean when performance is at a premium.
Python's capabilities seem to rapidly be approaching what I can do with C, and God knows I want to never malloc() again, but as long as compiled binaries can be made only "Not easily," I don't think it's going to unseat Perl for my heavy-duty scripting language slot.
Re:18 Months (Score:5, Insightful)
Re:Supprised (Score:5, Insightful)
Well, some of the things I like about python:
1: tightly structured code.
2: less punctuation.
3: more readable syntax.
4: full OOP from the ground up (in contrast to perl where the OOP is bolted on with references).
5: short production cycle.
Many of these things can be found in other languages as well. So it largely comes down a matter of preference.
From the little I have seen, python seems to be a command line language. Is it anywhere similar to Visual Basic, which I have come to see and experience through a GUI?
Check out tkinter and wxPython.
Re:Is it just me? (Score:5, Insightful)
List comprehensions are not "tricks," they are an extremely powerful language feature. Newbies should be taught how to use them, and translating their loop-based code into list comprehensions is probably the best way to do that.
Python can be written from either an imperative standpoint or a pseudo-functional one. Most of the highly skilled Python programmers code in the pseudo-functional style, because it is more efficient and (arguably) more elegant.
Sure, you can get into some pretty scary territory with various combinations of sum(), map(), reduce(), and list comprehensions but that's your choice. I admit that there should not be such a big performance gap between the different styles... This is due to not enough effort being spent on improving the VM.
CommonLisp for the 21st century?! (Score:2, Insightful)
There are two big differences. One is that CommonLisp made it a lot easier to treat programs as data and vice versa, and it had a built-in high-performance native compiler. On the other hand, Python integrates a lot better with Linux and UNIX, there are tons more libraries for it, and is easier for new users to learn.
Re:I *want* to be enthused, but... (Score:3, Insightful)
IMHO - there are still uses for C, there are absolutely no uses for C++ nowadays. Moreover - there is no C++. I mean - I've been tracking (and sometimes using) C++ developments since the early days till recent and I can tell you - the amount of pileup that they produced in modern C++ compared even to early C++'s (not to say about more sane languages) is totally ridiculous. No - inventing a new language construct for bloody every particular problem does not make a good language. Well - if you want a complex system - use dynamic languages (Python, Lisp, Smalltalk - whatever suits you. Heck - PHP even if you know how to manage your globals). If you want something small and embedded - you should not overcomplicate - use C (refer to Linux sources, for example, to see how people code in C). If you want low-level performance and reliability in complex systems - I hate to say it, but use Java (large portions of IL2 - flight simulator - are written in Java, totally amazing stuff). Of course, if you like brainfucking - C++ may be for you, but it's really a bird that does not fly. On amount of time and energy that you'll waste on learning C++ you can pick half a dozen of better languages.
If still not convinced - check out how many CPU instructions are wasted for such a simple thing as returning a C++ string object from a function. When I show it to C++ "gurus" many are enlightened.
Re:Damn (Score:2, Insightful)
Re:CommonLisp for the 21st century?! (Score:1, Insightful)
For once thing is the "big difference" you describe: you can't transparently process code as data. That means no MACROS, which is what makes Lisp so damn powerful.
I think people see "lambda" and they somehow think that Python has something to do with Lisp.
How do you return an anonymous function from a function in Python? How do you build a function at run time? It's not easy or obvious.
Why the Decimal data type is needed (Score:3, Insightful)
>>> 1.1
1.1000000000000001
Thus, the Decimal data type was born.
From PEP 327: "The inaccuracy isn't always visible when you print the number because the FP-to-decimal-string conversion is provided by the C library, and most C libraries try to produce sensible output. Even if it's not displayed, however, the inaccuracy is still there and subsequent operations can magnify the error."
sigils sneaking in (Score:4, Insightful)
Welcome to the sigil club! Pandoras box is now open! '$' can't be too far behind
Re:I *want* to be enthused, but... (Score:3, Insightful)
That's a very good question. However, just because programming in C is difficult doesn't mean that it's the best language to write high-level languages in. C has many design flaws that people have gotten so used to, they assume there's no other way of doing things.
If you like programming in C because it's a challenge, then by all means do so. However, I would classify that hobby with people who program in Intercal and similar. Those languages are challenging too.
I see a real need for a language that is as easy to program in as Python, yet as potentially fast as C. As far as I know such a language doesn't exist yet, but I see no fundamental obstacles preventing us from creating one. It's just a matter of time.
Do you really want a future where not a single person actually knows what is happening inside that CPU, just because "it's hard?"
Yes, an essential part of a programmer's training is learning exactly what is happening inside the machine. However, a human being cannot keep track of everything at once. That's why we use abstraction. A high-level language (not C) abstracts away the details the computer is smart enough to handle, and leaves the material which the computer is not smart enough to handle.
Programming is fundamentally hard. Making the job harder than it needs to be can be fun, but for day-to-day work, it just doesn't make sense.
TTFN
Re:OK Trolls... (Score:2, Insightful)
Re:Supprised (Score:3, Insightful)
Sarcasm aside, it's not uncommon for me to work in four vastly different programming languages in a single day (usually java, ocaml, python, and C). That's not counting the ``lesser'' languages like sh, javascript, etc...
If I hear people talking about how a language or development environment does wonders for their productivity, I'll give it a shot. I can usually pick up languages pretty fast. I admit it took me a week or maybe even longer before I really ``got'' ocaml, though. But I had a good time trying.
I learned python initially because it had the best xmlrpc implementation. My first actual project was one that read a format definition for the tiger database and then used it to parse all of the zip file exports to load them into postgres. I ran it on several machines for about a week with very few errors (my own errors, that is) after spending a couple of hours writing the loader. That impressed me quite a bit for my first use of a language.
Don't look for an excuse to learn something, though. Just do it. Give it some time. If you don't like where it's taking you, then take what you got out of it and learn something else.
If all you know is VB, though, it's going to take quite a bit of learning before you know what a good language feels like.
WTF? (Score:4, Insightful)
I'm very proficient with C, Python and Bash, and I can tell you for a fact: Bash and Python barely compete against each other.
Bash has nothing in the way of nice datatypes. Bash is very slow while Python can be nearly as fast as C (I've gotten it up to 80% when relying heavily on C libraries like regex). Bash can't do more than the most trivial things without helper programs, which while useful, takes forever because it has to keep spawning processes.
For a high level language, Bash has pathetic memory management. Pretty much the only way to get some things done is tempfiles, which is worse than malloc because they're not removed if you don't clean them up.
If you can't hold more than two languages in your head, go home and learn Java and C#. You're only going to get made fun of on slashdot.
Re:CommonLisp for the 21st century?! (Score:1, Insightful)
Well, it's not dying, but it's not exactly flowering either.
Common Lisp still needs what it has needed for nearly two decades: a cleaned up and thoroughly revised standard. There is a lot of cruft in it that simply doesn't matter anymore these days.
Re:I *want* to be enthused, but... (Score:2, Insightful)
But Bash does not do anything. To accomplish something you have to use all the command line tools, like grep, sed, and awk. Put those tools in the language and you have Ruby or Perl.
Shell scripts are only really quick to develop because they mirror what we would type via the CLI. Thus the name, "script".
Re:Why the Decimal data type is needed (Score:3, Insightful)
python - awesome (Score:5, Insightful)
All those funny symbols, casting back and forth in perl just getting in the way yet don't really say anything useful ... here is an example:
whether or not this is good code is not the point, I have to make it work, look at all that pointless markup, in python this same thing would look like this:
(leading . stands for a space )which version would you rather read?
or that uselessly verbose java where you have to write X number of lines before any action starts ...
Python is a simple, clean and powerful language where the real value comes tomorrow or next month, when you have to understand and modify what you wrote today. There are no objective measures of this quality you have to try it to believe it.
Re:genexps (Score:5, Insightful)
Consider the example you gave: In Ruby, you can accomplish the same thing by writing: where "objGenerator" is an object that mixes in the "Enumerable" module. An even better way (that really avoids building an intermediate list, even of integers) is: There is one thing that generators give you that blocks can't, that is very, very cool. With a generator, you can create programs with a pipeline architecture, where different steps of the pipeline all can be written as if they have the main loop.
Imagine you are writing a compiler. You could write (be easy on my syntax, I haven't written Python in a while) The beauty is that both your lexer and your parser can be written as if they have the main loop, and all they have to do is yield a token/expression when they find one. In reality, it's pipelined and you get the efficiency of not having to build up the entire list of tokens before you start parsing.
Re:Is it just me? (Score:4, Insightful)
Since Python 2.x there is a move toward iterators and generators. Rather than seeing this as bloats I would say this Python is maturing to handle real world applications. If you are handling simple data and performance is not an issue, use regular lists. If you writing application to handle arbitrary large data set or performance is an issue, go for iterators and generators. List comprehension is a neat language construct but I don't see any need to rush rewriting anything.
Re:genexps (Score:4, Insightful)
You could also add this to the "Enumerable" mixin: Now you can call "sum" on any object that implements "Enumerable", and the example becomes: