by gbuk2013 · 7y ago · 0 comments
The nature of the language is that without iron code discipline Javascript code inevitably turns into a mud-ball.
Apart from the obvious “many-eyes” benefits, frameworks also provide structure that buys extra time before this happens.
Could you outline what you think makes JS more likely to turn into mud-balls compared to other languages?
In my experience, no matter what language you use, or with what pardigm, unless you model and design your software architecture with discipline, you gonna end up with a mud-ball.
Has less to do with the language and more about the process you use to model your domain.
Loose types, pass by reference, near-limitless mutability, scoping rules (without “use strict” to save the day) and asynchronous nature of the things it is used for are some of the things that come to mind with JS.
All of these are actually very powerful features that make it into the language I love, but care is definitely needed. ;)
It’s more about architecture and discipline, and far, far more about simply caring about performance. (And larger teams make it much harder to care about performance.)
For personal background in my firm agreement with capableweb, I work primarily in JavaScript professionally, tend to use Rust privately, and have used a variety of other languages and worked with both good and bad code bases (mostly good); and I care very much about performance.
But the language has such a low threshold that it allows for incredible productivity while writing shitty code. But by the time you realise just what you have done (or someone else realised when they have to work on your codebase) its too late and it’s time for a rewrite.
What makes JS special is how accessible it is and just how much mess you can make before reality bites. That said, I will take a Javascript mud-ball over an enterprise Java one any time! ;)
I'm not quite sure why so many people think JS is pass by reference.
Everything in JS is passed by value. In fact, unlike some other languages (Swift, C++, etc), the only thing you _can_ do is pass by value. That some of those values are actually references doesn't really have anything to do with evaluation strategy.
More than that, assignment of an object is also only by reference which is super useful and great potential for spaghetti code at the same time.
How it is implemented under the hood I could not care less because it is not exposed to me as a programmer (unlike in C).
This sounds like almost every programming language which is not a functional one actually (it even fits C!).
With Javascript you cannot have strict types and you cannot pass objects by value and asynchronous programming is the norm.
C is also a lot less forgiving so it takes more skill to even be able to create a mud-ball of a reasonable size. ;)
In my limited experience, functional programming languages just move a significant amount of difficulty up-front to the code. Perhaps it makes for less difficulty in architecture - I never suck around for long enough to find out. The difficulty threshold is enough to keep out lesser programmers, which certainly helps code quality. The price is that far fewer people use the language.
Plain JS is hell to refactor. Between arbitrary autocasting, little tooling and no useful type system, if you don't have a very detailed test suite, you won't find the parts of your code that are broken now. Also, if you do, you now have to reimplement all those tests that did nothing else than to check your call signatures.
Ease of refactoring is a major indicator for a good enterprise language, as constant refactoring is basically the main development process. If your devs are afraid to touch certain pieces of code because nobody knows what the ramifications are, your software is already dying.
That's why TypeScript is taking off so nicely. People crave those static guarantees that JS doesn't have.
Having good and smarter tests helps more for ease of refactoring than having everything mapped to types. But I might just have seen bad examples of TypeScript codebases.
With the appropriate amount of skill and discipline, however, this stage can be postponed for longer than the life of the application. Typescript is absolutely not required.
The real gain is to be had in pushing the mudball stage as far into the product's life cycle in absolute terms as possible.
In that sense, nothing is required, but some things help. I argue that TypeScript helps.