Remix.run Logo
▲ ninkendo 6 hours ago

I get that for C++ to have all this overloading it needs constructors, but Swift doesn't take the same bet as C++ does when it comes to overloading, yet it still has first-class constructors anyway. So do lots of other languages (Java, C#, TypeScript, etc.) Swift is especially interesting because it's basically a successor language to Objective-C, and Objective-C did not have first class constructors (`-init`/`-initWithFoo:` is just a convention), they chose to add it anyway.

▲marcosdumay 5 hours ago | parent [-]

The convenience vs. designated initialization in Swift is exactly the same kind of attempt to overload normal language syntax.

Outside of that, Swift has only normal OOP constructors, that are something completely different, and almost not a pain at all. Normal constructors are just a control layer on top of memory initialization that lets you write custom rules for it. It becomes necessary when you have protected memory in your objects, because the external code can't just go and set it, but even languages like Python understand it's convenient to have a defined place to set things up.