<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jul 16, 2015 at 6:44 PM, Michael Van Canneyt <span dir="ltr"><<a href="mailto:michael@freepascal.org" target="_blank">michael@freepascal.org</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">
On Thu, 16 Jul 2015, Maciej Izak wrote:<br>
</span><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
2015-07-16 17:23 GMT+02:00 Sven Barth <<a href="mailto:pascaldragon@googlemail.com" target="_blank">pascaldragon@googlemail.com</a>>:<br>
<br>
Then let me tell you that generic methods will arrive in mode ObjFPC (and thus its syntax) first, because the Delphi syntax is a PITA to parse/handle.<br>
<br>
(in fact generic methods are already working in mode ObjFPC in my local repo, I just want to get the Delphi ones working a little bit before commiting to trunk)<br>
<br>
<br>
@Sven, @Michael<br>
<br>
I am using generics all the time for many things.<br>
<br>
IMO using "generic/specialize" syntax because it is more simple to implement in compiler is very strange motivation. Using specialize keyword maybe is good in pure theory but is non practical<br>
(generic keyword in type declaration is not so bad).<br>
<br>
You can torture me (!!!) but I will not use so many unnecessary words for simple things.<br>
By using this complicated syntax you will kill all functional/generic approach.<br>
</blockquote>
<br></span>
No problem. Use mode Delphi then, that's what it is for.<br>
<br>
<sarcasm><br>
Why bother with mode objfpc ? It only makes life more difficult. You need to use @ when there is no need really, you are restricted in your choice of names. Why use it at all ?<br>
</sarcasm/><br>
<br>
And you are discussing with the wrong person. I don't think generics are very useful to begin with.<br>
I can see a use case for a simpler declaration of collections, but that's about it.<br></blockquote><div><br></div><div>Buddy, with generics you can do other things besides fast creation of lists. =) Please take a look at this little sample below.</div><div><br></div><div>Generics are very useful, and one of many possibilities that generics provides is the "compilation time validation", for example, see this small code below:</div><div><br></div><div>=== begin code ===</div><div><br></div><div>TPersonDao = class(TObject)</div><div>public</div><div> procedure Save(APerson: TObject);</div><div>end;</div><div><br></div><div>TPersonDao.Save(APerson: TObject);</div><div>begin</div><div> if not (APerson is TPerson) then<br></div><div> raise EPersonDaoInvalidType.CreateResFmt(@SInvalidEntityClass, [APerson.ClassName, TPerson.ClassName]);</div><div> // other codes for TPerson persistance ...</div><div>end;</div><div><br></div><div>=== end code ===<br></div><div><br></div><div>This code above will check if the instance of my parameter is from a TPerson class, if so, persist it, otherwise raise an exception. It avoids something like this:</div><div><br></div><div>=== begin code ===<br></div><div><br></div><div>var</div><div> VProduct: TProduct;</div><div> ...</div><div> VSomePersonDao: TPersonDao;</div><div>begin</div><div> ...</div><div> VSomePersonDao.Save(VProduct); // a type, for example (mistakes happen, we are human =D )</div><div><br></div><div>=== end code ===<br></div><div><br></div><div>OK, it will raise an exception "Cannot persist a 'TProduct' using a 'TPersonDao'". Nice, but this error will be showed in production and for my customer, and it is very bad. =/ Using generics you can avoid it:</div><div><br></div><div>=== begin code ===<br></div><div><br></div><div><div>TPersonDao<T> = class(TObject)</div><div>public</div><div> procedure Save(APerson: T);</div><div>end;</div><div><br></div><div>TPersonDao.Save(APerson: T);</div><div>begin</div><div> // the codes for TPerson persistance ...<br></div><div>end;</div></div><div><br></div><div>=== end code ===<br></div><div><br></div><div>It does not need EPersonDaoInvalidType, because:</div><div><br></div><div>=== begin code ===<br></div><div><br></div><div><div>var</div><div> VProduct: TProduct;</div><div> ...</div><div> VSomePersonDao: TPersonDao<TPerson>;<br></div><div>begin</div><div> ...</div><div> VSomePersonDao.Save(VProduct);</div></div><div><br></div><div>=== end code ===<br></div><div><br></div><div>The compiler will stop the compilation saying something like "Incompatible specialization type in 'TPersonDao', got 'TProduct', expected 'TPerson'". So one more runtime error will be avoided.</div><div><br></div><div>And you can do more:</div><div><br></div><div>TSessionDao.Persist<TPeson>(VPerson); // inline specialization</div><div><br></div><div>or:</div><div><br></div><div>VPersonList := TSessionDao.Load<TPeson>; // inline specialization avoinding casts</div><div><br></div><div>It is only some of many generic possibilities.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Silvio mentioned his company is moving to Node.js. That means Javascript. I program Javascript myself. Javascript is an unbelievably primitive language, yet is is increasingly popular.</blockquote><div><br></div><div>=)</div><div><br></div><div>We are using Object Pascal in a desktop ERP written with Delphi 7, and currently we are migrating some our modules to the XE8 (unfortunatelly XE8 is pretty expensive, but ... =/ ). Our ERP has many online features like online registration, SMS/e-mail notifications, reports, charts, and provides several resources for Android/Web via a SSL API written with FCL-Web/Brook, and it is working perfectly, but our productivity is a bit slow for to do new features, because -- and unfortunately -- it is increasingly difficult to find professionals interested in Delphi/Pascal programming. =(<br></div><div><br></div><div>Currently I made a wery fast websocket server[1] using Node.js, and I had some dificult to find an updated WS Pascal client compatible with FPC 3 and XE8, so I found one called Bauglir websocket, after some changes I could compile it in both compilers. But I found some comercial clients, but unfortunatelly it could not compile in FPC because they are using generic classes from the Delphi Generic.Collections. Ironically, there are zillions WS clients written in JS.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
To me, that tells me that all these additions to Object Pascal which everyone claims are 'so essential' are in fact pure nonsense. Eye candy to make it look modern.</blockquote><div><br></div><div>Buddy, I don't think so. Pascal is a very nice language, but it could be modernized to be compatible with the current very fast necessity of our customers, allowing us to do core more fast, and this new features (generics, custom attributes etc) could be very helpful. Yes, in mantis there are already many more important issues to be fixed, but we can see some people interested in helping to do these new features, so IMHO I think it would be interesting to hear them a little more. =)</div><div><br></div><div>Sure, I can't speak more to avoid being a little off-topic hehe.</div><div><br></div><div>[1] - wss://<a href="http://duallsistemas.com.br:8001/">duallsistemas.com.br:8001/</a> (the public version is just a echo server using the 'echo-protocol' as protocol, you can use a terminal[2] for test it).<br></div><div>[2] - <a href="https://chrome.google.com/webstore/detail/dark-websocket-terminal/dmogdjmcpfaibncngoolgljgocdabhke">https://chrome.google.com/webstore/detail/dark-websocket-terminal/dmogdjmcpfaibncngoolgljgocdabhke</a></div><div><br></div><div>-- </div></div><div class="gmail_signature">Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a></div>
</div></div>