5 ms·
1.7x is probably misleading here. The example in the post is less than 100 lines long, which makes it very difficult to tell how the python code could be shorte
by Wilduck 15y ago
1.7x is probably misleading here. The example in the post is less than 100 lines long, which makes it very difficult to tell how the python code could be shorter. For example, in this tiny example program he writes, the author creates a "artist" class:
class Artist:
def __init__(self, name):
self.name = name
def __str__(self):
return self.name
Anyone familiar with python will realize that if this is the only functionality you need, than a bare string could be used instead, eliminating this code entirely.
At the end of this article (Update 3), the author links to a blog post that describes a reduction in lines of code from 90,000 to 12,000 after a re-write [1]. He claims that this reduction is more the product of increased domain knowledge than any sort of language benefit.
I think that really gets at the crux of the issue. Rapid prototyping, ease of understanding, clarity, ease of modification, could not only be equally important to code size, but could also directly influence it.
[1] http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_swit...
- Uchikoma 15y agoNot sure I can follow, "Anyone familiar with python will realize that if this is the only functionality you need, than a bare string could be used instead, eliminating this code entirely." Your argument was: the LOC is too high compared to Java because a class is used instead of a String? Or is there a shorter syntax for constructors, methods and attributes?
- Wilduck 15y agoWell, the only methods implemented in this class are the __init__ method, which is a constructor and the __str__ method which tells Python what to spit out when print is called. Since Python has the capability of duck-typing, if I had an instance of an artist class, and a string with the artists name in it, I could use them in the exact same way with regards to the functionality implemented in the artist class. That is, I could type "print some_artist" and either would print out the name. But, my larger point was that lines of code is tied in to a much more complex relationship that the developer has with their language and the problem domain. And that this is kind of a silly example to claim that Java is 1.7x more verbose than Python.
- awj 15y agoHis argument was: if the only two things your class does are take in a string when constructed and return it on demand, you don't need the class.
- BrandonM 15y agoExactly... in this case, the functionality of Artist() is a subset of the functionality of str(). In Python, you would just name the variable "artist", assign a string to it, and be done with it.