Modify

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#3067 closed Feature Request (Rejected)

1 line If...Else Statement

Reported by: TheDcoder Owned by:
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Cc:

Description

Ability to run a 1 line If...Else statement like this:

If False Then MsgBox(0, 0, 0) Else MsgBox(0, 0, 1)

Attachments (0)

Change History (7)

comment:1 follow-up: Changed 9 years ago by Jos

Why?
Which problem does this solve?

Jos

comment:2 in reply to: ↑ 1 Changed 9 years ago by TheDcoder

Replying to Jos:

Why?
Which problem does this solve?

Jos

Feature Request :)

comment:3 follow-up: Changed 9 years ago by 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

comment:4 in reply to: ↑ 3 Changed 9 years ago by TheDcoder

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 Changed 9 years ago by Jos

  • Resolution set to Rejected
  • Status changed from new to closed

Use Ternary when you need a oneliner.

Jos

comment:6 Changed 9 years ago by guinness

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.

comment:7 Changed 9 years ago by TheDcoder

I understand, thanks for taking the time :)

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.