<div dir="ltr"><div><div><div><div><div><div><div>Hello,<br><br></div>My name is Victor, been a developer (C, delphi, php, java, js) for the last 10 years or so and lately I had the chance to try swift. I have a suggestion/question regarding initializers.<br><br></div>Sidenote: If this is not the correct mailing list for this can you please redirect me to the right place?<br><br></div>Consider the following 2 classes and code:<br><br></div>class A {<br></div>     var x:Int<br><br></div>     init() {<br></div>         x = 1<br><div>     }<br><div><div>}<br><br></div><div>class B : A {<br></div><div>    override init() {<br></div><div>         super.init() // Swift FORCES this call<br></div><div>         x = 2<br></div><div>    }<br></div><div>}<br><br></div><div>var a:B<br></div><div>for i in 0...99999999 {<br></div><div>    a = B()  // Whatever... some code that inits B.<br></div><div>}<br></div><div><br></div><div>This results in 99999999 x = 1 then 99999999 x = 2... the x = 1 being totally useless in this particular case.<br><br></div><div>In this case, if you don&#39;t make the super init you get a compile error.<br><br></div><div><b>Now... I see the use of this. It ensure that all members are initialized. For example if A had a private variable (another strange choice here with what private means in swift but I haven&#39;t thought on it yet so... maybe is a cool choice), the B init could not initialize it. I also understand that the cases when you need this minor performance gain are rather rare (but they do still exist). So I guess the choice for the super.init() had that reasoning.<br><br></b></div><div>Still... my suggestion would be to give a warning, maybe force a key word before the init (like iKnowWhatImDoing init() {}), THEN in case vars are still not inited give a runtime error (afaik Objective C for example gives a warning). That ensures everything is ok and also allows programmers that have strange cases to treat them accordingly.<br><br></div><div>Anyway... that would be my suggestion. Maybe this was discussed before also... If this was discussed before can you please point me to the discussion? I like to understand the choices for the tools I use.<br><br><br></div><div>P.S. Please excuse any grammatical errors... English is not my first language.<br></div><div><br></div><div>Thank you for your time and have a great day,<br></div><div>Petrescu Victor<br></div></div></div></div>