NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
▲We have traits at home (axelmagn.com)
detourdog 13 minutes ago [-]
First I had heard of duck-typing.

https://en.wikipedia.org/wiki/Duck_typing

After reading the page I was left with the question of isn't that dynamic inheritance? The seems like dynamic runtime.

Panzerschrek 9 hours ago [-]
I see little to no benefits of introducing such "traits" into a language having duck-typing in templates. It may sometimes improve code readability (slightly), but with more boilerplate code for traits handling in exchange. And the result machine code will be identical to code with no traits at all (with only duck-typing).

C++ is a good example of this. It had duck-typing in templates for decades. Then some sort of trait-like mechanism named concepts has been introduced. The only benefit of them seems to be slightly better error messages if someone misuses a template class/function.

dnautics 22 minutes ago [-]
> The only benefit of them seems to be slightly better error messages if someone misuses a template class/function.

Seems like a pretty valuable benefit?

tialaramex 8 hours ago [-]
I'm not a Zig expert but it looks as though the intent is that duck-typing is not a core part of this idea. Having traits allows Carol to implement Ben's Teleport trait for Alice's Goose.

With duck-typing Carol needs to either prevail upon Alice to make you a teleporting Goose, or make her own "CarolsTeleportingGoose" wrapper type which implements the teleporting functions.

indiosmo 9 hours ago [-]
Concepts are great for overload sets where previously you needed enable_if gymnastics. Also useful for if constexpr.

If you do template metaprogramming it makes your life a lot easier.

ZeroDayDreamer 9 hours ago [-]
[flagged]
no1guangming 10 hours ago [-]
Can't load the page
Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact
Rendered at 18:00:26 GMT+0000 (Coordinated Universal Time) with Vercel.