You are here

Javascript.

I wouldn't have thought that a language that pretty much threw out all of the rules of good language design would come to occupy a place in my heart, standing with the likes of romances with C++. But then we do live in strange times.

I started my career like many other computer programmers of my time in the C/C++ era. I mastered my pointers. I mastered pointers to pointers. I mastered pointers to arrays. I mastered pointers to arrays of pointers. How many stars is that, f***?

But then the world changed.

Direct access to memory was now looked down upon. In came the garbage collectors and took away the pointers. Only embers remained. Still a NullPointerException and your program died. Ouch!

Programming languages were focused on making things safe. The clever stuff that only few programmers cared to understand was removed so that large teams of programmers could work away, like drones building software. The clever stuff was clever, but hard to debug. Companies got worried. What would happen when their star programmer resigned? Who would debug the f*** they left behind?

I think it started with Java. It must have...

You have to declare all the possible exceptions your method can throw. And the person using your method will have to handle them all, or re-declare them. The compiler was watching all and getting harder to please. Try, what a pain in the, NullPointerException. Catch, should it have been a NullReferenceException, I wonder? Did they get the naming right finally?

I understood the reasons but I missed the clever stuff you could do in C++, if you knew how to do it safely and properly.

Meanwhile Microsoft developed C# and incorporated some of the best features of popular languages like C++, Java and Python. C# is a fantastic language to work with. Thank you Microsoft.

Microsoft had its pulse on what programmers loved. They brought back the good stuff like function pointers, err no, delegates, ahem. Lambda functions, high-five Python. And string, after all "the world without string is chaos"1. Any C++ programmer worth their salt has attempted writing their own String type that they wanted to be better than any other out there, but landed up being full of bugs, except std::string of course. And C#s string works with Unicode, no fuss. C# gave me hope. Await.

They saw the potential of this nascent language that did not shoehorn you into types or classes of objects.

Software engineering is maturing as a discipline. Was it ruby? on rails? The tools got better. I mean Objective C, Apple, seriously!? But with XCode by your side completing the code, even that was manageable, stay strong. Not just code completion, there were helpful tips from the compilers. Take C#, not many complaints about how it is unhappy with your code, just gentle reminders in the right direction, like that variable you perhaps forgot to initialise. But there was more awesomeness in the works, like refactoring by renaming functions and extracting parameters in Visual Studio. And dependency management. A golden NuGet.

Unit-testing got big too. Clever mocking libraries, test runners, coverage analysers. The tooling around programming just got so much better.

Thinking was changing, again. You didn't need a large team of programmers to churn out code. More didn't mean faster. The waterfall had dried up and you had to be Agile. The marketing department loved this. They sprinkled it liberally all over the corporate website. Do you Agile to survive or do you survive to Agile? What's your mantra? Got a coach yet?

Languages still remain primarily safe. No, you aren't allowed direct access to memory like in the old C++ days. Those were bad practises. Still cool though, being able to de-reference pointers to f*** in your head, I think. But yes, the safety offered by modern programming languages is reassuring. Delegates, lambdas, async. It is well thought out and cool in its own way, I guess.

Nothing is familiar except the curly bracket, a false sense of security.

Then there is Javascript. The vagabond. Return, and unless your brackets be on the same line ye shall be doomed. I had tried my hand at it, in the browser of course. Small snippets of Javascript, getting bigger and unwieldy very quickly. I always ran back to the safe confines of "proper" languages. I appreciated the compilers and loathed the Javascript interpreter. I encapsulated myself away from the horror. Error, [Object]. IE7. Alert, no debugger. Go figure.

But I know some others persisted. They saw the potential of this nascent language that did not shoehorn you into types or classes of objects. They came up with JQuery, JSLint, promises and polyfills. It was something about it being fast, asynchronous, single-threaded they said. Something nimble about it I didn't seem to get. I felt it was unsafe and safety was paramount wasn't it? But the ones that persisted had promises to keep, and miles to go. And they kept going, building then breaking pyramids of doom.

Sweat, tears, Angular. Whoa! You couldn't turn away from Angular. And NodeJS built on top of V8. And a web server in a couple of lines of code. You just had to see it to believe it. The Web, now a platform for apps with Javascript coursing through its heart. Open-source was coming back, but not like in the GNU era, with the whole copy-right copy-left debate. It was simple. It was modular. It was asynchronous. Because it was linted and unit-tested, it kept its promises2. REST assured. Have a Mocha, or Chai, if you prefer. Be sure your brackets stay on the same line as your returns and careful don't release Zalgo3.

Yes, it is difficult moving away from the safety of classes, types and a watchful compiler, into the seemingly lawless land of vars and functions. From sequential steps to asynchronous events. Nothing is familiar except the curly bracket, a false sense of security. Your vars are still in scope and though that equals this, this has changed under your nose but not that. You need to be strict. It requires a different way of thinking. But then it clicks. It is unsafe, a lot of it is unsafe. The challenge of writing good safe Javascript is perhaps equal in skill to writing good safe code in the romances of C/C++ where pointers lay bare your memory. But remember software engineering has matured since. The tools are so much better, and free! Linters and test frameworks. Is your code covered? The community and the collaboration is great. The examples have gotten better. A language need not be safe but your approach to working with it can be. It requires discipline of method and a rigour in approach. And yet it demands a new way of thinking. It can be as much or as little as you want it to be. It comes with freedom but it demands skill.

Javascript has brought me closure. Here be dragons.

To Javascript, with love. KISS. ({})