I recently wrote an article for Nettuts+, “Cargo-Culting in JavaScript“. In it I cover the concept of cargo-cult programming and specific techniques that seem to be cargo-culted off quite frequently in JavaScript.
I found that writing the article took a great deal longer than I’d anticipated. Writing an opinionated piece is always a little risky and making the prose itself measured and reasonable is hard work.
Rereading it I realise it seems a little preachy. I think that may just be the nature of the principle behind the article though.
What’s quite funny is that regular tutorials and code samples inject the same amount of opinion and subjective preference but it is under the guise of code and so you don’t feel manipulated or provoked. Instead you feel appreciative and subdued. This is in contrast to prose… it only takes a bit and you’ll feel preached-to.
Code, on the other hand, seems factual and robotic. You can hardly debate a piece of code (if you try you’re either a “nitpicker” or “troll”). But shared code is far more pervasive a manipulator than we’d like to think. If it wasn’t then cargo-cult-programming wouldn’t exist. Techniques, both good and bad, spread like wildfire.
Thanks for reading! Please share your thoughts with me on Twitter. Have a great day!
It was an excellent read, James. I am definitely guilty of picking up habits due to widespread occurrence, and not out of true reasoning.
The problem seems to be a confusion around popular practice vs. best practice. I think the problem for many beginners (me), is that front end development, although incredibly accessible, can still be very confusing. We are desperate for answers and understanding, so much so that we look at seemingly experienced developers’ code and treat it as a best practice, without diving into the subject further and coming to our own conclusion.
I think this article (on your site) should be an author’s note over on Nettuts+.
Teaching people to use better data structures and assertions (for non minified JS libraries) would solve many issues you raised and would focus people to the cause (the data), instead of the effect (the code).
I’ve seen so many times code that could have made easy readable, less bug prone, if the data structures would have been defined better.
Hi fellow programmers,
This problem has become so popular recently with the need for classes in javascript, programmers end up trying
simulate them using javascript’s prototype system.
Real programmers use classes which now includes Javascript programmers.
———————————————————————–
This means writing and maintaining hacky code which if we want to learn from our past mistakes in programming is best left to the compiler. We dont want to return to hand-coding assembly-like languages, compilers will now generate better code; optimized even. And give us compile-time checking etc.
Let me tell you there’s a free compiler called classyscript at http://classyscript.com.
The language is a super set of javascript allowing classes and inheritance but compiling to standard javascript which will run in the browser.
Thanks,
Phil T