Me, Leslie and Ron
-
Here's a representative function from a codebase I had the pleasure of wading into this morning.
Questionable indentation aside, marvel at the intelligent, scalable, and maintainable approach that was adopted for user permissions.
/// <summary> /// Depending on the type of user logging in, we show or hide buttons /// </summary> private void CheckButtonsForLoggedInUser() { //Hide all buttons first VisibilityOfAllButtonsIs(true); int userID = BasePage.LoggedInUser.UserID; if (userID == 9) btnErrorLog.Visible = true; if (userID == 1 || userID == 6 || userID == 8) // Me, Leslie and Ron { VisibilityOfAllButtonsIs(true); } else if (userID == 4 || userID == 2 || userID == 3) //April, Andy and Tom { btnPhotosWithGraphicsDesigner.Visible = true; btnUploadPhotograph.Visible = true; } else if (userID == 5) // Larry { btnUploadPhotograph.Visible = true; } }
-
@DoctorJones 9 user IDs is enough for anybody.
-
@DoctorJones Fuckin' Larry, that luser.
-
Next point on our agenda today: Larry is leaving us, we are sad to see him go
-
@DoctorJones said in Me, Leslie and Ron:
//Hide all buttons first VisibilityOfAllButtonsIs(true);
if (userID == 1 || userID == 6 || userID == 8) // Me, Leslie and Ron { VisibilityOfAllButtonsIs(true); }
So what is it going to be? Do "Me", Leslie and Ron have no buttons or all buttons? Either way, why repeat it?
-
@DoctorJones said in Me, Leslie and Ron:
Me, Leslie and Ron
King Crimson - Neal And Jack And Me (live).flv – 05:40
— Jenny Kibermurka
-
I feel sorry for Stevie, who was userID number 8.
-
@Mikael_Svahnberg said in Me, Leslie and Ron:
I feel sorry for Stevie, who was userID number 8.
No, 8 is Ron. Stevie must be 7, except Stevie has a goldfish and his neighbor smokes Camels, so Leslie must live in a green house.
-
@Maciejasjmj said in Me, Leslie and Ron:
@Mikael_Svahnberg said in Me, Leslie and Ron:
I feel sorry for Stevie, who was userID number 8.
No, 8 is Ron. Stevie must be 7, except Stevie has a goldfish and his neighbor smokes Camels, so Leslie must live in a green house.
Wait. Who drives the red car?
-
@Mikael_Svahnberg said in Me, Leslie and Ron:
Wait. Who drives the red car?
This season, Sebastian and Kimi.
-
@DoctorJones said in Me, Leslie and Ron:
if (userID == 9) if (userID == 1 || userID == 6 || userID == 8) // Me, Leslie and Ron if (userID == 4 || userID == 2 || userID == 3) //April, Andy and Tom if (userID == 5) // Larry
Spaceballs – [00:07..00:42] 00:42
— modernguy
-
@JBert said in Me, Leslie and Ron:
@DoctorJones said in Me, Leslie and Ron:
//Hide all buttons first VisibilityOfAllButtonsIs(true);
if (userID == 1 || userID == 6 || userID == 8) // Me, Leslie and Ron { VisibilityOfAllButtonsIs(true); }
So what is it going to be? Do "Me", Leslie and Ron have no buttons or all buttons? Either way, why repeat it?
That top one should be
//Hide all buttons first VisibilityOfAllButtonsIs(false);
Chalk up another wtf...
-
@DoctorJones said in Me, Leslie and Ron:
Chalk up another wtf
And another for the name, since it sounds like a tester, but is actually a setter.
-
If only I could share the whole codebase with you. It'd be a lot of fun to have a WTF installation of Crucible
-
Come on, does nobody see the real problem in that code? "Me, Leslie and Ron"? Mentioning themselves first? Now that's just plain wrong XD
-
@Akko I agree: 'Ron, Leslie, and Me' is a much better movie title.
-
-
-
what fucking madman writes else-if on two lines
-
@RaceProUK said in Me, Leslie and Ron:
I agree: 'Ron, Leslie, and Me' is a much better movie title.
Wouldn't "Ron, Leslie, and I" more grammarly?
Edit: I see it would depend on context.
-
@Zecc said in Me, Leslie and Ron:
@RaceProUK said in Me, Leslie and Ron:
I agree: 'Ron, Leslie, and Me' is a much better movie title.
Wouldn't "Ron, Leslie, and I" more grammarly?
Edit: I see it would depend on context.By now everyone reading this topic should know that you can only correctly write it as "The Three Stooges".
-
@fwd said in Me, Leslie and Ron:
what fucking madman writes else-if on two lines
I think... no, couldn't be... but what else could it be? They probably don't know what an else-if is, and think that there can only be an if and an else. That's the way the indentation and line spacing is structured; as if every
else
inelse if
is a newelse{}
block containing anif{}
and anotherelse{}
.
-
@fwd said in Me, Leslie and Ron:
what fucking madman writes else-if on two lines
Yeah, they missed the braces! Clearly it should be:
if (userID == 1 || userID == 6 || userID == 8) // Me, Leslie and Ron { VisibilityOfAllButtonsIs(true); } else { if (userID == 4 || userID == 2 || userID == 3) //April, Andy and Tom { btnPhotosWithGraphicsDesigner.Visible = true; btnUploadPhotograph.Visible = true; } else { if (userID == 5) // Larry { btnUploadPhotograph.Visible = true; } } }
-
@loopback0 You, sir, are a heretic.
-
if ( Programming style == the way God intended ) { braces.style = "Egyptian"; } else { user.type = "Barbarian"; }
-
@izzion said in Me, Leslie and Ron:
if ( Programming style == the way God intended ) { braces.style = "Egyptian"; } else { user.type = "Barbarian"; }
if parentheses == "unnecessary" { go func() { fmt.Println("why are we writing code like this") }() } else { panic("OH GOD BEN L IS POSTING GO AGAIN") }
-
@izzion
Friends don't let friends write else with ears
-
@Fox said in Me, Leslie and Ron:
That's the way the indentation and line spacing is structured; as if every else in else if is a new else{} block containing an if{} and another else{}.
Isn't that also how it works, abusing the "else can have a single statement without braces after it" rule of most programming languages? Sure,
else if
is an idiom, but it's not a dedicated language construct from what I know.
-
@Maciejasjmj said in Me, Leslie and Ron:
Sure, else if is an idiom, but it's not a dedicated language construct from what I know
It is in VB. There's an
ElseIf
keyword
-
@Jaloopa said in Me, Leslie and Ron:
@Maciejasjmj said in Me, Leslie and Ron:
Sure, else if is an idiom, but it's not a dedicated language construct from what I know
It is in VB. There's an
ElseIf
keywordAnd Python's
elif
and Perl'elsif
.
-
I've once been bitten by a language (can' remember which) where the precedence rules made the
else
branch associate with the "outerest"if
. That is:if (...) if (...) { ... } else { ... }
...actually meant:
if (...) if (...) { ... } else { ... }
Of course, TRWTF was me for not using braces, but I was young and foolish back then.
-
@Zecc said in Me, Leslie and Ron:
@Jaloopa said in Me, Leslie and Ron:
@Maciejasjmj said in Me, Leslie and Ron:
Sure, else if is an idiom, but it's not a dedicated language construct from what I know
It is in VB. There's an
ElseIf
keywordAnd Python's
elif
and Perl'elsif
.When PHP's version (
elseif
) is the only one that doesn't look like an abomination, you know something is wrong...
-
@Zecc I think C# does that.
@Zecc said in Me, Leslie and Ron:
TRWTF was me for not using
parenthesesbracesFTFY :P
TBH, I don't always use braces myself, though it depends on the language: in C#, I'll omit them, but in JS, I never omit them.
-
@Zecc said in Me, Leslie and Ron:
Perl'
elsif
.That just looks like someone @accalia'd the name
elsie
-
@RaceProUK said in Me, Leslie and Ron:
FTFY
I FTFM in the meantime too. :P
Edit:
"date modified" of my post: 2017-02-28T11:57:20.811Z
"date published" of your post: 2017-02-28T11:56:51.197Z
You win this round. (though I blame network latency).
-
@ben_lubar said in Me, Leslie and Ron:
@izzion said in Me, Leslie and Ron:
if ( Programming style == the way God intended ) { braces.style = "Egyptian"; } else { user.type = "Barbarian"; }
if parentheses == "unnecessary" { go func() { fmt.Println("why are we writing code like this") }() } else { panic("OH GOD BEN L IS POSTING GO AGAIN") }
(when (eq (proper) (language)) (message "Clearly, the parenthesis should go *before* the if statement."))
-
@izzion said in Me, Leslie and Ron:
if ( Programming style == the way God intended ) { braces.style = "Egyptian"; } else { user.type = "Barbarian"; }
Did you mean
if ( Programming style == the way God intended ) { braces.style = "Egyptian"; } else { user.type = "Barbarian"; }
-
So, no-one does this?
if (Programming style == the way God intended) { braces.style = "Egyptian"; } else { user.type = "Barbarian"; }
-
if (Programming style == the way God intended) { braces.style = "Egyptian";} else { user.type = "Barbarian";}
The braces are on their own indent level so easy to scan down. The close braces and
else
aren't really necessary for understanding the code flow so they're on the end of the line.
-
-
@RaceProUK said in Me, Leslie and Ron:
So, no-one does this?
if (Programming style == the way God intended) { braces.style = "Egyptian"; } else { user.type = "Barbarian"; }
I do it like that, but with the braces on the same indentation level as the if and else statements. The only right way!
-
@Zecc said in Me, Leslie and Ron:
I've once been bitten by a language (can' remember which) where the precedence rules made the
else
branch associate with the "outerest"if
. That is:if (...) if (...) { ... } else { ... }
...actually meant:
if (...) if (...) { ... } else { ... }
Of course, TRWTF was me for not using braces, but I was young and foolish back then.
My favorite was the time I encountered a similar problem even when using braces properly. I forget what language, but I remember I had a bitch figuring out what the problem was. I ended up having an empty else statement to fix it.
-
@Zecc said in Me, Leslie and Ron:
I've once been bitten by a language (can' remember which) where the precedence rules made the
else
branch associate with the "outerest"if
. That is:if (...) if (...) { ... } else { ... }
...actually meant:
if (...) if (...) { ... } else { ... }
Of course, TRWTF was me for not using braces, but I was young and foolish back then.
Well of course those two mean the same, they're both ambiguous (and get you a warning in gcc)
-
@Zecc
I don't think that problem was the fact that the language matched the else with the outer if, but rather that the language only matches the first "line" as part of an if, unless braces tell it otherwise. ISTR that's what VB does...if (condition) execute(whentrue) execute(always)
versus
if (condition) { execute(whentrue) execute(whentrue) }
So, basically, you wrote the first code path, instead of the second.
Edit: not that VB uses ;
Edit filed under: I'm a PHP developer;
-
@PleegWat said in Me, Leslie and Ron:
Well of course those two mean the same, they're both ambiguous (and get you a warning in gcc)
Yes, they are exactly the same if you ignore whitespace, and I don't think it's easy to defend one as being more correct than the other.
-
@Jaloopa said in Me, Leslie and Ron:
The close braces and else aren't really necessary for understanding the code flow so they're on the end of the line.
How do you quickly scan through and find the else statement that matches an if statement? How do you easily find the end of a conditional block? If you're scanning the ends of lines, your eye is jumping all over, whereas scanning the beginning of the line, you can lock onto a particular indentation point and scan straight down.
-
@abarker said in Me, Leslie and Ron:
How do you quickly scan through and find the else statement that matches an if statement?
Press
%
on the opening brace.All praise the church of ViM.
-
@PleegWat said in Me, Leslie and Ron:
@abarker said in Me, Leslie and Ron:
How do you quickly scan through and find the else statement that matches an if statement?
Press
%
on the opening brace.All praise the church of ViM.
And if a cow-orker or future maintainer doesn't share your religion? They're just fucked, then?
-
@abarker That's what consistent bracing style and indentation are for.
But you asked for something specific.
Oh, and burn the heretic.
-
@abarker Maybe they should get a proper IDE!!!! </blakeyrat>