4 ms·
> Go's handling of accessors for structures inside structures and structural typing. Could you give an example of this? > But I would like to add Rust's use o
by dom96 11y ago
> Go's handling of accessors for structures inside structures and structural typing.
Could you give an example of this?
> But I would like to add Rust's use of '!' for macros and Python's slicing syntax.
Have you seen the Nim `a[x .. ^1]` syntax?
- Symmetry 11y agoIt's been a while since I've used Go but I seem to recall that you can say foo.baz instead of foo.bar.baz if baz is a unique name in that struct hierarchy. Which makes choosing composition over inheritance nicer. For the structural typing thing that just means that you declare interfaces that functions can accept and any struct that can fulfill that interface does. Sort of like static duck typing but all the used methods are checked at compile time. But more generally I'm not a fan of using inheritance as a way of achieving polymorphism and I like Go's approach here more than Nim's. No, I hadn't seen the 'a[x .. ^1]' syntax. Does that mean 'The items of a from x to the second from the last'? If so I'm glad that the semantics are there but Python's syntax is still nicer.
- dom96 11y agoHave you seen Nim's concepts? [1] They sound similar to what you're describing. The semantics are slightly different from Python. 'a[x .. ^1]' means 'The items of a from x to the last element'
- dom96 11y agoOops, forgot to include link to concepts: http://nim-lang.org/docs/manual.html#generics-concepts http://nim-lang.org/docs/manual.html#generics-concepts
- Symmetry 11y agoAnd if Nim replaces inheritance with concepts and composition I'd be quite happy. But I think they'll end up existing side by side and most things will use inheritance based polymorphism.