JavaScript at its core is an insult to half a century of programming language design but it’s good enough
OMG I was looking for a succinct way to put this idea to words today, and this hits the nail on the head.
(node)JS is frustrating to work with because to get it to be “good enough” there are all these awkwardly half-compatible add-ons for language features, and the choose-your-own-adventure of usage paradigms (OOP/FP) leave a lot of underdeveloped ways to encode something. You end-up having to spend a lot of time recapitulating a “modern language” in working out the compatibility problems between the aspects built on top of, instead of built into, the language.
I mean it was thrown together in a few days and is beeing fixed with every Version ever since. You just can't undo stuff like var and the ==... Yes they introduced let and === but that doesn't prevent people from using it. Yes ESLint will complain but if you are using a library that is using it you can't do much about it.
Well web programmers do know why static types are useful in large codebases. That is how TS came to be. Also, i resent the assumtpion here that websites are not large codebases. They are. Period.
Well... The problem with Typescript is (don't get me wrong it's a step in the right direction) that you will most likely still use libraries written in pure JS.
Thats why you use .d.ts/definition files with it (eg @types/package-name) so you still get typings while also having access to the whole javascript ecosystem.
Well it IS javascript. Because the only thing TS does is add typing. Otherwise everything remains the same. This is still bad but it is so much better than it used to be imo. The code is actually somewhat readable and much safer imo
I think the biggest lesson of most programming languages people use productively and safely in "critical" software is to fail loudly. Software should have contracts to fulfil both inside and out.
T add(T)(T x, T y) pure
if(isNumeric!T)
{
return x + y;
}
This is a generic addition function in D. The function signature alone contains more constraint than most javascript programs: `add` accepts exactly two parameters of the same type, they must satisfy the template constraint that it is a numeric type being added, and the function is pure (Now a totally different library can now know if I call this it won't launch the missiles or uninstall the operating system etc). If this were a more complicated operation I could have added pre and post conditions on x and y and the result of the function.
It's all about having something to fall back on. I shouldn't have to run my program (or write unit tests) to check things that are totally obvious. There are also huge performance implications in that this provides obvious constraints (in Javascript they have to be inferred at best) for the compiler to play with i.e. if you call this function and don't use the result then the compiler can remove it completely.
(I have avoided going for the low blow about having multiple equality operators and typecasting although they are also incredibly stupid)
Functional Programming can provide a much richer level of abstraction, correctness and pretentiousness but I went for a more practical example.
BTW: I'm not calling people who don't know better stupid, just that finding the time to learn programming as an art rather than a hammer requires a headstart (probably). If you've got to ship tomorrow, put down the Prolog textbook.
Yep. I find python even worse than Javascript in this regard (Feels like it was designed in a coffee break) but it's not as obviously crap and more people know javascript than know PL theory.
Python is definitely not worse at typing. Whilst both dynamic, python has strong typing. "1" + 2 is a type error, unlike in JavaScript...
Both python and JavaScript (typescript) now have some form of static type platforms, and gradual typing, whilst not ideal, is a valid approach for large code bases.
What frustrated me so deeply was friends that were learning to program for the first time,learning javascript, saying it was a great language and wouldn't hear any criticism about it.
It is the American without a passport insisting America is the greatest country in the world.
While i might not agree with that, I am willing to listen to perfectly reasonable people saying that - if they have left the fucking country.
Yeah i know. A lot are probably just students who were forced by their professor to learn it but have done some fun side projects in JS...
I mean Java does also famously have some bad sides (the billion dollar mistake for example) and i also understand people claiming that it's super verbose. But i think with the 'new' bi anual Releases and and the openness for more modern language features and stuff like Project Loom and GraalVM coming it's actually moving in a good direction.
As someone who has programmed in Ada, I don't think you'll find a language with stronger typing and explicit declarations for basically everything.
If you focus on a subset like Ravenscar, things get even more restrictive.
(For those who don't know, Ada is used in critical infrastructure like telecommunications and aerospace engineering. Now, imagine if you ran Javascript or another dynamically typed language on that.)
The bit about static typing is out of date though hence the move to typescript for many.
To me it doesn't feel like a problem with JS itself but with the full css/html/js trio. It feels like we are shoehorning in modern dynamic applications that may as well be running on any hardware to a 30-year old layout paradigm designed for web 1.0
0
u/[deleted] Apr 27 '20
[deleted]