Performance java vs. python

namekuseijin namekuseijin at gmail.com
Wed May 20 13:46:38 EDT 2009


On Tue, May 19, 2009 at 7:21 PM, David Stanek <dstanek at dstanek.com> wrote:
> On Tue, May 19, 2009 at 5:43 PM, namekuseijin <namekuseijin at gmail.com> wrote:
>> someone said:
>>>>>>
>>>>>> If you took a look at Java, you would
>>>>>> notice that the core language syntax is much simpler than Python's.
>>
>> thanks for the laughs whoever you are!
>>
>
> I'm no Java fan, but I do agree that the core language is a bit easier
> for people to grasp. I have also heard that from other developers as
> well.

Really?  Core language, eh?

Just take a look at just the summary of the Java language spec:
http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html

Then compare with the summary for Python 3.0 language reference:
http://docs.python.org/3.0/reference/

Like comparing a mammoth to a zebra.

Besides, how is:
for( int i=0; i<10; i++ )

simpler than:
for i in (range(10))

?

Scripting languages like Python eventually led Java to provide a more
friendly for, which they call, quite appropriately, enhacedFor.
Here's it in action:
for (Map.Entry<String, Integer> e : histogram.entrySet())

in Python:
for e in histogram.items()

fun.

Here's a more complete example, available a bit down from:
http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.14.2

Map<String, Integer> histogram = ...;
    double total = 0;
    for (int i : histogram.values())
        total += i;
    for (Map.Entry<String, Integer> e : histogram.entrySet())
        System.out.println(e.getKey() + "       " + e.getValue() / total);

in Python:
histogram = ...
total=0
for i in histogram.values():  total+=i
for e in histogram.items():
    print(  e[0] + "     " + str( e[1]/float(total) ))

yeah, surely a friggin' lot more complex... and we didn't even come to
use any of Java's HUUUGE APIs, just the core lang... BTW, I'm amused
that Java's string concatanating doesn't require an explicit cast from
the float result.

anyway, again, thanks for the laughs.



More information about the Python-list mailing list