Saturday, 27 July 2013

A cow is to Cowley

My dear friend Ryan has decided he'd like to learn a programming language. Now this has provoked much debate between the #boss and I. Actually, it's provoked no debate as both the languages initially on offer to the young chap are not the best place to start, though it's debatable what *is* the best place to start.


He commented that he'd just heard some beardy types in sandals asking "what's the difference, they've both got Java in?". Let me explain...

Firstly, as part of the day job I get to use both on occasions, Javascript for a little bit of front end work on webviews or webtools to offload some of the rendering from the server and, even more occasionally when working on applications for Android. I'm really not a fan, though I do like that I can keep things off the wire with Javascript. But the big differences are:
  • There is *no* common root between the languages, the (possibly urban legend) story is that Netscape came up with the name to make people think they were related as Java was the Next Big Thing™ at the time.
  • Java uses an implicit this scope for non-static methods as well as an implicit class scope. Javascript has an implicit global scope. The implications of this are pretty wide ;-)
  • Java is statically typed whereas Java is dynamically typed and this can be abused at will
  • Java is also strongly typed...
  • Java uses block based scoping (yay!) but Javascript uses function based scoping (there be dragons)
  • Java is class based but Javascript is prototype based. Which means more opportunity for abuse as you casually add new prototypes for a giggle
  • Java has constructors that can only be called on construction, Javascript constructors are just normal functions and can be a bit rock and roll in appearance.
  • Java demands all non-block statements to have semicolons at the end, Javascript will play merry and add some for you in certain circumstances.
  • Java can only be variadic if specifically defined, Javascript lets you run merrily through the code chucking daisies and roses abound one day, but doing nothing the next.
  • Java doesn't have real closures, they have to be faked, but Javascript is quite grown up and has them.
  • Java is tied to its class and can't be redefined at runtime, Javascript isn't and can be redefined at will
  • Java is usually compiled to byte code before distribution (no peaking at the source), Javascript is usually distributed in source form and interpreted on the fly. Which is nice as you can see how things are done.
Finally, other popular comparisons:
  • Java is to Javascript as a ham is to hamster
  • Java is to Javascript as a car is to carpet
And my personal view... Java looks like fun at first but becomes a pain the the proverbial and never goes back to being nice. Javascript though looks like a badgers interpretation of a Van Gogh but you learn to love and appreciate it once you learn the tricks.

No comments:

Post a Comment