News for hackers. Stuff that matters.
Re:Structure and Interpretation of Computer Programs – JavaS... by YorickPeterse on Wednesday December 18, 2019 @10:35AM (#21825861)
Yes, it's such a great language that `{} + []` is a valid program.
Re:Structure and Interpretation of Computer Programs – JavaS... by nobleach on Wednesday December 18, 2019 @10:59AM (#21826154)
Do you find yourself accidentally doing that often? A few of the things from the "Wat" video fall into that category. "Things no one would have ever thought to try, yet a dynamic language will fully allow". If you want to point out valid concerns with JS, the double-equal implicit coercion is a far more frightening "gotcha".
Re:Structure and Interpretation of Computer Programs – JavaS... by derefr on Wednesday December 18, 2019 @11:33AM (#21826532)
Not lexically, no, but dynamically, sure, all the time. JS lets me receive an arbitrary value in a variable `foo`, and "add" it to another arbitrary value in a variable `bar`, without having any opportunity to specify what semantics I mean by "add." Fixing the semantics of the operation is the whole point of specifying it!

Personally, I favor languages that go "almost too far" in the opposite direction, e.g. Elixir. In Elixir, operator[] (a.k.a. the Access protocol) is generic across several types, but the semantics are very strictly constrained; not only does the access have to "mean" getting some kind of element from a container, but it's also only defined where it has a fixed O(1) time-complexity.

This sort of design being conventional in Elixir, means that you can usually predict, just from the lexical environment (a.k.a. "the code on the screen") what the runtime behavior will be of said code—which includes being able to "read off" a time/space complexity for the code—without needing to check how each ADT involved has implemented its generics, let alone having to check for implicit type coercions.

Re:Structure and Interpretation of Computer Programs – JavaS... by b0rsuk on Wednesday December 18, 2019 @11:26AM (#21826459)
Few people do that outside of code obfuscation contests, but the point is JS has heaps of gotchas like that, each waiting to bite you. How about:

x = 5;

(no var declaration). Extremely easy to do by accident. Lots of these will be left for backwards compatibility. In JS errors often go silent and I developed a strong dislike for any language that does that, including Vimscript and Lua (and I do like Vim).

Re:Structure and Interpretation of Computer Programs – JavaS... by nobleach on Wednesday December 18, 2019 @11:39AM (#21826613)
I'd agree that global declaration is far more egregious. A sibling comment recommends a linter, and I'd probably agree. It's sad that it was ever allowed as one that is copying and pasting code to another location can easily cause this case to happen.
Re:Structure and Interpretation of Computer Programs – JavaS... by jimws on Wednesday December 18, 2019 @11:31AM (#21826517)
Problems like this can be easily caught by linters like eslint or standardjs.
Re:Structure and Interpretation of Computer Programs – JavaS... by s_y_n_t_a_x on Wednesday December 18, 2019 @12:21PM (#21827075)
No JS developer would do that.

We all know that is global.

Nowadays you use `const` or `let`.

Any JS developer will have a linter that will tell them incase they somehow made that mistake.

Re:Structure and Interpretation of Computer Programs – JavaS... by tombert on Wednesday December 18, 2019 @12:49PM (#21827337)
Eh, I actually like JS but I have definitely forgotten to add a "var" or "let" a few times, or sometimes I will do it correctly, get a bit overzealous with cutting, and accidentally remove the initial var declaration.

I'm not saying that it breaks the language, but it definitely is irritating, especially if you're not using a linter.

Re:Structure and Interpretation of Computer Programs – JavaS... by s_y_n_t_a_x on Wednesday December 18, 2019 @07:36PM (#21830983)
I come from Lua so I'm used to declaring local variables with "local".

Also, I like knowing which variables won't be reassigned (const), and which will (let).

Re:Structure and Interpretation of Computer Programs – JavaS... by shakna on Thursday December 19, 2019 @04:36AM (#21833359)
Whilst I do find it irritating, I don't mind about the scope default so much, but I've certainly run into it (forgetting to specify) a lot.

Mostly because JS is not the only language that I'll be working with at a time, and if I'm dancing between three or four and they have similar syntax, then mistakes creep in.

Re:Structure and Interpretation of Computer Programs – JavaS... by jdminhbg on Wednesday December 18, 2019 @05:14PM (#21830037)
That's all fine, but those are all workarounds for a design mistake in the language.
Re:Structure and Interpretation of Computer Programs – JavaS... by s_y_n_t_a_x on Wednesday December 18, 2019 @07:43PM (#21831033)
No it's a choice, apparently people can't have one.
Re:Structure and Interpretation of Computer Programs – JavaS... by shakna on Wednesday December 18, 2019 @11:37AM (#21826581)
I have had REST endpoints that promise to only ever return an array return an object, so, yes. Yes this does happen in the wild.
Re:Structure and Interpretation of Computer Programs – JavaS... by mpfundstein on Wednesday December 18, 2019 @05:06PM (#21829969)
Every read about the crazy things you can do with C?
Re:Structure and Interpretation of Computer Programs – JavaS... by ngcc_hk on Wednesday December 18, 2019 @05:34PM (#21830184)
But at least you know ... it is not dangerous if you know you are in danger kind.
Re:Structure and Interpretation of Computer Programs – JavaS... by s_y_n_t_a_x on Wednesday December 18, 2019 @10:43AM (#21825944)
What an extremely weak criticism that has been played out.

1) Don't concatenate them in the first place

2) Use TypeScript

Pro-tip, if the world is going JS and you don't get it, it's probably you.

With JS (TypeScript) I can develop on every platform natively (React Native).

I can compile to native code. (AssemblyScript).

I'm not saying you can't do those things on other languages, but JS is becoming a powerhouse thanks to it's ecosystem.

Also, you see many other communities like Rust copying lessons learned from web developers (React/Redux/etc)

Re:Structure and Interpretation of Computer Programs – JavaS... by caiocaiocaio on Wednesday December 18, 2019 @11:12AM (#21826295)
Javascript is such a good language that, even after two decades of fixes, it's only good when you use a different language - specifically created to address JS's many problems - that compiles to it.
Re:Structure and Interpretation of Computer Programs – JavaS... by s_y_n_t_a_x on Wednesday December 18, 2019 @12:18PM (#21827035)
TypeScript is JavaScript. They follow and contribute to the Ecmascript spec.

It pretty much just strips the typing out when "compiling".

All the JS problems have been solved in ES6+

There are many languages that have supersets.

Re:Structure and Interpretation of Computer Programs – JavaS... by ptx on Wednesday December 18, 2019 @02:24PM (#21828310)
> develop on every platform natively (React Native)

If "native" means bundling a runtime and having your program pass serialized messages to a different thread where the actual native platform code lives, the same can be said for any language. You just need to build the wrappers for the native API – which is a lot of work but could be done for QBASIC running in DOSBox just as well as for JS running on V8.

Re:Structure and Interpretation of Computer Programs – JavaS... by s_y_n_t_a_x on Wednesday December 18, 2019 @04:14PM (#21829552)
Yes, but it hasn't been done for any other language.