Re:Why does ++[[]][+[]]+[+[]] return the string "10"?
by bugtodiffer on Tuesday October 08, 2024 @10:59AM
(#41778072)
Did you know we almost had a lisp style language in our browsers? But Sun's marketing budget on "Java" made something that sounded similar (JavaScript) favored more
people wouldn't have these weird questions if we had used good programming languages from the start, but marketing dollars changed this timeline forever and every new generation learns about wtf-js
Re:Why does ++[[]][+[]]+[+[]] return the string "10"?
by wruza on Tuesday October 08, 2024 @11:12AM
(#41778221)
This has nothing to do with a language flavor though, cause it’s coercion rules at play here, which could be done right and were (I believe) ok in Java.
Lisps in browsers of that time would suffer from the same idea, which is “let’s make relaxed/ambiguous rules for noob script kids and cool one-liners”. Which is a mistake that many people made back then (perl, php, sh). Anything that has a potential for growth must have strict typing and non-funny coercion from the beginning.
It’s this naive idea that ruined whole ecosystems.
Re:Why does ++[[]][+[]]+[+[]] return the string "10"?
by azinman2 on Tuesday October 08, 2024 @11:46AM
(#41778647)
Without making it easy for people to get started, it’s unclear what scale would have been achieved during critical days when things were growing. No one could have predicted back then what the web would become, nor the need for full app development on it (things like flash and Java applets seemed more like the way that would go).
Why would you want to cut off normal people from attempting to communicate to join a community that was linking humanity together for the first time? This strikes me as elitist. Proper programmers with years of experience shouldn’t be the only ones allowed in.
Re:Why does ++[[]][+[]]+[+[]] return the string "10"?
by wruza on Tuesday October 08, 2024 @12:38PM
(#41779195)
There are levels to this. You can make it harder by forcing them to adhere to some boilerplate protocols and quirky patterns and you can make [0] behave as 0. The former is a barrier, the latter is an unnecessary toy that actually messes with beginners. This idea was wrong not because beginners shouldn’t program. It’s wrong cause it makes the road unnecessarily bumpy for everyone. If you have ([T] | T) in your api, which actually was the reason for it, iirc, just make a function toT() that returns T either way.
Re:Why does ++[[]][+[]]+[+[]] return the string "10"?
by tzs on Tuesday October 08, 2024 @12:53PM
(#41779346)
People getting started can handle more advanced things than most people think they can. Look at Arduino, which is many people's introduction to programming. That's C/C++.
Re:Why does ++[[]][+[]]+[+[]] return the string "10"?
by arp242 on Tuesday October 08, 2024 @12:19PM
(#41779017)
You can have a C-like language without JS's typing ridiculousness. Many exist, such as Java. Blaming JS's special needs type system on Java and "marketing dollars" is a ridiculous take.
It was not in the original JS and added later on after someone asked/convinced Eich to do it (who quickly came to regret it, but by then "people were using it", and we're stuck with it today). He's talked about this a few times in interviews and talked about it on HN.
Re:Why does ++[[]][+[]]+[+[]] return the string "10"?
by somat on Tuesday October 08, 2024 @11:26AM
(#41778397)
Some days I feel the biggest failure of the web is how (script lang="whatever") does not work.
Yes I know the obvious problem with that, it would probably require changing our fundamental understanding of how a web browser works, I suspect the webbrowser would need to be at it's core an application specific vm designed around untrusted input. that is strict limits on cpu time, gated device access, etc. then the dom generator, languages and rendering engine would be implemented in this asvm.
The secondary problem, is this would probably destroy one of the webs greatest assets, everything is in plain text. yes, I know, there are all sorts of hoops you can jump through to obsfucate the text, but that is the thing, the default is shipping the source around. to do otherwise takes effort. A asvm based system would default to shipping compiled binaries around, which would suck.
But fundamentally changing the web is a boil the ocean type problem, never going to happen, we are stuck with our current web, much of it good, and much of it bad.
Re:Why does ++[[]][+[]]+[+[]] return the string "10"?
by bilekas on Tuesday October 08, 2024 @11:17AM
(#41778279)
As I understand it was called JavaScript because it was not compiled, infact its interpreted i.e a script. And it was used to enrich the HTML interactions specifically which would mean no compile in the browser which back in the day were terrible. So Netscape and Sun came together to bring us Javascript.. It was also rushed because there was some competition with Microsoft I guess with VBScript or some derivation of that. So while JS is certainly 'quirky` I would hate to see what Microsofts version might look like today.
Re:Why does ++[[]][+[]]+[+[]] return the string "10"?
by hnbad on Tuesday October 08, 2024 @11:37AM
(#41778542)
The reason JavaScript exists is that it was targeting hobbyists and non-programmers for whom Java would have been too much of a barrier to entry. That's why it's called that and why it was referred to as a "companion language" to Java at the time.
Remember, Java applets were supposed to be how you build Rich Internet Applications.
Re:Why does ++[[]][+[]]+[+[]] return the string "10"?
by hnbad on Tuesday October 08, 2024 @11:34AM
(#41778506)
"Almost" is overstating it a bit. It's true that the original idea Eich was proposed with was "Scheme in the browser" but Sun moved in before Java was even officially announced by name. JavaScript was intended as a "companion language" to Java pretty much from the start.
It's more realistic that we'd have ended up with VBScript dominating the browser landscape instead (Microsoft half-heartedly tried to acquire Netscape before the Sun deal and it's unlike Netscape would have lasted this long without the cooperation with Sun) and nobody wants to live in that timeline.
Re:Why does ++[[]][+[]]+[+[]] return the string "10"?
by Sohcahtoa82 on Tuesday October 08, 2024 @04:18PM
(#41781446)
I wouldn't mind JS as much if its type system wasn't an utter disaster.
Basically everything in that WAT talk should be an error. If your code is throwing type errors, then either it's shitty code or you're trusting non-validated input, in which case you should be able to catch the type error and return an error back to whoever sent you the data.
Re:Why does ++[[]][+[]]+[+[]] return the string "10"?
by Aardwolf on Tuesday October 08, 2024 @11:12AM
(#41778222)
++[++[+[]][+[]]][+[]]
outputs 2 as a Number (rather than as string). How high could we go with those 3 characters ([, ] and +, no spaces) with less-than-exponential scaling compared to amount of digits of the result, as Number (as string it's easy by concatenating digits of course)?
I'm thinking it's not possible without being able to use '*'
people wouldn't have these weird questions if we had used good programming languages from the start, but marketing dollars changed this timeline forever and every new generation learns about wtf-js
Lisps in browsers of that time would suffer from the same idea, which is “let’s make relaxed/ambiguous rules for noob script kids and cool one-liners”. Which is a mistake that many people made back then (perl, php, sh). Anything that has a potential for growth must have strict typing and non-funny coercion from the beginning.
It’s this naive idea that ruined whole ecosystems.
Why would you want to cut off normal people from attempting to communicate to join a community that was linking humanity together for the first time? This strikes me as elitist. Proper programmers with years of experience shouldn’t be the only ones allowed in.
We have “use strict;” for “serious” devs.
It was not in the original JS and added later on after someone asked/convinced Eich to do it (who quickly came to regret it, but by then "people were using it", and we're stuck with it today). He's talked about this a few times in interviews and talked about it on HN.
Yes I know the obvious problem with that, it would probably require changing our fundamental understanding of how a web browser works, I suspect the webbrowser would need to be at it's core an application specific vm designed around untrusted input. that is strict limits on cpu time, gated device access, etc. then the dom generator, languages and rendering engine would be implemented in this asvm.
The secondary problem, is this would probably destroy one of the webs greatest assets, everything is in plain text. yes, I know, there are all sorts of hoops you can jump through to obsfucate the text, but that is the thing, the default is shipping the source around. to do otherwise takes effort. A asvm based system would default to shipping compiled binaries around, which would suck.
But fundamentally changing the web is a boil the ocean type problem, never going to happen, we are stuck with our current web, much of it good, and much of it bad.
Remember, Java applets were supposed to be how you build Rich Internet Applications.
I recommend reading the "prehistory" chapters of this book: https://dl.acm.org/doi/pdf/10.1145/3386327
It's more realistic that we'd have ended up with VBScript dominating the browser landscape instead (Microsoft half-heartedly tried to acquire Netscape before the Sun deal and it's unlike Netscape would have lasted this long without the cooperation with Sun) and nobody wants to live in that timeline.
https://www.destroyallsoftware.com/talks/wat
Basically everything in that WAT talk should be an error. If your code is throwing type errors, then either it's shitty code or you're trusting non-validated input, in which case you should be able to catch the type error and return an error back to whoever sent you the data.
I'm thinking it's not possible without being able to use '*'
I expected `8`. `10` left me in disbelief before I found the accepted answer on the question.
print(chr(sum(range(ord(min(str(not())))))))
> ඞ
Source: https://x.com/chordbug/status/1834642829919781369
Has anyone seen a transpiler for regular JS into jsfuck?
It would be like maxify-obscurify