Live data from Hacker News

JavaScript Is Weird

jsisweird.com

331–340 of 383 posts

Re: JavaScript Is Weird

#331
post #127

I have plenty of complaints about Javascript, but most of these aren't it. I haven't done any serious javascript in something like 6 years, and I still got most of this right without much effort. #4, #13, #14, #21 and #24 are floating point problems and are nothing to do with JavaScript. A bunch of them are just "learn the language" issues: #2 I only got wrong because I never noticed JS allows trailing commas. Traili…

> #2 I only got wrong because I never noticed JS allows trailing commas.

No one used to risk it because IE was inconsistent with what it meant.

Re: JavaScript Is Weird

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

We have this on our interview test. It was the one almost everyone got wrong except for a couple people who ended up being really detail oriented and had deep knowledge (as opposed to broad).

We consider >70% passing.

Re: JavaScript Is Weird

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

We have this on our interview test. It was the one almost everyone got wrong except for a couple people who ended up being really detail oriented and had deep knowledge (as opposed to broad). We consider >70% passing.

I'd honestly consider these types of questions one of the poorest ways to test front end developers.

The only reason I have learned some of that oddball stuff with JavaScript is because of some job interviews e.g. when I was earlier in my career, I used to Google things like "top 30 questions asked in a JS interview", etc, but I forget it after that until I'm about to look for another job. However I wouldn't do this type of learning any longer, since I wouldn't want to apply for a company asking these types of questions.

In the end at work you should use ES6/TypeScript with linting, proper tests and these cases would never occur.

Re: JavaScript Is Weird

#334

Earlier quoted context omitted.

Having designed programming curriculum, I have to disagree that the language is a bad language for beginners (though it is very far from ideal). To be fair the primary reason is not really a virtue of Javascript per se, but the fact that it runs in the browser is a large pedagogical gain that no other language can easily match and is hard to overstate. Learning to program is overwhelming for most students, and settin…

I wonder if Typescript would make a great first language, since a subset of it runs in the browser, but the IDE and compiler can prevent some very bad bugs.

It might be a good extension after they'd spent a good amount of time in plain Javascript, 50-200 hours in depending on age IMO (younger -> more).

Adding types is, again, confusing to most beginning students and adding any sort of build process is asking for tears.

The bugs, while unpleasant, just aren't actually that bad pedagogically. Students readily accept explanations of the form "computers are dumb and do what you tell them, if you tell them to do something that doesn't make sense they will do something that doesn't make sense" which is close enough to correct to not give them a terrible mental that is difficult to unlearn later.

Additionally, at this stage of learning students should be writing many small programs. Such programs are typically easy for teaching aids to debug in seconds (or to suggest a radically simplified re-write).

Re: JavaScript Is Weird

#335

Earlier quoted context omitted.

> no need for more bloat What bloat are you referring to? TS compiles down to plain JS.

Toolchain bloat is still bloat.

To call TypeScript, a very strong type system which compiles down to terse JS with no extra JS for even complex types, and thus accordingly removes the need for all sorts of tests, "toolchain bloat" is a fairly one-dimensional view of things

Edit: I accept the downvotes for my tone and have updated it. However, I do feel that by the exact same argument "toolchain bloat" exists, surely one could seamlessly argue "testing bloat" exists, and it should be transparent from the popularity of TypeScript that it's a good tradeoff

Re: JavaScript Is Weird

#336

Earlier quoted context omitted.

I once lost most of an afternoon debugging an issue where orders in a PHP e-commerce system would very occasionally fail. Turns out several months before, someone was doing some refactoring, moved some methods around, but also changed a "==" to a "===" in the process. Generally a good idea, but it slipped through to production without anyone noticing or breaking any tests. The issue ended up being that a rare code pa…

The problem here is == was used in the beginning. Always use ===.

Unfortunately "use X from the beginning" is rarely a solution when you're no longer at the beginning.

Re: JavaScript Is Weird

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

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 be.

Re: JavaScript Is Weird

#338

if you block JS you get this message > This website is literally about JavaScript. I mean what did you expect, a .NET application? This website is 99.9% poorly optimized and highly questionable JS. And yet, you have JS turned off.

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! "

Noscript page also includes:

var answers="I SAID STOP CHEATING! >:( You will get answers and explanations at the end, you dang dastardly dangusson."

I love sites that have easter-eggs in noscript/console. Noscript I can see being annoying (i.e. instead of showing content), but there are some exceptions like this site.

Re: JavaScript Is Weird

#339
post #75

Earlier quoted context omitted.

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…

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 may have been ratified six years ago, but it's not the target code your front-end build chain spits out

C++14 may have been ratified 7 years ago but it's not the target code your build chain spits out

> Look, I've been programming JS since it was invented...

You're free to write pure assembly, and you don't.

> Regarding dynamic languages on microcontrollers

Python in particular has made this kind of programming mainstream

> 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

You're gatekeeping, and that's also your ego. You need to work on that.

> there's a reason that you can implement a lisp in c, but that the contrary is not viable nor makes any sense.

What!? I can build C in Lisp as much as I can build any other language. I parse the syntax, create machine code, and output a binary. How the hell do you think languages are built? How do you think C was built?

Just stop, man. It's not gibberish but it's bullshit.

Re: JavaScript Is Weird

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

Not really, it's a nice shorthand for "exactly one of these must pass":

  x = checkFoo()
  y = checkBar()
  z = checkBaz()
  if (1 === (x + y + z)) {
      ....
  }
It's a rare construction but I have used it intentionally once or twice in the past decade.
Post reply on HN