Live data from Hacker News

JavaScript Is Weird

jsisweird.com

351–360 of 383 posts

Re: JavaScript Is Weird

#351
post #282
post #197

Earlier quoted context omitted.

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

That’s the same for everything, no? I assume most JavaScript websites come packaged with their (transpiled, minified) versions of the “standard library” of whatever framework they’re using. And that has to be transmitted as gzipped bundles of plaintext javascript.

Further, tree shaking is much harder with a dynamic language.

My understanding is that a WebAssembly implementation would usually be smaller than a JavaScript one, assuming you’re using a language without a runtime.

Re: JavaScript Is Weird

#352
post #339

Earlier quoted context omitted.

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…

Hey so can I write a device driver in JavaScript and is it a good language for that? How about my dma controller and python? What am I reading here. Not a comp sci major eh? Pass me something by reference in JavaScript, please

What's your point, exactly? You can write a driver in practically any language.

> Not a comp sci major eh?

I guess you're a comp sci major.

Re: JavaScript Is Weird

#353

Earlier quoted context omitted.

I don't think they have it (although, you can do whatever you want with babel nowadays, I guess). It was a suggestion aimed at programming languages in general.

The javascript equivalent would be an expression like 'use strict';

I was being flip; I should have used a smiley, I guess. Sorry.

Re: JavaScript Is Weird

#355
post #100

Earlier quoted context omitted.

The same for “== considered harmful”. I scanned the entire comparison table and the only unobvious or error-prone cases are those you never really do in programming. https://stackoverflow.com/a/23465314 For me it’s only rows [[]], [0], [1], i.e. array-unfolding related, but all others are regular weak-typed comparisons like in perl and other dynamic semantics. Edit: just realized “if (array)” is okay, nevermind.

> the only unobvious or error-prone cases are those you never really do in programming. You never do them on purpose. The problem is when you do them by accident because of a mistake in your code, and the error slips through unnoticed, doing the wrong thing. > weak-typed comparisons like in perl Perl has separate operators for working on strings vs numbers, so you are always explicit about performing a numerical vs s…

you are always explicit about performing a numerical vs string comparison

But the values which you compare do not have to be of the same type, and it does not end at scalars (which are really ephemeral in their exact typing even in native API, see perlapi). Basically it has two flavors of ==, each with its own preferred coercion. Perl also has contexts, e.g. boolean and scalar which can operate on lists and hashes (@list == 5). While the form is different, semantics are similar.

The problem is when you do them by accident because of a mistake in your code, and the error slips through unnoticed, doing the wrong thing

If your string array contains some [[0]] by accident, I’d say there is not much left to do anyway. === doesn’t report this either, it only has narrower trueness, which may decrease or increase an error surface depending on how your conditions are spelled. And to be clear, I’m not arguing against using === in places where identity^ or strict equality check is necessary or desired (you may desire it most of the times and that’s valid). My concern is that (a) everyone blames == anywhere, for completely zealous reasons, (b) I have to type a poem to test for null and calm down someone’s anxiety.

^ I know it’s not exactly identity, but is close enough for practical purposes

Re: JavaScript Is Weird

#356
post #341
post #337

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

So you are saying that because we need to do validation in a very specific case, we should just throw the towel and do validations every time?

The IO entry point of your code will always be unknown no matter what programming language you are using. In typescript, you do validations in these cases to make sure outside data fits into your type system, from then on (probably about 99% of the rest of the code) won't need any validation whatsoever because the compiler is already doing it for you.

Bloat is the amount of time you lose doing code review to check if things are possibly null or doing null checks on stuff that is never null or a bunch of other stuff that the compiler will do for you just by writing some minimal types. The compiler does this stuff automatically without getting tired, can't say the same thing for humans.

Re: JavaScript Is Weird

#357

Earlier quoted context omitted.

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…

> C will at least give you warning about types 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, m…

Sure, we can go into very true, but specific cases. But in a day to day usage: When you're writing plain JS, you have to do extra work to get type checks. When you're writing plain C, you have to use an unusual environment to not get basic type checks.

Re: JavaScript Is Weird

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

> these are not footguns and should not be used to attack JavaScript No one is calling them that except you. The site says it right at the front : > most of this syntax is probably, and hopefully, not something you use in your daily life. Your obsession with having to choose Side A or Side B won't let you see this for what it is... Just showing weird syntax in JS. That's all. Good lord.

I am not choosing a side here.

However, deciding which language to use for a certain task is a legitimate choice that people to make. When making such decision, people need to analysis the pros and cons of a language. For countless times, I have seen people claiming JavaScript is bad/inconsistent/weird for reasons like `"1" + 1 === "11"` but `"1" - 1 === 0`. All I am saying here is things like these should not weigh too much when deciding whether to use JavaScript.

Re: JavaScript Is Weird

#359
post #339

Earlier quoted context omitted.

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…

Hey so can I write a device driver in JavaScript and is it a good language for that? How about my dma controller and python? What am I reading here. Not a comp sci major eh? Pass me something by reference in JavaScript, please

Anything is a “good language for that” if it meets your needs. If you can run the js VM in 128KB of RAM and have decent performance, why not? I guess you would be ok with a Lisp in a microcontroller even though it would also run a VM?

Do you think Arduino would have had any success at all if you had to write C or Assembly to use it?

Post reply on HN