Earlier quoted context omitted.
TypeScript wont magically fix type errors. It is not that hard, to sanitize any expected parameter for functions and their output, typescript wont do that for you. So if you typecheck i/o values per se, using typescript only slows down dev process, as this can be easily done in vanilla javascript. no need for more bloat, but only for some defensive programming.
TypeScript "magically" fixes the need for defensive programming by ensuring you won't write unsanitary code or invoke functions with possibly null&undefined values by accident. So then clearly the defensive programming is the bloat, because you could avoid it entirely by putting a type system in place to prevent you ever putting yourself in a situation where null&undefined get passed to functions you don't want it to…
JavaScript Is Weird
341–350 of 383 posts
Re: JavaScript Is Weird
#342Earlier quoted context omitted.
The site is called "JavaScript Is Weird", not "Weird Javascript", even if they tell you that the examples aren't common they're still saying that this weirdness is unique to JS. Which definitely isn't true in the case of basic floating point precision problems
> The site is called "JavaScript Is Weird", not "Weird Javascript" am i being punkd?
Re: JavaScript Is Weird
#343Earlier quoted context omitted.
TypeScript "magically" fixes the need for defensive programming by ensuring you won't write unsanitary code or invoke functions with possibly null&undefined values by accident. So then clearly the defensive programming is the bloat, because you could avoid it entirely by putting a type system in place to prevent you ever putting yourself in a situation where null&undefined get passed to functions you don't want it to…
This falls apart the moment you're pulling remote data at runtime. You're right back to defensive programming since there's no more type system to help you at that point.
Someone arguing a little defensive programming is equivalently strong to a type system is clearly unaware just how much work a good type system does for you. I of course agree with you: when you're fetching data that you don't know the type of, recklessly casting it to some type is going to cause issues. This is true in every language that has ever existed. It's also why tools like IO-TS[0] exist, and of course you can enforce this with JSON Schema techniques or custom validators or a million other options.
Edit: in case the ultimate point of this comment is not clear, by using a type system and some type validator on your fetches, you are able to reduce the need for defensive programming exclusively to your fetch points. Clearly, defensive programming at the fetch points was already needed, so this is why I do not agree with the claim TypeScript's value add disappears from remote fetches.
Re: JavaScript Is Weird
#344Earlier quoted context omitted.
Context boundary meaning where it interfaces with javascript?
The points where you parse JSON, for example.
Re: JavaScript Is Weird
#3450.2 + 0.1 === 0.3 That's not really a JS problem, that's a floating point problem. Plenty of languages will have the same issue. +!![] "" - - "" (null - 0) + "0" Calling these things weird is fair enough but I can't help thinking this is code you'd never actually write outside of the context of a "Look how weird JS is!" post. It's like picking examples from the Annual Obfuscated C Contest to show how hard it is to un…
The site does say so in the introduction > Even if you're a JS developer, most of this syntax is probably, and hopefully, not something you use in your daily life. So I think you should look at this site more as something fun you might not have known if you're an js developer than as criticism of js. That being said, the !!"" isn't that weird of a syntax is it? I see and use the double exclamation mark all the time.
> the !!"" isn't that weird of a syntax is it?
Why would someone say not not empty string in code somewhere? Or do you mean seeing !!var_that_could_have_empty_string isn't too weird?
Re: JavaScript Is Weird
#3460.2 + 0.1 === 0.3 That's not really a JS problem, that's a floating point problem. Plenty of languages will have the same issue. +!![] "" - - "" (null - 0) + "0" Calling these things weird is fair enough but I can't help thinking this is code you'd never actually write outside of the context of a "Look how weird JS is!" post. It's like picking examples from the Annual Obfuscated C Contest to show how hard it is to un…
In my humble and admittedly little experience, its not what you intentionally write, but what gets unintentionally written and needs to be debugged later. Carmack-like people utilising this stuff for good are few and far between, for your everyday joe programmer this is a footgun, a very-nonobvious and non-intuitive one (hence footgun moniker) that they write in crunch, it slips past reviews because reviewers are jus…
Re: JavaScript Is Weird
#3470.2 + 0.1 === 0.3 That's not really a JS problem, that's a floating point problem. Plenty of languages will have the same issue. +!![] "" - - "" (null - 0) + "0" Calling these things weird is fair enough but I can't help thinking this is code you'd never actually write outside of the context of a "Look how weird JS is!" post. It's like picking examples from the Annual Obfuscated C Contest to show how hard it is to un…
I think the situation is a bit different. This situation looks different in reality. The result may be (null-0)+"0", but the actual code will be foo()-bar()+baz(). And C will at least give you warning about types, even if NULL-0+"0" could give you an address. Plain JS without extra tooling would happily give you the unexpected result. Some other dynamic languages would at least throw an exception about incompatible t…
For the same reason that, as the saying goes, there is no such thing as a "compiled language", no, "C" doesn't give you a warning about types. The compiler you're using gives you a warning. If you want a typechecking pass over JS, then use a tool that does typechecking. Eschewing with a typechecker and then complaining about the lack of type mismatch warnings, however, makes little sense.
Re: JavaScript Is Weird
#348Earlier quoted context omitted.
gibberish? "JS as a language has nothing to do with browser APIs, why would you judge it based on that?" Excuse me? That is precisely what JS is based upon. Lemme give you a prime example: JS = a single threaded event loop, ON PURPOSE. That directly affected Node.js as an implementation. Your browser has an embedded scripting engine. Embedded, meaning, the source code for your browser includes the scripting language…
And you boil all that down to 'JS is trash'? > JS = a single threaded event loop, ON PURPOSE. That directly affected Node.js as an implementation. That's not a criticism. It's not different to desktop app dev where you try to keep your processing away from the main thread, only it provides an easier interface through async programming. Synchronous = main thread; async = other thread. Amazingly intuitive model. > ES6…
Re: JavaScript Is Weird
#349Judging by the title, it sounded like the biggest discovery of 2021... by someone waking after a long coma. It was discovered in 2012: https://www.destroyallsoftware.com/talks/wat I really enjoyed the questions... and even though I am working in TypeScript, I got only 9/25. Precisely because I avoid f---ed up parts of JS, except for trivia games ( https://dorey.github.io/JavaScript-Equality-Table/unified/ , http://ww…
https://xkcd.com/1053/ There are a lot of people being born every year. If a 16-18 year old teenager is getting into web development, they were 4-6 when that talk was given in 2012. Sure, that talk still appears here and there, but it's past its prime and you'd have to be in the right place at the right time to run into it. Crockford's book (JS: The Good Parts) was ubiquitous among JS devs who were coding between 200…
Though, I hope that now people learn JS without its worst parts.
In any real codebase, expressions such as `true + ''` should not be understood. They should be eradicated.
Re: JavaScript Is Weird
#350Earlier quoted context omitted.
Both of these examples are well-known (and not unexpected) behaviours. I assume you already know why it behaves like that. If not, I can explain it. > [1, 2, 3] + [4, 5, 6] // -> "1,2,34,5,6" What would you expect instead? > [,,,].length // -> 3 Is there any use case where you would want to deal with sparse arrays?
> [1, 2, 3] + [4, 5, 6] // -> "1,2,34,5,6" > What would you expect instead? If I let my first instinct speak: [1,2,3,4,5,6] And then if I think a little more, then maybe: [5,7,9] //with obvious caveats In no way do I expect what GP actually provided.