EugeneK 27 Posted 23 hours ago Conditional operator coming in Delphi 13 https://blogs.embarcadero.com/coming-in-rad-studio-13-a-conditional-ternary-operator-for-the-delphi-language/ It is not clear from blog post are both expressions evaluated every time or based on condition? I think is most important thing about this feature. 3 Share this post Link to post
@AT 1 Posted 22 hours ago First impression: nice to have this operator. Second impression: supporting code running in for FPC and Delphi becomes harder and harder. I would prefer to have one of items below in Delphi and FPC: pure generic functions with syntax function XXX<T>(paramas...): result_type . Having such function covers case above and many other cases. operator if overloading. Share this post Link to post
omnibrain 23 Posted 21 hours ago Wow, I hated the ternary operator in every language I encountered so far. But this one with pascal keywords seems almost bearable. But, I'm sure it will bring all sorts of new anti-patterns to Delphi. And I don't think a language saddled with 'with' needs any more anti-patterns. 3 Share this post Link to post
Anders Melander 2044 Posted 21 hours ago 1 hour ago, EugeneK said: https://blogs.embarcadero.com/coming-in-rad-studio-13-a-conditional-ternary-operator-for-the-delphi-language/ Quote This has been one of the most requested language enhancements by customers for quite some time Yeah, right 🤦♂️ More syntactic sugar, the compiler codegen is still a joke, and we still haven't got SIMD intrinsics. The only time I've ever wished for a ternary operator was when porting C code and being in a rush. But I wouldn't mind all this fluff (since I don't have to use it) - if they would also throw an occasional bone to those of us that need low level performance. 57 minutes ago, @AT said: Second impression: supporting code running in for FPC and Delphi becomes harder and harder. Yes, but you don't have to use it. 3 Share this post Link to post
EugeneK 27 Posted 20 hours ago 30 minutes ago, Anders Melander said: Yeah, right 🤦♂️ It is true at least based on votes in old quality.embarcadero.com portal. Share this post Link to post
Anders Melander 2044 Posted 20 hours ago 3 minutes ago, EugeneK said: It is true at least based on votes in old quality.embarcadero.com portal. Perhaps, but I seriously doubt that it's a representative metric with regard to the needs of the current Delphi users. In all of the Delphi shops that I've ever worked in, I think I was the only one who ever posted something there and even I gave up on that in the end. Share this post Link to post
Remy Lebeau 1626 Posted 17 hours ago 5 hours ago, @AT said: Second impression: supporting code running in for FPC and Delphi becomes harder and harder. Actually, a patch was already created for FreePascal to add this very same conditional operator (FPC already had an IfThen() intrinsic); https://forum.lazarus.freepascal.org/index.php/topic,71398.msg556926.html#msg556926 2 1 Share this post Link to post
@AT 1 Posted 15 hours ago (edited) 5 hours ago, Remy Lebeau said: Actually, a patch was already created for FreePascal Good news. Thank you Remy for keeping us informed! However, Next improvements can bring more value in the Delphi and FreePascal languages: As I pointed earlier - pure generic function declaration can help much. generic constrains by type sets like it implemented in the GoLang. generate smarter code for generic methods. Now the code duplicates for all types. Implementing 1 and 2 allows to implement regular functions like: iif<T>(Condition: boolean; A, B: T): T; overload; inline; begin if Condition then Result:=A else Result:=B; end; max<T: number>(A,B: T); overload; inline; begin if A=>B then Result:=A else Result:=B; end; min<T: enum>(A,B: T); inline; begin if A<=B then Result:=A else Result:=B; end; etc. P.S. number, enum, etc. are could be group sets which union group of compatible types. Edited 12 hours ago by @AT 1 Share this post Link to post
dummzeuch 1663 Posted 12 hours ago I wonder whether there will be a code formatter that supports this. Given that they deprecated the existing one since Delphi 11, I somehow doubt it. 2 1 Share this post Link to post
DelphiUdIT 256 Posted 12 hours ago (edited) 4 hours ago, Remy Lebeau said: Actually, a patch was already created for FreePascal to add this very same conditional operator (FPC already had an IfThen() intrinsic); https://forum.lazarus.freepascal.org/index.php/topic,71398.msg556926.html#msg556926 I don't think so, if you read the full topic you'll see that there is no patch on FPC and they are working on (I don't know how much). May be after the public release of Rad Studio 13 whit all notes they will speed up the production of a patch. Edited 12 hours ago by DelphiUdIT Share this post Link to post
DelphiUdIT 256 Posted 12 hours ago (edited) Make a prevision on what they will produce is only a fantasy. I think, 'cause the next is a major release, that will only be the beginning of a series of new features that will be proposed to us. But, ...... if some MVP were authorized to release some other substantial news, even if not seasoned with technical details .... Edited 12 hours ago by DelphiUdIT Share this post Link to post
Tommi Prami 155 Posted 12 hours ago On this atleast syuntax is readable X := if Left < 100 then 22 else 45; For example C-syntax is not what I really can say that I like. int result = (x > 5) ? 10 : 20; even worse if writte like this int result=(x>5)?10:20; Syntax highlighting saves a bit for sure but still easy to miss those... One character operator thingies... -Tee- 1 Share this post Link to post
DelphiUdIT 256 Posted 10 hours ago (edited) 12 hours ago, EugeneK said: It is not clear from blog post are both expressions evaluated every time or based on condition? I think is most important thing about this feature. In the example thay gave, the equivalent expression is a typical IF, so we can deduce that the new expression also behaves in this way: the part not affected by the condition will not be evaluated. Of course, only they or the release can confirm this. Edited 10 hours ago by DelphiUdIT 1 Share this post Link to post
Kryvich 177 Posted 10 hours ago Great! This is a very long awaited addition for me. I hope they also add a case statement for string types 3 Share this post Link to post
Patrick PREMARTIN 146 Posted 10 hours ago 2 hours ago, DelphiUdIT said: if some MVP were authorized to release some other substantial news, even if not seasoned with technical details .... The beta is under NDA, we can't talk except when we are authorized... or after an official post like for the ternary operator. Many new (and updated) things are in the Ganymede beta(s), not sure all will be released for 13.0 Florence. Stay tuned. 😉 1 Share this post Link to post
Patrick PREMARTIN 146 Posted 10 hours ago 27 minutes ago, DelphiUdIT said: In the example thay gave, the equivalent expression is a typical IF, so we can deduce that the new expression also behaves in this way: the part not affected by the condition will not be evaluated. Of course, only they or the release can confirm this. The Delphi ternary operator will be a real ternary operator. It's different from ifthen() functions. Share this post Link to post
DelphiUdIT 256 Posted 10 hours ago (edited) 17 minutes ago, Kryvich said: Great! This is a very long awaited addition for me. I hope they also add a case statement for string types You can look at examples posted, they use strings in ShowMessage .... Edited 10 hours ago by DelphiUdIT Answer not related ... Share this post Link to post
Sherlock 685 Posted 10 hours ago 2 hours ago, DelphiUdIT said: if some MVP were authorized to release some other substantial news, even if not seasoned with technical details If you are a current subscriber to Delphi, you should have received an invitation to Beta test.... Share this post Link to post
Patrick PREMARTIN 146 Posted 10 hours ago 1 minute ago, DelphiUdIT said: You can look at examples posted, they use strings in ShowMessage .... yes, but it's different from a "case" with strings like Quote case s of 'hello':dosomething; else dootherthig; end; Share this post Link to post
DelphiUdIT 256 Posted 10 hours ago 1 minute ago, Patrick PREMARTIN said: yes, but it's different from a "case" with strings like 12 minutes ago, Kryvich said: Great! This is a very long awaited addition for me. I hope they also add a case statement for string types Sorry, I understood wrong the question. My fault. It's better thta I wait some more details before speaking ... Share this post Link to post
Dave Novo 56 Posted 5 hours ago 9 hours ago, @AT said: However, Next improvements can bring more value in the Delphi and FreePascal languages: As I pointed earlier - pure generic function declaration can help much. generic constrains by type sets like it implemented in the GoLang. generate smarter code for generic methods. Now the code duplicates for all types. Implementing 1 and 2 allows to implement regular functions like: iif<T>(Condition: boolean; A, B: T): T; overload; inline; begin if Condition then Result:=A else Result:=B; end; max<T: number>(A,B: T); overload; inline; begin if A=>B then Result:=A else Result:=B; end; min<T: enum>(A,B: T); inline; begin if A<=B then Result:=A else Result:=B; end; The difference between a ternary operator and iif<T> as you describe is that both operators are not evaluated with the ternary operator. Only the one satisfying the condition For example isVisible:=if Assigned(Foo) then Foo.Visible else False which will work vs isVisible:=iif<Boolean>(Assigned(Foo),Foo.Visible,False) which will crash if Foo is not assigned, according to the implementation you describe. Share this post Link to post
Remy Lebeau 1626 Posted 2 hours ago 10 hours ago, DelphiUdIT said: I don't think so, if you read the full topic you'll see that there is no patch on FPC and they are working on (I don't know how much). I didn't say it was *submitted* for merge into FPC. I said it was *created*. There is a patch file attached to the forum post that I linked to: "It's roughly 30 lines of code and took 15 minutes to create the attached patch for fpc main" Share this post Link to post