JavaScript Is Basic's Offspring
Written by Mike James   
Friday, 02 November 2012

JavaScript is often described as the most misunderstood of programming languages but why is this? Part of the reason is that JavaScript is Basic's heir to everything it once owned.

Basic is a language we all loved to hate.
                               And now JavaScript is the new hate.

Basic was rough, it was ready and it was ugly. It had nothing to admire except of course that it was very easy to learn and use. Basic got a bad press from anyone who knew better but over time Basic developed into a language that you could not only do things quickly in but you could do them well.

You need to remember that there are no bad languages, just bad programmers.

OK, this is a platitude and good languages help good programmers be better programmers and make better programs. They make being neat and tidy and doing a proper job easier but there is a lot to be said for a language that has the common touch. A language that knows what you want to do and gives you what you need without the extras and the overheads. 

Such a language was Basic and so is JavaScript.

There are many ways that languages come into being but they are mostly created by people with an idea, a philosophy. That philosophy can be object orientation, it can be functional programming, logic programing or well you name it. Programmers tend to believe in things and build these things into the languages they create. This tends to produce languages that are more like marketing tools for their philosophies than practical "get the job done" tools.

However, there are one or two languages that are born out of necessity. This is how Basic came about. From a humble beginning as teaching language, it was beaten into shape by being used by lots of people on lots of different home computers. It evolved to include the features that the programmers of the time needed. Simple graphics commands and sound were added, not because they fitted into some paradigm, but because they were essential.  Then it took the leap onto Windows and Visual Basic continued the pragmatic development of the language.

Basic was a language built by use and not by design and the same is true of JavaScript.

You almost certainly know the story of how JavaScript came into being. It was created by Brendan Eich as a scripting language for an early version of the NetScape Navigator browser. Yes you may also know that the name JavaScript was picked to get some reflected glory from Java, i.e. it was a marketing exercise. In practice, of course, JavaScript has little in common with Java - they are both languages descended from the C side of the family tree, but that's about it.

What you might not know is that Eich had very little time to do the job - to quote:

 It had to be done in ten days or something worse than JS would have happened.

Worse!

There are people around who can't imagine anything worse than JavaScript but ... Brendan Eich did a great job getting the language on the right road.

JavaScript has a lot of C like syntax but it deviates from most of the object-oriented languages that derived from it, like Java and C++. In fact JavaScript is modeled on many aspects of Scheme - a Lisp-like functional language. Eich joined Netscape with the idea that he would implement a Scheme-like language but the project became more urgent and JavaScript was the result.

In a mad rush to build a language, JavaScript was influenced by Scheme a functional language and Self a classless object oriented language. It acquired first class functions from Scheme and prototype inheritance from Self. Perhaps these are the two features that make JavaScript so misunderstood. It also  incorporated features from Java, which is probably the real cause for the language not being as elegant as it could have been.

JavaScript had to be interpreted and this leads naturally to a dynamic language but this is to miss the point that dynamic languages tend to be weakly typed and weakly typed languages are easier to use.

Try explaining to a beginner the distinction between an integer and a float. Try explaining the difference between "100" and 100. The point is that if it is hard for a beginner it is also just plain hard.

You can take the point of view that typing is there to protect you from mistakes.

You can also take the point of view that most of the mistakes that are caught are caused by typing.

Even so JavaScript gets lots of criticism from programmers used to strong typing for its free and easy way with data. Yes it's not perfect but it is easy and easy is usually better than hard.

What is really remarkable is that JavaScript acquired a classless object system. Objects are created as they are need and modified as needed. Efficiency is mostly taken care of by the prototype idea - i.e. borrowing methods defined on other objects which act as prototypes for new objects.

Notice, and this is really important, JavaScript does not have a type hierarchy.

It can't really have a type hierarchy because there is no class and no inheritance. This is another thing that Java and C++ programmers can't fathom. How can you have a language that has objects but no classes, no inheritance and no hierarchical type system.

The JavaScript programmer on the other hand is mystified as to why class based languages end up stopping you from writing natural code to the extent that they have to invent ways around the problems created by strong typing like generics.

If you believe that strong typing is essential to making a language a good language I need to point out now that it isn't strong typing within the language that matters. Strong typing simply lets the compiler or the environment check that you are not doing anything silly. You really don't need strong typing to invent tools that can do a very similar job.

In other words, strong typing doesn't need to be built into a language to allow tools to be created that do the same job.

If you don't believe me take a look at the JavaScript implementation within Visual Studio 2012. It provides you with lots of help via Intellisense and effectively type checking at design time. Yet the JavaScript it works with is still weakly typed and dynamic. You could even quote Microsoft's new TypeScript extension to JavaScript as proof that you don't need strong typing in a language to get the benefits of type checking.

The point of all of this is that JavaScript is like Basic, a language that has evolved to best meet the challenges of the way it is being used. It is a "street" language rather than an academic language.

If you think of JavaScript more as a sort of Lisp-like functional language that has been made into a practical tool by being used and misused, then you are closer to the truth. It was often said that Basic was Fortran for the people.

JavaScript is Lisp for the people.

Would it have been a better language if Brendan Eich had been given more than ten days?

Probably not.

 

Related Articles

Why JavaScript is a Jem

JavaScript Inherits the Earth

blog comments powered by Disqus

To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin,  or sign up for our weekly newsletter.

 

Banner

Last Updated ( Friday, 27 September 2013 )
 
 

   
RSS feed of all content
I Programmer - full contents
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.