<div dir="auto"><div><div class="gmail_quote"><div dir="ltr">Am Mo., 12. Nov. 2018, 03:12 hat Ryan Joseph <<a href="mailto:ryan@thealchemistguild.com">ryan@thealchemistguild.com</a>> geschrieben:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Nov 12, 2018, at 12:25 AM, Sven Barth via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-pascal@lists.freepascal.org</a>> wrote:<br>
> <br>
> I'm not convinced that this feature is really needed, because one can simply create a constant and assign that, would transport a clear name as well.<br>
<br>
This is for runtime though and necessarily for constants. It’s just a short hand for initializing records so you don’t need to make boiler plate constructors. Often time when you create a new record you add a constructor so you can init in one line. Swift and c++ both have this default constructor and it’s a nice time saver.<br>
<br>
for example:<br>
<br>
struct Vec2 {<br>
float x,y;<br>
};<br>
<br>
int main() {<br>
Vec2 v = {1,2};<br>
v = {v.x + 1, v.y + 1}; <br>
return 0;<br>
}<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">The advantage of the typecast like syntax is that you can get compiler errors if for whatever reason the order of the fields is changed as they are all named. </div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> But *if* I had to decide I would pick #1, cause then there wouldn't be the chance to break existing code if a user decides to add a constructor to their record and some other code relies on there not being a constructor. Also due to the syntax TYPENAME(FIELDNAME:VALUE[;FIELDNAME:VALUE[;…]]) it's in principle possible to have the parser distinguish whether it's a typecast or a default constructor.<br>
<br>
Yeah there could be name conflicts then. Maybe there should be some way to explicitly state you want the constructor with a certain name, i.e.,<br>
<br>
type<br>
TVec2 = record<br>
x, y: integer;<br>
constructor create; default;<br>
end;<br>
<br>
??? I don’t know, just an idea.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">That is a constructor that takes no arguments. How do you think that is useful for a constructor that *does* take arguments? That is absolutely not clear at all for the user. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div></div>