if (Boolean.TRUE.equals(condition)) which is what SonarQube's default Java rules will recommend. (edit: in case anyone wonders, it's because of null safety; if (condition) throws an NPE if condition is null, Boolean.TRUE.equals(condition) just evaluates to false)
try {
if (condition) { /* code whatever */ }
} catch (MommaAintRaisedNoCowardException _) {
log.error("No bugs to be seen here no sirreee");
}
public class MommaAintRaisedNoCowardException
extends NullPointerException
{ /* standard exception stuff */ }
Reminds me of one time in a class. I needed to get from one datatype to another with no clear way... I kinda did "variable.toThis.toThat.toAnother.toTarget". Asked rhe teacher if there was an easier way and he just looked at it and went "the fuck is that?" I was all "exactly!" XD
97
u/y0shii3 1d ago
How you do it
vs how your teacher does it
vs how your classmate does it
vs how Spring devs do it
63
u/Ignisami 1d ago edited 1d ago
You're missing
if (Boolean.TRUE.equals(condition))which is what SonarQube's default Java rules will recommend. (edit: in case anyone wonders, it's because of null safety;if (condition)throws an NPE ifconditionis null,Boolean.TRUE.equals(condition)just evaluates tofalse)19
u/yousirnaime 1d ago
if( LlmService.request(" does this seem truthy, respond only 'yes' or 'no' : " . condition) == '{"response":{"message":"yes"}}'){
}
10
u/Simple-Olive895 1d ago
if (myBool == true) {
}
11
u/Varderal 1d ago
Reminds me of one time in a class. I needed to get from one datatype to another with no clear way... I kinda did "variable.toThis.toThat.toAnother.toTarget". Asked rhe teacher if there was an easier way and he just looked at it and went "the fuck is that?" I was all "exactly!" XD
4
u/Forward_Republic_610 1d ago
I am missing the hangman in the last picture.
4
u/Dinatoc_208 1d ago
when you're paid per line of code
2
u/CjMori23 1d ago
This is what the twitter devs that didn’t get fired were writing
1
u/NoodlyGirl2000 1d ago
I do have a lot of fond memories of Java, but I also think C# does it so much better
1
u/induality 1d ago edited 1d ago
The fourth one isn’t even correct. The comparator compare method returns an int. You need to check that that return value equals zero.
1
u/tatstytastycakes 1d ago
class vs homework vs quiz vs exam
1
u/DONARUDO_TURANPU 1d ago
Doesn't Java have some ternary operator like JS? That would be the first image but in full HD 3D
1
u/Zezerok 1d ago
I do most time 1 and sometimes 2 for the readability
1
u/AndromedaGalaxy29 1d ago
second one is good for readability sometimes
0
u/ThePhyseter 1d ago
Guy #3 came from Javascript and never learned about == vs ===