/ Hathaway Weblog / Java vs. Python

Shane :: Python :: June 16, 2004 # Java vs. Python

When I moved from C++ to Java about eight years ago, I thought the language wars were finally over. Here was a language that manages memory allocation, potentially compiles to very speedy code, integrates secure execution, works on both a big server and a little PDA, runs in both Unix and Windows, and comes with a big library. I became far more productive as a coder when I switched to Java. I wrote a web application server customized for distance education and sold it to several schools. I hopped on the Java bandwagon.

However, over the next four years, the fun of writing software slowly eroded. I spent a lot of time trying to reduce the memory footprint of my applications and working around bugs in the libraries. Since Java encourages a lot of formality, I started to write system architectures for every little concept. I wanted all of my code to live up to Sun's "100% pure Java" standard. I fell into long-term analysis paralysis.

Finally, I began re-opening my eyes to software that wasn't written in Java. I stumbled upon Zope, an open source web application server written in the Python programming language. Zope, it turns out, had already solved most of the problems I had with my homegrown application server, and it was well on its way to solving the rest. I starting writing software for Zope, then the company that publishes Zope hired me.

At first, holding to traditions, I wanted to convince the company to port Zope to Java. But as I got deeper into Python, I started to see the differences in attitude between Python and Java. Java's attitude has many absolutes: objects are better than functions, all differences between platforms should be abstracted away, libraries should always be written in Java for portability, fast execution requires hand-coded optimization, and it is best that one company has absolute control over the language so it doesn't become fragmented.

Python's attitude is quite different: functions are just as useful as classes, cross-platform compatibility is important but not all platforms are alike, bridging to libraries written in other languages is important, fast execution requires good algorithms, and the language should be controlled by culture rather than licensing.

I think Python's advantages over Java are easy to understand once you see the difference in attitude. I wrote in Python for four years, enjoying it all the way. Now I'm writing in Java for the Church, simultaneously trying to help the rest of the software development staff see the advantages of Python and Zope. I'm more successful with Java than I was before, since I no longer confine myself to Sun's vision, but we could open our vision so much more by switching to Python.

I'm trying to advocate my position quietly and with a very open mind. Another developer has a very strong preference for Microsoft's .NET, so I'm trying hard to learn and respect .NET. I'll do the same for anyone else on the team.

Comments

carlos (May 18, 2005 00:47)

I concur... I had the same experience with Java. After nearly 5 years programming it, and learning all those J2EE libraries and endless frameworks (ejb, struts, hibernate, swing, jdo, etc etc etc) I got very very tired. I recall how one day I walked out of work and my hands hurt so much from typing Java code, because Java is so needlessly verbose. After long reflection, I realised that Java library and framework designers were so in love with their own concept of pureness, object-oriented that it became ridiculous. Talk about over-engineering! And frankly, why do we have to know something as huge as struts (as good as it may be) just to render stupid web pages! I had a long look at my 11 years of programming and wondered if I would ever enjoy it again. I seriously considered quitting it altogether and retraining in another career. I dreaded programming.

Then one day I discovered Zope. It allowed me to learn about Python, which I was very suspicious of. I hated the tab-spacing. I tried it anyway. I kind of liked it. Then I discovered the wxPython GUI kit. I decided to recode a Swing app in wxPython. I fell in love. I was done in 1/3 the time. The performance was at least as good. I didn't worry anymore about my client machines running out of memory because I didn't have the piece of garbage JVM memory leaking machine to worry about anymore.

What's more, Python led me back to my days of C and C++... because I later discovered that Python was like scripting C/C++ in so many ways. I discovered the standard library of Python mirrored the C standard library. I was back to my earlier days when I enjoyed programming so much, but now 11 years later. Now I code in C++ and embed Python, and I as sure-footed in all the programming I do. No more Java for me, and I don't care how much those big corporations are paying because they bought all the hype.

(June 06, 2005 19:22)

I want you to move to Ruby!!

What's more, Ruby led me back to my days of C and C++... because I later discovered that Ruby was like scripting C/C++ in so many ways. I discovered the standard library of Ruby mirrored the C standard library. I was back to my earlier days when I enjoyed programming so much, but now 11 years later. Now I code in C++ and embed Ruby, and I as sure-footed in all the programming I do. No more Java for me, and I don't care how much those big corporations are paying because they bought all the hype.

Shane Hathaway (June 06, 2005 22:09)

I don't see a point in using Ruby at the moment. Python is the better BASIC that I wanted on the Commodore 64 / Atari 400 / Apple ][, the scriptable C/C++ that I wanted with MS-DOS and Turbo C++, the liberated Java I wanted with Microsoft Windows, and the clean syntax I wanted with Linux scripting. Ruby doesn't add any more.

That may change, of course, if you Ruby guys can offer major things Python doesn't have, but I haven't seen anything yet. (No, Rails is not an alternative to Zope.)

Some say you should learn a new programming language every year. Personally, I don't think a year is near enough time to properly evaluate a language, since languages are more than just another grammar. Each one has their own way of thinking. Like Chess, the rules are easy, but learning the right strategy in every situation takes much longer.

So I'll continue learning Python for now. I'm thoroughly happy with it. :-)

ionkoder (June 20, 2005 10:22)

I have dabbled in many programming languages including Logo, Basic, QBasic, Assembler, Authority, Pascal, Turbo Pascal, Visual Basic, C, C++, Erlang and PHP. I do not consider myself to be a subject matter expert. I did a lot of research into how Java woks and I have to say that I am just not interested in learning it. From my point of view, Java is a bloated and slow language.

In reality, many programming languages we work with today are compiled using a C compiler so what does that tell you? There has not been a recent programming language since the C language that has changed the world.

Personally, I see a world where CPUs, memory, storage etc. are no longer plugged into the motherboard and are instead plugged into the grid network. As a programmer, I should just be able to say "Allocate X CPUs, Y MB memory and Z MB storage to this process." The grid should just automatically handle hardware resource allocation. If I need more hardware resources, I should just be able to add them to the grid network and I should not have to upgrade components such as motherboards to take advantage of new types of CPUs, memory, storage, etc. People are sick of spending huge amounts of money to keep their computers up to date.

cole (July 05, 2005 20:39)

i dont even understand python.?????????????????????????????? thats supposed to be easy.

stephen (July 12, 2005 03:28)

Python was my first computer language. I've gone on to do significant amounts of programming with C++, Java, and PHP. Of these languages, Java is my least favorite - I dread starting projects in it.

C++ is about power and potentiality. PHP is about speedy, painless web development (perfect for the projects I need it for). PHP also has the best documentation of any language I've used to date. Python is pure programming bliss - it's the only language I actually think of as 'fun' to work with. The others are means to an end; Python is a joy in and of itself.

juanpi (August 05, 2005 20:35)

I simply love python... But is true that PHP is "he best documentation of any language I've used to date". PHP has one simple library for each necessity. The good thing is that we counted on lenguages open source for each flavor. Zorry, I do not speak ingles.

Jonathan Hendler (August 10, 2005 20:33)

PHP has been my language for 5 years. I've avoided Java successfully. I consider that an accompliment considering that in 1995 I was at a convention when I was a graphic designer and there was some frantic headhunter. I know I am handsome, but I was suprised when this woman approached me and asked "Do you know java? Can you learn it?". I explained I was a graphic designer, and did 3d. She seemed dissappointed. I wasn't - what was she thinking? If she was that excited it must be snake oil.

On the other hand I have seen Java used successfully in interesting proof of concepts academic environements. Some people say that they love java's multi threading. I say that's because they don't want java to appear slow. ;-) (ok, enough Java bashing, well one more) Maybe JNI can help? The worst part of Java is that it is a preferred language for government applications. As for performance, there are always other JVMs and caching like Resin. And then there is JYTHON!!!

System Message: ERROR/3 (<string>, line 6)

Unexpected indentation.
Does Python have true multi-threading?

With PHP I limited to scripting and web services although there is a TCL kit now. And even a language called Scriptol that seems to export to PHP and C++.

Python, in all the research I've done, has never listed something it can't do. Is it slower than PHP? I heard Zope can be slow and complicated to develop for. I'd like to move to python but I have to get paid to do something other than web development!

Vladimir (August 12, 2005 08:54)

> Does Python have true multi-threading?

Yes and no. Python objects themself cannot be manipulated in several threads in parallel. Python interpreter has a global mutex for this purpose.

BUT

You may write multi-threaded apps without bothering about this, except the case you need performance. Every C call that may wait (for i/o completion, for example) releases this mutex. So, this is not a problem.

In case you really need performance, write a module in C or C++ and release the mutex every time you do not need to access Python objects and interpreter in C/C++ code.

So, take it easy.

<a href="http://www.datanumeric.com/">Datanumeric</a> (November 02, 2005 04:50)

Python and Ruby seems to be the in languages these days.

brandon (May 04, 2006 09:27)

"I want you to move to Ruby!!

What's more, Ruby led me back to my days of C and C++... because I later discovered that Ruby was like scripting C/C++ in so many ways. I discovered the standard library of Ruby mirrored the C standard library. I was back to my earlier days when I enjoyed programming so much, but now 11 years later. Now I code in C++ and embed Ruby, and I as sure-footed in all the programming I do. No more Java for me, and I don't care how much those big corporations are paying because they bought all the hype."

ruby is a great language and rails is super cool. i actually perfer ruby syntax better. there is how ever one huge problem with ruby that makes python superior. ruby is implicit and python is explicit. this will make doing large projects or improving pervious projects much much much easier. (this is also why you can code a little faster and get something up a little quicker in ruby then python. but over all for medium to large or complex projects i think python would save you more time. if your looking to just get something to gether quick then why not use php. a logical, powerful, easy to maintain application is the whole reason to use python over php anyway isn't it?)

alot of people don't like being forced to used indentation however one really good thing about this is that it forces you to have clean looking code and also everyone's code should atleast look the same.

while its not a huge deal python is easier to read.

i think its gunna take maybe 5 years for ruby to catch up to python as far as support and other stuff. hopefully they'll give you the option to use ruby as an explicit typed language.

python with c++ (using swig)...its the yellow brick road.

Andrew Gryaznov (May 10, 2006 00:41)

The main advantage of python is definitely the speed of development. This factor (unfortunately or not) comes to the first place in modern programming styles. The XP, RAD are born to meet the customers growing needs and expectations, and modern ultrafast CPUs are born to execute python :)

If we get more time on the project (which is unlikely) we will rewrite the code in Java. And I bet the CPU giants will appreciate us writing python and advising buying faster hardware ;-)

I myself, given all the GPL tools and using python can now write code many-many times faster than I used to in C, perl or Java. I even think some of the projects would have never been completed in reasonable time if there was not python. I'm in love with python & I'm in love with all the OpenSource!

btw, python boots faster, and thus can perform all the GNU tools-intergrated operations way faster than Java can.

sheldon (November 08, 2006 09:47)

Is python faster than java when it comes to parsing and processing large volumes of data (10 GB) at a time. eg. the data is a large ascii text file with messages and each message needs to be parsed and processed.

How would you compare the execution time of Python and Java.

Thanks a lot.

No further comments may be added.

Click below to fill in the scripture reference.
Your browser is not able to display the scripture fill-in program. To see it, enable Javascript or use Mozilla 1.0 or better.
For behold, it is not meet that I should command in all things; for he that is compelled in all things, the same is a slothful and not a wise servant; wherefore he receiveth no reward. Verily I say, men should be anxiously engaged in a good cause, and do many things of their own free will, and bring to pass much righteousness;

Church: lds scriptures provident games pearls kzion shiblon film chancellor gateway cumorah byutv happiness nephi
Zope: freezope org com zen labs newbies zettai warnes
Python: home pyzine daily icanprogram
Genealogy: cyndi
Weblogs: jeffrey paul jon joel another-shane guido barry jeremy windley chrism zac
News: quakes lwn dc weather deseret zeitgeist softwarelivre
Zaurus: software developer
Tech: tango spintronics thin
Semantic: aaron sean
Reference: css rdf html4 javascript geckodom iecss emacs phrases acronyms
Reverse: advogato slashdot
Misc: gimp-savvy directory soda jokes shouldexist pdphoto