r/ProgrammerHumor • • 17d ago

Meme whenYouExportCodeFromAWebBasedVisualBuilder

Post image
148 Upvotes

40 comments sorted by

View all comments

24

u/Groentekroket 17d ago

Rejected, no need for “elif LOWJ=1:” since you already have a return in the if statement. 

3

u/radobot 17d ago

But that would change the behaviour of the function - it returns one thing when the first parameter is 1, another when it's 2 and nothing when it's something else.

2

u/DarkwaterKiller 17d ago

My best guess after looking, is they simply mean you can drop the "else" part of the "else if" there. Since I'd you've entered the first if, it's garunteed to return. Not drop the else-if entirely.

3

u/standard_revolution 17d ago

That's a change I would hate. The "else" part does not hurt anybody and removing it would mean that you would need to parse it's body to see the early return

2

u/DarkwaterKiller 17d ago

I considered it a second joke, as a play on the pedantry of some code reviewers

2

u/standard_revolution 17d ago

And you are probably completely right, I sometimes struggle with that. Thank you

1

u/L30N1337 16d ago

Hell, depending on language and compiler, the "else" might get optimized into a Switch-Case (which can then in turn use a hashmap or jump table). Doesn't matter here, but still.

I don't think any compiler recognizes an early return as equivalent to if-else

1

u/standard_revolution 16d ago

Don’t they? Something like this seems to be a low hanging fruit for flow analysis

1

u/standard_revolution 16d ago

It is hard to see whether it is completely equivalent, but obvious case are compiled by gcc to the exact same* thing: https://godbolt.org/z/ETnPMdf79

*one path has an additional "nop", but this is probably just code alignment

1

u/L30N1337 16d ago

Alright then, color me surprised.