-
Website
http://www.enigmacurry.com/ -
Original page
http://www.enigmacurry.com/2007/04/20/python-vs-java/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
prasant
1 comment · 1 points
-
Christopher D. Walborn
1 comment · 1 points
-
Tim Lesher
1 comment · 1 points
-
Alex K
1 comment · 1 points
-
EnigmaCurry
11 comments · 1 points
-
-
Popular Threads
-
EnigmaCurry
1 day ago · 3 comments
-
EnigmaCurry
As for readability: as with any language that comes with experience; I have to strain quite hard to read you python example!
You're right of course, an IDE can help a lot. I've got my emacs snippets working pretty nicely now. One of them expands "print" to "System.out.println();" which works quite nicely for my python trained fingers.
As far as actually using something other than emacs... I can make the switch from python to java if I have to... but I don't think I can handle giving up my emacs :)
Seriously though, I have tried Eclipse but I can't even figure out how to do a simple macro. I use macros at least once an hour with Emacs. Can IDEA do macros?
Smalltalk ftw?
Me: Where did I talk about the history of Object Orientation? I realize that Smalltalk came before both Java and Python, but that has no bearing on the comparison at hand.
BTW, python doesn't have "list.remove(list)"? I guess you'd have to use set differences, which actually sort of makes sense.
Nice indentation! :)
Yes, there are two classes. However, Java requires the main function to be wrapped in a public class. This is loosley analogous to the "if __name__ == '__main__':" in python.
However, it does appear that I have some problems with my java code.. I'll upload a remake later today.
"Dick and Jane" is also easier to read than an essay written by Carl Sagan. Readability only counts when it's balanced with economy and expressiveness.
I think at every level Java adds non essential vebosity to the code. IMO, the only line of python that is less readable than java is "for x in someApples: appleList.remove(x)" .. that line only exists because python can't do set operations on lists. If this example had been using the native set class instead it would have been "appleList.difference(someApples)" which is on par with java's "appleList.removeAll(someApples)"
Most people who are unfamiliar with programming languages are usually at least familiar with basic algebra. In algebra you would usually write things such as "x=4" rather than "Integer x = 4". Also for matrices (essentially the mathematical representation of a list or table) is easily represented as something like "alist = [1,2,3,4]" instead of "List<something> alist = new ArrayList</something><something>(Arrays.asList((1,2,3,4)));" .. IMO Python is much more inline with basic algrebraic notation than Java is.</something>
ты б еще вспомнил C++ да с Бейсиком сравнил
import java.util.*;
public class Apple {
private String type;
public Apple(String type) { this.type = type; }
public String toString() { return type; }
public static void main(String[] args) {
String[] appleTypes = {"golden delicious", "gala", "granny smith", "fuji", "red", "braeburn"};
ArrayList appleList = new ArrayList();
for (String type : appleTypes) appleList.add(new Apple(type));
System.out.println("appleList: " + appleList);
List someApples = new ArrayList(appleList.subList(0, 3));
System.out.println("someApples: " + someApples);
appleList.removeAll(someApples);
System.out.println("appleList: " + appleList);
}
}
The link feature works, you just need to put some text inside the and tags. I fixed it for you above.
Your code is certainly shorter than mine, but it seems quite obtuse to me. Would you actually write Java code that way? It seem not very OO IMHO.
Thanks for dropping by.
Well, I agree with u that Python does more in less lines of code. At least in this case I think I cant reduce the code, unless I put everything in 1 line, but that would be completely horrible, lol. In your case u can reduce even more ur lines of code (ie all apples in 1 line), so I must respect that.
About OO, my code is following OO rules. Maybe it is strange because of the main() method inside the same Apple class, but that is not a problem, u can use the Apple as a normal object. The only difference is that it has a main() method. If u want, u can add main() in every class to do some tests or to have an example of how to use your classes. But u must remember that by convention the class that will run your application must be called 'MainClass'.
Now, 5 years later, assuming that I had a choice (and I often do), I would choose Python over Java for all but the largest software projects ... say greater than 100,000 lines of Java code (40,000 lines of Python code). While there are exceptions where existing Java libraries provide a higher return on investment compared to Python, it takes a very large project for the general advantages of Java to become apparent.
And I know hard core Python programmers who think I'm nuts to use Java in these cases as well.
I love Python whereas Java is a decent meal ticket.
Python is really very good, I had to learn it because of my job.
Now I am testing Jython, its a python implementation that runs over JVM and can use Java API.
getting error on your python sample code : http://pastebin.com/m43daa46c
>>>
Traceback (most recent call last):
File "/home/robert/Documents/python/p2.py", line 7, in <module>
appleList = [Apple('golden delicious'),
TypeError: this constructor takes no arguments