Attachments (0)
Change History (7)
follow-up: 2 comment:1 by , 11 years ago
comment:2 by , 11 years ago
follow-up: 4 comment:3 by , 11 years ago
Understood as much but I am not really sure you thought this through.
Which basic like language is using this format of an single If--Else--Endif?
To me the only result is that it makes script less readable, but that's also a matter of taste.
Jos
comment:4 by , 11 years ago
Replying to Jos:
Understood as much but I am not really sure you thought this through.
Which basic like language is using this format of an single If--Else--Endif?
To me the only result is that it makes script less readable, but that's also a matter of taste.
Jos
I have many If...Else...EndIf which only contain 1 line of code in each condition, Also if that If structure is in a already another structure like Switch...EndSwitch it just sucks... As a person who hates spaghetti code, I prefer to use 1 line If statement where possible... Also it makes the code more readable I think, this an example:
; 1 liner If IsValid($sString) Then MsgBox($MB_ICONINFROMATION, "Success", "Done") Else MsgBox($MB_ICONERROR, "Error", "An error has occurred")
; 3 liner
If IsValid($sString) Then
MsgBox($MB_ICONINFROMATION, "Success", "Done")
Else
MsgBox($MB_ICONERROR, "Error", "An error has occurred")
EndIf
The 1 liner is more readable to a normal person than the 3 liner
TD :)
comment:5 by , 11 years ago
| Resolution: | → Rejected |
|---|---|
| Status: | new → closed |
Use Ternary when you need a oneliner.
Jos
comment:6 by , 11 years ago
To add to what Jos said. Don't use ternary for control flow, which is the example you have presented us here. Instead use the ternary operator for something like:
MsgBox($MB_SYSTEMMODAL, '', 'The following string is ' & (IsValid('AEIOU') ? '' : 'not') & ' valid') ; Notice how I have kept the operator scope as small as possible, by only appending 'not' if IsValid() returns false.
The 1 liner is more readable to a normal person than the 3 liner
This is nothing more than speculation, which should be backed up by hard evidence.
As for your request, you don't see developers writing this:
// K&R style, used in Java for example
if (true) { ... } else { ... }
// Usually
if (true) {
...
} else {
...
}
// I prefer Allman, which I use in PHP and C#
If you do, then they have no consideration for others maintaining their code.

Why?
Which problem does this solve?
Jos