[1] http://codemonkeyism.com/comparing-java-and-python-is-java-1...
[2] http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_swit...
[1] http://codemonkeyism.com/comparing-java-and-python-is-java-1...
[2] http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_swit...
class Artist:
def __init__(self, name):
self.name = name
def __str__(self):
return self.name
There may be an argument to, as you say, "Never, never, never use String in Java" (or other statically typed languages), but a class like this in a duck-typed language such as Python is nonsensical.I'm not even arguing that Python's dynamically typed approach is necessarily better overall than Java, but if you're going to evaluate the two in terms of verbosity then you really have to compare idiomatic code in both languages. Whereas if you continue writing Java in Python, of course you'll only see a 2x improvement.
Not sure what your argument has to do with dynamically typed references? How would one create a constructor for an object that takes an argument (name)?
" but a class like this in a duck-typed language such as Python is nonsensical."
Does this mean people do not use classes in Python (e.g. for DDD)?
All three of the classes in the example are basically worthless. Including SongList, which is the one with the most logic (a single line) and which you didn't even use at the end. Here's the three classes, at their most future-proof:
from collections import namedtuple
Song = namedtuple('Song', 'name duration artist')
Artist = namedtuple('Artist', 'name')
class SongList(list): pass
and as a side-note, this: for song in (song for song in songList if song.duration < 10):
print "%s by %s (%d)" % (song.name, song.artist, song.duration)
is needlessly complex, why the comprehension? Just write a loop and a conditional: for song in songList:
if song.duration < 10:
print "{0.name} by {0.artist.name} ({0.duration})".format(song)Do you think when the classes are larger with some logic, the ratio of Java/Python LOC would change?
My intent with the post was to create empiric knowledge, I'm not a follower of the idea anecdotal 'evidence' trumps all that is pervasive in our industry. So thanks for your opinion, but I'm not interested in the least in anecdotes when comparing languages.
To answer your question, though, yes: all other arguments about Python vs. Java aside, the LOC ratio would change dramatically in Python's favor once you start to add actual program logic. (Unless you're stuck with an architecture astronaut for a Python programmer.)