Pages

2016-10-27

Go for C# developers: Polymorphism

One of the things I miss the most in Go is polymorphism. I must confess that the lack of polymorphism is one of those things that still annoys me sometimes.

I'm not sure this is the official explanation, but one good thing with a language that does not support polymorphism is that it forces you to name methods explicitly. For example I think Read vs ReadAt vs ReadByte all make sense.

However there are some cases where it is just ugly in my opinion; NewWriter vs NewWriterLevel vs NewWriterLevelDict. Whenever somebody is unable to find a descriptive name where polymorphism would make sense, the just append an argument type to the name.

And frankly I haven't made up my mind on what is worse; allowing polymorphism or ugly names like FooIntStringString. I do like how Go forces you to come up with better names, but that requires you to try harder and not settle for just adding an argument type.

2 comments:

  1. I don't know Go, but it sounds like you're talking about method overloading, not polymorphism...

    ReplyDelete
  2. We are both right. I am indeed talking about method overloading; also known as ad-hoc polymorphism: https://en.wikipedia.org/wiki/Polymorphism_(computer_science)

    ReplyDelete