By continuing to use this site you are agreeing to our use of cookies, as set out in our privacy policy.

« go back Tech comment

JavaScript: tabs versus spaces

Article by Chris Sawyer Javascript.jpg

The world is full of surprises: boxers wear gloves to protect their hands, not their faces; the white part of a barcode also contains data; and the JavaScript steering committee is recommending we go back to using semicolons.

While almost everyone knows that people who prefer spaces over tabs are inhuman sociopaths that punch kittens for fun in their spare time, for a few years now the general trend in JavaScript development has been to go without and rely on JavaScript’s Automatic Semicolon Insertion (ASI) to handle it. There’s a commonly used de facto standard aptly called ‘the JavaScript Standard Style’ at standardjs.com – that works with lots of editors/IDEs. This has been sound advice for a couple of reasons:

  • For developers new to JavaScript, knowing when to use a semicolon and when to leave one out requires experience and can be frustrating.
  • Code looks cleaner without them.

However, The ECMAScript (the specification on which JavaScript is based) steering group TC39, can see a future where it might be prudent to go back to manually inserting them. The language specification is increasing in complexity and sometimes the syntax around certain declarations, e.g. class fields, is too ambiguous for the ASI and tricky bugs can be introduced. Babel plugins that introduce new language features ASAP are also common and these too can challenge the ASI as well as one’s sanity… ‘trailing commas in array syntax’, I’m looking at you.

The most important thing is not whether you use semicolons or not, but that the whole team uses the client’s standard. If the client doesn’t care, then use them, but make sure you use a linter such as ESLint, or configure and share your IDE’s grammar settings. If all the member of your team are using a JetBrains IDE, e.g. IntelliJ IDEA, then you can automatically share many aspects of the IDE and language configuration.

Among the many distressing statistics that come from Stack Overflow’s review of 2017 – other than that PERL is still alive – was the fact that US developers who use tabs (kind, generous, fighting for all the good in the world types) have a median salary that’s roughly 30% less than the despicable kitten-punching space-preferring developers. Where’s the justice? Still, it’s worth a read…

ARCHITECTURAL LOGIC

In the pantheon of great phrases to drop into a sales conversation when the topic turns to software architecture, comes: ‘So, rather than the Lambda architecture, you want a Kappa architecture – where the emphasis is on streamed data rather than batches so you can ditch the data store.’ This is a trend that we’ll see more of – you’re not cutting off options and you can still do batch, if necessary.

Lambda architectures often revolve around Hadoop-based solutions whereas Kappa architectures are often based on streaming (well, micro-batching really) via Apache Spark and using a log concept as the data store rather than a traditional SQL server. Our internal researchers are constantly investigating these architectures (among several others).

Spark is often used is because of its flexibility; it’ll use Hadoop’s YARN if you’ve got it and its plugins support SQL, Streaming, GraphX Graph DB and Machine Learning – that’s a lot of flexibility, especially when you consider it already has great language/API support from Scala, Java, Python and ‘R’. Another benefit is it’s fully supported by Microsoft through its Azure HDInsight service. It started out as a proof of validity of the Apache Mesos file system, but became so impressive in its own right, it totally eclipsed Mesos. There are quite a few Pluralsight courses on Spark to get you started.

BLUEPRINT FOR SUCCESS

When it comes to a great UI library for ReactJS, I’m totally impressed by the quality and breadth of components provided by BlueprintJS. Whenever any of our clients give us the choice, then this library should always be given a serious evaluation. Although it’s written in TypeScript, you can use either TypeScript or ‘normal’ JavaScript ES2015+. Version 2 should be out soon and is even better.