Java is Better Than JavaScript
Tоday I was participating in a discussion on one Java forum – the question was if Java is easy or difficult programming language to learn. IMO, Java is not difficult to lear, to teach, and to use. It’s a strongly-typed compiled language with tools that help you out to identify most of the error before you even run the program.
While participating in this discussion I was writing code in a different programming language called JavaScript, which gave me a chance to illustrate that lots of things Java developer take for granted, while there are people who work in a more hostile environment called JavaScript.
I had a working program, and decided to add JavaScript handler function to illustrate HTML form submission with jQuery for our upcoming book. I’ve been writing this code in Eclipse-based IDE called Aptana. I’ve added this handler for the submit event to a Donation form:
$('#donate-form-container').submit(function(){
var formData = $(this).serialize();
console.log("The Donation form is serialized: " + formData);
returm false;
});
Ran the program – it rendered the Web page, HTML looks fins, but nothing worked. IDE didn’t give any errors. Started a browser debugger – Firebug. Now I’ll going to put a breakpoint in this newly added function and find the problem. How hard could it be? I’ve added just this little fragment to a working program. Easy Peasy.
Oops. Where is my main.js? Nowhere to be found. Only jQuery script is available.
Was my main.js even downloaded? Let’s check the Network tab. Yes, it’s here:
After applying deductive reasoning (as in Sherlock Holmes stories) I figured out that the script has arrived to the browser, which instead of adding it to the DOM, showed a middle finger without explaining why. As any normal person, I started to to find who someone else to blame. May be this Firebug is buggy and just doesn’t want to show my nice script? Tried Chrome with Developer Tools – same story. The script arrived, got the finger and I have nothing to debug.
Well, there is no one else to blame. Let me just re-read my own code. Man, I misspelled the word return and wrote “returm false;” instead, which deserves a capital punishment. Changing m to n did the trick, and now both Chrome and Firefox are happy to add my JavaScript code to DOM.
What’s the moral of this story:
1. Java developers should know that they take lots of things for granted and should not complain that their life is difficult!
2. The fact that it takes less code to write Hello World program in JavaScript doesn’t mean that it’s an easy programming language. Don’t trust me? Watch this.



Although comparing the two is not a very bright idea in my opinion, why did you assume that javascript is an easy language, to start from ?!
Basiuk T.V. (@Velizary)
February 8, 2013 at 11:28 pm
Strange. I have a bug in the console (firebug and chrome developer tools) -
Uncaught SyntaxError: Unexpected token false
Maybe the problem in your work environment?
Lance
February 9, 2013 at 8:53 am
I’m using Chrome v.24 and Firefox v.18 under MAC OS, and you?
Yakov Fain
February 9, 2013 at 1:06 pm
Something wrong http://jsfiddle.net/suaron/BXhmA/ , http://i.imgur.com/dgVFEuN.png
Dmytro
February 9, 2013 at 2:16 pm
I’m using Chrome 24.0.1312.57, Firefox 18.0.2 and Ubuntu 12.04. http://i.imgur.com/IN4VSDL.png
Lance
February 9, 2013 at 4:42 pm
Windows 7, Chrome 24
all as expected: http://cs323918.userapi.com/v323918087/45dc/e3b9zkTkVLQ.jpg
About jokes from video – actually its look strange only first time but if insight to rules – all is logically. So java is not better than javascript – it is just another.
Vasyl Khrystiuk
February 9, 2013 at 10:21 pm
returm -> return
Dmytro
February 9, 2013 at 2:19 pm
imho it’s the poor Aptana IDE
look at this shot from JetBrains WebStorm
http://cl.ly/image/352l0W2U2o10/Image%202013-02-10%20at%201.57.19%20AM.png
also, there’s a Code > Inspect Code option
http://cl.ly/image/1z0C1R282b2H/Image%202013-02-10%20at%202.03.00%20AM.png
I use the EAP (Early Access Program) version (betas) of WebStorm for free – legally
the video was very funny, thanks, you may entertain yourself with a book JavaScript for Assholes
https://leanpub.com/javascriptforassholes
Будам, хочу выразить благодарность за подкасты, с удовольствием слушаю и жду мэйл с уведомление о новом подкасте из Амерички.
О, пришло что-то там про футбол, запускаю айтюнс…
pribilinskiy
February 10, 2013 at 12:16 am
I have WebStorm too – bought it legally for real money (not counterfeit bills)
It’s definitely much better than Aptana. But for the book project I want to stick to the free IDE for as long as possible.
Yakov Fain
February 10, 2013 at 1:10 am
Tough Guy
pribilinskiy
February 10, 2013 at 1:15 am
TypeScript is much better than JavaScript. You should definitely check it out. Here is the specification pdf: http://www.typescriptlang.org/Content/TypeScript%20Language%20Specification.pdf
And by the way, JetBrains WebStorm 6 EAP support TS out of the box. http://confluence.jetbrains.com/display/WI/WebStorm+6+EAP
Qwer
February 10, 2013 at 12:51 pm
Tomorrow, someone will show me TypeScript.
Yakov Fain
February 10, 2013 at 1:57 pm
Here’s a nice video from John Lindquist showing TypeScript support in WebStorm: http://www.youtube.com/watch?feature=player_embedded&v=589eWAcIfsI
pribilinskiy
February 11, 2013 at 2:32 am
Any other suggestions for strongly-typed languages that compile to JS? Preferably ones that work in Eclipse?
Brian Trapp
February 25, 2013 at 2:35 am
What is difference between “return false” and “returM false”?
guest
May 8, 2013 at 8:18 am