NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
▲We have traits at home (axelmagn.com)
Panzerschrek 2 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.

tialaramex 36 minutes 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 1 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.

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