Live data from Hacker News

JavaScript Is Weird

jsisweird.com

271–280 of 383 posts

Re: JavaScript Is Weird

#271

Earlier quoted context omitted.

The fact that there has to be a different language on top of your language to make it same days all that needs saying really.

This goes for all compiled languages?

We invented compiled languages because of issues with writing everything in assembly. In other words, we invented C because assembly wasn't very good.

Just like we invented TypeScript because JavaScript wasn't very good.

Re: JavaScript Is Weird

#272
post #134

Earlier quoted context omitted.

In Go: https://play.golang.org/p/G8jOKtIj4AY

Can anyone explain this to me?

`!` is added to values in most languages as a shorthand for saying "give me the opposite boolean value of this. So `!true` would equal `false`

Some people add two exclamation points as a shorthand to cast a value to a boolean. So if you wanted to see if something was 'truthy', you could say `!!truthyValue` and it would return ` true` instead of the value itself. Literally what your asking the language is "give me the opposite boolean value of the opposite boolean value of `truthyValue`"

Now you can probably see why three exclamation points is silly, it's not giving you anything that a single exclamation point wouldn't give you. Both `!truthyValue` and `!!!truthyValue` evaluate to false, you are literally saying "give me the opposite boolean value of the opposite boolean value of the opposite boolean value of `truthyValue`"

The example in Go is intentionally misleading because Go lets you reassign the values for `true` and `false`. It's going through all the same steps I described above, but it's starting with a value opposite of what you think it is

Re: JavaScript Is Weird

#274

Earlier quoted context omitted.

JavaScript sorting numbers alphabetically is a fact I simply cannot get over. I know I should be pragmatic as an engineer but this goes against the core of my being. Awful.

Since it’s (imo) default-wrong in English, I’ve chosen to think of it as a nice way to point devs to something that’s locale-aware like Intl.Collator instead. If it “just worked” in English, most of us would never think to use the correct utility instead.

This is a bit of a tangent, but that makes me wonder… are there any languages where this particular collation would be correct?

Re: JavaScript Is Weird

#275
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.

Re: JavaScript Is Weird

#276
post #98
post #89

Earlier quoted context omitted.

Yes, the quotation from dictonary.com exactly supports what I am saying. It's a piece of spoken dialect not standard English. It's as if I was after using hiberno-English constructions in a HN comment. Will you go on out of that.

If your comments were comprehensible to most HN readers, I wouldn't see the problem in using Hiberno-English, or any other colloquialisms.

If you consistently wrote in the way that Goofy talks then most HN readers would understand you just dandy but you wouldn't look no ways good. 'so [adjective] of a [noun]' is a Goofyism which doesn't belong in even middle-register spoken English. (Of course writing in dialect is completely fine if you're doing it for effect or for some other specific reason.)

Re: JavaScript Is Weird

#277
post #173

I really think we should stop pushing things like that or the wat talk ( https://www.destroyallsoftware.com/talks/wat ). Sure it's funny and all, but it's not helping people understand. We're presenting Javascript as some kind of stupid black magic tool, which is not. You can very easily find the standard online, and go through the examples to understand. Sure it's unintuitive, I agree, but lots of things in programm…

I don't even think it is unintuitive. There are very few things here (if any) that make no sense, and a few are literally just basic understanding of floating point spec. And then of course a few questions are basically obfuscated-C levels of code, where you won't get the answer correct unless you get your pen and paper out.

I'd argue that if you don't know about type coercion in JS, you don't really know JS. It's a feature; none of these operators will throw; it's a conscious design choice.

Re: JavaScript Is Weird

#278
post #168

Earlier quoted context omitted.

I agree. If native apis didn’t return nulls in some cases, and undefined was named “undef” at least, null could be ditched. But then again, it’s only because js has no bad habit of treating the same of non-existence and undefinedness^. If not json (which has no undefined), we could ditch null. But it’s there and with === it leads to either object.someField === null || object.someFeild === undefined madness, or to a p…

null and undefined is one of the things Javascript actually got right imo. Undefined is what lets Javascript turn what other dynamic language would throw as a runtime error into a value. "I do not have a definition for the thing you want" and "the thing you want is known to be unknown" are two totally different concepts that languages with only null to lean on must collapse into a single concept.

I've never found this to be a useful difference in practice. Also, JavaScript really doesn't use it correctly to begin with. Arrays are a mess. Like the poster below, I usually cast to one of them, except I cast to null.

Re: JavaScript Is Weird

#279
post #276
post #98

Earlier quoted context omitted.

If your comments were comprehensible to most HN readers, I wouldn't see the problem in using Hiberno-English, or any other colloquialisms.

If you consistently wrote in the way that Goofy talks then most HN readers would understand you just dandy but you wouldn't look no ways good. 'so [adjective] of a [noun]' is a Goofyism which doesn't belong in even middle-register spoken English. (Of course writing in dialect is completely fine if you're doing it for effect or for some other specific reason.)

That's completely your opinion, though - there's nothing in the guidelines or FAQs that say that.

When on HN, I engage with things I find interesting, irregardless of how good their ritten. If we intimidate users with an expected level of ability in written English, we'll be excluding a lot of interesting comments.

Re: JavaScript Is Weird

#280
Could [,,,] be used to optimize an array allocation? Say I'll need an array of fixed size. Could this method be used to help the interpreter to allocate an array more efficiently?
Post reply on HN