logoalt Hacker News

pjmlp • today at 4:05 PM • 3 replies • view on HN

Because in languages like C++ and Swift, contrary to your other examples, the goal is that library types should be able to do everything that built-in types expose.

Thus you need all mechanisms to implement the same capabilities, thus constructors, by the way they are not alone in this approach.


Replies

aw1621107 • today at 4:22 PM

That feels a bit like begging the question? Library types only need constructors to replicate built-in types if built-in types use constructors themselves. But do built-in types need constructors? What is lost by just using regular functions?

Also I was under impression that Rust at least has a similar goal?

➕ show 1 reply
ninkendo • today at 4:12 PM

I don't see the link between constructors and whether or not built-in types have special treatment. Care to enlighten the class?

➕ show 2 replies