4 ms·
And operator overloading. TS code tends to look like this `c.add(b.add(a))` or `add(add(a, b), c)` instead of `a + b + c` as you might write in Python. That wa
by SuboptimalEng 3y ago
And operator overloading. TS code tends to look like this `c.add(b.add(a))` or `add(add(a, b), c)` instead of `a + b + c` as you might write in Python.
That was my biggest pain-point with using TS for graphics related projects. If operator overloading existed, then TS would be a no brainer for entry level graphics + AI/ML projects.
Edit: This gets more complicated when doing operations that force you to manually respect PEMDAS. For example, `add(div(a, b), multiply(c, d))` in TypeScript would simplify to `a / b + c * d` in Python. The TS version is unreadable.
- killthebuddha 3y agoAnother option that's not quite as good as `a + b + c` but that is possible with TypeScript is a fluent API: const sum = a.add(b).add(c);
- leeoniya 3y agoor add(a,b,c)
- praeclarum 3y agoYes that syntax works right now.
- mlajtos 3y agoIndeed. "Object-oriented" fluent notation is basically equivalent to infix notation. https://mlajtos.mu/posts/new-kind-of-paper-2 https://mlajtos.mu/posts/new-kind-of-paper-2
- crubier 3y agoI actually think that tagged template strings in JS/TS could be a much better version of operator overloading! https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... This would give access to any math notation in a more flexible way, implementing a custom DSL in a type safe but expressive way. Imagine writing stuff like const result = math`${a} + ${b} / ${c}`
- crubier 3y agoI got nerdsniped and made a small library to test this concept. Might maintain https://github.com/crubier/opov https://github.com/crubier/opov