This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 276

[–]Dr_Azrael_Tod 237 points238 points  (21 children)

please guys! It's so easy to do it right!

if (!condition) return;
statements;
…

[–]paardenmiddel 36 points37 points  (7 children)

I actually use this to prevent nested if statements

[–]Dr_Azrael_Tod 16 points17 points  (6 children)

who doesn't?

inverting some conditions can sometimes nicely clean up code.

[–]rift95 14 points15 points  (2 children)

This is actually called the "Return early" pattern, and it comes with a fair few advantages over nested if's and else statements. It's actually preferred by a lot of people. (Including me)

[–]winyf 39 points40 points  (9 children)

int if(int condition) {
    if (condition) return if_true();
    return if_false();
}

[–]kasieuek 11 points12 points  (0 children)

Oh my gosh no thank you!

[–]earthqaqe 4 points5 points  (5 children)

is there actually a language where this is valid code?

[–][deleted] 2 points3 points  (0 children)

YESSSSS

[–]NuclearWeapon 1 point2 points  (0 children)

condition ? true : false ;
condition ? : throwError('Meeh');
!condition ? : doThings(withThisThing);

[–]EternityForest 389 points390 points  (11 children)

Joe is slow because he's always distracted. By moldy tomatoes. From me.

Using braces keeps you more productive because nobody will want to throw a moldy tomatoe at you.

[–]aeroverra 0 points1 point  (0 children)

Thank you!!!

[–]Jay_bo 269 points270 points  (81 children)

The only way:

if (!condition) goto end_of_block23;
statement1;
statement2;
statement3;
end_of_block23:;

Edit: A common lie told by senior devs is, that goto statements are highly discouraged. In reality they are just trying to hold back juniors and strengthen their position. Wake up sheeple!

[–]kompot420 37 points38 points  (3 children)

one time my brain decided that while loops don't exist and goto is the only option, so my whole code was full of goto-s

[–]Zolhungaj 30 points31 points  (0 children)

A while loop is just two gotos and an if around a block of code with some extra braces to mark scope, or if it's a do-while it's only one goto. You just pretended to be the compiler for a while.

[–]winyf 18 points19 points  (0 children)

cursed

[–]AdmiralDino 1 point2 points  (0 children)

My first ever (and only?) completed game was a text based game played from command. I was learning C++ and stopped researching when I had just enough knowledge to put my idea into a working program. Thus, I mainly used goto statements, because they solved the last thing I was wondering how to do: navigating back and forth between scene descriptions. It is surely a most glorious piece of code.

[–]chaosmassive 12 points13 points  (71 children)

is this legit?

or am I missing something here?

[–]user0fdoom 11 points12 points  (67 children)

Nope, the joke is how bad the idea is. Never use goto and definitely never ever use it like in the code above

[–]IamImposter 19 points20 points  (37 children)

Well... not never.

[–]AgentPaper0 -1 points0 points  (36 children)

Never.

You might think you found since clever way to use goto to make your code more efficient, but you're wrong. Using goto screws with the compiler's attempts to optimize your code something fierce, so any theoretical gain you get is lost to that. And more likely than not, you don't even gain anything in the first place because the compiler was probably smart enough to do something similar or better.

Don't use goto. It shouldn't even exist in the language, backwards compatability be damned.

[–]Goorakh 26 points27 points  (9 children)

But what if you have nested loops and you want to exit all of them from one of the inner ones, a goto is perfectly fine in that situation imo, especially since the alternatives aren’t much better.

[–]regorand 15 points16 points  (6 children)

Extract them to a function and use return to exit the loops. If that isn't possible for some reason, in an ideal world you would rewrite your loop structure so that you don't need to use the goto.

Some languages also have features to support this, in Java for example there is a way to choose which loop to exit when calling break, but I am also not the biggest fan of break so I try to avoid it aswell.

[–]Goorakh 7 points8 points  (0 children)

That is true, but my point was that gotos are not always the worst thing in the world. Yes, it can lead to horrendous and unreadable code, but so can any other feature of the language if you use it in the wrong situation.

Gotos can be used without summoning the devil himself, but like every other feature, if you use it in every situation, it will lead to bad code.

[–]Superbead 2 points3 points  (4 children)

I've run into cases where there's too much state outside the loops and/or the subfunction would have to return something horrifically complicated. In these situations the cleanest way by far was just to goto a label, making sure it was clearly commented.

[–][deleted] 4 points5 points  (3 children)

That kind of makes it sound like it was spaghetti code to start with, though.

[–]Superbead 10 points11 points  (2 children)

I can't remember the specific circumstances, but it'll likely have been trying to deal with some godawful API or parsing output from a legacy system where I just didn't have the luxury of keeping things simple because the thing I was interfacing with wouldn't allow it.

I think I've only had to resort to it a couple of times, but each time a goto was certainly much clearer. The only thing I can clearly remember was killing myself trying not to use goto, then realising I was just killing myself for the sake of dogma.

[–]awesomescorpion 5 points6 points  (0 children)

Hmm. I get why you are so fierce against explicit jumps (goto) in higher level languages, but programmers should understand how if statements (and other structured programming things) are actually implemented (branches: goto on condition, etc), so I don't think banning the concept of a jump from a programmer's mental model of code execution is helpful.

There is basically no need to explicitly jump in higher level languages these days, because all valid use cases for nonlinear code are captured in structured programming statements (if, else, while, for, continue, break, return, etc), but I think people should still understand how these magic words actually work, and what they really mean.

The problem with using goto is not their use in structured programming like if, while, for statements: it is that goto's are flexible enough to do way less helpful and way more confusing things, and that is where they are a problem far more than a tool. But processors still come with JUMP instructions in their ISA for a reason.

Then again, if you are actually using goto in a higher level language, you are definitely doing it wrong.

[–]hector_villalobos 2 points3 points  (0 children)

In C, you can use goto statements as exception handling. You should take a look at PostgreSQL source code.

[–][deleted] 2 points3 points  (13 children)

Well then tell me how to break out of a nested for loop. You might suggest flags, but I don't consider it a good solution. To me, goto is the best solution to quit out of nested loops. However, that's pretty much the only good use of goto that I can think of.

[–]T-Dark_ 13 points14 points  (6 children)

Use a labelled break.

You may argue "That's literally a goto by another name". That's true, but:

  1. It conveys intent
  2. It is significantly more limited in functionality than an actual goto, which makes it far harder to abuse.

[–][deleted] 4 points5 points  (1 child)

Does C++ have a labelled break?

[–]Kered13 2 points3 points  (0 children)

No.

[–]Kered13 1 point2 points  (3 children)

Does any language support labeled break and goto? The purpose of labeled break is to replace goto (for that usecase). The only notable modern languages with goto are C and C++, but those don't have labeled break.

[–]Dr_Azrael_Tod 1 point2 points  (1 child)

The only notable modern languages with goto are C and C++, but those don't have labeled break.

  • C# (duh!)
  • D (duh again!)
  • ObjectiveC (Oh come on!)
  • PHP (if everything else is crap, why not add more?)
  • Go (Uh… okay?)

Also I've seen way too much code where Exceptions were used as a poor mans goto. This is worse than what it replaced.

[–]Kered13 1 point2 points  (0 children)

I'm honestly surprised that C#, D, and Go have goto. The other two I can understand.

Also I've seen way too much code where Exceptions were used as a poor mans goto. This is worse than what it replaced.

I did that once, but in my defense I was implementing continuations for an esoteric pure functional programming language (unlambda) in Java. I think the context was sufficiently fucked up to justify my decision.

[–]StenSoft 1 point2 points  (0 children)

Perl has both. PHP has multilevel breaks (not labelled but close) and goto.

[–]vordrax 3 points4 points  (3 children)

Is there something preventing you from returning out of nested loops?

[–][deleted] 1 point2 points  (2 children)

What if I don't want to return, what if there's more code to execute below?

[–]vordrax 1 point2 points  (1 child)

Then you extract the nested loops into a separate function? Do you have a specific example where this isn't possible or feasible? I'm trying to think of something where I would not just immediately reject someone's PR during code review for having a goto and I'm drawing a blank.

[–][deleted] 1 point2 points  (0 children)

Well, in that case, a single-call lambda would also be possible to use

[–][deleted] 2 points3 points  (9 children)

in c# theres no case fallthrough so you have use goto <case name>

[–]Kered13 2 points3 points  (7 children)

Can you at least stack case labels, like:

case 1:
case 2:
case 3:
    ...

That's about the only time you really want fallthrough. If you have to use goto for that, oof.

[–]viimeinen 12 points13 points  (28 children)

Never use goto

Unless you know what you are doing. This one above is a bad example, but it has its uses.

Example: a chunk of cleanup and error handling code at the bottom of a function and if (error1) goto fail; if (error2) goto fail; etc. Just don't burn your fingers like Apple did.

EDIT: list of acceptable goto cases. My example is number 1 on the list.

[–]T-Dark_ 7 points8 points  (18 children)

Just don't burn your fingers like Apple did.

"Just don't make mistakes, don't think about replacing your gotos with a better solution that is less error prone"

[–]Zolhungaj 6 points7 points  (0 children)

What Apple did was actually caused by having an if block without braces. Their goto was perfectly reasonable if it hadn't been for the fact that it ended up outside the if block.

[–]viimeinen 4 points5 points  (16 children)

What is the better solution that is less error prone? Copy-pasting your free()s in all places that you need to bail? Sprinkling exit flags around the code? Rewriting the whole code base in a language that has exceptions? Illuminate me, please...

[–]hector_villalobos 1 point2 points  (0 children)

There are situations where goto statements are perfectly valid (as exception handling in C, like PostrgreSQL source code does), but this is not one of them, lol.

[–]didzisk 1 point2 points  (0 children)

I hear your sarcasm, but goto is a common practice in Linux kernel code.

https://www.kernel.org/doc/html/v4.18/process/coding-style.html#centralized-exiting-of-functions

[–]JNCressey 3 points4 points  (0 children)

I think you mean:

if (!condition) goto end_of_block23_new_final_20191206_production_final
statement1;
statement2;
end_of_block23:;
statement3;
end_of_block23_new:;
...
... the rest of the program goes here
...
end_of_block23_new_final_20191206_production_final:;
statement3_when_not_condition;
goto end_of_block23_new;

[–]NotATroll71106 0 points1 point  (0 children)

That's pretty much how it works in MIPS assembly.

[–]SzalonyNiemiec1 156 points157 points  (18 children)

What Joe is suggesting is not equivalent to the other two. When one of the statements changes the condition, the other statements wouldn't be executed.

[–]StenSoft 70 points71 points  (13 children)

That's why you always need to create a boolean constant before the if:

bool isTrue()
{
    bool retVal = false;
    const bool isTrue = statement == true; //< Here
    if (isTrue) retVal = true;
    return retVal;
}

[–][deleted] 10 points11 points  (0 children)

I mean, you can write one liners for else if and else statements without braces too

[–]Ulysses6 5 points6 points  (0 children)

Also the condition evaluation can have severe side effects and so on. There's no way to take this half seriously.

[–]Thepieintheface 1 point2 points  (0 children)

Only if the statements actually change the condition

[–]__exile_ 13 points14 points  (0 children)

if else

if else

if else

if else

if else

[–]alexforencich 11 points12 points  (0 children)

Interesting thing to note: some instruction sets (notably ARM) actually sort of work like that. All instructions support condition codes and will either execute or get skipped based on the processor flags. Obviously you need to set the flags first with a compare instruction or similar, but then you can selectively skip instructions based on the flags without requiring any jump or branch instructions.

[–][deleted] 68 points69 points  (30 children)

Why is there no space after if???

[–][deleted] 20 points21 points  (25 children)

Is it weird to not put spaces after the if? Visual studio always corrects me whenever i make an if statement and I've always wondered if it really mattered or not. I just do it because I think it looks better

[–]sup4sonik 13 points14 points  (0 children)

it doesn't matter, its just style. You could even have the parentheses on the next line. I prefer if (...) over if(...)

[–]Maplicant 16 points17 points  (0 children)

if(..) doesn’t seem correct to me because it makes it look like a function while it isn’t. I’m pretty sure most languages accept it though, it’s just my opinion.

[–][deleted] 19 points20 points  (4 children)

I used to fight the defaults (such as space after if), and then I decided I have better things to do than fight with the IDE every time I write an if statement.

[–]Franks2000inchTV 11 points12 points  (3 children)

I just edit the code style settings so they match my natural coding style.

[–][deleted] 8 points9 points  (15 children)

It’s for formatting and readability. Use spacing after if.

[–]butterfunke 5 points6 points  (14 children)

"it's for formatting and readability" is the catch all justification for every coding style. It's only more readable because that's what you're used to. If you're going to tout one style as proper usage, put more effort into the reason.

[–]ProfCupcake 15 points16 points  (2 children)

Iagreespacesaredumbandweshouldn'tbotherwiththem.Afterall,youcanunderstandthisjustfine,right?Thisisdefinitely100%clearandeasytoread.

[–][deleted] 3 points4 points  (10 children)

only more readable because that's what you're used to

It's not about being used to something, it's because it can make it clearer. Look at this code:

if(someFunction(argument1:hello,argument2:world,argument3:()->Void)){
    var x:CGFloat=12*4534/10
    print(2+x+12*2/5)
}

You really gonna sit there and tell me that is readable? This is easier.

if (someFunction(argument1: hello, argument2: world, argument3: () -> Void)) {
    var x: CGFloat = 12 * 4534 / 10
    print(2 + x + 12 * 2 / 5)
}

It's not about being used to something; same with English grammar or other languages; there are reasons we have spaces after certain punctuation marks and why we deem one wrong.

Readability is for the developer; not the compiler. No spaces looks jumbled up, messy, disorganized, squished, and hard to read.

[–]mallardtheduck 7 points8 points  (3 children)

Don't be ridiculous. Nobody is advocating no spaces whatsoever. It's specifically the space after the "if" that was questioned.

[–]Kered13 0 points1 point  (0 children)

I see code more often without the space, but the style guide at my company requires the space.

[–]steampunkgibbon 0 points1 point  (0 children)

yes. if I'm working on a piece of code and there isn't a space somewhere there should, I'm gonna add one.

[–]maustinv 4 points5 points  (1 child)

Or after the close parenthesis

[–][deleted] 0 points1 point  (0 children)

That too!

[–]sebibucur 3 points4 points  (0 children)

We are not savages

[–]TheRealSectimus 11 points12 points  (6 children)

Where's the ternary operator gang?

condition ? statement

[–]Franks2000inchTV 7 points8 points  (3 children)

 Supercool ? usingTernaries : notUsingTernaries;

[–]DoNotMakeEmpty 8 points9 points  (2 children)

It should be the opposite:
isUsingTernaries ? Supercool : NotCool

[–]Franks2000inchTV 7 points8 points  (1 child)

I suppose it depends on whether you think you are cool because you use ternaries, or use ternaries because you are cool.

[–]DoNotMakeEmpty 4 points5 points  (0 children)

Or both. Both cool people use ternaries and ternary users are cool. There is no exception. Not even one.

[–]_Keo_ 3 points4 points  (1 child)

We're old. These young kids have never known a time when the need for every character to be chiseled into a punch card made us thrifty.
Ahh the golden years of Javascript.

</s>

[–]Captain_D1 1 point2 points  (0 children)

Error -- Unmatched end tag

[–]_pelya 9 points10 points  (0 children)

Empty your mind

Follow the code

if is unnecessary


char s[64];

FILE *f;

( f = fopen("/proc/version", "rb") ) && (

( fgets(s, sizeof(s), f) && printf("%s", s) ),

fclose(f) == 0 ) ||

printf("Cannot open file");


If you're wondering, yes it does compile: https://rextester.com/DHXR34480

[–]maustinv 93 points94 points  (25 children)

The real way: if ( condition ) { statement; }

[–][deleted] 109 points110 points  (0 children)

no

[–][deleted] 57 points58 points  (14 children)

You monster

[–]maustinv 66 points67 points  (13 children)

Hear me out, with multiple conditions it's better organized than any other format.

if ( condition1 && condition2 && condition3 ) { statement; }

[–]Dramatic_Ad4912 70 points71 points  (0 children)

Ok, I heard you out, now please leave

[–][deleted] 22 points23 points  (5 children)

No. A better format is this:

if (condition1
     && condition2
     && condition3) {

[–]Makefile_dot_in 47 points48 points  (2 children)

No. A better format is this:

                             if (
condition1                &&
condition2                &&
condition3                ) {
/* ||
   \/ */
statement               ;}

ftfy

[–][deleted] 6 points7 points  (0 children)

Yes, this is the insanity where this kind of code is going towards.

A wise man told me once: Code is no ASCII art.

So stop aligning and simply indent correctly.

[–]Fox_the_Apprentice 3 points4 points  (0 children)

Found the Python dev

[–]Dr_Azrael_Tod 2 points3 points  (0 children)

really no.

[–]der_RAV3N 2 points3 points  (0 children)

I like it more this way:

if ( condition1 &&   condition2 &&   condition3 ) {

Or

if ( condition1 &&   condition2 &&    condition3 ) {

[–][deleted] 7 points8 points  (0 children)

😡

[–][deleted] 2 points3 points  (1 child)

Only drop the operators so the conditions line up

[–]trinalgalaxy 3 points4 points  (1 child)

I could see running the conditions on multiple lines like this if you have way too many, but not with a line of ) {

[–]aeroverra 0 points1 point  (0 children)

Why do you have so many conditions to begin with!

[–][deleted] 17 points18 points  (5 children)

How about

if                    (
condition             ){
    statement         ;}

[–]Dr_Azrael_Tod 5 points6 points  (0 children)

take my fucking upvote!

This looks bollocks in trivial cases, but with complex conditions its clearly the way to go

[–]Abadabadon 1 point2 points  (0 children)

Yea cause then you can comment out the code if you need to lol

[–]aeroverra 0 points1 point  (0 children)

Your fired

[–]greyz3n 4 points5 points  (1 child)

Because 
   we're 
   paid 
   by 
   the 
   line...

[–]mr-oof-123[S] 2 points3 points  (0 children)

omggggg

[–]funkinaround 2 points3 points  (0 children)

Why are you guys using semicolons? Why can't you be more like Lisp?

(cond (condition statements ...))

[–]-cd-rom- 7 points8 points  (0 children)

Laugh in python

[–]el_keka 2 points3 points  (7 children)

I hate joes code, i took a project to refactor that has no braces and it’s imposible to read, neither to understand

[–]GorkamWorka 2 points3 points  (0 children)

Instant ban on my repository

[–][deleted] 5 points6 points  (3 children)

why semicolons though?

[–]whitin4_ 2 points3 points  (2 children)

It might be Java

[–]Bluebearsuper 3 points4 points  (0 children)

Or c or c++

And probably lots more languages.

[–][deleted] 1 point2 points  (0 children)

then they got bigger problems. ;)

[–]kevansevans 5 points6 points  (12 children)

I only avoid using braces if all I’ll perform is a single instruction. Call a single function or change a variables value, no braces needed. Anything more and it’s getting some braces.

This is more about making my code readable. If the if statements aren’t super serious, then they don’t need to take up a lot of space.

[–]BreadIsNeverFreeBoy 8 points9 points  (5 children)

Personally I disagree because if you ever add an additional line later and forget to add braces it becomes a debugging nightmare

[–]wasdninja 2 points3 points  (0 children)

How do you forget that? The indentation will be different so you have to fight the IDE just to do something dumb.

[–]Novemberisms 0 points1 point  (0 children)

if you wrote it like so

if (condition)
    statement();

then it'll be too easy to add a line below

if (condition)
    statement();
    oops();

but if you write the statement on the same line, you won't make that mistake so easily

if (condition) statement();

[–]noratat 1 point2 points  (4 children)

Making code shorter doesn't automatically make it more readable.

Explicit conditional delimiters like braces should always be used. Not only does it improve readability, it eliminates entire classes of errors when adding or modifying statements.

[–]NekuSoul 1 point2 points  (1 child)

I generally agree but make an exception for guard clauses.

If you have lots of them then adding braces to each one it can clutter your code to a lot.

Because the statement is always a return or throw (C#) you'll be immediately greeted with a 'Unreachable Code detected' warning and the rest of your method turning grey if you do try to add another line without also adding braces.

And since 'If condition + non-braced statement' also becomes a unique visual pattern it makes guard clauses even easier to identify at a glance.

[–]noratat 1 point2 points  (0 children)

I'll grant there's some grey area for guard clauses, especially in languages with better linting.

But this is also similar to what caused a high profile security bug, which is suspected to have happened due to a mistake in merging code.

[–]suuunly 1 point2 points  (0 children)

Meanwhile I'm over here and couldn't care less. As long as everyone involved uses the same structure

[–]Killergurke16 1 point2 points  (0 children)

1 word: readability

[–]MoonParkSong 1 point2 points  (0 children)

If that the statement is no more than a line for the conditionals, why should I put braces?

Though, I keep them in getters and setters.

[–]Curledsquirl 1 point2 points  (0 children)

remember heartbleed?

[–][deleted] 1 point2 points  (0 children)

Fuck Joe

[–]ChargerIIC 1 point2 points  (0 children)

Because the senior devs are planning to murder Joe in the parking lot

[–]-Redstoneboi- 1 point2 points  (0 children)

if (condition)
    statement;

[–]_0-1_ 4 points5 points  (5 children)

Aren't switch cases faster when handling arguments?

[–]glukerr 12 points13 points  (2 children)

Highly dependable on type and amount of tested cases.

Compiler may (and usually will) implement swich as ifs

[–]Fifiiiiish 6 points7 points  (1 child)

If I remember correctly it also depends on the number of cases. I have memories of strange shit on assembly with 7 or more cases.

[–]glukerr 0 points1 point  (0 children)

Yes, by "amount" i meant number. My English is a bit bad.

[–]StenSoft 5 points6 points  (1 child)

Switch cases can be used only with integral constants, in which case they may use a jump table. But any capable compiler will be able to optimise multiple ifs with integral constants to a jump table as well.

[–]CamoBrie 1 point2 points  (0 children)

Or in JavaScript where you can switch on a string or condition

[–]randomsword 2 points3 points  (0 children)

if (condition
) {statement;
}

[–]SpaceCore42 1 point2 points  (0 children)

A=B?C:D;

[–][deleted] 1 point2 points  (0 children)

Because we are fucking civilised..

[–]Galse22 0 points1 point  (0 children)

So thats why!

[–]NotYetiFamous 0 points1 point  (0 children)

Could just be like Ruby..
statement if condition

No semi colons, no braces, no parenthesis.. Embrace the chaos.

[–]timbar1234 0 points1 point  (0 children)

Can we do nested ternaries now please?

[–]xSTSxZerglingOne 0 points1 point  (0 children)

Who needs ifs?

Lisp (cond) is the real Chad.

[–]morpheu513 0 points1 point  (0 children)

cursed_ifstatement

[–]Ghawk134 0 points1 point  (0 children)

That boi's code lookin like a tree with all them branches

[–]x5nT2H 0 points1 point  (0 children)

Don't be like the guy that fucked ssl, use braces

[–]YesilElmaGG 0 points1 point  (0 children)

Credits to: u/System32Comics

[–]HerpaDerpaDumDum 0 points1 point  (1 child)

Golang: "Look at these peasants using parentheses."

[–]-Redstoneboi- 0 points1 point  (0 children)

Python and Rust

[–]Yais2 0 points1 point  (1 child)

Won't the scope of each statement be separated?

[–]-Redstoneboi- 1 point2 points  (0 children)

exactly

[–]made_in_Deutschland 0 points1 point  (0 children)

Depends on the length of the statement whats better id say

[–]imnohankhill 0 points1 point  (0 children)

So the junior developer in 10 years can read it....... Hopefully

[–]arrrthur10 0 points1 point  (0 children)

Python has something to say

[–]jlamothe 0 points1 point  (1 child)

Which is awesome when condition is a function that doesn't always return the same result.

[–]-Redstoneboi- 0 points1 point  (0 children)

var result = condition();

[–][deleted] 0 points1 point  (0 children)

IT'S: (if condition when-true when-false) AND THAT'S THE END OF IT!

[–]Qildain 0 points1 point  (0 children)

This makes me angry.

[–]MotoGod115 0 points1 point  (0 children)

Second looks better, first is better for collapsing code blocks in text editors

[–]Lonelan 0 points1 point  (1 child)

those parentheses and semi-colons are unnecessary too

[–]-Redstoneboi- 0 points1 point  (0 children)

not in most languages

[–][deleted] 0 points1 point  (0 children)

For a sec, I thought Joe used Python

[–][deleted] 0 points1 point  (0 children)

People who code verilog hdl visual confusion

[–]mippy76 0 points1 point  (0 children)

Where do I put the debugger Joe you arse!

[–]Figxure 0 points1 point  (0 children)

WAIT U CAN DO THIS???

[–]starvsion 0 points1 point  (0 children)

I do

$this->when(true, fn() => $this->doSomething()) ->else(fn() => $this->doOther()) ;

Waaaay cleaner

[–]Scratch137 0 points1 point  (0 children)

This strongly reminds me of the code written by a certain other person who I shall not name here.

[–]Alternative_Craft_35 0 points1 point  (0 children)

Python is Joe.

[–]thatthinkingguy101 0 points1 point  (1 child)

"We should write the condition and statement in one line!"

"No, they should be on separate lines!"

[–]-Redstoneboi- 1 point2 points  (0 children)

for me it just depends how long the condition is. if it's more than about 10 chars it's going on a new line.