<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On Jan 31, 2017, at 3:13 PM, Victor Petrescu &lt;<a href="mailto:victor.petrescu13@gmail.com" class="">victor.petrescu13@gmail.com</a>&gt; wrote:</div><div class=""><div dir="ltr" class="">@John McCall The expense at runtime issue of course. The fact that I need to add one more line would never bother me enough to bother a few hundreds ppl in turn :).<br class=""></div></div></blockquote><div><br class=""></div>Are you under the impression that the compiler is unable to inline the super.init() call?</div><div><br class=""></div><div>John.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Jan 31, 2017 at 9:51 PM, John McCall <span dir="ltr" class="">&lt;<a href="mailto:rjmccall@apple.com" target="_blank" class="">rjmccall@apple.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 28, 2017, at 1:07 PM, Victor Petrescu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class="">Hello,<br class=""><br class=""></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 class=""><br class=""></div>Sidenote: If this is not the correct mailing list for this can you please redirect me to the right place?<br class=""><br class=""></div>Consider the following 2 classes and code:<br class=""><br class=""></div>class A {<br class=""></div>&nbsp;&nbsp;&nbsp;&nbsp; var x:Int<br class=""><br class=""></div>&nbsp;&nbsp;&nbsp;&nbsp; init() {<br class=""></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = 1<br class=""><div class="">&nbsp;&nbsp;&nbsp;&nbsp; }<br class=""><div class=""><div class="">}<br class=""><br class=""></div><div class="">class B : A {<br class=""></div><div class="">&nbsp;&nbsp;&nbsp; override init() {<br class=""></div><div class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super.init() // Swift FORCES this call<br class=""></div><div class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = 2<br class=""></div><div class="">&nbsp;&nbsp;&nbsp; }<br class=""></div><div class="">}<br class=""><br class=""></div><div class="">var a:B<br class=""></div><div class="">for i in 0...99999999 {<br class=""></div><div class="">&nbsp;&nbsp;&nbsp; a = B()&nbsp; // Whatever... some code that inits B.<br class=""></div><div class="">}<br class=""></div><div class=""><br class=""></div><div class="">This results in 99999999 x = 1 then 99999999 x = 2... the x = 1 being totally useless in this particular case.<br class=""><br class=""></div><div class="">In this case, if you don't make the super init you get a compile error.<br class=""><br class=""></div><div class=""><b class="">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'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 class=""><br class=""></b></div></div></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class="">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 class=""><br class=""></div><div class="">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 class=""></div></div></div></div></div></blockquote><div class=""><br class=""></div>What problem are you trying to solve here?&nbsp; Are you annoyed at having to write super.init() and/or initialize your instance variables instead of having the compiler "do the right thing" automatically, or are you worried that calling super.init() will be a small but unnecessary expense at runtime?&nbsp; Because these seem like completely different problems that should be addressed in completely different ways.</div><div class=""><br class=""></div><div class="">John.</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><br class=""><br class=""></div><div class="">P.S. Please excuse any grammatical errors... English is not my first language.<br class=""></div><div class=""><br class=""></div><div class="">Thank you for your time and have a great day,<br class=""></div><div class="">Petrescu Victor<br class=""></div></div></div></div>
______________________________<wbr class="">_________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class=""></div></blockquote></div><br class=""></div></blockquote></div><br class=""></div></div></div>
</div></blockquote></div><br class=""></body></html>