advanced (lemmy.world)
submitted 3 months ago by hairinmybellybutt to c/[email protected]
you are viewing a single comment's thread
view the rest of the comments
[-] [email protected] 8 points 3 months ago

If you're in a language that supports it, please don't use if (false) use if ($disallowAllUsers = false && $whateverTheRealConditionIs)

[-] [email protected] 5 points 3 months ago

Never seen this, what language or buildsystem is this?

[-] [email protected] 3 points 3 months ago* (last edited 3 months ago)

That specific language is PHP, but the tip is applicable in any language that supports inline assignment.

[-] [email protected] 6 points 3 months ago
if (true === $wantToCauseErrorsForFun) {
[-] [email protected] 1 points 3 months ago

The assignment syntax is too close to comparison, which is what is more typical in that position. I would recommend

const bool _isFeatureEnabled = false;
if (_isFeatureEnabled && ...)

if not a proper feature flag (or just remove the code).

[-] SpaceNoodle -1 points 3 months ago

It seems much worse to use a setter in an if statement.

[-] [email protected] 0 points 3 months ago

Think of it as inline attribution/documentation.

this post was submitted on 21 Nov 2023
423 points (97.1% liked)

Programmer Humor

9822 readers
47 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)


founded 4 years ago