this post was submitted on 21 Nov 2023
422 points (96.9% liked)

Programmer Humor

31434 readers
1647 users here now

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

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 8 points 8 months ago (3 children)

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

[–] [email protected] 5 points 8 months ago (1 children)

Never seen this, what language or buildsystem is this?

[–] [email protected] 3 points 8 months ago* (last edited 8 months ago) (1 children)

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

[–] [email protected] 6 points 8 months ago
if (true === $wantToCauseErrorsForFun) {
    badOldFunction();
} 
[–] [email protected] 1 points 8 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 8 months ago (1 children)

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

[–] [email protected] 0 points 8 months ago

Think of it as inline attribution/documentation.