Fog Creek Software
g
Discussion Board




Java or Python?

I'm not trying to start any language debates, but at the same time I'm curious.

If you had to learn either Python or Java, which would you pick?  Why?

I'm trying to teach myself Python -- no reason other than it's fun learning a new syntax -- and all the while I have this O'Reilly book, "Learning Java," sitting on my desk that looks kind of entising.

Are there any reasons, any opinions, out there that I'm missing that would/could/should get me to pickup the Java book for a while?  I know about Jython/JPython, but I'm strictly asking from the "Language X has feature Y that made my effeciency increase Z%" perspective.

Thanks.

Andrew Burton
Wednesday, February 18, 2004

I like Python a lot better than Java, but your language choice depends on what you would like to do. I find Java too heavyweight, while Python is refreshingly light (but not super-fast).

runtime
Wednesday, February 18, 2004

Python
    looks
    like
    a
    fun
    language

Check out WikiPedia's Hello World in every language page:

http://en.wikipedia.org/wiki/Hello_world

Java

    public class Hello {
        public static void main(String[] args) {
            System.out.println("Hello, world!");
        }
    }


Python

    print "Hello, world!"

www.MarkTAW.com
Wednesday, February 18, 2004

http://www.jython.org/

MD
Wednesday, February 18, 2004

Why choose?  Learn both.

Java is a bit more formal than Python, and it is more widely used in situations which might bring you an income.

Python is just fun.  Ever since I learned Python, I find myself missing tuples and the % operator when I use any other language.

Eric Sink
Wednesday, February 18, 2004

I was into java (though mostly JSP/Servlets) a few years ago, but today I'd rather go for python than try to revive my Java skills.
I am not to clear on why. It might be because I feel that Java is very complex and there are alot of different concepts for different applications that take some effort to remeber and understand. Python, as far as I know, is just python so to speak, where as J2EE is a world of mysterious things most of which I never understood.

The one drawback with python, that kind of hindred me from going futher when I looked at it a while back is that there is no solid way of protecting the source. That and a good JIT compiler would probably make me give it another go.

Eric Debois
Wednesday, February 18, 2004

"""no solid way of protecting the source"""

http://lists.copyleft.no/pipermail/pyrex/2004-February/000603.html


"""a good JIT compiler"""

http://psyco.sourceforge.net/

Also, with regard to the original poster's question, see:

http://www.ferg.org/projects/python_java_side-by-side.html

One interesting thing about Python in Java is that they have a *lot* in common, once you ignore static typing and the syntax.  Translating Java to Python mostly consists of throwing out all the crap classes you had to make in Java that you didn't really need, and deleting braces.  ;)  Translating the other way, though...  well, there's always Jython.  :)

Phillip J. Eby
Wednesday, February 18, 2004

I have been looking around for the "Delphi Next Generation" and Python sure is one of the best candidates. It's best feature is code readability. As we all know readability is the silver bullet in software development. Other good things are that Python is cross platform, the active development (Python grows at an incredible pace) and the fact that it is GPL type open source. Design decisions are taken with the end-users as main focus and not the share holders profitability.

My main concerns are execution speed and lack of a decent GUI builder. Even with the current JIT compilers, speed is nowhere near C++ or Delphi. Several GUI builders look promising but none are ready for prime time (read come close to Delphi/VB). There may be some commercial alternatives, but I haven't found them yet. Then there is the issue of which GUI library to use: wxPython, pyGTK, pyQT, etc. QT looks the nicest but suffers from license issues. Using QT it would nullify one of the main reasons for choosing Python in the first place.

I'm not too sure about the weak typing either. I prefer my bugs to show up at compile time rather than on my end user's computer. But it could well be that the advantages outweigh the disadvantages in this area.

In short: Python is looking very promising but not enough to make me jump yet.

Jan Derk
Wednesday, February 18, 2004

Andrew,

Depends entirely on what you do. On the Linux side of the computational pond I tend to know a little about all of the scripting languages (Perl, Tcl, Python), compiled languages (C++, C, Java).. and

I have found that most of the things most everyone do can be done using a scripting language. Administrative tools, one off tools, even applications you write for yourself to enhance your productivity. This is oppose to compiled languages, where there are few if any opportunities to edit other's c code or the c code of an existing software you rely on.

If you do high performance programming or scientific programming and performance is an issue you can always concentrate on Java. Java has earn some rights to be in the spotlight for these programming needs..

If you can do magic with c, then you can always use scripting languages as a control interface to your c code. SWIG, an interface you can wrap around your c libraries, mades your library available to Python, Tcl and Perl. JNI is also something you can use to make c libraries accessible to Java, but it's a bit of a pain (although it's not a big enough pain to avoid Java just solely for this reason--unless JNI is a big part of your software).

Li-fan Chen
Wednesday, February 18, 2004

Python is an interpreted language which is for some bizarre reason burdened with static typing.

Java is a statically-typed language which is for some bizarre reason burdened with the runtime performance of, like, bash or something.

Both pull a sort of Gordian-knot solution to the runtime-efficiency-vs.-expressiveness tradeoff by sacrificing both in return for nothing. As *languages*...? Flip a coin.

What that leaves is side issues.

If you're writing for end users, Java is not well or widely supported on clients, so you can't use Java. In stark contrast, Python isn't supported either, so you can't use Python.

You can't count on anybody having the run-time in either case (this is also true of every other fragile-ly-run-time-dependent language implementation on Earth -- which on Linux includes hip and edgy stuff like K&R C (but not bash, at least... yes, you can always rely on bash... which is why they used it to write the TCP/IP stack. In fact, bash itself is written in bash! It's turtles all the way down!)).

If it's the kind of thing where you can count on the user installing the run-time just to use your product -- or if nobody uses the target platform anyway, or if nobody is expected to use the product -- then that's not an issue.

If it *is* an issue, use a different language. C++ may take longer, but there is no conceivable business justification for investing *any* time in writing code that won't run on the target platform. VB is fine, too, if your target platform is Win32, though many programmers don't enjoy using it.

So what's left? One of them may perform marginally worse than the other for what you want to do, and one may be marginally more ill-suited to expressing what you'll need to express.

But without further clarity in terms of what you plan to *do* with it, the question can't be answered.

aarrgghh
Wednesday, February 18, 2004

Ok, I haven't done Python, so I'm not going to trash it, but I'll give what I like about java (and this is compared to other scripting languages like perl, php, vbscript). 

Java, the language, is *incredibly* simple.  Its also very easy to get started.  You can build useful applications right away.  Gui, web, whatever.  Its easy.  Yes, it can get very complicated when you start using some of the J2EE classes, but the language itself is very simple.  I recommend java to people who want to learn programming, because, unlike C++, you can see your results (which are practical in a lot of cases) in only a few hours.  Now, Python may be all this and more, but I can't say.  I will say a good java programmer is hard to come by.  We're interviewing now for someone, and we see a ton of java buzwords on resumes, but most don't know the language. 

vince
Wednesday, February 18, 2004

Anyone ever noticed how being badly informed and highly opinionated tends to make people look foolish?

Eric Debois
Wednesday, February 18, 2004

i've completed large projects with both. i've decided i never want to work on a "large project" again. I've never had the desire to use java for a personal project. I've used python for personal projects. However I keep going back to PERL for personal projects, as CPAN usually has some module that does 80% of what I'm trying to do.


Wednesday, February 18, 2004

"CPAN usually has some module that does 80%"

True dat.  I've "written" of ton programs that were just copy/paste from a couple of different modules.

Dan Brown
Wednesday, February 18, 2004

I should have course said that Python is dynamically typed instead of weakly. Duh.

Jan Derk
Wednesday, February 18, 2004

I think you can be up and doing productive things in Python much faster than Java.  There's a lot of modules written for both, but I think it's easier to plug them together in Python.

OTOH, Sun is supposedly coming out with  a more "VB-Like" IDE, so maybe that'll change.

Lee
Wednesday, February 18, 2004

What some people said about CPAN is true, CPAN is awesome.

The same can be said of any popular programming language, go googling for some examples is never too difficult.

Try these queries on google (replace #feature# with the feature you want, and see which language has more community in that area)

site:sourceforge.net perl #feature#

site:sourceforge.net java #feature#

site:sourceforge.net python #feature#

site:sourceforge.net c++ #feature#

Example: site:sourceforge.net java "regular expression"

Other sites: freshmeat.net

Li-fan Chen
Wednesday, February 18, 2004

Do you know how to program? Do you know object oriented programming? What do you mean by learn a language...just syntax?

Tom Vu
Wednesday, February 18, 2004

Continuing tom vu's point. Java and Python, subtract a few braces here, and add a few type declarations there... the shit all looks the same to me.  If you know how to program in the general sense, it shouldn't be too hard to pick up what you need to know about either language. 

That said, if you want an either/or answer, I would recommend learning python first just because there is less detail you have to learn before you can be productive. You just download active state python, or open up a terminal on your powerbook, and away you go. You should be able to write a useful script after about 4 hours.

On the lookout for Bella (he's flamed replies to this very question before), if you want to know which one will get you work more easily, you probably want to go with java.

However, with my experience I would recommend you try to avoid a java job. If you can find a job that uses python, you've found a much cooler job than 90% of the programming jobs out there...


Wednesday, February 18, 2004

The big bit of learning either Java or Python is learning to use the standard libraries effectively.  The two are quite different in some areas, but similar in others, and both are huge.  On top of the standard library, there are (at least for Python) also a bunch of common third party libraries that provide a lot of useful functionality.  For Python, look at Twisted, ReportLab, Numeric, PyGTK, wxPython, ..., even Zope.

All jobs use Python, they just don't know it yet :-)

Tim Evans
Wednesday, February 18, 2004

"""the fact that it is GPL type open source"""

Actually, the Python license is BSD-style, so you can actually bundle the entire Python interpreter and libraries inside a proprietary application, with no further obligations.  Thus, many proprietary applications embed Python as a scripting language, in much the same way that Excel embeds VBA.


"""If it's the kind of thing where you can count on the user installing the run-time just to use your product -- or if nobody uses the target platform anyway, or if nobody is expected to use the product -- then that's not an issue."""

This is a silly objection for both Python and Java.  There are plenty of installers available that will install the runtime support for you, or wrap up a Python app into a single executable.  Since the Python interpreter itself is small, and you only need to include the modules you actually use, the resulting application can be quite modest in size.  I'm pretty positive you can buy installation tools for Java that will do much the same thing.  The main difficulty w/Java is that unless you use a native compiler like 'gcj', you are probably going to be stuck needing a third-party runtime (e.g. Sun, MS, or IBM VM).  Python is a bit ahead of the game here, because you can compile your own custom version of the interpreter if you need/want to.  That's not really an option with the popular Java implementations.

So, it's kind of silly to say that you should write in C/C++ if people don't have the runtime.  Python *is* written in C!  And tools like 'py2exe' will even do the dirty work for you:

http://starship.python.net/crew/theller/py2exe/

In particular, note all the stuff about how it can create NT services, COM servers, console and GUI apps, etc.  Not bad for a free installer.

By the way, because commercial apps written in or using Python don't have to rely on a separately-installed third-party VM, you don't have to worry about VM version hell, wherein somebody installs a newer VM for some other app and breaks yours.

Phillip J. Eby
Wednesday, February 18, 2004

"Jython, lest you do not know of it, is the most compelling weapon the Java platform has for its survival into the 21st century"

That *is* funny.

Alex.ro
Wednesday, February 18, 2004

Learn python. Then use jython to learn java. Nothing like have access to all the java classes interactively. It really is a best of both solution. And yes, it's also not hteright tool for many things. But look at how much attention sun is giving a dynamic scritping laguage for the jvm. No need Scott, jython is here today.

fool for python
Wednesday, February 18, 2004

I am a Ruby fan ! There is a book about it that is just being made that might be of interest to some of you: http://poignantguide.net/ruby/

That said, I think you should learn Java 1.5 ! It has some cool features that most of us will be using in the next decade, even if Java won't be as good as our loved programming languages :)

Java has strong libraries (perhaps the strongest libraries) and strong IDEs (perhaps the strongest IDEs). But it isn't supported by Microsoft and that is a strong point against it too :P

Once you have learned Java you will probably learn other similar languages (Python, Ruby, C#), so start with the right foot .

Dewd
Wednesday, February 18, 2004

Thanks everyone for the words and wisdom.  I'm going to read through here a few more times since it was too much to soak up in a once through. :)

Eric Sink: Ideally, I will pick up both.  I guess I'm looking for a path to follow first.

Li-fan Chen: The thing I want to do, literally, is just learn a new language.  Perl and PHP are the meat of my job, and that's not going to change.  Learning Java or Python is just something to keep my brain greased.

Tom Vu: I know Perl, PHP and Visual Basic mostly; bits of C, C++, C#; and a tad bit of Lisp and Python.

Thanks everyone again for the advice.  Thanks.

Andrew Burton
Thursday, February 19, 2004

Tom Vu: "learn a new syntax" to me means learning about a language, it's history, and the mindset of the language.  How to think in terms of the language -- to me, there's a huge difference in the thinking behind a Perl program and a Lisp one.  I don't know if that makes much sense to anyone but me. :)

Andrew Burton
Thursday, February 19, 2004

If you're learning to get work,  Java.

If you're learning for fun.  Both.

Koz
Thursday, February 19, 2004

I recently got an offer for a Jython position.  (Yeah, they never tell you what you do, they say the dumb language.)  So there exist potential rewards due to lack of competition.  Of course, you do want to have written actual apps in both.

Python the language is more productive than Java the language.  If you worry about static typing, use unit tests.  The basic Python programming environment is fine for learning; you get an interactive prompt.  The intro is well-written and the usenet group is helpful.  You also get more latitude in techniques; you can use functions more than in Java.  I imagine Python -> Java is better than Java -> Python, but of course I don't know your psychology.

When you learn Java, it'll be the big ol' collection of libraries that give some people the fits.  But Patrick Chan's _Java Class Libraries_ books are good despite being way outdated.  They give decent examples and overviews of libraries.  Plus, the Javadocs are uptodate and available in Winhelp format.  The sourcecode to the libraries is ez2read.

Tayssir John Gabbour
Thursday, February 19, 2004

Definitely go for Python then.

If you've already got a decent hang of OOP (who hasn't these days?), there's little, if anything, that Java as a language can teach you. The only benefit you get is the ability to quickly read the examples in modern books on software design.

Python is far more innovative and applicable to the field you're in.

Egor Shipovalov
Thursday, February 19, 2004

My 2cent
Jobs offerings:
Here Java winds hand down. Perhaps actually the best bet in any language. In some years with Net this may change.

IDE:
Here Java also wins. Ecplise for example is not matched in the python community. I actually write all my Python Code with Vim. It's ok but often I'd love to have a good IDE

Support:
I don't mention the company support. But even just the possible documentation in Java is great.
'Refactoring' uses Java Examples. Take a look at the Junit website. It's amazing.
Mostly all the hyped trends (XP..) are shown in Java Examples.

Language itself for a beginner:
Well there Python wins. You can start much quicker.
The language is nice and polished.

Panna
Thursday, February 19, 2004

I'd say go for Python first (though you really should try Ruby as well.)

Python is the most useful additional skill to acquire.  Even if you program for a living, a good scripting language is the most useful tool you could ever have.

I program in VB for a living, but I save myself so much time knocking out quick disposable code generators in Ruby rather than typing it all up.

Learning Java really means learning the Java API.  Learning Java syntax only takes a few days.  Less if you know C.

When you ready to move on to Java you can use Jython to explore the API, especially Swing.

Ged Byrne
Thursday, February 19, 2004

Sorry, should say:

If if you program _in another language_ for a living.

Ged Byrne
Thursday, February 19, 2004

<Ged Byrne>
Learning Java really means learning the Java API.  Learning Java syntax only takes a few days.  Less if you know C.
</Ged Byrne>

  I agree with Ged.  I've already "started learning" Java a few times, and the syntax was very easy to get, since I had already worked a little with C++.

  But I never really used Java, even for a personal project, so I don't know the library at all.

  Now I'm willing to learn Python too, and then give Java another shot.

Ricardo Antunes da Costa
Thursday, February 19, 2004

I've used Python for a year professional, and Java for several before that.  I miss Java's interactive IDEs and debuggers and still use Java for little home hacks, although I'm doing more in Perl these days.  Even Perl has an interactive debugger mode which Python lacks.

Python defers lots of error checking until run-time which makes bugs more fatal, hence if i had to choose a production language it probably wouldn't be Python.  We use it for scripting; I just wrote a program today that talks to Google and does automated queries and sucks down pages - that sort of thing.  Perl would be just as appropriate to a lot of the work we do, but it less readable.

But ultimately, do you expect to find a job in one language or the other? Then go to monster.com and scan for jobs in your area - you'll probably find hundreds for Java, might find one or two for Python.  Learning the J2EE part of most of those jobs is a diffrerent story altogether; that you'll have a hard time self-learning, but knowing the language is a good start.

Bathmophobic skier
Thursday, February 19, 2004

Anyone use one of the python plugins for eclipse to do python development?  e.g. http://pydev.sourceforge.net  Looks like python ide's are on the way.

It seems to me that Ruby and Python are fighting for the same programming space.  Any comments on the merits of one over the other?

Python Programmer Wannabe
Thursday, February 19, 2004

Umm, Python DOES have an interactive debugger. It's the pdb module, and comes with the standard distribution. Out of the box it's your basic gdb-style command line debugger, but there are third party addons that wrap guis around it and all that good stuff.

Chris Tavares
Thursday, February 19, 2004

"""an interactive debugger mode which Python lacks"""

Not only does Python have an interactive debugger, it's got graphical ones too, in most of the IDEs.  (Python does actually have numerous commercial and open-source IDE's, with varying feature sets.)  Many of them even support debugging threads, or doing remote debugging (i.e. debug an app running on a webserver from your desktop).


"""defers lots of error checking until run-time which makes bugs more fatal"""

You must be joking.  :)  I use Java programs that spit out NullPointerExceptions all the time.  Regardless of language, failing to trap errors means a fatally flawed program.  Type checking is not error checking.  If you want to do type checking on your Python programs, there are tools like PyChecker, PyLint, and others you can use to do compiler-style checking.


"""It seems to me that Ruby and Python are fighting for the same programming space.  Any comments on the merits of one over the other?"""

Alex Martelli once wrote an indepth comparison of the two that you might Google for.  His comparison is more objective and friendly than mine might be.  Personally, I think the only thing that Ruby actually usefully adds over Python is anonymous blocks -- which aren't something I often need, and using a nested function instead is rarely a big deal anyway.

But I find it really annoying that Ruby advocates run around claiming that Python isn't object oriented because in Ruby "everything''s an object."  When I ask how this is any different from Python, they don't seem to have anything to add.  Anyway, Alex Martelli's comparison will give you a less biased opinion than mine.  :)

Phillip J. Eby
Thursday, February 19, 2004

Oh, by the way, see this thread:

http://discuss.fogcreek.com/joelonsoftware/default.asp?cmd=show&ixPost=65804

for more Python v. Ruby discussion.

Phillip J. Eby
Thursday, February 19, 2004

"Perl and PHP are the meat of my job, and that's not going to change. "

Ok with this knowledge then I would say learn Java. Why? Because in java you have interfaces, abstract classes, strong typing, etc. In python, you have the same things as perl and php on a basic level and you would only be learning new things if you go deeper (where 98% of people don't go.)

Tom Vu
Thursday, February 19, 2004

The thing with Ruby is that it is just so nice to use.

The thing to do is just try Ruby for just one job. 

Like me, you may think Ruby is the finest language ever written, and wish more languages were the same.

Otherwise you just won't see the point.

Ged Byrne
Friday, February 20, 2004

Ged Byrne, you are pretty big about advocating Ruby, why not start a thread and talk about some of the things it's good for (or better at).

Li-fan Chen
Friday, February 20, 2004

ruby is kind of like perl. only not quite as fucked up - but almost. thus it appeals to "HACKERS" in the old school sense.  It is from japan, so it reminds you of schoolgirls, karate, kamikazes, sumo wrestlers, akira, hot sake, hello kitty, and so forth. This is a big aesthetic win for a certain subsector of the nerd world.  The ruby-cocoa bridge is also much better than any of the other scripting language + cocoa bridges...so another aesthetic win (combines the SAAB of computers (apple powerbook) with an esoteric scripting language)).


Friday, February 20, 2004

I was in the same situation and I asked myself that question many times before.
I think that if you're into it just for fun and you don't have an urgent need to learn something for making a living, the best choice is python. Why?

Because python supports the same paradigm (object oriented programming) as well as the procedural style.
This means that although there are syntactic differences, the programming skills, concepts and practices you'll learn by using python will be same you would need if you decide to learn java (or c++, c#, delphi, etc).

What's more, python lets you learn all these advanced topics in a very easy way. The hardest think about learning to program is understanding its concepts, thinking like a programmer.
Once you know a language, learning a second one is just a matter of days (or hours), because all you have to learn is the sintax, not the concepts.

Python lets you write a solution to a problem you have now almost inmediately, while using other language would require much more time, testing and debugging. The only downside is that it will usually run slower than an equivalent c program, for example.

What how good is a program that is finished one month after you came across the problem you were trying to solve?
Isn't it better to do it in python and have the solution now, even if it runs a couple of seconds slower?

Luis Gonzalez
Saturday, June 5, 2004

Instead of wasting your time to learn java .. why don't u look at C/C++ (more powerful) .... uppss I heard someone yawning about portability.. hmm why don't u guys check out wxwidgets ?  Once again I say --> Java is just a marketing hype ... what a useless language.

Python is very good in prototyping early stage of application.

Combination of C/C++ (critical stuff) and python (GUI --> check out wxpython or else) will hold the power of ROI (return on investment) that is MONEY.

My2cents experience.

anton oey
Tuesday, August 3, 2004

*  Recent Topics

*  Fog Creek Home