Live data from Hacker News

Show HN: ES7 Decorator library adds types checking, memoization, and more to JS

github.com

41–43 of 43 posts

Re: Show HN: ES7 Decorator library adds types checking, memoization, and more to JS

#41

Can someone recommend a simple and easy-to-approach tutorial into ES7 decorators? I have used decorators successfully in my previous Python projects, and I'm eager to start using them in JS. Unfortunately, I haven't yet come across a good guide till now.

Check out the spec: https://github.com/wycats/javascript-decorators

Re: Show HN: ES7 Decorator library adds types checking, memoization, and more to JS

#42
post #39

I used to argue for type decorations, like in most C like languages, but then changed my mind. When programming in a high level language like JavaScript, you should not think about types. Thinking about types will only limit your creativity and problem solving. Instead, you should focus on the logic abstraction. Also you shouldn't lock yourself into classifications. Instead, just check the input and throw an error if…

>Also you shouldn't lock yourself into classifications. Instead, just check the input and throw an error if it doesn't fit. I really don't see the gain here - instead of delegating the typechecks to a tool, the compiler you clutter your code with them. You still have to think about the types, functions/methods (public ones) start with at one, two or more ifs and you even have a hit on runtime perfomance.

By helping out the compiler you can get better performance. But I like to think that current JavaScript engines or future ones are quite smart and can optimize beyond that.

Lets say you are writing software for a cargo company ... The code has well defined classes. The company now wants to expend by including buss goods. But in the code, the terminals and containers will only accept trucks ... It would be better if the terminal code checked if the good fitted etc.

Thinking about Buss vs Truck is much better then thinking about Array vs Object, but you shouldn't let classifications limit the solutions either.

Re: Show HN: ES7 Decorator library adds types checking, memoization, and more to JS

#43
post #20

Interesting - I wonder whether TypeScript could compile down to this when ES7 is accepted and live in browsers. As it is, I do prefer the syntax of TypeScript.

This does runtime checking. Flow and Typescript do static type checking. Which, as long as the systems are sound, means you don't need a runtime component.

TypeScript isn't sound, and does rely on runtime checking for a small amount of stuff. I don't know about Flow.
Post reply on HN