News for hackers. Stuff that matters.
Re:TC39, ECMAScript, and the Future of JavaScript by danielbarla on Tuesday June 27, 2017 @03:39AM (#14643230)
Well, in C#-land, we often use / abuse attributes to get information about a class or property at runtime. This way, framework or library code can inspect entities that you've authored, and dynamically deal with them. Perhaps a decent example is validation, where a declarative style has gained a lot of popularity. A JS example might be:

  @required firstName;
This simply declares the intent / rule, but does not provide the implementation.

We can argue terseness vs verbosity, implicitness vs explicitness all day - I'd argue that for certain basic things that you do highly frequently, a terse and implicit style is not a bad thing. It tends to increase the signal-to-noise ratio of your code, allowing the developer to focus on things that really are interesting, and not have to read through a lot of boilerplate.

Re:TC39, ECMAScript, and the Future of JavaScript by abritinthebay on Tuesday June 27, 2017 @03:45AM (#14643246)
Hmmm a required flag is a nice idea (but better exposed using interfaces as an idiom I’d argue) but it’s not selling me on the wider use case.

If we were talking about very basic things then yes, sure, but I’d also argue that if they are truly basic then we could restrict decorators to built-in ones only (as those are the basics).

Much like there are “magic” Symbols like Symbol.iterator.

Re:TC39, ECMAScript, and the Future of JavaScript by danielbarla on Tuesday June 27, 2017 @03:58AM (#14643287)
That's interesting. My knowledge of JS is a bit lacking, so I'm struggling to see the equivalence of the interfaces approach. E.g., is it possible to parametrize interfaces with actual values, such as @maxLength(20)? Also, how do you apply interfaces down to the field-level, where they are of primitive types, such as number or string?
Re:TC39, ECMAScript, and the Future of JavaScript by abritinthebay on Tuesday June 27, 2017 @11:35AM (#14646345)
That feels like a job for getters/setters, no?
Re:TC39, ECMAScript, and the Future of JavaScript by danielbarla on Wednesday June 28, 2017 @01:33AM (#14651915)
I guess it depends what style you favour. I can't imagine using getters/setters like that in JS today, and not have major pains from it (things like not being able to use data binding frameworks easily, etc).