Please stop pushing JavaScript down my throat.

by Admin 2. September 2012 09:45

I am primarily a web applications software engineer.  This has been my career path for last 12 of the 17 years I have been working.  That being said, I never overlook the merits of client applications in certain situations (graphically intense, constant connection or the need to integrate with other applications).  I have always found that any code that you have complete control over should keep in mind the following paradigms:

Standard OO principals:

  • Polymorphism: IAnimal -> Mammal -> Dog -> Basset Hound
  • Inheritance: Dog::Eats(){ return “Dog Food”}: Dog overrides Eat From Mammal where it is overridden from IAnimal.
  • Interfacing: IAnimal can be passed around regardless of the type of the inheriting animal.
  • Encapsulation: There is no reason to expose everything to everyone. Something’s should be exposed to the sub classes and (like in life) some things should just be private.

Other important constructs:

  • “Compiled” vs. “Interpreted”: This construct allows programming languages to be compiled down to a lower level language making them run as fast as possible on the target platform.
  • Type Safety (Strongly Typed): Increases performance and reduces runtime errors because the compiler catches issues and optimizes performance for the particular types. NOTE: I incorrectly stated performance is increased with type safety.  This is incorrect, it is a compile time construct and will not increase performance.

Now web applications by default are multiplatform targeted.  They should react the same way on one IE 9 running on Windows as on Chrome running on Mac (they don’t, but bear with me I am getting to the point).  This is where JavaScript excels. Since the actually code is pushed down to the compliant browsers the implementation of that code is left to the browser with guidance of ECMA standards.

I love JavaScript, I love JQuery, I think it is awesome.  But stop trying to make me run it on my servers or on my desktop FOR EVERYTHING.  .Net, Java, C++ all work great as compiled server side languages. Objective C and the previous also work awesome as compiled rich client applications (as long as you know the target system).  So why on earth would I want a language that breaks 3 of my core tenants of programming when I know the target system?

Yes for those that don’t know it let me reiterate JavaScript is not encapsulated, there is no way to mark a method as private. It is certainly not complied (sorry Closure you are an optimizer and calling yourself a compiler is an insult to anyone that has ever built a real compiler).  Finally it isn’t type safe.   I can do the following:

var something = 1; //something is an int
something =  "Ted"; //something is an string
something = function () { return "ted"; } //something is a method pointer
something = 1.34343; //something is a float
something = [1,2,3,4,5]; //something is an array

WOW, something can do anything, and I guarantee the above will run with no issues.  Yes I can do something similar with dynamic types, but there is a time and a place for dynamicity and all the time is not it.  

So when I read about Node.JS used in place of IIS/Apache and JSDB/TaffyDB used in place of Oracle/Sql Server or MySql I shudder a bit.  The only constant theme for why I should do this: is the same language is used client side and server side.  No performance gains (BTW scalability and performance are two completely different dynamics) and no additional features.  Sorry I just can't jump on the bandwagon.

I may sound like a bitter old programmer when I hear the terms "Bandwidth is cheap" or "Processors can handle a lot more these days" or "Just add some more memory/servers".  But why write less efficient code in the the first place.  Always weigh the benefits of performance vs. maintainability.  One should not completely override the other.

Learn PL/TSQL, learn an OO language, learn a server side scripting language(Perl, Python, Ruby), learn JavaScript and learn HTML.  But more importantly, learn when to use each and keep it where it belongs.  To quote my Grandfather, "Just because you can do something doesn’t mean you should."

Tags: , , ,

JavaScript | jquery | NodeJS | OOD | SQL Server

blog comments powered by Disqus


<<  April 2014  >>

View posts in large calendar

Page List


Comment RSS