Developer Viewpoint — Experiences and thoughts on JavaScript
I think computer viruses should count as life.
Stephen Hawking
Developer Viewpoint is regular section on the blog a section, read previous posts How has Dynamics 365 changed in the last few years, What is DevOps and when should you use it?. The discussion takes the shape of a dialogue and in this issue, Ekhor Asemota explores the topic of JavaScript with Aidan O’Leary.
Aidan is a Microsoft Dynamics CRM Consultant within the Microsoft business unit. He is an ambitious, enthusiastic and experienced software developer. He enjoys anything computer-related and endeavours to keep up-to-date with new developments in technology such as machine learning and crypto currency. Aidan has experience in technologies such as C#, ASP.NET\MVC, SQL Server and CRM. He currently focuses on .NET, Dynamics 365 and JavaScript.
Ekhor: You have been working with JavaScript for a while now and very comfortable with the language unlike many .NET software engineers. What were the factors that influenced you to learn JavaScript?
Aidan: I originally started learning JavaScript before I started working with .Net. This was when I was at university which was a few years ago. I started looking at it as part of a Web Development unit and using it to perform front end scripting. Since then JavaScript has come a long way and with the wider adoption of node.js it is being used for a lot more than just front-end scripting.
Ekhor: Many software engineers share this common belief that most JavaScript developers do not adhere to tried and tested software engineering principles such as the SOLID principles. Do you think this belief is correct or even justified?
Aidan: So, I would probably say that this statement had some truth to it in the past, although it is getting better. One of the reasons for this is how easy the language is to pick-up for beginners and the many different ways and freedom it gives you to do things. I also think that to abide by SOLID principles you need to take an object-oriented approach. And in the past one of the slightly confusing parts to JavaScript was how to implement this using Prototypal inheritance, and there not being a clearly defined class as part of the language. With the introduction of ECMAScript 6 clearly defined classes have been introduced so I think this has brought improvements.
Ekhor: I once worked on a .NET code base that had a single method with more than 2000 lines of codes! What is the worst thing you have seen in a JavaScript code base and are there practices that can mitigate this?
Aidan: I have seen a similar thing in JavaScript where one method has had 2000 lines of code and it has been contained within a file which has over 6000 lines of code. I think like any other programming language to mitigate this kind of thing I think you should modularise your JS code as much as possible, follow SOLID principles, and implement design patterns where appropriate.
Ekhor: There are many JavaScript frameworks out there. Why do I need a framework? Can’t I just write JavaScript without any of these frameworks?
Aidan: Yes. You could write JS without a framework and in some cases if it is only a small application this may be the most efficient way to go, but as JS applications become larger using a framework can save you a lot of time and effort especially since a lot of frameworks have whole teams of people working on them. Some of them also try to encourage using good practices when developing JS. For example, AngularJS encourages services to be provided to your components through dependency injection. It also encourages you to break your application down into smaller modules and components. This can improve reuse and code quality.
Ekhor: Continuing with the frameworks, it can be really confusing to decide which one to choose. jQuery, Angular, React, Vue the list is endless. Why do I need to learn how to use these frameworks? Is there a deficiency in the JavaScript language which these frameworks are addressing? If yes, why don’t they fix the language?
Aidan: In the past with jQuery one of the reasons to use jQuery was to prevent issues with different browsers although I wouldn’t say this is as much an issue anymore, also the language has improved a lot since then. I believe that most of the frameworks now try to save you time and encourage doing things in a certain way. This can be good when working in a team as everyone can understand better how things are working and new members can get up to speed quickly.
Ekhor: Which of the current JavaScript frameworks would you recommend and why?
Aidan: That is a hard choice I would encourage learning a bit about few of them as you never know which one you may need to use in the future. That being said I haven’t really looked at Vue.js yet.
In terms of frameworks I have looked at, I really like Angular and React. I think for front end web development, either of these could be used. Recently, I’ve been looking at mobile development with these frameworks. They both have frameworks to achieve this, even if they work in different ways. Ionic is the angular approach and can be used for building Hybrid mobile apps which run in a WebView on a mobile device. React-Native allows you to leverage React knowledge in creating native mobile apps.
In terms of server-side development, I like the express framework for quickly creating a RESTful API. I also like a framework called Socket.io which quickly allows me to spin up a web socket server. It’s awesome for real time applications for example creating a live chat or drawing application.
Another less known framework I looked at in the past was Meteorjs which was pretty quick to get a full blown real-time application up and running, although this has lost popularity due to some people having concerns about the performance.
Ekhor: Still on frameworks, does it even make sense to learn any framework since they change very quickly. For example, Angular has changed drastically through the versions.
Aidan: Haha! I was pretty annoyed when I’d spent time learning Angular 1 and then Angular 2 came along. They’d changed everything! I had to spend time learning it again. Although it is sometimes frustrating when this happens, I believe you should still spend a bit of time learning them as you learn other things not just the framework when you are learning and using them. Also, we work in the Software industry and everything changes at a fast pace so learning new things is part of our nature.
Ekhor: Do you think Typescript is a good fix to address most of the issues developers have with JavaScript?
Aidan: I think Typescript is a good fix and I also think as new versions of ECMAScript are released most of the issues are being addressed.
Ekhor: Finally, what would be your recommendations for a software engineer who wants to become competent with JavaScript?
Aidan: I would recommend spending a bit of time learning the language first. Maybe go through a book. I recommend “JavaScript: The Good Parts”, or “Eloquent JavaScript: A Modern Introduction to Programming” (The online version is free). Next spend a bit of time learning about node.js. After that learn a front-end framework either React or Angular. Then finally give yourself a project to build to get your hands dirty. If you can’t think of anything go with a Todo list.