Live data from Hacker News

JavaScript Is Weird

jsisweird.com

221–230 of 383 posts

Re: JavaScript Is Weird

#221
post #79

Earlier quoted context omitted.

If you open the console to check after you're finished, it says: "What, are you going to check if the results are accurate? Go ahead " But if you open it console while doing the test, it says: "Hey, stop cheating! "

Why the hell can websites tell that I'm in the console? If I want to inspect some parts of a website (perhaps save an image), then I don't want that website to interfere.

Not used in this case but if you open the console docked (which is the default as opposed to a separate window) then the resolution of the window will change.

Re: JavaScript Is Weird

#222

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.

I keep having this argument with my boss but he refuses to let me write machine code.

If the good lord wanted us to code in assembly language, he'd have made transistors operate on mnemonics, not electric currents.

Re: JavaScript Is Weird

#223
post #75

Earlier quoted context omitted.

It is 'trash' for the general purpose 'one-size-fits-all' programming language that it's fans want to impose upon the world. (I shake my head at microcontrollers running dynamic languages. "micro-python" = spare me. line breaks over a TTY? there's the primary question of on-chip resources and a giant shim between the physical realities of a microcontroller and some high-level fantasies about what programming "should…

That’s a load of gibberish. JS as a language has nothing to do with browser APIs, why would you judge it based on that? Also, ES6 was ratified six years ago. Seems like you had a bad experience with espruino / jerryscript or something and are projecting based on that? Dynamic languages are easier to program in. That’s a fact, and why they are so popular.

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 engine, and JS can run on that and script various permitted things via the browser API.

ES6 may have been ratified six years ago, but it's not the target code your front-end build chain spits out, is it... browsers don't uniformly support it yet. fun facts.

Look, I've been programming JS since it was invented. I'm not impressed by "classes" that don't exist, arrow functions, async/await, futures, promises, fibers, and assorted hacks that don't mirror the actual CODE (what computers execute) a JS engine actually is based upon. I don't need these tools, why should I use something that I need to transpile when I can code directly for browsers as they are in 2021, including legacy browsers? I don't find ES6 "easier" in any way..

Regarding dynamic languages on microcontrollers: Dynamic languages cannot directly control memory allocation and manipulation, typically are heap based and have no concept of a stack frame, and are basically just a computer program written whose corresponding code instructions (machine code) and execution path is scripted by your high-level language. Read a JS engines source code, study embedded C, and get back to me as to how suitable you find it for timing deterministic embedded programming. LOL

Types are directly related to memory size allocations.

Study the recent crop of LLVM languages, including some very interesting ones like LuaJIT, which should be right up your alley, and note the role Garbage Collection (check the Boehm implementation, for example) plays in many of the object-oriented languages, as well as Go.

Look at the actual assembler instructions you require a computer to perform as a result of your high level specification.

I am NOT speaking gibberish.

I agree that dynamic languages are considered easier to program in.

When speaking of programming languages, they are not all on the same level. One cannot say "oh assembler is fine and all but i prefer lua", as it's like comparing apples and atoms.

there's a reason that you can implement a lisp in c, but that the contrary is not viable nor makes any sense. (although metaprogramming c with lisp makes a lot of sense :D)

Re: JavaScript Is Weird

#224
post #142

Earlier quoted context omitted.

I rather have the language say "Error, this is garbage!" than silently output garbage.

Which is why we use Typescript

Typescript doesn’t save you from all the weird things happening at runtime. A missing check at a context boundary and you can have a wild time (been there).

Re: JavaScript Is Weird

#225
I’ve taught programming to people who struggled because they were misusing JS and the answer they were getting back coincidentally worked for some inputs but not others.

Imagine trying to explain to them that this was their fault? Even trying to find the words to explain what happened made me feel bad that their first experience programming was tarnished by a language that will gladly allow you to do nonsense.

Re: JavaScript Is Weird

#226
post #178

Probably unpopular opinion: Most of these are just the weirdness of the language caused by the (not-so-wise) design decision that those simple operators should never throw. In my opinion, these are not footguns and should not be used to attack JavaScript, because regular programmers are very unlikely to run into them (which is why when presented, they seem so obscure). However, that is not to say JavaScript is withou…

Most of these edge cases should result in clear errors. Chances are, if you're adding two arrays somewhere in your application, something else has gone terribly wrong, and just telling the programmer "this makes no sense" would be a much more sensible solution than returning garbage and letting it cause problems somewhere else, further from the real cause of the problem.

Re: JavaScript Is Weird

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

The problem is undefined is used in places null makes much more sense (like a result of the find function). I follow the rule to never use null and convert to/from undefined if needed by some library.

Re: JavaScript Is Weird

#228
post #133
post #97

I stopped at the first example (true + false). If you write code like this, you have bigger problems than using JavaScript. For most of the examples, it's like saying "Here's what happens when you plug a fan to a faucet". There's no point really. JavaScript is weird just like any other language can be weird when you use it in weird ways. And yes, it's certainly one of the weirdest. If you want to talk about things we…

> I stopped at the first example (true + false). So you never did something like this: x = performCalculation(getParam1()) y = performCalculation(getParam2()) sum = x + y only to discover that "performCalculation()" sometimes returns a boolean instead of a number? JS is a dynamically typed language after all and functions like function f(x) { if (x >= 0) { return Math.sqrt(x) } else { return false } } are perfectly v…

I've not run into that kind of issue in years. Read the docs of the function you're attempting to call.

Also, in this case, the function should return NaN so it's not polymorphic.

Re: JavaScript Is Weird

#229
NaN++ is sometimes a TypeError in environments that define NaN as read only, that one’s sometimes wrong.

The float examples aren’t weird in JS, they’re the same in all languages that use IEEE 754 floats, which specifies that NaN != x, where x is anything.

“This is due to a decision made by the IEEE-754 committee for a few reasons, such as space efficiency and the fact that the function isNaN didn't exist at the time.”

This explanation feels like it’s trying hard to downplay the reasons and make it sound arbitrary and almost whimsical. It doesn’t make sense to allow NaN - NaN = 0 (Note that Infinity - Infinity == NaN), and it’s important that NaNs used as input to computation produce NaNs as output (other than when using boolean tests).

Re: JavaScript Is Weird

#230
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…

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.
Post reply on HN