arik-so / ldk-parser

0 stars 2 forks source link

Constructor classification consideration #16

Closed arik-so closed 1 year ago

arik-so commented 1 year ago

Currently, any method within a type that produces the type itself is considered a constructor, provided its name isn't clone.

Should we restrict that classification and make only methods constructors if their name is new?

An interesting example is the Retry struct, whose sole initializing method is called attempts, not new. When it's a constructor, initialization just looks like Retry(a: 3). If it weren't a constructor, it would read Retry.initWithAttempts(a: 3).

On the other hand, some types like BackgroundProcessor have a constructor whose name is simply default and not new. Food for thought.

tnull commented 1 year ago

Hm good question, I think another frequent pattern are conversion constructors that follow the rust convention of from_X. If they are not made constructors, I believe these would currently result in initX, which should however likely rather be initWithX?

arik-so commented 1 year ago

Done in 4ee29b0dd8a0f4256f16684dd48adbd0284e6226.