Live data from Hacker News

JavaScript Is Weird

jsisweird.com

281–290 of 383 posts

Re: JavaScript Is Weird

#281
post #19

0.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…

Knowing that the underlying representation will vary is CS101 material. It applies to almost every language because that's how the hardware works.

Hardware doesn't exist in any meaningful way for 90% or professional programmers anymore.

Way too much abstraction for that to be an argument.

Re: JavaScript Is Weird

#282
post #197
post #44

Earlier quoted context omitted.

WASM is not a good solution in a lot of situations. In short: - you have to package your complete runtime in the Wasm binary, this leads to a large binary and memory footprint - DOM manipulation requires calling Javascript code, and calling JS from WASM is costly

You only need to package your runtime if you’re using a language that requires a runtime :) Languages that perform their own memory management (C, C++, Rust etc) will be extremely small. Just one big array of bytes/instructions.

you still need to provide their standard library, at least the subset used by your program

Re: JavaScript Is Weird

#283
post #233

Earlier quoted context omitted.

Yeah guess this is where Typescript comes in

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.

> no need for more bloat

What bloat are you referring to? TS compiles down to plain JS.

Re: JavaScript Is Weird

#284

> JavaScript is a great programming language, but ... Why are we so afraid to call trash "trash"? It's not attacking the creator, but just how can we make progress if things are not perceived as they are? https://wtfjs.com

because people here wasted years to learn all the quirks in JS and now they should realize all that was a mistake? Much better to downvote negative comments.

Re: JavaScript Is Weird

#285
post #62

Earlier quoted context omitted.

No. Popularity does not indicate quality. Judging the quality of something by its popularity is a form of cyclical reasoning. Especially when there is an obvious alternative explanation, namely that JS is the only language you can in the browser without transpiling and for a long time the only one period. While the fact JS can be used to build all these things puts a floor on its quality, that floor is uselessly low.

I'm not using popularity as the metric. "1 million identical websites were built with JavaScript" wouldn't say much beyond the first website. But that there is a very broad range of successful applications partly relying on JavaScript for their success undercuts the idea that JavaScript is inherently rubbish. Whether it has some subjective "quality" is a conversation best left for art galleries.

"The proof that JS is actually pretty good is that it has been used to build so many things."

[French Narrator] 5 minutes later...

"I'm not using popularity as the metric."

Re: JavaScript Is Weird

#287

UX nit: would have preferred question-by-question feedback on right answer and overall score, quite a lot to get through 25 questions before you get any reward for your effort :)

Same - it was clear to me by question 2 that I was going to be guessing on the rest of the quiz. Having to fill out the rest before getting feedback was a formality at that point.

By the time I saw the answers, I couldn't remember why I guessed which way on each question.

Re: JavaScript Is Weird

#288
post #51
post #19

0.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…

> That's not really a JS problem, that's a floating point problem More accurately it's a binary problem. 0.1 and 0.3 have non-terminating representations in binary, so it's completely irrelevant whether you're using fixed or floating point. Any number that can be represented as the sum of powers of 2 and 5 have a terminating decimal representation, whereas only numbers that can be represented as the sum of powers of…

No, it is problem for any base. For example decimal system can represent 1/5,1/4, 1/8 and 1/2 properly. But, what about 1/3, 1/7, 1/6, 1/9 as decimal numbers with finite number of digits.

This will be a problem for any base representation when it has to be boxed in finite number of digits or memory.

One good thing is decimal is widely used format, so it is good to go with that for representing stuff. But, it is more of an accidental advantage that decimal has. Nothing more.

Re: JavaScript Is Weird

#289
post #236

Earlier quoted context omitted.

Someone had linked on here a website that showed the 0.3 thing in practically almost every programming language and their output. I wish I could remember the domain / url cause it is interesting to compare languages defaults. I know most languages have ways to handle it correctly.

https://0.30000000000000004.com/

Yes this is it! Thanks for that, I do appreciate that they show multiple approaches in each language to showcase which one gives you the desired result.

Re: JavaScript Is Weird

#290
post #19

0.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've been thinking for a while that modern languages shouldn't default to floating point computations. They're exactly the right thing if you do data stuff or scientific computing, but given how much of the internet relies on things like e-commerce and how often floating point is still misused for dealing with money, coupled with the fact that even many senior developers aren't fully aware of the subtleties of floati…

> "# use-floating-point" pragma

I haven't come across the "pragma" directive in a Javascript context. I guess it's another new feature (I have trouble keeping up these days).

Post reply on HN