And my point is and was: It doesn't *need* to be both type safe *and*
reusable, unless you are focusing your energy on writing frameworks or
treating type safety as a goal solely for it's own sake. It's perfectly
fine to write small stuff yourself (for example like this) with explicit
types and it's perfectly fine to locally not have strict compiler checks if
you are doing something complicated that needs to be reusable. If you focus
on application writers, instead of the authors of the frameworks they might
use, you'll recognize that either choice just isn't that bad.

On Wed, Jun 22, 2016 at 9:36 AM, <andrew.mez...@gmail.com> wrote:

> >> perfectly type safe.
>
> Perfectly type safe but not perfectly reusable.
>
> What If we slightly complicate the task?
>
> Now is my code and I want to see on your code exampe (perfectly type safe
> but and perfectly reusable)
>
> type Foo<K, V> interface {
>   Get(key K) V
>   Set(key K, val V)
> }
> func foo() (int, Foo<string, int>) {
>   foo := &Foo<string, int>{}
>   // ...
>   foos := []Foo<K,V>{}
>   // ...
>   k := "London"
>   // ...
>   return 55, foo2(foos, 55, k)
> }
> // This code is type safe and reusable
> foo2<K, V> (foos []Foo<K,V>, i int, key K) (V, Foo<K,V>) {
>   foo := foos[i]
>   return foo.Get(key), foo
> }
>
> --
> 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