[Pitch] An operator for getting a type

Hi everyone.
Doesn't it seem that the current approach looks a bit out of place?
type(of: self).someClassMethod()

Even using something like
variable.class.someClassMethod() feels slightly weird.

Wouldn't it be great to have an operator for that? I think that emphasising is a good thing, this way it will be absolutely clear what is happening after a glance.

For example:
variable::someClassMethod()

In my opinion, even though it resembles C++, it looks fresh and could improve code readability.
What do you think?

1 Like

IMO I wouldn't want to burn :: on this. Why are you doing type(of: self) instead of MyType.someClassMethod?

Edit: Although thinking more on it, I don't think :: would be a terrible idea.

When SE-0068 is implemented:

  • type(of: self).someClassMethod()
  • Self.someClassMethod()
3 Likes

I wonder if this will ever get implemented. It's been accepted for ages now. Mhhm maybe it doesn't affect ABI stability. Then it will be delayed I guess.

1 Like

Oh, I didn’t know about it.
I usualy try to avoid hardcoding class calls as it affects reusability. Moreover, if the name is long it looks messy.
What if I had to get a type of an object?
object.Self.classMethod() looks weird

@tkrajacic, it is still planned but at a lower priority than ABI, according to the latest comment in SR-1340.

@shalamowww, the object.Self.classMethod() syntax was not accepted by the core team.