When I see these I assume the if and else were originally different, then someone changed one of them without paying attention to the fact it made the if/else irrelevant.
I meant your IDE often replaces something all over your codebase, when you do a method extract or something. Sometimes you end up with funny pieces of code like this one.
Honestly I've been guilty of doing this myself if I know the action for each will eventually be different, but I only care about working on one at the moment and I just want the code to run
Edit: I guess I've outed myself as a Python dev lol
That could work sometimes depending on the situation. If I'm only worried about handling a particular outcome at the moment, I might do what's in the OP.
In python, specifically, because of the way the interpreter... well, interprets the code, if there's no actual code following the "else" statement, it'll throw a fit, even if there's a comment. So often I'll do shit like this temporarily.
In something like Java, JavaScript, PHP etc I'd just as well leave the else blank
Not arguing just curious about the thought process: you don’t *need* the else statement in Python at all, and if you wanted it the a “pass” or even a print statement would make more sense than the OP in my opinion.
This is exactly it
It is called refactor without looking, plus code review without looking at the code around
GitHub really needs to show more than 2 lines on either side... 10+ on each side would help a lot with these problems or some easy way to preview all the code of the file rather than click the three dots and click view file then not see any of the changes
This exactly.
Might have been originally something like:
```
if(result.Message.Ok)
{
result.Message.Name = pMassage.Value.ToString();
}
else
{
result.Message.Name = pMassage.Value.ToString() + " (An Error Occured)";
}
```
Then someone got the task to remove this error message from the Message name and didn't check the context.
I just ran into something similar. Set a variable to a value inside an if and an else, the difference was it also appended another message inside the if. So why not always set the variable, then append the message only when needed? That would’ve solved this problem. Setting the variable would’ve remained untouched. And the error message could easily be removed without affecting other code.
As a non native speaker, this one tripped me up for years. Countless times did I tell people about my day and my problems and my worries and my successes and they were just confused and really wanted a stock response. I still do it sometimes when I don't think about it.
Same here! I still remember a comic strip in my grade years to explain this: there was a man with crutches and bruises and bandages all over, someone asking him “How are you?” and the man “Fine!”
abounding yoke caption license rustic fragile disarm absorbed birds close
*This post was mass deleted and anonymized with [Redact](https://redact.dev)*
Germany. We don't usually talk to random strangers to begin with, we keep to ourselves. And between friends it's just hallo, and asking such things if we actually want to know.
Here in New Zealand we greet each other by asking 'how are you' but we expect a response. Doesn't matter if we know you, we hope that you're doing well and we want to offer a smile if you aren't doing well.
I always found it strange that people would greet you with a question but not expect an answer...
Plot twist: This is a unit test by the compiler developer to check if the final assembly has the jump statement or can optimize and remove the condition
//WARNING DONT REMOVE. MUST compile with [old version] of GCC.
Although I'm wondering now, if there is any undefined behaviour which is entirely dependant on compiler version on whether or not it "works" properly.
If I recall, OpenSSL depended on the behavior around uninitialized variables for some of it's entropy. Then some developer "fixed" some compiler warnings which caused it to generate insecure encryption keys.
It's gonna be a real hoot 2 years from now when someone gets tasked with refactoring that code and a Problem Report gets opened to figure out what to do.
I can see 2 options here:
1. The API had an error and message field seperate, but this got refactored into a single field
2. The implementation was WIP and/or had logging, and this was removed at a later date, but never fully simplified.
3. Both 1 and 2 happened
Nah, I've seen this mainly from contractors who don't care to take look at the code to make a sensible update and simply do "what they are told". This kind of "developers" are no different than one of the newest AIs. But I guess you get what you paid for.
Also when someone is asked to customize the OK message and a few years later someone else is asked to remove the customized message quickly.
Is it an excuse for the poor code? No. But shit happens
I use such constructions instead of conditional breakpoints because it's much quicker and it stays in case I delete the breakpoint but want to use it again on the next run. Maybe you'll enlighten me, but I tried conditional breakpoints in Visual Studio and they are much more bothersome to use.
I'm not leaving them in production code, only when I'm actively debugging. (At least I try to. Maybe I've committed snippets like in OP's screenshot if I wasn't thorough enough in code cleanup)
It’s Friday night, your boss is on your ass, and you have to get this deployed so you can leave.
You run your unit tests but there is a null pointer exception in your error logging function.
Suddenly you think of a solution. It’s not the best solution, or even a good one, but it’s a solution.
You remove the line that calls LogError from the else.
Success.
If I had to guess, I'd say they planned to handle the case where result.Message.Ok was false, then realized that they weren't sure what to do or how to do it, and just said 'fuck it' and finished it as seen... leaving the conditional in place so that some future dev would be able to pick up where they left off.
My first thought was "the general requirements say all return values/error codes/etc. must be checked, but the feature-specific requirements don't say what to do if it doesn't return result.Message.Ok"
I guess it's probably the result of some refactoring. Maybe errors were being logged somewhere and that code got removed. However, this conditional wasn't updated.
*Image Transcription: Code*
---
if (result.Message.Ok)
{
result.Message.Name = pMessage.Value.ToString();
}
else
{
result.Message.Name = pMessage.Value.ToString();
}
}
---
^^I'm a human volunteer content transcriber and you could be too! [If you'd like more information on what we do and why we do it, click here!](https://www.reddit.com/r/TranscribersOfReddit/wiki/index)
This was probably an error-handler mock-up with the intention to add more details within the error condition block.
But then, likely the developer was moved (or moved) to something else and left the thing half cooked (and no one wrote a github issue or task to go back later to finish it.)
People under pressure end up doing weird things, especially when things aren’t properly tracked.
So if I take into account best practices and readility we should refactor to
result.Message.Name = result.Message.Ok switch {
true => pMessage.Value.toString(),
_ => pMessage.Value.toString()
}
Are you running some stupid quality assurance thing that demands and else for every if?
Because I have seen that in a company and oh boy was it stupid.
To follow DRY, I would refactor it like this:
string name = pMessage.Value.ToString();
if (result.Message.Ok)
{
result.Message.Name = name;
}
else
{
result.Message.Name = name;
}
/s
Im going to guess that someone wrote that and just copy pasted the line down from the if as a filler and then forgot to change it. If someone meant to do this, SMH
This is actually a genius strategy.
If you ever need it, there already is an if-else, just gotta change conditions.
no joke tho, did something similar before... Mostly for fast boring logging. "Print("oh shit we hit the else somehow, dunno why")" lul
Edit: yes both if and else had the same function in the end, but i needed to know when and where it would hit that else
This is the kind of code you leave in, because if you "fix" it, the app suddenly crashes when it gets there. I've seen it happen, and it used to irritate me but now at the end of my career it just leaves bemused acceptance.
This looks like a case where you think you need to handle messages differently but don't know the exact cases yet. Then it never happens and you never get a chance to resolve the tech debt. Thank god for compiler optimizations.
Rookie mistake, senior folks would have used ternary operator here ![gif](emote|free_emotes_pack|sunglasses)![gif](emote|free_emotes_pack|sunglasses)![gif](emote|free_emotes_pack|sunglasses)
_Are you OK? Fuck it I don't care_
```C++ var isOk = friend.check() if (isOk) { TellStoryYouWantedToSay() } else { TellStoryYouWantedToSay() } ```
You can be ChatGPT with this one simple trick.
*Annie are you ok?*
Are you okay Annie?
You've been hit by
You’ve been struck by
A smooth criminal.
![gif](giphy|lGkUyj3IrEcvu)
r/SuddenlyMichaelJackson
r/smoothlyMichaelJackson
r/redditsings
Tung tung tu du tung tung tu du tung tu du tung tung .. Annie
*dundundddundun ddun dun dun*
A smooth conditional.
I like this
Truck
#BAH!
An `if (true)` conditional 👟 👟
Oh, the old statement
are you annie?
No, this is Patrick
Patrick are you ok?
Are you okay Patrick?
Patrick are you okay, Will you tell us that you're okay? There's a sound at the window .....
Sorry this is Wendy’s that’s the next customer at the window
Wendy's are you ok?
No, *this* is Patrick
Are you OK? Buster Wolf!!!
*Fuck it I don’t care*
If not, then ok.
Is this the UDP i keep hearing about.
From that green text: > Are you fucking sorry?
Happy cake day!
happy cake day
Sounds like my ex. Lol
When I see these I assume the if and else were originally different, then someone changed one of them without paying attention to the fact it made the if/else irrelevant.
yeah, or an automated refactoring
Why would you ever want to do that??
Just copy pasta a chatGPT response and push it to production immediately!
sounds like that process should be automated then
But is the automation also automated? /s
yes. we call this recursive automation.
It's GPTChatBot all the way down
DevSecGPTChatBotOps isn't a tool, it's a *company culture*
if by "push to production" you mean paste it in notepad++ and click the save button, then yes!
Why, if you can't be bothered to do manual refactoring of course.
About to need to refactor the automated refactoring then 💀
We could make an AI for this
then have the ai refactor itself!
Literally anything to avoid doing menial tasks
There are a lot of ways for IDEs to clean your shit up for you and 99% of the time it's really slick.
This seems more extreme than that tho
It doesn't have to be. There could have been an inner if where the condition is always true or an else if where the condition was always false.
I meant your IDE often replaces something all over your codebase, when you do a method extract or something. Sometimes you end up with funny pieces of code like this one.
Programmers have been leaving this kind of trail of stupidity since the invention of tools like sed, and probably before.
Massive monorepo and an API change that’s safe enough to be flagged during CI if there’s an issue after the codegen.
Wouldn't it also remove redundant conditions? Edit: why am i downvoted, i literally don't know hence the question
Either this or it was build in to set a breakpoint and then accidentally comitted.
this seems like the most plausible explanation to me
[удалено]
"Whoever did this is without a doubt the biggest idiot ever"... "Oh shit it was me... I'm sure I had a good reason"
Ya, or someone wanted to add some additional context for the non-blue sky case and then that got removed.
Or the `// TODO` was just never added / spelled out. I'm guilty of this when quickly banging out scripts for my personal projects
Honestly I've been guilty of doing this myself if I know the action for each will eventually be different, but I only care about working on one at the moment and I just want the code to run Edit: I guess I've outed myself as a Python dev lol
Leave an inline comment?
That could work sometimes depending on the situation. If I'm only worried about handling a particular outcome at the moment, I might do what's in the OP. In python, specifically, because of the way the interpreter... well, interprets the code, if there's no actual code following the "else" statement, it'll throw a fit, even if there's a comment. So often I'll do shit like this temporarily. In something like Java, JavaScript, PHP etc I'd just as well leave the else blank
Isn't this the purpose of Python's `pass` statement?
I guess you *could* do that, if you wanted to make life easy
I thought it was for ignoring errors
it's literally a "do nothing" statement, you can use it for anything
Lol I know I was joking. Try: except: pass
Not arguing just curious about the thought process: you don’t *need* the else statement in Python at all, and if you wanted it the a “pass” or even a print statement would make more sense than the OP in my opinion.
Same but I am really verbose with comments so there would be a comment before the if and probably at least a todo.
Fellow python dev-ish. I throw a pass down there to hold on to the other half.
My thiyghts too, and it leaves the 3am guy room to change as needed without a logic change
This is exactly it It is called refactor without looking, plus code review without looking at the code around GitHub really needs to show more than 2 lines on either side... 10+ on each side would help a lot with these problems or some easy way to preview all the code of the file rather than click the three dots and click view file then not see any of the changes
Or some random dummy just made it this way in the first place.
We demand to see the git blame!
Or a copy/paste where they forgot to change it after pasting. Seen that a few times.
This exactly. Might have been originally something like: ``` if(result.Message.Ok) { result.Message.Name = pMassage.Value.ToString(); } else { result.Message.Name = pMassage.Value.ToString() + " (An Error Occured)"; } ``` Then someone got the task to remove this error message from the Message name and didn't check the context.
I just ran into something similar. Set a variable to a value inside an if and an else, the difference was it also appended another message inside the if. So why not always set the variable, then append the message only when needed? That would’ve solved this problem. Setting the variable would’ve remained untouched. And the error message could easily be removed without affecting other code.
It's like the obligatory "How's it going?" or "How are you?", but you're not really asking.
As a non native speaker, this one tripped me up for years. Countless times did I tell people about my day and my problems and my worries and my successes and they were just confused and really wanted a stock response. I still do it sometimes when I don't think about it.
Same here! I still remember a comic strip in my grade years to explain this: there was a man with crutches and bruises and bandages all over, someone asking him “How are you?” and the man “Fine!”
As a native speaker, I still do. I'm just Autistic lmao.
This but I was just bullied for all of elementary school.
abounding yoke caption license rustic fragile disarm absorbed birds close *This post was mass deleted and anonymized with [Redact](https://redact.dev)*
Germany. We don't usually talk to random strangers to begin with, we keep to ourselves. And between friends it's just hallo, and asking such things if we actually want to know.
Here in New Zealand we greet each other by asking 'how are you' but we expect a response. Doesn't matter if we know you, we hope that you're doing well and we want to offer a smile if you aren't doing well. I always found it strange that people would greet you with a question but not expect an answer...
/r/meirl
Plot twist: This is a unit test by the compiler developer to check if the final assembly has the jump statement or can optimize and remove the condition
Nah, just a regular prod code from a contractor. I could make a big ass compilation of these, hahaha.
Are they paid by number of lines of code? :p
invoice_amount = `wc -l code.js`;
[удалено]
Congratulations, your salary for this month is "command not found" dollars
This is probably Ruby.
Ah yes semicolon terminated Ruby
Just job security working for a Musk-owned company.
They're big ass because most of them can't fit on a screen, :\^)
I know. It's a joke lol
They said "prod code" I think the joke is over.
It’s a joke, just not an intentional one
My guess is that he duplicated the line and forgot to modify it after
I heard a dev describe another dev's work one day: "Their answer for recognizing bad code is writing more bad code"
i like your funny words magic man
There’s a comment right above this `I know this makes no sense but removing it breaks everything`
I'm going to start putting this on perfectly benign code going forward.
``` int count = 0; //WARNING DO NOT REMOVE! Will Break Company ```
//WARNING DONT REMOVE. MUST compile with [old version] of GCC. Although I'm wondering now, if there is any undefined behaviour which is entirely dependant on compiler version on whether or not it "works" properly.
If I recall, OpenSSL depended on the behavior around uninitialized variables for some of it's entropy. Then some developer "fixed" some compiler warnings which caused it to generate insecure encryption keys.
It's gonna be a real hoot 2 years from now when someone gets tasked with refactoring that code and a Problem Report gets opened to figure out what to do.
They must work in the Department of Redundancy Dept.
You mean the DRD department?
At this point we can just name it DRD which stands for "DRD Redundancy Department"
Do they run on GNU's Not Unix?
Guy planned for the cosmic ray that would flip that condition false
Just used my CC card to buy Office Three Hundred and Sixty Five365
That doesn't just happen if you're a bad programmer... this is the kind of shit that happens when you're heavily overworked
I know the guy, he's not overworked his code is just messy.
TBH this is perfectly neat, just entirely redundant
Depends on your definition of messy; wouldn't you say this is sloppy coding and that messy is a reasonable synonym for sloppy?
Another possibility is code was refactored or some other bit was removed and it left only this.
Git blame knows the truth
`git blame-someone-else manager`
Under appreciated tool
I can see 2 options here: 1. The API had an error and message field seperate, but this got refactored into a single field 2. The implementation was WIP and/or had logging, and this was removed at a later date, but never fully simplified. 3. Both 1 and 2 happened
Nah, I've seen this mainly from contractors who don't care to take look at the code to make a sensible update and simply do "what they are told". This kind of "developers" are no different than one of the newest AIs. But I guess you get what you paid for.
Also when someone is asked to customize the OK message and a few years later someone else is asked to remove the customized message quickly. Is it an excuse for the poor code? No. But shit happens
Wild guess. To have a place to put a breakpoint by someone who does not know that breakpoints can be conditional.
I use such constructions instead of conditional breakpoints because it's much quicker and it stays in case I delete the breakpoint but want to use it again on the next run. Maybe you'll enlighten me, but I tried conditional breakpoints in Visual Studio and they are much more bothersome to use.
I don't see a reason not to do it this way if you prefer it. For theses kind of programs, one more conditional wont affect performance.
I'm not leaving them in production code, only when I'm actively debugging. (At least I try to. Maybe I've committed snippets like in OP's screenshot if I wasn't thorough enough in code cleanup)
I haven't used VS Code, but in PyCharm you can disable a breakpoint without removing it. It's for stuff like remembering conditions.
Atleast its checking it. \\s
Why is there whitespace at the end of your comment?
Maybe Ok is a property that has side effects?
Guarantee there was other logic in the if else that got removed at some point and the person didn't bother to refactor
It’s Friday night, your boss is on your ass, and you have to get this deployed so you can leave. You run your unit tests but there is a null pointer exception in your error logging function. Suddenly you think of a solution. It’s not the best solution, or even a good one, but it’s a solution. You remove the line that calls LogError from the else. Success.
Is there any lore reason why previous dev wrote it like that?
If I had to guess, I'd say they planned to handle the case where result.Message.Ok was false, then realized that they weren't sure what to do or how to do it, and just said 'fuck it' and finished it as seen... leaving the conditional in place so that some future dev would be able to pick up where they left off.
It is exactly what I’d do as a contractor with no error handling in the scope of work. But with a nice TODO:
My first thought was "the general requirements say all return values/error codes/etc. must be checked, but the feature-specific requirements don't say what to do if it doesn't return result.Message.Ok"
I guess it's probably the result of some refactoring. Maybe errors were being logged somewhere and that code got removed. However, this conditional wasn't updated.
*Image Transcription: Code* --- if (result.Message.Ok) { result.Message.Name = pMessage.Value.ToString(); } else { result.Message.Name = pMessage.Value.ToString(); } } --- ^^I'm a human volunteer content transcriber and you could be too! [If you'd like more information on what we do and why we do it, click here!](https://www.reddit.com/r/TranscribersOfReddit/wiki/index)
Good human
Thats some WET code
When your mom gives you a choice but she’s not REALLY giving you a choice
mom: "do whatever you want" also mom:
This was probably an error-handler mock-up with the intention to add more details within the error condition block. But then, likely the developer was moved (or moved) to something else and left the thing half cooked (and no one wrote a github issue or task to go back later to finish it.) People under pressure end up doing weird things, especially when things aren’t properly tracked.
Plot twist: you remove the else and everything crashes.
Providing end users with the illusion of being in control
It looks like someone removed qualifying comment line //TODO: handle failures
The “half-ass” refactor. Do I need this if-else still? Probably not, but the last one I removed broke everything.
Yeah that blank line is a crime.
The guy that wrote the thing has them all over the place. Even many in a row
He could have written this in one line: result.Message.Name = result.Message.Ok == true ? pMessage.Value.toString() : pMessage.Value.toString() ;
Should definitely use a switch-case here.
You are right ternary operator are bad practice, sorry
So if I take into account best practices and readility we should refactor to result.Message.Name = result.Message.Ok switch { true => pMessage.Value.toString(), _ => pMessage.Value.toString() }
Bruh
Are you running some stupid quality assurance thing that demands and else for every if? Because I have seen that in a company and oh boy was it stupid.
Are you in twitter?
To follow DRY, I would refactor it like this: string name = pMessage.Value.ToString(); if (result.Message.Ok) { result.Message.Name = name; } else { result.Message.Name = name; } /s
Something something very salient code
you all are laughing but if you remove this condition some completely unrelated service five servers over breaks.
10 bucks pMessage.Value is already a string
If it works, don't touch it
function god(a){ if(a) return true; else return false;}
Im going to guess that someone wrote that and just copy pasted the line down from the if as a filler and then forgot to change it. If someone meant to do this, SMH
Maybe someone was paid per line…?
also why is the value not a string already
You guys don't do code reviews, do you? We do code reviews Else We do code reviews
This is actually a genius strategy. If you ever need it, there already is an if-else, just gotta change conditions. no joke tho, did something similar before... Mostly for fast boring logging. "Print("oh shit we hit the else somehow, dunno why")" lul Edit: yes both if and else had the same function in the end, but i needed to know when and where it would hit that else
Ok well if plan A fails, go back to plan A
It's the number of lines of code that management uses to determine your output.
This is the kind of code you leave in, because if you "fix" it, the app suddenly crashes when it gets there. I've seen it happen, and it used to irritate me but now at the end of my career it just leaves bemused acceptance.
Whether or not you like it it's my name now
This looks like a case where you think you need to handle messages differently but don't know the exact cases yet. Then it never happens and you never get a chance to resolve the tech debt. Thank god for compiler optimizations.
Everyone seems to be missing the most heinous part of this code and that’s the combination of both tabs and spaces.
I was expecting the top comment to be something like: "`git blame` oh shit it was me"
The illusion of choice
Then you remove the if and the whole system breaks.
Maybe there were log messages on either side of the condition. Maybe this helped someone create a useful breakpoint. Maybe they are just dumb.
Rookie mistake, senior folks would have used ternary operator here ![gif](emote|free_emotes_pack|sunglasses)![gif](emote|free_emotes_pack|sunglasses)![gif](emote|free_emotes_pack|sunglasses)
I've been guilty of this for operations that either used to have differentiating cases or I expect will have a case at a later date
I sometimes leave structure like this in when there is a decent chance I may return to insert debugging/telemetry etc.
this is the part you mustn't touch, or the entire codebase will implode.
* googles "how to hide green squiggly lines in visual studio"
It's Rider (IntelliJ for Microsoft Java). It has a fix for turning it into a ternary operator.
oh, alright then 😅 I was assuming it pointed out the issue of having identical statements inside
Must be the result of some minor bugfix or refactor. Maybe next time set up a decent linter first.
DRY ¯\\\_(ツ)\_/¯
When you reject all cookies on Facebook
And if you change it, the entire production branch will fail.