Comment by zac23or

1 day ago

Great article!

I like Go and Rust, but sometimes I feel like they lack tools that other languages have just because they WANT to be different, without any real benefit.

Whenever I read Go code, I see a lot more error handling code than usual because the language doesn't have exceptions...

And sometimes Go/Rust code is more complex because it also lacks some OOP tools, and there are no tools to replace them.

So, Go/Rust has a lot more boilerplate code than I would expect from modern languages.

For example, in Delphi, an interface can be implemented by a property:

  type
  TMyClass = class(TInterfacedObject, IMyInterface)
  private
    FMyInterfaceImpl: TMyInterfaceImplementation; // A  field containing the actual implementation
   public
     constructor Create;
     destructor Destroy; override;
     property MyInterface: IMyInterface read  FMyInterfaceImpl implements IMyInterface;
   end;

This isn't possible in Go/Rust. And the Go documentation I read strongly recommended using Composition, without good tools for that.

This "new way is the best way, period ignore good things of the past" is common.

When MySQL didn't have transactions, the documentation said "perform operations atomically" without saying exactly how.

MongoDB didn't have transactions until version 4.0. They said it wasn't important.

When Go didn't have generics, there were a bunch of "patterns" to replace generics... which in practice did not replace.

The lack of inheritance in Go/Rust leaves me with the same impression. The new patterns do not replace the inheritance or other tools.

"We don't have this tool in the language because people used it wrong in the old languages." Don't worry, people will use the new tools wrong too!

Go allows deferring an implementation of an interface to a member of a type. It is somewhat unintuitive, and I think the field has to be an unnamed one.

Similarly, if a field implements a trait in Rust, you can expose it via `AsRef` and `AsMutRef`, just return a reference to it.

These are not ideal tools, and I find the Go solution rather unintuitive, but they solve the problems that I would've solved with inheritance in other languages. I rarely use them.

  • Thanks. I had been searching for this for a project in the past and couldn't find it in Go or Rust. Before posting, I asked chatgpt, and he said it wasn't possible...