# What do you consider this new if - after that syntax

I was simply considering something that would certainly be actually trendy to have in my if - elif - else regulates.


if condition:
stuff()
elif condition:
otherstuff()
then:
stuff_that_applies_to_both()
else:
stuff_that_doesnt_aply_to_either()


So primarily a then will certainly be run when any one of the problems are run EXCEPT the else problem. Do you assume this serves? It resembles the shot - other than - else of python.

I assume several of you are quibbling a really initial execution. The then block would certainly be similar to the else block in a try-except block in python. The actual factor I recommend this is for scenarios similar to this.


m = {}
if condition == '1':
m['condition'] = condition
elif condition2 == '3':
m['condition2'] = condition2
elif condition3 == 'False':
m['condition3'] = True
then:
run_test_that_relies_on_one_of_the_conditions_being_true()

return m


The then block is scoped to the first if similar to the else is. So nesting jobs penalty. And also if you require to run a method prior to the if declarations, that actually has absolutely nothing to do with this usage instance.

0
2019-12-02 03:13:12
Source Share

It feels like a trendy suggestion. Nonetheless the only trouble i visualize is you are extra vulnerable to pests. Like creating an if/else if and also calling blah () in after that. Creating an added else if that does not desire blah, getting rid of blah from after that and also including it to your ifs/elseifs. After that when you or an additional designer add an additional declaration you might anticipate blah to be called yet not.

Or you can have numerous ifs, write a blah and also neglect all ifs yet one need this which would certainly damage something. Additionally opportunities are if you require them to adhere to every if you'll place it under the if block. Perhaps establishing a bool in else (NoUpdate = real) and also simply write a if (! NoUpdate) straight under which is more clear and also can be set by an if

I am simply claiming it appears extra vulnerable to pests, not that i do not such as the suggestion. I wouldnt mind seeing it in a language yet i cant visualize any kind of situtaion where i would certainly utilize it if my language does sustain it.

0
2019-12-04 04:34:39
Source

I assume it looks dreadful. If you desire code to pursue a selection of problems after that either (a) reconsider those problems or (b) set a variable to shown success standing.

0
2019-12-03 05:13:21
Source

Generally you can currently do this with a switch/case and also a switch/case gives extra tweaked control over what you are recommending.

It additionally does not read effectively practically. If A else if B after that C. Doesn't indicate to a person that C will certainly be implemented if either A or B review to real.

0
2019-12-03 05:12:43
Source

I would not mind making use of something similar to this myself today. Yet, to ensure I would certainly utilize it concerning as usually as I make use of repeat till.

Code would certainly at the very least look far better without the unnecessary nesting. Although I favor Else If to elif. I would certainly change the Then with Do and also the last Else with Otherwise.

0
2019-12-03 05:12:06
Source

Interesting, yet appears to me (unquestionably rather embeded in my means) an invite for readability, reasoning, and also syntax troubles.

Edit : Your if - elif is really straightforward - what happens if there were 10 elifs? 20? Would certainly all problems require to be real? What are the opportunities of that?
Your if - elif is really straightforward - what happens if there were 10 elifs? 20? Would not that make this rather unreadable?

Additionally, can conveniently be attained by attempted - and also - real well-known technique :

if (thisCondition or thatCondition)
{
if (thisCondition)
stuff();
else
otherstuff();

stuff_that_applies_to_both();
}
else
{
stuff_that_doesn't_aply_sic_to_either();
}


What takes place if "stuff_that_applies_to_both" demands to take place prior to the specific actions? Your code does not manage this instance :

if (thisCondition or thatCondition)
{
stuff_that_applies_to_both();

if (thisCondition)
stuff();
else
otherstuff();
}
else
{
stuff_that_doesn't_aply_sic_to_either();
}


Finally, this syntax permits better adaptability with even more problems : if (thisCondition or thatCondition or anotherCondition) { stuff_that_applies_to_all () ;

  // Any combination of the three conditions using
// whichever logical syntax you'd like here
if (thisCondition and anotherCondition)
stuff();
else if (thisCondition or thatCondition)
stuff_number_2();
else
otherstuff();
}
else
{
stuff_that_doesn't_aply_sic_to_either();
}


I have actually been making use of if/else, yet can have as conveniently made use of a button declaration with a flag :

Boolean conditionApplies = true;

switch (someConditionToCheck)
{
case thisCondition:
stuff();
break;

case thatCondition:
otherStuff();
break;

default:
stuff_that_doesnt_aply_sic_to_either();
conditionApplies = false;
break;
}

if (conditionApplies)
stuff_that_applies_to_both();


Note that I really did not in fact require the conditionApplies flag - I can have included the "stuff_that_applies_to_both () " function to both the non - default problems - I simply did this so it looks even more like the syntax specified over, albeit the "then" as opposed to the "else".

Consequently, it appears to me to be a really specialized syntax, where an extra basic syntax loads the costs and also even more.

+1 for thinking about a feasible attribute (maintain doing that!), yet I would not elect to implement it.

0
2019-12-03 05:10:13
Source