Earlier quoted context omitted.
Just because something is popular isn't reason for it to be good. Examples: fossil fuels, (over)fishing, rage-based engagement, hard drugs.
On the contrary - the number of people taking hard drugs to get high is fantastic evidence that they are good for getting high. Otherwise, why would people be buying and taking them?
JavaScript Is Weird
291–300 of 383 posts
Re: JavaScript Is Weird
#292Earlier quoted context omitted.
We are not saying this because we are afraid to say it, but because it is not true. JS is a great programming language with a lot of quirks and footguns, most of them easily avoidable by enforcing good coding styles, using easily available and widespread tooling. And most language have linters or compilers that issue coding-style related warnings, including C, so this is not specific to Javascript.
Why is JS a great programming language?
There are also great things about it: the ease at which one can write in a functional style code, anonymous functions (vs Python), closures (vs Java), immutable strings, the fact that there is not a shitload of classes to instantiate to achieve anything (vs Java), block-scoped variable definitions, sane default function parameter handling (vs Python).
Javascript engines are also very fast nowadays because of the ton of engineering going into them.
I'd say, above all arguments, you can rapidly build very fast, lightweight and program programs with it.
Sure, you can pull a shitload of pointless dependencies and write bloatware that re-render the world on each keypress, and that's what many people do. And to make things worse, they wrap their shit with an entire browser that uses a lot of ram and processing power. But you are not forced to do that. You can also write efficient server code that does not show up in top, has few dependencies if at all, consume a negligible amount of memory and run without failure for months. That's possible too. Frontend-wise, you have amazing frameworks like Svelte that do wonders and would allow you to build very lightweight apps rapidly.
That said I would often pick TypeScript so your program is statically type-checked and your code is documented through types, especially for more-than-one-person / non-trivial projects.
I also use and like other languages like Python and D (and a bit of Rust) that have good stuff which JS doesn't have (list comprehension, borrowing, traits, named parameter, sane coercion to False…), or bad stuff which JS has. Javascript is not always the best answer, or even a good answers, but it can be one.
Re: JavaScript Is Weird
#293TypeScript to the rescue! I just prefer strongly typed languages, but it's things like this that disappear (for the most part) when you have types. I personally can't keep types in my head as well as some, so when the language forces me to, it helps a lot. Vanilla JS just makes me feel like I'm walking on egg shells. Then we can get into a lot of fun when we get to type systems like SML and Rust where you start to re…
Re: JavaScript Is Weird
#294I’ve taught programming to people who struggled because they were misusing JS and the answer they were getting back coincidentally worked for some inputs but not others. Imagine trying to explain to them that this was their fault? Even trying to find the words to explain what happened made me feel bad that their first experience programming was tarnished by a language that will gladly allow you to do nonsense.
Can it be that JS is not good starting language then? Maybe strongly typed compiled languages would be a better fit? One can argue that if you want to program it might be too much information for starters - but IMO basic types are such a fundamental concept that it would be better to teach that concept early on. It also clears up a lot of newbie confusion as you cannot assign string to an int by mistake with strongly…
@ozim, I don't believe you are trolling!
JS is an absolutely awful language for beginners; it's a 155mm howitzer pointed at your foot. Although you can get the hang of the basics quickly, AND it runs in the browser (super-convenient unless you're headless), those "basics" that you thought you'd got the hang of turn out to have semantics that make sense, but are not what you expected.
I wrote JS (about 0.2 of my time, I guess) for my job, for about 20 years. I got 18 out of 25 on that test. Now, I think it was actually an easy test; I got a third of my answers wrong because I haven't learned about a third of JS semantics. I'm either not very good, or not as smart as I like to think.
A certain recent colleague of mine would probably have got 25/25; he was cleverer than me, and he was REALLY into Javascript.
Try a Pascal-type language, to learn an imperative-type language. Modula2 is better. Learning Prolog is (I think) purely declarative, so it gives you the view from the other side of the curtain - as it were. Forth is a perfectly-feasible beginner's language; it was the second language I learned.
I can't recommend any OO language for beginners. Not because I think all OO languages are way too difficult, only all the ones I've used. I haven't used Smalltalk.
I haven't used any flavour of Lisp. That language is so pliable that I'm sure there's a flavour that would be good for beginners.
[edit] Actually, I wish I had learned a functional language like Lisp as my starting language; I strongly suspect that would have made me a better programmer throughout my career.
Re: JavaScript Is Weird
#2950.2 + 0.1 === 0.3 That's not really a JS problem, that's a floating point problem. Plenty of languages will have the same issue. +!![] "" - - "" (null - 0) + "0" Calling these things weird is fair enough but I can't help thinking this is code you'd never actually write outside of the context of a "Look how weird JS is!" post. It's like picking examples from the Annual Obfuscated C Contest to show how hard it is to un…
> That's not really a JS problem, that's a floating point problem More accurately it's a binary problem. 0.1 and 0.3 have non-terminating representations in binary, so it's completely irrelevant whether you're using fixed or floating point. Any number that can be represented as the sum of powers of 2 and 5 have a terminating decimal representation, whereas only numbers that can be represented as the sum of powers of…
Re: JavaScript Is Weird
#296Earlier quoted context omitted.
The site does say so in the introduction > Even if you're a JS developer, most of this syntax is probably, and hopefully, not something you use in your daily life. So I think you should look at this site more as something fun you might not have known if you're an js developer than as criticism of js. That being said, the !!"" isn't that weird of a syntax is it? I see and use the double exclamation mark all the time.
The output is "weird" if you don't know the rules for operator precedence and how things convert to their primitive values. Most people arent going to "know" what '+!![]' will resolve to because it makes literally no sense to combine those operators into a single expression in anything approaching normal code.
Re: JavaScript Is Weird
#297Probably 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.
Re: JavaScript Is Weird
#298Earlier 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…
Re: JavaScript Is Weird
#299Earlier quoted context omitted.
Knowing that the underlying representation will vary is CS101 material. It applies to almost every language because that's how the hardware works.
Hardware doesn't exist in any meaningful way for 90% or professional programmers anymore. Way too much abstraction for that to be an argument.