3 ms·
"var x = (function(){})() is just not readable, but it is error prone." How so? I have no trouble reading that, it's certainly clearer than most of the c++ tem
by zanethomas 5y ago
"var x = (function(){})() is just not readable, but it is error prone."
How so? I have no trouble reading that, it's certainly clearer than most of the c++ templates I've seen, and error prone? For example?
- tgv 5y agoIt's a bit apples and oranges. That declaration doesn't have the power of a C++ template. A C++ class is much simpler. One of the problems of the style is that you can't easily split it up. Another one is that it allows you to redeclare/reassign x. A third one is that it doesn't tell the reader what it's doing. You'd have to look carefully to find that out. And then there's the "extends" functions, which everyone implements slightly differently. So, for me, the "class" keyword is a positive change that helps overcome JavaScript's dynamic nature a bit.
- zanethomas 5y agoconst x = ... it's usual to read code to understand it "helps overcome JavaScript's dynamic nature", you say that like it's a good thing
- tgv 5y agoWeren't class and const introduced in the same version? > like it's a good thing I think so. If you have full control over your own code, and you write in e.g. TypeScript, you don't need it. Otherwise, it can prevent errors that take forever to debug.
- zanethomas 5y agoThe utility of const does nothing to support adding classes to javascript. TypeScript, also unnecessary and often just a pita. I've written very much javascript and have never had a bug that took "forever to debug'. Programmers who like classes, and type-checking, and all the other syntactic sugar should, imo, just use languages that support such things and leave javascript alone. I learned a lot about programming from the SICP when it first came out. I appreciate and use the good things Scheme inspired in javascript. And with very rare exceptions, such as const, let, and enhancements to builtin objects such as arrays, I still use vanilla js. I create new objects using factory functions and have zero use for classes. However adding Map, Set, and similar objects to what is essentially the javascript library is fine with me as they do not impact the core syntax of js.