Welcome to the news archive. Here you'll find all the news items, ordered by date. You can use the links below to read other news items, or go back to the archive overview.
2008-04-10 11:27 - Python vs. Java
The major reason my company doesn't use Python, is Java's static typing. If only Python had that, my life would be so much nicer. Here is an example of code I have to work with.
The code in Java:
private List<Identifier> barcodeTypeOnly(List<Identifier> ids)
{
final List<Identifier> barcodes = new ArrayList<Identifier>();
for (Identifier id : ids)
{
if (id.getType().equals(Identifier.TYPEBARCODE))
{
barcodes.add(id);
}
}
return barcodes;
}
What it would look like in Python:
barcodes = [i for i in ids if i.type == Identifier.TYPEBARCODE]
Nuff said.
Comments
If you want to understand something that's written, it's useful to know the language ;-)
However, if you know Python, the one line is definitely easy to read.
by Sybren - 2 years, 3 months ago.
On your companies need for type checking: try Strong Typing vs. Strong Testing.
People forget that Python is strongly typed, but the type checking is done at run time, and types apply to objects rather than to variables.
Yep, it may not be what a Java/C++/C# programmer is used to, but it works well.
-
Paddy.
by Paddy3118 - 2 years, 3 months ago.
Indeed, strong typing works well.
My company (me included) want an IDE with good code completion. To get this, either the Python code needs to be run (not a good idea in general) or the code needs some indication of the types of the variables used.
Python 3 will include something that might make the latter possible, but I think it is not going to become the standard Python implementation any time soon.
We'll just have to see what the future brings us.
by Sybren - 2 years, 3 months ago.
"... or the code needs some indication of the types of the variables used."
It might feel like jumping in at the deep end, but a lot of Python users write great code with the editors and IDEs available. The simplification and shortening of code, less reliance on deeply nested inheritance hierarchy's, the use of modules rather than every class needing to be in separate files,... all of these make navigating Python projects easier. Try http://dirtsimple.org/2004/12/python-is-not-java.html
-
Paddy.
by Paddy3118 - 2 years, 3 months ago.
Thanks for the link, it's a great read.
I agree that writing and reading Python is a lot easier than Java. It's just that I have to write Java for my job, so I'm pretty used to having near-perfect code completion.
The comment at the end "And if you miss your Java IDE, consider the possibility that it's because your Python program is much more complex than it needs to be." does tell me I want the wrong thing. However, with a team of about 8 people working on the same software, you can't always know every parameter to every function by heart. Having code completion or a window that shows the docstring for the name under your cursor would help in such cases.
by Sybren - 2 years, 3 months ago.
Hi again, The Idle IDE that comes with python has tool tips, but other IDEs include SPE, wingIDE, and Komodo. Microsoft is integrating IronPython into Visual Studio and the Eclipse framework has Python support too:
http://pythonide.stani.be/ http://pydev.sourceforge.net/ http://www.activestate.com/Products/komodo_ide/index.mhtml http://www.wingware.com/ http://www.codeplex.com/IronPythonStudio
(In no particular order).
Have fun, Paddy.
by paddy3118 - 2 years, 3 months ago.
Post a comment
All fields are required, except when otherwise noted. You can use a limited subset of Restructured Text to markup the comment.
It might take up to five minutes for your comment to show up, due to caching of the pages.
To me you're proving here that shorter code is definitely not easier to understand by definition ;-) Have a good day, Mr. Stüvel.eu
by Sander Verhagen - 2 years, 3 months ago.