Epic codefest: 7 programming languages in 7 days

We challenged our developers to learn Clojure, Scala, JavaScript, Ruby, Java, Kotlin, and Go in a day. Here's how easy it is to make the switch

1 2 3 4 5 6 7 8 9 Page 5
Page 5 of 9

Day four: JavaScript Granny
Developer: Deep Mistry, Java/Spring guy hell-bent on a NoSQL future, and yes, that is his real name

Derived from Java, Scheme (derived from Lisp), and Self (derived from Smalltalk), JavaScript has become the go-to language for most front-end developers. It has become a fundamental language for writing for Web apps mainly because RESTful APIs (using JSON) have become standard, as opposed to SOAP (using XML). When your back end is also written in JavaScript, JSON marshaling and unmarshaling becomes a near flawless natural process.

In fact while writing Granny's Addressbook in JavaScript, I didn't even think once about the whole marshaling/unmarshaling process. It occurred to me only after a POST request worked correctly that I had actually never mapped the JavaScript object at all. The weirdest thing for me (a Java Spring guy) was not thinking in terms of object-oriented design. Using variables without defining their types, passing entire methods -- er, functions -- as arguments, and closures on variables whose functions have returned long back felt totally insane the first time. However, within 24 hours of working with it, I was already starting to like it and am unsure now that I will see Java the same way as before.

I used Node.js and Express framework. I also used a node-postgres client for Node.js to work with PostgreSQL as a back-end database. I used JetBrains WebStorm IDE, which I found very easy to work with, especially since I'm already familiar with IntelliJ IDEA. WebStorm has extensive support for Node.js and Express. In fact, it includes the option to create a Node.js Express project out of the box. (WebStorm is proprietary, but I used the 30-day trial version.)

To create Granny, all I needed to do was to create a right run configuration using the app.js file (which WebStorm auto-generated), and I was good to go. One thing that I did struggle with was the lack of an option for plain-old HTML views. Instead, I was offered .jade and .jshtml views, which I was completely unfamiliar with. I did find a simple work-around, however; instead of configuring the IDE to use HTML, I let it use Jade and simply performed import <foo.html> -- and I was done.

If I were asked to implement another RESTful back end in JavaScript, I would definitely use Node.js and Express. It would be much easier and faster for me now that I know the basics of how this combo handles the flow.

I learned a lot about JavaScript and functional languages in general, including how to make Web apps with minimal code. With Java and Spring I now feel that I am writing tons of classes, interfaces, and XML files for something that could be done in a few lines of JavaScript. It got me more interested in dynamic languages, which I would most certainly pursue during my free time.

I had lots of questions regarding JavaScript in general, for which I went through some of Douglas Crockford's lectures to get a quick boot starter for JavaScript. Apart from that, for many of the database connectivity questions I went to the documentation on the node-postgres GitHub page. Otherwise, for most of the questions regarding Express or Node.js I simply searched the Internet and found similar questions on Stack Overflow.

But unless there is any reasonable valid reason for using JavaScript for the back end, I wouldn't recommend doing so. It worked pretty well for a small project like Granny's Addressbook, but add scalability, security, and larger project requirements, and I'm pretty sure more problems would creep up. For any small project that doesn't include these as requirements, using Node.js and Express would be my choice, if not for the ease of working with JSON, then for simplicity.

The other drawback is that there doesn't seem to be any extensive, easy support for databases. Yes, I was lucky enough to find a Postgres client, but that was an open source project written by someone who used the framework before. Let's say I wanted to switch to MongoDB, Neo4j, MySQL, Couchbase -- there's support for a few of these, but the switch wouldn't be easy. We basically would need to rewrite almost all the code.

1 2 3 4 5 6 7 8 9 Page 5
Page 5 of 9
How to choose a low-code development platform