60,000 Lines of Javascript

Share this article

Koranteng Ofosu-Amaah makes some fascinating and insightful remarks on Applications vs. W3C DOM (this goes back to July, 2003 BTW – skip past the ad). Stepping out of the discussion of rich web applications for a moment, what struck a cord was point 8. “Javascript is too Flexible”;

In the 60,000 lines of Javascript I’ve been dealing with, I’ve sometimes found up to 7 ways to solve the same issue in the code; some approaches being incredibly powerful, ‘smart’ and idiosyncratic but when it come down to it incomprehensible in the long run.

Part of this problem is specific to Javascript – try searching Google for Javascript and inheritance and compare the advice you get – but think there’s a general issue here which applies to all the dynamic languages. Koranteng calls for an effort by developers to codify best practices.

Over the last year have seen more and more people talking about best practices in PHP which is a very good thing, but at the same time, still seeing new developers making “mistakes” PHP allowed them to make. At the other end of the scale there’s developers who know a language well and can’t resist adding ‘smart’ features. That needs to be a golden rule of what not to do with dynamic languages – don’t extend the language (at least not using the language itself).

In PHP that probably means things like “don’t define a class String”. In Javscript perhaps it’s adding a property “superclass” to make inheritance possible. Meanwhile Python, which has a great design by default, draws things like this.

Trying to grasp the designers intent should be the first step of getting “serious” with a dynamic language. In the absence of a clear statement of intent (and PHP has many grey areas) it’s time to open the debate up with other developers.

Next on the list of best practices should probably be “you must write unit tests”. Perl, PHP, Python and Javascript (that I’ve used) have excellent unit test frameworks available.

What else?

The Platform Divide

Back to Koranteng;

Not to get into language wars but I’ll offer a bounty for whoever solves this issue. I want to be spoilt as much as a J2EE or .Net programmer is spoilt.

There’s a challenge ;) Sadly the big software houses are still missing this boat. The attitude is summarized by Thin To My Chagrin (Nov 2003);

But the best advice I can give you is simply use the right tool for the right job. The script languages are fabulous tools for their intended purpose. So are C# and C++. But they really are quite awful at doing each other’s jobs!

Personally think that’s a self fulfilling prophecy. It’s because the big vendors hold this kind of view that the state of dynamic languages is improving only incrementally, through Open Source (which may be a good thing). Microsoft does seem to be hedging it’s bets though, with the odd smart hire

The counter, in favor of dynamic languages, begins with Strong Typing vs. Strong Testing and ends in results like wxPython, Gmail and A9.

In contrast to Thin To My Chagrin, Koranteng makes further excellent commentary in On rich web applications, AlphaBlox and Oddpost (with follow up here – uptime varies).

Harry FuecksHarry Fuecks
View Author

Harry Fuecks is the Engineering Project Lead at Tamedia and formerly the Head of Engineering at Squirro. He is a data-driven facilitator, leader, coach and specializes in line management, hiring software engineers, analytics, mobile, and marketing. Harry also enjoys writing and you can read his articles on SitePoint and Medium.

Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week