4 ms·
Nit-pick: Javascript is not simple; I personally think it has among the most complex language semantics out of all commonly used languages.
by GrantMoyer 2y ago
Nit-pick: Javascript is not simple; I personally think it has among the most complex language semantics out of all commonly used languages.
- HelloNurse 2y agoJavascript would be a simple hybrid of object oriented and functional principles if backward compatibility with old hacks and "robust" use for web page scripting didn't require a host of redundant features, syntactic bizarre special cases and and evil semantic choices: -- comments, iterating objects and arrays, the absurd equality operators and type conversions, and so on.
- efnx 2y agoPrototypal inheritance can be pretty awkward and complicated. It’s evident in that few young JS devs ever use it, and many don’t even know about it!
- chuckadams 2y agoI'm an old JS dev, having been around from its beginning, and I avoid JS's OOP system of prototypes too (along with the class syntax) and stick to only static closures in object literals. VueJS and TypeScript are also mostly written in that style, so I'm in good company. I'm tickled pink that we're at the point where a dev actually _can_ forget that the OOP system exists, because its a horror show. I learned OOP on a prototype-based system (LambdaMOO) so it's not like it's foreign to me, JS's system is just so full of warts and wats it's not funny. It's scary how good TS is at inferring the type, it'll even infer an instance of a class from a literal, so the interop with class-based code is almost seamless (almost: just don't try destructuring a "real" object or re-binding `this` on a static closure)
- Lerc 2y agoCan you give an example outside of the weirdness caused by automaticy converting types? (Or 'with', which is kind-of in purgatory now) I have considered a non backwards compatible JavaScript descendant to clean things up. It would be interesting to hear what you consider to be problems.
- GrantMoyer 2y agoOff the top of my head: - There's both undefined and null - There's three ways to declare variable - typeof vs instanceof - for in vs for of - the way `this` works - semantics of functions called with the wrong number of args There's far more that I can't immediately recall.
- throwawaymaths 2y agoprototypes vs class
- Lerc 2y agoA lot of that is what I had in mind. Things like for...of and let fix glaring problems by introducing new things instead of changing to maintain backwards compatibility. A lot of the fixes are just removing the old broken way of doing things. I'd still probably change 'for x of ...' to implicitly be 'const x' and require let if you are doing shenanigans with changing the values. I am surprisingly ok with null and undefined. Null means not a thing, undefined means there is not even the notion of the thing. I'm pretty sure there are more than three ways to declare a variable. x=5 let x=5 var x=5 window.x=5 window["x"]=5 //arguably the same as above. Object.defineProperty(window,"x",{value:5}) Object.assign(window,{x:5}) at least
- paulddraper 2y agoMany of those are setting properties, not variables. A variable reference can lookup properties on the global object, or other objects with ‘with’
- int_19h 2y ago> Null means not a thing, undefined means there is not even the notion of the thing. If only "undefined" was consistently the same as lack of variable / collection entry, it would be understandable. But as things are, {x: 1, y: undefined} is not the same as {x: 1} in many ways - indeed, so much so that TS distinguishes between these two cases in its type system.
- 2y ago
- bungle 2y agoSimplicity in high-level: Lua, low-level: Zig (combined in one (complex): Rust?)