this post was submitted on 27 Dec 2023
706 points (98.8% liked)

Programmer Humor

19817 readers
529 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] Bye 5 points 1 year ago (4 children)

I don’t work with web stuff, why is js so weird? Can you write a website in other languages, like c# or python?

[–] [email protected] 21 points 1 year ago (2 children)

Can you write a website in other languages, like c# or python?

sure, as long as it compiles to javascript

[–] Bye 6 points 1 year ago (4 children)

But the browser can’t handle other languages? That seems a bit silly

[–] pankkake 16 points 1 year ago (1 children)

There's a push towards WebAssembly. Officially it's not supported yet, but most browsers can handle it. I don't know how mature the project is though.

But yeah, essentially everything on the web is JS.

[–] Static_Rocket 15 points 1 year ago (2 children)

Even webassembly needs a JS stub loader right now. I still can't believe that's a requirement.

[–] [email protected] 3 points 1 year ago (1 children)

Sure, but you can get frameworks that generate that for you. I've written whole webpages in WASM without writing any JS.

You don't get around reading JS documentation, though. Especially the DOM API is just documented as JS, and you basically hope that your framework makes it obvious enough how to write that in your non-JS language of choice.

[–] Static_Rocket 5 points 1 year ago (1 children)

This is exactly the reason why I can't believe that was ever a requirement. I would have crazy respect for webassembly if it could stand on it's own as it would allow people to completely move away from JS, but if JS is still in the stack in any way it will introduce a (even if it is minimal) compatibility and maintenance cost in the long run.

[–] [email protected] 3 points 1 year ago

I used to think so, too, but on the one hand, the DOM API is absolutely massive. Going through the standardization, implementation and documentation process another time would take decades.

And on the other hand, a language-agnostic API in WebAssembly would mean specifying it WebAssembly itself. And well, it's Assembly-like, so what's currently a single line for calling a JS function would turn into tens of lines of low-level code.

Ultimately, you'd want code from some other high-level language to give you a summary of how you may need to call your language-specific wrapper. In practice, that's likely even worse than translating it from JS, because the high-level call isn't standardized.

[–] [email protected] 2 points 1 year ago (1 children)

i believe they plan to remove that requirement? at least i know they are trying to use a native wasm<->dom api instead of wasm<->js<->dom, which is slow

[–] Static_Rocket 1 points 1 year ago (1 children)

Big if true, do you have a link to follow that development? I've been curious about some languages that compile to JS+WASM but I've been waiting for something like this to finally cut out the middle man and give me an excuse to learn WASM directly.

[–] [email protected] 1 points 1 year ago

its just what i have heard.

[–] [email protected] 5 points 1 year ago

If they could, JavaScript wouldn't be nearly a popular

[–] [email protected] 3 points 1 year ago

There's actually in theory all the pieces in place to use a different scripting language, because in the early days, there really were multiple. But yeah, the massive DOM API is only really standardized+implemented+documented for JS, so you don't get around it in the end.

As the others said, though, WebAssembly is starting to become a thing and the JS boilerplate for calling the DOM API can be generated for you.

[–] [email protected] 1 points 1 year ago
[–] [email protected] 6 points 1 year ago (1 children)

Most of the weirdness comes from being designed for the web, and specifically for working with forms. The value of a form field will always be a string, which is a simple and straightforward idea, but then the trouble showed up when we tried to make it more convenient to work that way.

[–] [email protected] 16 points 1 year ago (2 children)

Actually, most of the weirdness comes from having been originally designed in a matter of 10 days by a single engineer working to accommodate a tight release schedule.

[–] [email protected] 2 points 1 year ago (1 children)

I mean, do you think that has more explanatory power though? The type coercion rules are actually more elaborate with == than necessary for equality checking, because it was intended as a clever convenience for working with strings. If it was really all about the short timeline, wouldn't you just skip that and do a more straightforward equality comparison, like the algorithm that === implements?

Besides, it's not like everything in the language was conceived and implemented in those 10 days. The language has been evolving steadily since then. I'm not even sure if the modern == comparison algorithm worked that way in the first iteration.

Personally, I find it more useful to understand the context that lets me say "that's a quirky consequence of a sensible principle," rather than blaming it on the "ten days" legend generically.

[–] [email protected] 3 points 1 year ago (1 children)

I think the "ten days" explanation has the merit of being charitable, because it implies that Brendan Eich wouldn't have made such short-sighted design choices under more favorable circumstances.

(I do not believe that it's a "sensible principle" to treat text as such a fundamental form of data that a basic language feature like the equality operator should be entirely shaped around it. Surely the consequences of building an entire language around text manipulation should be apparent by considering how awkward Posix-style shells are for any nontrivial scripts.)

[–] [email protected] 2 points 1 year ago (1 children)

Well... The circumstances were that he was asked to whip up a little scripting language, that felt a little like Java and a little like Scheme, which could be used to add simple manipulations and interactions to web pages. Specifically to web pages. Not webservers, mobile apps, databases, banking systems, physics simulations, robotics... Only web pages. And nobody had even conceived yet of something like Google Sheets-- It was simple HTML forms and DOM manipulation.

IMO in that context, it makes alot of sense. I think it was probably still the wrong decision-- definitely with the benefit of hindsight, and quite possibly even at the time, even in that narrow context. Way more trouble than it's worth.

But it's beneficial to know that there was a principled (if misguided) reason behind it, that ties into the nature and history of the language-- It's not simply "dude was in a hurry and not thinking." Both are kinda true, but the former perspective helps us understand something useful, whereas the latter doesn't get us anywhere interesting.

[–] [email protected] 3 points 1 year ago

TBF he probably had know way of knowing that the language he was creating would one day end up being as popular as it is now.

I guess the moral of the story is that you can never really predict what long term consequences your decisions might have down the road.

[–] [email protected] 1 points 1 year ago

What software isn't?

[–] [email protected] 1 points 1 year ago

Can you write a website in other languages, like c# or python?

Yeah, anything that outputs HTML and CSS can do so. There's a module for Apache to write webpages in Python (libapache-mod-python) and I'm p sure someone somewhere made a module to do it in Rust already except they're infighting over whether tag parsing in it should be marked unsafe.

For that matter you do can write web pages in your shell eg.: bash, that's what CGI is all about.

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago)

I guess why it's weird because of the loose rules it follows, like what is mentioned about === and ==. There is WebAssembly which kinda acts like Javabyte code or CIL there used to be huge hype that it's going to replace JavaScript, though it's not used that much today. I think why there is low adoption is mainly because JavaScript is good enough, it's widespread and easy to learn.