JavaScript: One language to rule them all?

caonUlisses
CloudBoost
Published in
4 min readDec 19, 2017

--

Forget about the callback hell part, this isn’t a thing anymore (art by Carlos Azaustre).

Be me, 23, PHP developer, as hooked to Laravel as a dumb fish to a nail, working as many hours as I could and feeling great.

I had an awesome daily routine. I’ve spent hours refactoring code to make it more understandable (sometimes, I was hired to do just that) and I used to build my apps with as little overhead as possible (or so I thought). Just hit that command that creates the backbone from a specific framework and start your MVC.

But then, one day, I gave up.

I heard about how NodeJS was making people’s life better and how it should soon become the only option available for web development, ruling everything else, but there was a problem…

I hated JavaScript. When I could, I would use a transpiled language or a heavy library so I didn’t have to touch it. The whole idea seemed stupid. The globals, callbacks, binding… Then, all of a sudden, functional code, all the buzz words and obnoxious hipsters waving hands and screaming about how cool the new features of (insert ES version here) were. It looked like JavaScript was a new Star Wars movie, by the behavior of its loyal fans. Every time a new feature was announced or a library got popular, you could see tons of hipsters with JS t-shirts all over the internet arguing against anything else, like you would need to refactor everything to use this new code sugar syntax improvement.

Let me make this clear: this is not a rant against any language, framework or technology, this is nothing but a story of how I learned to broad my view and change my routine to embrace something different.

The fear of dealing with JS was something I dealt with all the time, everybody said it was awful and broken. Everything seemed like a hack, never a solution. But guess what? It can be a solution.

As time went by I started to look more and more at JS code, waiting anxiously to see the badly written, poorly designed ideas and talk about its flaws. It didn’t happen. A lot of good code is written in JavaScript. I don’t think any other programming language has a community so conscious about codding standards and best practices than JS.

Most Node.js developers know the ins and outs of the language and at least know what a promise is or how to use async/await to improve old codebases.

PHP, on the other hand, is lagging far behind on this matter. The overall concern about best practices and standards is unsatisfactory. The last projects I’ve been into were so awful I couldn’t even believe. One had a ‘helper.php’ file, with 12k+ LOC, with the same functions repeated over and over, waiting for it to be refactored, imported manually into each class of what used to be a Laravel app and 60+ ternary operators on each controller to check things that weren’t even being used anymore. I’ve seen good PHP, it looks great, is readable and understandable, but bad PHP can get as hellish as bad JS.

When it comes to frontend, nowadays you’ll hardly deal with bad code if you don’t want to (for loops inside for loops inside an if statement, variables named ‘a’, etc). You’ll probably never try to guess what will return from the callback’s callback’s callback. The libraries and frameworks are getting as powerful as they can be, providing ways to create an webapp, a pwa, a hybrid mobile app or even native mobile apps.

Now I’m developing most of my code on JS, be it backend or frontend. The ability to use the same code on both sides is a HUGE feature. Axios, for example, is used on both sides for HTTP communication (between microservices and between client/server).

JavaScript isn’t a monster anymore (it can be, but only if you try very hard), you can use it without feeling dirty by the end of the day. At least try it, like you should try every language you come across. Take a look at Golang, Erlang, Ruby, Python, C++, Lua, Bash, Vimscript, Java, C#, study as much as you can, but first of all, take a look at the language you detest the most… You may end up loving it.

Although it grew a lot, JavaScript is not the best language out there, neither should be treated as the One Language to Rule then All. It’s a beautiful, tiny language, that can be really great for some specific problems, but we do not live on no Middle-Earth, there’s no magic at all. There are options and decisions. So no. JS is not the last hype train we’ll see, neither the only viable way for software developers on 2018, but it won’t hurt you to try it.

SELF-PROMOTION AREA

If you want to talk about code (or anything else), hit me on twitter and if you want to see what I’m up to, check out my github.

--

--