4 ms·
On one hand, you do have JavaScript ubiquity, on the other hand, you have the JavaScript "WTF" equality and typing conversion matrix, "WTF" scoping, and dozens
by Demiurge 2y ago
On one hand, you do have JavaScript ubiquity, on the other hand, you have the JavaScript "WTF" equality and typing conversion matrix, "WTF" scoping, and dozens of other foot guns that Lua doesn't have. Some people would rather everyone learned Lua subtle differences and wrote less buggy code. I've had to use for the web for 20 years, and if I have any choice, I would avoid it.
Anyway, every language has some fans, and I don't mean to dismiss them, but ubiquity is not the top priority, all the time.
- therein 2y agoThere is the equality gotchas on JavaScript but then you have 1-indexed arrays in Lua, which is a footgun that I know exists, I try to avoid shooting myself in the foot with it but I keep doing it. It is beyond a footgun, more like a footgun concealed as a shoehorn. Either way I find embedding a Lua VM into a project so much easier than embedding a Javascript one.
- kragen 2y agoWhich JS VMs have you tried embedding? People in this thread have suggested https://github.com/Moddable-OpenSource/moddable https://github.com/Moddable-OpenSource/moddable, https://bellard.org/quickjs/ https://bellard.org/quickjs/, and https://duktape.org/ https://duktape.org/, but I haven't tried any of them.
- Demiurge 2y agoIndexing, I give you this one... I think it was intended as some kind of a gift to a "non programmer", a choice many other older language made, by the history decided to go another way, unfortunately for Lua. Still, I haven't had any issues adjusting to this one, personally. It seems kind of like Python whitespacing, I think I forget about it.
- leptons 2y agoThe only people saying "WTF" about Javascript are people who haven't taken the time to learn how to use it effectively. There are "WTF" things about every language, not just Javascript. Noobs are going to find the footguns in any language. Every language can be misused. I've been using Javascript over 20 years and have never thought it was any worse than any other language. Yes, it's dynamic, and yes, you can do stupid things with that dynamism, but for someone who actually knows how to use it, it's quite easy to work with. I recently started using Lua and I'm not impressed at all. It's just another language, it's really up to the programmer what can be done with it, just like Javascript.
- 3a2d29 2y agoThis is the common arguement used by people defending languages with tons of footguns. If this is true, why not write everything in C++? Javscript includes so many footguns that people know are bad (see the billion of examples of different types being added and getting random answers). Every langauge has some difficult parts, pretending that means any amount is fine is crazy. Javascript has earned its reputation.
- leptons 2y ago>(see the billion of examples of different types being added and getting random answers) Almost every "footgun" people cite about Javascript is something that would never be written as working code, by any competent programmer - they are "WTF" in that the person writing the "gotcha" has to go way outside of normal programming behavior to get the "WTF" result. Most of these "WTF" examples should be taken with a grain of salt. If you're expecting to "WTF" about Javascript's type inference/coercion, that works according to some logical rules. https://media.geeksforgeeks.org/wp-content/uploads/advanced-javascript-backend-basics.png https://media.geeksforgeeks.org/wp-content/uploads/advanced-... This matrix should be pretty easy to understand. Yes some things might seem weird like [[]] == false, and [1] == true, but nobody should be writing code like that, it's just illogical to do anything this way and I don't consider it to be a "gotcha". "Just because you can, doesn't mean you should" can be said about footguns in every language. Yes, there are "WTF"s, but just like if I were to write a C++ "WTF", it wouldn't be something that most people would be tripped up by unless they were specifically looking for a way to say "WTF" about the language. These "javascript sucks" internet arguments have persisted for decades, and it's always complaints about the language that are citing unreasonable examples to prove a point that a programming language has some rough edges. Every programming language has some rough edges. Javascript maybe has more footguns than some other languages because it is so dynamic, and the dynamism has its benefits too that other languages don't have. I do like it and I use it effectively, YMMV. People just seem to be specifically mad at Javascript because it's so popular and was made so by being the defacto standard for web browsers. It's part jealousy and part frustration that their favorite programming language isn't the one that web browsers include by default.
- IshKebab 2y agoFortunately most of JavaScript's WTFs are avoidable (though I do wish they'd add a "really strict;" mode that actually removed them).
- Demiurge 2y agoYeah, that would be great. I remember this was helpful in Perl, and ES6 days.
- wruza 2y agoJavaScript has very nice scoping compared to Lua. Js needs no forwards which in Lua turn into ugly “local foo; … … … foo = function()…end”. All functions are “hoisted” by default. Js also uses “export”s or “module.exports[…]” instead of returning a symbol table, which allows cross-referencing. Js has a function scope (var) together with local scoping. Js doesn’t allow accidental shadowing in the same scope. Lua: local x; local x; silently creates two variables, good luck debugging that closure. Js type coercion is only insane in the parts where operation itself makes zero sense. Please don’t tell me that ![0] or [] + {} makes sense to you or that you use them in other languages. Or that s+n and n+s seems safe everywhere except in js. Js has a ternary operator and ?? ?. ??= operator group. Lua only has that “and-or” crutch and “not X” which returns true only for nil and false. Js “…arr” is a first class citizen while in Lua “…” decays into its last value if you want to follow it. Js (normally) ordered properties system is much more convenient in dev and debug time than an unordered mess of meta-hashtables. Js doesn’t require you to { myPropertyHere = gotSomeObject.myPropertyHere, … IllRepeatThisAsManyTimesAsNeeded = gotSomeObject.causeWhyNot, } gotSomeObject.someNumericField = gotSomeObject.someNumericField + 1 which is extremely abhorrent DX in 2024.