16.9.12

JavaScript rules!

There's a question I often ask myself: What's missing in Linux? In F/OSS world?
I have a list of answers for this question but there's one answer that might surprise you: We miss a general-purpose-easy-to-learn-easy-to-use programming language.
I think this answer might come as surprise to most people while considering the abundance of programming languages around us like Perl, Python, Ruby, PHP and others but I always felt there was something else missing. Looking back at history I would like to take a controversial example for this topic from the commercial world: The VB6 example. Sure it was a horrible horrible language but people actually used it for their every-day use. I used to see it all around - Windows people wrote utilities with it, wrote prototypes and in some cases even entire projects with it (god forbid!). People were happy with it and that's what really matters.

In the distant past I loved PHP so much that I used to have this "silly" idea that PHP should be used everywhere - on server side , on client side (because I used to think JS sucks), for shell scripts and even for GUI applications but my colleagues and friends used to dismiss this idea by saying PHP is good for server side scripting because it was designed for it and that's where it should stay. I guess they were right but the idea that one scripting language can and should be able to do everything was stuck in my mind. I was a good PHP developer but I never really got to know JS as well (and that's too bad) but since than a lot has happened.

JavaScript has got a new life and that's already old news by now! It got to be 1st place on some Language Popularity Ranking Lists and everybody noticed it - MS with their HTML5+JS applications in Windows 8 , Gnome (v3) having their new and shiny Gnome Shell written entirely in JS, QT with their QT Quick, Mozilla used it to extend Firefox in the past and now I have a feeling they will build a new OS around it.

A few months ago I decided that I had my fair share of living under a rock and that I should check out JS seriously. After looking for recommendations I bought "Javascript the good parts" and started using JS for a little web project I'm working on in the background. I decided to use the "full javascript stack". Here are some projects I found very useful and interesting in the past few months:

  • node.js (js in server side, check out npm - the nice package manager)
  • express (js framework to write server side applications)
  • mongodb (schema-less database, JS-like syntax for queries and JSON for results, very cool)
  • backbone.js (popular framework for client side)
  • JQuery (who doesn't know this one?)
  • Twitter Bootstrap (related to CSS but awesome for lazy developers who still like their poorly designed web pages to look good)
I don't know if it's the one language to rule them all (mostly because I was wrong so many times before :-P) but I can tell you one thing: The developers community is big enough, The projects are alive. Lots of ready-to-use components with permissive licenses, lots of support (in stack overflow). bottom line: lots of fun.

5 comments:

Tomer said...

FYI, Mozilla already building an operating system around JavaScript.

levdev said...

Ok, seriously, I had to mark this one WTF!

Sorry, it isn't mean as an insult.

I know this might start a religious war, as these things usually do, but in my experience, JS is a horrible language!

I mean it is a complete mess!

It is suppose to be "object oriented", or at least people try to use it that way, but it has no dedicated syntax for it so you end up declaring classes as functions.

And good luck separating variable scopes...

Maybe I am a part of an older generation (though I am only 30), but if JS was the first programming language I had to learn, I would probably think computers are crazy and make no sense.

A while ago, I got to dismantle a malware JS script, to try and understand what it does.
And my conclusion was: this is what this language was designed for - writing code that will confuse the enemy :-P

And I am saying this after experience with (in that order):
QBASIC
VB 6
Turbo Pascal
C
Visual C++ (Yes, including MFC its almost a language of its own)
C++ (the real, standard kind)
Java
Python

Well, maybe I am missing something, but probably because it is declared implicitly :P

shlomil said...

@Tomer: I said it in the post - that Mozilla's new OS is probably going to be based on JS but I don't know this project good enough and wasn't sure about the details. Thanks for clearing that up.

@levdev: The post and title was deliberatly designed to make you go "WTF?!" :) . Now that I got your attention I would like to say that ... sure! JS might look horrible to the common OOP programmers at first sight. I know this because just like you I despised JS before I took the time to really learn it. A lot of people despise JS because they expect JS to be something else. Some people even think JS should be "fixed" (Google Dart).

If you ever really took the time to learn JS you should have known JS was never supposed to be an OOP language. It is a prototype-based (which makes some aspects of OOP possible) scripting language with first-class functions (which makes it possible to use a functional programming style and write event driven code). So let's just call it a multi-paradigm language, shall we? BTW, I totally see it right now as functional language. OSS projects use this feature extensively.

The thing is that during the years of browser development a lot of crap "evolved" into JS and stayed there. Levdev, I'm a little sorry for you because your job description includes reading malware code and that's why I'm not really surprised you hate JS. The only JS code you read is evil by design. I think you should read code from respected OSS projects, Maybe that'll provide a different view.

Anyways, because all that crap exists in JS, I was looking for a book that will re-introduce JS and only the useful parts of it. That's why I chose "JavaScript: The good parts". It's (only) a 140 pages-long book(let) and it only deals with the good parts although there is a little section in there talking about the bad parts you should avoid. Reading it was very easy because I already knew most of it but it gave me a good idea of how JS code should look like (when not written by malware guys;).

BTW, I'm a part of an even older generation (34) and I'm not going to list all the languages I used to know/use in the past because I think it's a bit childish but I feel like being cheeky and tell you that my list is bigger :-P I just love programming languages, what can I do :)

levdev said...

Well, looks like your post did the job (on the WTF part :D)!

But don't be sorry for me.
Reading malware code is not part of my job, it's just something I did once, as a challenge, kind of like solving a puzzle.

(I let some steam off about it here:
http://levdev.wordpress.com/2012/06/09/eval-is-evil/)

I realize of course, that malware code will usually show the ugliest part of any language used, and every language has its ugly parts.

But, as part of my job, I did have to do some custom maps using Google Maps API, which is built in the OO style.

On the plus side, it is designed to be easily extendable by plugging in your own class for the needed component (like a tile loader).

On the minus, as we seem to agree, OO in JS doesn't look so good.

Any way, maybe I still have some bias toward dynamic languages, though I really like Python because I found it good for both quick utility scripts and cross-platform GUI apps.

I think I will check out that book you recommended, since I will probably run in to a lot more JS in my job whether I like it or not...

So, Shana tova :)

shlomil said...

'eval' is evil according to 'JS: The good parts':
http://oreilly.com/javascript/excerpts/javascript-good-parts/bad-parts.html

Shana Tova to you as well :)