MyEarth Posted July 11, 2013 Share Posted July 11, 2013 There is any advantage to use this: (1 = 1) ? MsgBox($MB_OK, "Result: 1=1", "True!") : MsgBox($MB_OK, "Result: 1=1", "False!") Instead of this? If 1 = 1 Then MsgBox($MB_OK, "Result: 1=1", "True!") Else MsgBox($MB_OK, "Result: 1=1", "False!") EndIf Link to comment Share on other sites More sharing options...
James Posted July 11, 2013 Share Posted July 11, 2013 There is any advantage to use this: (1 = 1) ? MsgBox($MB_OK, "Result: 1=1", "True!") : MsgBox($MB_OK, "Result: 1=1", "False!") It's shorter syntax. It makes life easier when say you want to do a conditional in a string or something, without setting variables. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
jpm Posted July 11, 2013 Share Posted July 11, 2013 There is any advantage to use this: (1 = 1) ? MsgBox($MB_OK, "Result: 1=1", "True!") : MsgBox($MB_OK, "Result: 1=1", "False!") Instead of this? If 1 = 1 Then MsgBox($MB_OK, "Result: 1=1", "True!") Else MsgBox($MB_OK, "Result: 1=1", "False!") EndIf in this particular case no but see $tagREBARBANDINFO in StructureConstants.au3 or _Min/_Max in Math.au3 Link to comment Share on other sites More sharing options...
Administrators Jon Posted July 11, 2013 Administrators Share Posted July 11, 2013 It's just a shortcut that a few languages have. It's use depends on the coder. I personally don't use it at all even in C/C++, other coders like to use it everywhere. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
MyEarth Posted July 11, 2013 Author Share Posted July 11, 2013 (edited) Personally i don't like it, maybe is less code but it's not "readable" like an If...EndIf Edited July 11, 2013 by MyEarth Link to comment Share on other sites More sharing options...
James Posted July 11, 2013 Share Posted July 11, 2013 (edited) I personally don't use it at all even in C/C++, other coders like to use it everywhere.I love ternary. When I use them, I very rarely nest them inside of each other as this does get confusing.Personally i don't like it, maybe is less code but it's not "readable" like an If...EndIfIt's a good job that If..EndIf still exist Edited July 11, 2013 by James Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
MyEarth Posted July 11, 2013 Author Share Posted July 11, 2013 (edited) Just for know, why whe can't have the same logic of ternary but with a if...endif? If <expression> Then statement1 Else statement2 Maybe not multiple ElseIf but at least one Else on the same line? Edited July 11, 2013 by MyEarth Link to comment Share on other sites More sharing options...
guinness Posted July 11, 2013 Share Posted July 11, 2013 Just for know, why whe can't have the same logic of ternary but with a if...endif? If <expression> Then statement1 Else statement2 Maybe not multiple ElseIf but at least one Else on the same line? Now I find that confusing. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
James Posted July 11, 2013 Share Posted July 11, 2013 (edited) I find many a time, the reason I use ternary is to do a condition within a concatenation of strings. In AutoIt: $bDebug = False MsgBox(0, "", ($bDebug ? "Oh hai James, you're secretly the most awesome of them all.." : "Yo! You're awesome dude...")) Try doing that with an If...EndIf - usually you can't. Edited July 11, 2013 by James Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
MyEarth Posted July 11, 2013 Author Share Posted July 11, 2013 (edited) Why is confusing? It's the same logic of ternary but write in "autoit style". 1 line < 4 lines, with many ElseIf on the same line can be confusing, with only one Else for me it's a good compromise. Anyway i know will be never added Edit: James, i don't have say ternary is not useful, but in the most of the case you can do the same with If...EndIf and ternary isn't "redeable", at least for a noob like me Edited July 11, 2013 by MyEarth Link to comment Share on other sites More sharing options...
czardas Posted July 11, 2013 Share Posted July 11, 2013 (edited) Just for know, why whe can't have the same logic of ternary but with a if...endif? If <expression> Then statement1 Else statement2 Maybe not multiple ElseIf but at least one Else on the same line? You can write something like this on one line but it gets more complicated. Instead it's easier to just create a helper function which you can call to return the correct result (1 line of code in the main script), or use this new feature if more suitable. Edited July 11, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Mat Posted July 11, 2013 Share Posted July 11, 2013 (edited) I've seen something like that before, but it was "statement1 IF expression ELSE statement2". Think it might be python bit not actually sure.Generally I use the conditional operator for things like: ConsoleWrite($n & " green bottle" & ($n > 1 ? 's' : '') & @LF) Edited July 11, 2013 by Melba23 Removed apology as it is now in the right place! AutoIt Project Listing Link to comment Share on other sites More sharing options...
James Posted July 11, 2013 Share Posted July 11, 2013 Why is confusing? It's the same logic of ternary but write in "autoit style". 1 line < 4 lines, with many ElseIf on the same line can be confusing, with only one Else for me it's a good compromise. Anyway i know will be never added Edit: James, i don't have say ternary is not useful, but in the most of the case you can do the same with If...EndIf and ternary isn't "redeable", at least for a noob like me Ternary is confusing when you put them together, look at this: $bOne = False $bTwo = False $bThree = False $bFour = True ConsoleWrite(($bOne ? : "$bOne is True" : ($bTwo ? "$bTwo is True" : ($bThree ? "$bThree is True" : ($bFour ? "$bFour is True" : "Oh god, the Mayans were right, the world is going to end!")))) & @CRLF) Tell me that doesn't get confusing. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Richard Robertson Posted July 11, 2013 Share Posted July 11, 2013 Ternary is confusing when you put them together, look at this: $bOne = False $bTwo = False $bThree = False $bFour = True ConsoleWrite(($bOne ? : "$bOne is True" : ($bTwo ? "$bTwo is True" : ($bThree ? "$bThree is True" : ($bFour ? "$bFour is True" : "Oh god, the Mayans were right, the world is going to end!")))) & @CRLF) Tell me that doesn't get confusing. Not confusing at all. Optimizing compilers will just have the single line ConsoleWrite("Oh god, the Mayans were right, the world is going to end!" & @CRLF) Link to comment Share on other sites More sharing options...
trancexx Posted July 11, 2013 Share Posted July 11, 2013 (edited) Ternary is particularly useful when declaring constants. This goes for any language that has ternary. When dealing with const references even more. For example in AutoIt you would use ternary good if you would do this: Const $MY_SUPER_MEANINGFUL_CONST = @AutoItX64 ? "Bzz" : "Hrr" ;... ...Try without ternary and see what you get. Edited July 11, 2013 by trancexx czardas, James and jaberwacky 3 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
James Posted July 11, 2013 Share Posted July 11, 2013 Not confusing at all. Optimizing compilers will just have the single line ConsoleWrite("Oh god, the Mayans were right, the world is going to end!" & @CRLF) Last time I checked, humans aren't compilers. It's confusing for a human to read that when surrounded by other code, other conditions etc. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
trancexx Posted July 11, 2013 Share Posted July 11, 2013 And the OP is terrible terrible example. Less terrible would be: MsgBox($MB_OK, "Result: 1=1", (1 = 1) ? "True!" : "False!") ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
czardas Posted July 11, 2013 Share Posted July 11, 2013 (edited) Some of you have already seen it, but I find making this post hard to resist, and someone might be interested although the similarity ends with the word ternary. For another use of the word ternary see >FlipFlapFlop Edited July 11, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
MyEarth Posted July 11, 2013 Author Share Posted July 11, 2013 And the OP is terrible terrible example. Less terrible would be:MsgBox($MB_OK, "Result: 1=1", (1 = 1) ? "True!" : "False!") That example was made by Melba, i have just copy-past from him Bad bad example Melba lol Ok, ternary is so cool but we have lived without that for years, now we can make new thing that before? Link to comment Share on other sites More sharing options...
James Posted July 11, 2013 Share Posted July 11, 2013 Ok, ternary is so cool but we have lived without that for years, now we can make new thing that before? AutoIt is growing up. Many languages have ternary and since AutoIt is used now for some serious programming, it makes sense to aid the developer. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now