PDA

View Full Version : Python vs Java



Lupy
2008-12-31, 04:34 PM
I'm looking to learn a programming language, and since C and its family are too advanced for me right now, I'm trying to decide between Python and Java. The reason I am uncertain as to which to use, is that while Python is said to be easier to use, and more effective, I have heard that Java is "faster." What does this mean? Does it make Java significantly better to learn as my first programming language? I also hear that Python will be better to know in the future, but is this just a marketing ploy? I know X/HTML, but that's not saying much, and I've done some VBscript and Javascript, but nothing more advanced than custom popup windows for my computer.

So really it just comes down to, which one is easier to learn first? Thanks ahead of time Playgrounders, I know you'll have great advice. :smallsmile:

-Lupy

NOTE: I'm running Vista SP1, 32 bit, with 3gb of RAM and a 2.0ghz processor, if that makes any difference in the above mentioned "speed."

rankrath
2008-12-31, 04:39 PM
python. The syntax is simpler, the language as a whole has less rules, and it's a much better starting language than java.

The speed thing only matters if you're writing large programs, something you won't have to worry about if you're beginning programming.

Also, java is a language which has a number of peculiarities that occurs only in java, making it harder to learn another language if you start with java.

adanedhel9
2008-12-31, 05:15 PM
The speed issue is overrated. Speed should only be a deciding factor if is also a requirement, which is fairly rare.

For a beginning programmer, I'd choose Python over Java. Python is a lot easier to get started with than Java.

Reinboom
2008-12-31, 05:23 PM
I will say....
PHP.
You know html, so, the graphical interface side you already figured out.
It has very detailed error reporting capabilities.
It is very well documented.
It is useful for even everyday tasks (er, if you're like me.)

Also, its syntax is nice enough (and flexible enough), to be easy to learn/figure out.


Out of the two you gave though, python is easier. Java is too... unique if you are only after a stepping stone language.

Recaiden
2008-12-31, 05:57 PM
I would like to recommend Python out of those 2. Also, Jython (http://www.jython.org/Project/) I don't know much about it, but it seems relevant.

Tirian
2008-12-31, 06:01 PM
Of the choice you offer, Python is the better language. But if this is self-study to become a programmer, you should get a helmet and learn C. It shouldn't frighten you that much, but if it does you can do Pascal first. Even though there are a lot of great high-level languages out there, there is much to be said for starting with low-level languages so that you can know how to use the other languages properly at a later point.

I don't know about performance comparisons between Java and Python. I'd guess that they're pretty comparable. The key feature that Python delivers is development speed. If it takes an hour to write a C program that takes a second to run or ten minutes to write a Python script that takes three seconds to run, which is "faster"?

InaVegt
2008-12-31, 06:27 PM
One problem with python is it's lack of ;s to end statements. It's better to start programming with using these.

I would recommend python above Java, though. And Python is a very easy language to learn.

Pyrian
2008-12-31, 06:33 PM
If it takes an hour to write a C program that takes a second to run or ten minutes to write a Python script that takes three seconds to run, which is "faster"?That will depend a great deal on how many times it is run. :smallcool: Seriously, if I'm making a "run-once" sort of algorithm I'll usually just do it in Excel... Honestly, I find the multiplicity of languages kind of annoying, since I'm usually choosing a language based on the result I want rather than based on any attachment to a particular syntax. It would be cool if any and all given environments were compiler independent.

Perhaps I'll make a sort of post-compiler compiler that would allow you to write, for example, your Java Applet in Pascal and such.

Holocron Coder
2008-12-31, 07:04 PM
Having learned Java first, I can say it wasn't that hard to learn. However, I did learn Python a year or two later and practically learned it in my sleep.

Either would be fine, but Python would be easier to pick up. As a note, the Javascript you know may actually be useful in learning Java. The syntax is somewhat similar, as are the ideas.

Tirian
2008-12-31, 07:06 PM
That will depend a great deal on how many times it is run. :smallcool:

Yes, I didn't say that it was a rhetorical question. :smalltongue:

Grey Paladin
2008-12-31, 08:25 PM
PHP.


I'd say PHP is too easy - it offers many comforts which will be gone once you move to a language which is focused on optimization rather than rapid development.

@OP: I'd say Java - if you're going to program more seriously later on both Java and Python are subpar to the alternatives. Java offers you an excellent understanding of Object Oriented Programming once you master the basics, and if you're here to learn I think it is superior.

Though I started by learning x86 Assembly, so I may just be trying to make you suffer as I did =p.

Gray Jester
2009-01-01, 03:02 AM
Python.

Java is the work of evil and needs large pointy things stuck in it.

It has all the problems of a hard-to-code in language (like C).

And it has all the problems of a language run by VM.

It's painful to use in development (No, seriously. I prefer x86 asm to Java.), it has stupid weird quirks and annoying conventions, like the lack of 'pointers' while still actually having them and just attempting to handle everything back stage. It's terribly confusing if you think you're doing one thing, but it turns out you're actually doing something else because of a hidden pointer instead of an object copy or something like that.

As someone who -has- to use Java because of AP Computer Science, trust me on it: It is NOT a good language as a first language or even a second language. I wouldn't learn it until after C/C++ because at least then you'll know how things -should- work.

---

On the other hand, Python is apparently very easy to learn/use (my scripting language of choice is perl, so I haven't bothered learning Python yet, although apparently it's easier), and I know for a fact that it'd be faster writing then the Java.

If you want to be a serious programmer, learn C or C++, they really aren't that imposing.

Or, yaknow, x86 asm is wonderful if you really want to know how a computer 'thinks', but I warn you, too much and you start thinking in it (a problem for me with any language if I use it too much: I start structuring thoughts as programming things, or thinking in a foreign language), and that's just painful until you get back to thinking in whatever language of choice your head uses is back in there.

Zakama
2009-01-01, 06:36 AM
So if I could just hi-jack this thread a little bit...

On the Python site there are 2 versions of Python for Windows.

# Python 2.6.1 Windows installer (Windows binary -- does not include source)
# Python 2.6.1 Windows AMD64 installer (Windows AMD64 binary -- does not include source)

I'm a noob and don't know which to get. Here's my System Specs:

Operating System: Windows Vista Buisness (6.0, Build 6001)
System Manufacturer: Gateway
System Model: 9310X
BIOS: Default System BIOS
Processor Intel(R) Pentium(R) 4 CPU 3.20GHz (2 CPUs), ~3.2GHz
Memory: 1022MB RAM
Page File: 1286MB used, 1020 available
DirectX Version: DirectX 10

Thanks.

valadil
2009-01-01, 10:54 AM
If you can't handle C, Java won't be much of an improvement. Go with python.

Tirian
2009-01-01, 11:45 AM
Gray Jester's post is entirely true. Sucks about Java being the AP CS language -- it was Pascal when I took the class which is much more benign. I suppose it wouldn't get you much work out of high school, but Java doesn't either these days from what I hear.


On the other hand, Python is apparently very easy to learn/use (my scripting language of choice is perl, so I haven't bothered learning Python yet, although apparently it's easier), and I know for a fact that it'd be faster writing then the Java.

It's worth the trouble to upgrade from Perl to Python, at least for new development. The biggest thing that held me back was the smugness of Pythonistas who go out of their way to put down TMTOWTDI and DWIM and all of the great Perl concepts. Well, I'm here to tell you that TMTOWTDI is still how you program in Python and the most correct solution to a problem is usually the Perl-like one.

Lupy
2009-01-01, 01:22 PM
@Zakama:

You want the first one because you have a 32 bit processor, the second one would be for a 64 bit processor, if you ever need to know, just look up your processor on Wikipedia or Newegg.

Back on topic:

Thanks guys for all the help! I will definitely go pick up the Python for absolute beginners book next time I'm at the book store.

Another note:

Is it reasonable to think that if I work on it every day I can be competent by April? I'd like to have it down by the time I finish Middle School, so that I have a much better shot at getting into AP Compu-sci in High School.

Lentava-Heppa
2009-01-01, 05:45 PM
As someone who studies CS and works as a web developer I would like to go and unlike everyone else:
-recommend Java
-Disagree with the reasons


First of all, unlike some others have said, Java is not an easy language any more than others. Sure, absolutely simplest things are easy as you don't need to pay attention to pitfalls that trap many beginners (memory handling for example) but as anyone with any more experience in actually programming something can tell there is more to it. Much more important than minor details in syntax or what minor things you need to remember are actually good coding habits.

Anyone will in a bit of time learn syntax, etc. but that doesn't mean you are good for anything yet. So that you write clean, high quality code that is easy to read and easy to understand and modify by others who participate in the project. This is the hard part in programming and the thing you need to learn.


It isn't easy in Java either. It is easy to write code in any language but writing good code is the trick.

And for that Java is good to begin with. It encourages you to write good code, especially if you are a beginner much more than Python or C++ do. Neither encourages you to use objects in the proper manner the way that Java does (hell, C++ lets you write horrible abomination of a code mixing procedural and OOP freely). It is not even just with what the compiler allows you to do but can also see clearly in the attitudes behind books and tutorials on different languages when you've read enough.

This is the reason why practically all colleges have chosen to start by teaching Java though they clearly should explain it more to the students...

What comes to speed of the program, Java is the winner there too. Sure, the virtual machine takes a bit of memory but newest Java HotSpot with it's JIT compilation actually match C++ in numerous benchmarks. If you want to do anything resource spending in Python you need to write those parts in C and integrate them into your program (which Python lets you do, sure).

Java's graphical utilities far exceed those of Python.

And I haven't even gone to the "Java works on every platform" part. Sure, some people claim that it means "Code once, Debug everywhere" these days but by the time you need to go to the parts that work differently in different Java versions you should already have very good understanding of programming principles (which is what you want/need).


For a book I could give you a recommendation of getting "Agile Java - Crafting code with Test-Driven Development" by Jeff Langr. It teaches you to write tests to your code first and then write the code so that tests succeed, helping you avoid numerous bugs and speeding up your development. Hell, I could recommend the language just for that book alone.



I am not saying that Python sucks. In fact as a web developer I am rather fond of it myself. It is useful for a lot of large scripts and small programs that aren't enough resource hogs themselves that you would want to start Java's massive VM but in which you want to keep the fast writing and easy editability that you lose when writing and compiling C++ programs. It is a right tool for many jobs. I just don't think that learning basics of programming is one of those.

But who am I to speak? I originally began programming in PHP (and wouldn't recommend it for this either ;) ).



As for how competent you get... Well, I'm not from USA so I have no idea what these APs are. I doubt you'll be able to force yourself to study every day - and I don't think that it's effective learning strategy anyways - but by that time you could easily have gone through one book, perhaps two.

If those happen to be good books, you should be pretty competent compared to the needed level regardless of what language you choose.

rankrath
2009-01-01, 06:26 PM
@ Lentava-heppa: I recommend you read this (http://www.stsc.hill.af.mil/CrossTalk/2008/01/0801DewarSchonberg.html), a very good argument for avoiding java as a first language. It also contains some good general advice for a novice programmer.

valadil
2009-01-01, 06:59 PM
And for that Java is good to begin with. It encourages you to write good code, especially if you are a beginner much more than Python or C++ do. Neither encourages you to use objects in the proper manner the way that Java does

Encouraging you to use objects right away is a problem. Start with variables and functions, then move to objects. Dealing with objects is just too much to digest at first.

Zakama
2009-01-01, 07:21 PM
Thanks Lupy!

ufo
2009-01-01, 07:21 PM
*destroys track with a bomb and derails train*

Mildly related, can anyone refer me to an up-to-date free C++ compiler? I am trying to learn some basics of C++, but it seems that in my every attempt the internet is actively working against me.

On the subject, can anyone direct me towards a good tutorial on the matter?

Jack Squat
2009-01-01, 07:31 PM
*destroys track with a bomb and derails train*

Mildly related, can anyone refer me to an up-to-date free C++ compiler? I am trying to learn some basics of C++, but it seems that in my every attempt the internet is actively working against me.

On the subject, can anyone direct me towards a good tutorial on the matter?

http://www.cplusplus.com/ is a decent tutorial site from my experiance. Also, don't discount Wikipedia, they'll normally have example code (either real - normally python and/or C/++ - or sudocode, which is useful once you kinda know you way around)

As for free compilers...download Linux and use set it up to use VIM. Also, there's some Microsoft product, but it's godawful. check out here (http://www.thefreecountry.com/compilers/cpp.shtml), don't know what's all in there, didn't feel like surfing through.

Gray Jester
2009-01-02, 07:13 AM
First of all, unlike some others have said, Java is not an easy language any more than others. Sure, absolutely simplest things are easy as you don't need to pay attention to pitfalls that trap many beginners (memory handling for example) but as anyone with any more experience in actually programming something can tell there is more to it. Much more important than minor details in syntax or what minor things you need to remember are actually good coding habits.

Anyone will in a bit of time learn syntax, etc. but that doesn't mean you are good for anything yet. So that you write clean, high quality code that is easy to read and easy to understand and modify by others who participate in the project. This is the hard part in programming and the thing you need to learn.

It isn't easy in Java either. It is easy to write code in any language but writing good code is the trick.


All true. Bad code is ugly to read.



And for that Java is good to begin with. It encourages you to write good code, especially if you are a beginner much more than Python or C++ do. Neither encourages you to use objects in the proper manner the way that Java does (hell, C++ lets you write horrible abomination of a code mixing procedural and OOP freely). It is not even just with what the compiler allows you to do but can also see clearly in the attitudes behind books and tutorials on different languages when you've read enough.

This is the reason why practically all colleges have chosen to start by teaching Java though they clearly should explain it more to the students...


Beg to differ. I have seen much worse beginning Java then Python in terms of bad readability. AP Computer Science has more then enough of terrible programming conventions done by myself (Yes, I'm guilty of this. I just also know how to write good code when I really need to) and others to save lines of typing. We've even managed to turn classes that were supposed to implement accessors and just used them like structs because we could. Java doesn't teach good programming syntax more then any other language.



What comes to speed of the program, Java is the winner there too. Sure, the virtual machine takes a bit of memory but newest Java HotSpot with it's JIT compilation actually match C++ in numerous benchmarks. If you want to do anything resource spending in Python you need to write those parts in C and integrate them into your program (which Python lets you do, sure).


True enough, although with a standard, modern computer, python really isn't terrible and it's much faster to be programmed. C++ is still, imo, going to be baseline faster then Java assuming approximately equal optimization done by the compiler, simply because of the fact that it's compiled down to machine code, not byte code. I question the quality of the C++ compiler in those benchmarks.



Java's graphical utilities far exceed those of Python.


Graphical utilities are an afterthought for most programmers. I know all the stuff I write is command line, unless I feel that a GUI is really necessary. (And it never, ever really is, unless you're making the product to sell.)



And I haven't even gone to the "Java works on every platform" part. Sure, some people claim that it means "Code once, Debug everywhere" these days but by the time you need to go to the parts that work differently in different Java versions you should already have very good understanding of programming principles (which is what you want/need).


There are a few choice inappropriate quotes about this that are more inappropriate and more telling then just that, you know.



For a book I could give you a recommendation of getting "Agile Java - Crafting code with Test-Driven Development" by Jeff Langr. It teaches you to write tests to your code first and then write the code so that tests succeed, helping you avoid numerous bugs and speeding up your development. Hell, I could recommend the language just for that book alone.


Test driven development is wonderful. However, it is also painstaking for small level projects, which is what you would be doing early on. Wonderful for class testing in a larger group, though. However, I disagree that it's the best thing to teach someone who wants to learn the -basics- of a language: it's more a professional development trick that is useful in the long run.


I am not saying that Python sucks. In fact as a web developer I am rather fond of it myself. It is useful for a lot of large scripts and small programs that aren't enough resource hogs themselves that you would want to start Java's massive VM but in which you want to keep the fast writing and easy editability that you lose when writing and compiling C++ programs. It is a right tool for many jobs. I just don't think that learning basics of programming is one of those.

But who am I to speak? I originally began programming in PHP (and wouldn't recommend it for this either ;) ).




As for how competent you get... Well, I'm not from USA so I have no idea what these APs are. I doubt you'll be able to force yourself to study every day - and I don't think that it's effective learning strategy anyways - but by that time you could easily have gone through one book, perhaps two.

If those happen to be good books, you should be pretty competent compared to the needed level regardless of what language you choose.

AP Computer Science is supposedly about comparable to a freshman year computer science course at the college level. I sincerely have my doubts about that (although I don't hold my teacher in the highest respect after she made the claim that VB compiled down to machine code, having taught it for years...), but the more advanced one (which is getting discontinued) gets all the way to some fairly basic data structures (nothing as fun as x-y trees or graphs, though, just binary search trees, heaps, lists, and arrays).

I wouldn't recommend it as the best way to learn a language, though that might just be bias due to the quality of the class I'm in. However, even the lower level class (APCS: A, as opposed to AB) does a decent job of imparting the ideas of classes, object orientation, etc. to people. However, if the teacher isn't a good programmer, I would teach yourself the ideas outside of the class as well, so that you don't end up making the mistake of going too overboard with object orientation (For a class employee you need a class paycheck, for a class paycheck you need a class money, for a class money you need the classes 'dollars' and 'coins', for a class coin you need to implement metal, etc., all to calculate the employee's paycheck in a 'real world situation'). In that case, a function that calculates the employee's paycheck, and maybe an interface 'payable', or something like that.

I hope I didn't just start a holy war... :smalltongue:

----

Oh, Lupy:
If you're doing AP CS, I would either avoid learning Java so that you can spend the class learning something, or learn beforehand so that you get straight As. It's not a terribly hard/exacting course, though, at least where I am.* Since Java is the mandatory language for it, you have a huge leg up if you've gone through your standard basic Java book.

*Note: My idea of hard might not be the same as a normal person's. Take this with a grain of salt.

Tirian
2009-01-02, 12:40 PM
*destroys track with a bomb and derails train*

Mildly related, can anyone refer me to an up-to-date free C++ compiler? I am trying to learn some basics of C++, but it seems that in my every attempt the internet is actively working against me.

On the subject, can anyone direct me towards a good tutorial on the matter?

Microsoft Visual Studio Express (http://www.microsoft.com/express/product/default.aspx) is free. It's more geared toward writing windowed programs than console apps, and you've got to tie it down to make it compile in a DOS window. But it fits the budget.

I've got http://www.cplusplus.com/ bookmarked for class reference, but they have a tutorial. I can't vouch for it, but the rest of their documentation is very solid.

Lupy
2009-01-02, 10:18 PM
So... Before I dish out my hard earned allowance money, final word from everyone: I will not be screwed if I learn Python as my first language? I understand the value of doing LISP, Pearl, Java, and especially C and C++ later, but I can do Python now and be okay?

rankrath
2009-01-02, 10:26 PM
So... Before I dish out my hard earned allowance money, final word from everyone: I will not be screwed if I learn Python as my first language? I understand the value of doing LISP, Pearl, Java, and especially C and C++ later, but I can do Python now and be okay?

yes, python is probably the best language to learn first. go for it.