3 points · by idontwantthis · 4y ago · 8 comments
In JavaScript, no one is supposed to use the Boolean object constructor (new Boolean()). It is singularly unhelpful, and usually does the opposite of what you want. I've never seen a case for it.
Please correct me if there is some arcane reason to use it.
Do other languages have features like this that newbies might try to use once before getting burned and then literally never touch again no matter how advanced they get?
Are there interesting stories for why those features exist?
Little languages too: Makefiles, yacc/lex, etc. They were all a better solution than their forebears, but after years of usage, it's clear they have serious flaws.
In general, over the productive life of a language, experience evolves what is considered good, and features that at the time the language was written were fine, or even considered good, fall from favour as experience grows.
To be fair, some do better than others. C++ has basically become a different language over its lifetime -- C++20 is a _very_ different thing than the C++ I used in the late 80s! Much of what was new and interesting in early C++ is now considered dubious at best.
I think we're approaching a time where C (and C++) will be widely considered to have enough misfeatures that they will fall from use, especially in new applications. That's ok: C is 50 years old -- if we hadn't learned how to do it better in that time, I'd be worried!
The better C would be C++ without the ancient baggage it keeps dragging for backward compatibility. The most recent standards have dropped some of it already.
Mr Stroustrup and the C++ committee have, over the last 20+ years, continued to "evolve" C++ from being "C with classes" to C++20, in which classes are almost an historical artifact.
C++11 should have been a minimal cleanup of C++03, and C++14 onwards could have been a new language, with all the old baggage removed.
C++ will evolve as long as programming methodology hasn't been perfected. At this point it is immortal and the committee knows it.
> C++11 should have been a minimal cleanup of C++03
C++03 was a very minimal cleanup of C++98 aka ANSI C++. Therefore they were pressed to have much wanted features in the next standard, which was delayed repeatedly to make them ready.
> C++14 onwards could have been a new language, with all the old baggage removed.
The committee seems to gravitate toward first adding the superseding features and removing those rendered obsolete only in the next standard, to provide a clean upgrade path to legacy code. It also leaves time to see which features were really obsoleted.
`true` in Javascript is a primitive, so it doesn’t have any methods on it—it’s just a simple value. But you can do `true.toString()` in JS. How? The engine will automatically convert the primitive to an object so that you get those methods. It’s less useful for booleans, but strings obviously have lots of useful methods that you’d want to use with the actual underlying primitive values.
But yeah, since the language does it automatically for you, you should never do something like `new Boolean(true)`, or `new String(‘hello world’)`. The objects are created when you need them and cleaned up when you don’t.