Ha, I wrote this version before I saw that response:

https://play.golang.org/p/vO2TI7OeJk_E

On 7 September 2018 at 09:00, Nigel Tao <nigel...@golang.org> wrote:
> Building on Todd's example, you can add a little more type safety
> (having the map value type be a "func etc" instead of "reflect.Value)
> by Curry'ing the receiver: https://play.golang.org/p/n3sDpxfd2td
>
> I've also split up the single run function into two: one binds strings
> to functions, the second takes some strings (e.g. as args, but you
> could imagine from a REPL) and calls the corresponding functions.
> "Favor composition over inheritance" is old programming advice, not
> specific to Go, but is obviously applicable to Go, which does not have
> inheritance. Instead of having a FooCmd class that inherits from a Cmd
> base class that adds smarts (in this case, being 'scriptable' or being
> invokable from string input), have a dumb FooCmd type (and a dumb
> BarCmd type, etc.) and compose those dumb types with a runner type
> that does the binding / scriptability.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to