← Back to context

Comment by mrkeen

2 days ago

Weird, that's exactly how I feel reading Go:

  func (lst *List[T]) Push(v T) {
    if lst.tail == nil {
        lst.head = &element[T]{val: v}
        lst.tail = lst.head
    } else {
        lst.tail.next = &element[T]{val: v}
        lst.tail = lst.tail.next
    }

}

And this one doesn't even have the infamous error-checking.

You cherry picked a contrived example but that's one of the cleanest generics implementations.

Now imagine if it had semicolons, ->, ! and '.

  • > You cherry picked a contrived example

    List.add is contrived? What are you doing that's simpler the list.add?

    > but that's one of the cleanest generics implementations.

    You're saying it's typically worse than this?

    • He is referring to

        &element[T]{val: v}
      

      the & is a pointer, which is common across most languages, but the [T] is a dynamic type T. Otherwise it would be just

        &element{val: v}
      

      He says that element[T] is a clean/simple implementation of generics.