Here's a bold statement... (so I made the font bold)
JavaScript is the best programming language
Here's why...
JavaScript is the best programming language
Here's why...
- The language is extremely powerful. Let's imagine that we are inventing a new programming language. The most important thing we will focus on is "power." That means... write more elegant, more flexible, more readable programs... and write them even faster.
- Closures. A completely awesome, overlooked feature of JavaScript that we all (hopefully) take for granted. Closures allow you to create a new instance of a function which retains access to the context in which it was created. Examples are here: http://en.wikipedia.org/wiki/Closure_(computer_science).
- Dynamic data types. JavaScript variables aren't restricted to any particular datatype. Store a String, store a number, or store an Object. JavaScript automatically casts datatypes back and forth as needed.
- Objects are basically associative arrays, and vice-versa. Everyone loves associative arrays. The end.
- First-class and higher-order functions. Variables can store functions. You can pass functions as arguments to another function. A function can return another function. Functions in JavaScript can have an unlimited number of arguments. Anonymous functions? No problem. Functions in JavaScript are just awesome!
- OOP is easy. Objects are made up of properties. There is no distinction between properties and methods because functions are handled the same way as other datatypes. JavaScript supports inheritance. Constructors are just functions that are invoked using the new operator.
- JavaScript is prototype-based. Object oriented code is awesome (reduce coupling, encourage encapsulation, code re-use, etc). But, classes aren't the answer. Classes are too strict, resulting in strictly defined Objects, each with fixed properties and methods. With prototype-based OOP, you design Object prototypes (i.e classes) that can evolve throughout the lifetime of the program. Adding a new method to all instances of an Object can be done very efficiently at run-time with one line of code.
- JSON is a subset of the object literal notation of JavaScript. Use eval() on a JSON string and you successfully implemented Object deserialization - although in practice you would actually use JSON.parse(). Still... awesome!
- No concurrency headaches! That's right -- JavaScript is single-threaded. There is an event loop (hidden from view) and there are events and event handlers. Start an I/O operation with function call. When the I/O operation completes, an event handler function is called. Piece of cake! You don't need concurrency -- a single-core CPU only has a single thread anyway. If you want to utilize multiple CPU cores or build a computer cluster with Node.JS, just run multiple instances of your application and allow them to communicate via Sockets. Threads are slow and waste a lot of memory anyway.
- Other dynamic programming features. Eval(), func.call(), func.apply() are all features that should be used sparingly, yet they are still available when their use is appropriate.
http://www.w3schools.com/jsref/jsref_eval.asp
http://devlicio.us/blogs/sergio_pereira/archive/2009/02/09/javascript-5-ways-to-call-a-function.aspx - JavaScript is widely adopted. Almost every operating system has a web browser with JavaScript support. PCs, Macs, Cell phones, handhelds, tablets, & netbooks all have browsers that support JavaScript. While it is mostly used as a language for client-side browser applications, it is being increasingly used as a general programming language (even compiled)... Node.js is a good example. Also, due to JavaScript's wide adoption, JavaScript has a very large development community. There are a ton of JavaScript tutorials all over the Internet.
- A simple library backed by a ton of 3rd party libraries. JavaScript on the browser has an extremely simple API. The DOM is relatively straight-forward, as well. jQuery is just one example of a library that makes JavaScript much easier to use and much more readable. Node.js is also relatively simple.
- JavaScript is fast. JavaScript is among the fastest interpreted languages thanks to many recent advancements. (thank you, Google Chrome, et. al.). On some platforms, you can compile JavaScript. From what I've read, it's pretty fast, too.
- I forgot to mention the obvious. Developing in JavaScript is free.
JavaScript will soon become a common server-side programming language (perhaps running like CGI or NodeJS will take over). Web servers will be used for serving static pages. Technologies like JavaScript client-side and NodeJS will run the bulk of a "Web 3.0" application. Cutting-edge database back-ends like Redis will lead developers to lightning fast real-time applications.
If you don't know JavaScript learn it. If you hate JavaScript (which I did for many years), look again.
JavaScript ROCKS! The end!
Comments