zlacker

[parent] [thread] 6 comments
1. Subopt+(OP)[view] [source] 2023-05-20 02:41:45
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.

replies(2): >>killth+I1 >>crubie+D8
2. killth+I1[view] [source] 2023-05-20 03:11:15
>>Subopt+(OP)
Another 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);
replies(3): >>leeoni+x2 >>praecl+Q7 >>mlajto+ku
◧◩
3. leeoni+x2[view] [source] [discussion] 2023-05-20 03:21:43
>>killth+I1
or add(a,b,c)
◧◩
4. praecl+Q7[view] [source] [discussion] 2023-05-20 04:34:51
>>killth+I1
Yes that syntax works right now.
5. crubie+D8[view] [source] 2023-05-20 04:48:52
>>Subopt+(OP)
I 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/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}`

replies(1): >>crubie+Ol
◧◩
6. crubie+Ol[view] [source] [discussion] 2023-05-20 08:27:33
>>crubie+D8
I got nerdsniped and made a small library to test this concept. Might maintain

https://github.com/crubier/opov

◧◩
7. mlajto+ku[view] [source] [discussion] 2023-05-20 10:53:31
>>killth+I1
Indeed. "Object-oriented" fluent notation is basically equivalent to infix notation.

https://mlajtos.mu/posts/new-kind-of-paper-2

[go to top]