Learning JavaScript as a Scala developer

Apr 25, 2022 00:54


This is the first note in this journal about programming. I just felt the urge to share but didn't feel like jumping through the hoops to create myself a dedicated programming blog on another platform and I have very few programmers in my Facebook audience, so I decided to just use this journal. I chose English as a language for this article because it seems to there are more English speaking programmers than Russian speaking programmers (come to think of it, it is virtually impossible to become a programmer not knowing English, so the set of Russian speaking developers is a subset of English speaking developers). We'll see where it goes from here.

At first this article was meant to be about specific horror of JavaScript but then I thought I'd flesh it out because I might be not alone learning JS and maybe my writing could amuse or, hopefully, even help someone else.

So I have been a professional (as in paid to do that) Scala developer since 2013. Scala is a functional statically typed language with a well developed type system (this is true of Scala 2.x, Scala 3 is even better in this respect) and I got used to rigors of type consistency in exchange for compiler doing half of the work for me. There is even a saying among typed functional language programmers that if it compiles it probably works too (I think it originated from ML folks).



I always wanted to create useful apps that relieve people from repetitive and mundane tasks and allow them to focus on more creative things, so I figured in addition to strong backend skills I also need some to put frontend together. I tried starting with Vue.js, because testimonies suggested it was lighter and simpler than other popular frameworks, but first coding example in the tutorial planted a question in my mind I couldn't answer myself: "why do we need the complexity of frontend frameworks at all?" So I decided to learn frontend programming with vanilla JavaScript first. I prefer learning programming from videos, and luckily the company that outsources their coding to my company grants free access to LinkedIn Learning to their employees, so I got myself one.

I already tried learning JS a couple of years ago (I think it was with codeAcademy) but was not disciplined enough to follow through. So I picked it up again more determined and refreshed my memory about just how horrible JavaScript is to a person used to luxury of strong typing.

There is no type checking in JS. You can have a field in an object with a string value and a setter method for it and you can feed the setter a numeric value and it will set the field without telling you a word. You can check literally any type for trueness and the interpreter will gladly do that for you. There is a whole table of how values of different types are mapped to boolean true and false (there are surprises). What horrified me today when I tried to invoke a setter method for a field that the object didn't have is that it worked. Objects are usually assigned to consts in JS, and to me this makes no sense at all, because objects themselves are hyper-mutable: you may not only change the value of any field in an object, but also change the composition of an object completely, the very existence of fields and methods in it and it would still be okay to get it by the same const variable.

I'm sure I will find more horrific things in JavaScript along the way. What baffles me though is how did JavaScript giving developer so much freedom to screw themselves over become a de-facto standard for frontend programming (and a pretty popular backend language as well).

I'm bitterly missing a clear tutorial how to use monospace font on some text portions, so if you share one with me it would be greatly appreciated.

programming, scala, javascript, js

Previous post
Up