WelcomeUser Guide
ToSPrivacyCanary
DonateBugsLicense

©2025 Poal.co

(post is archived)

[–] 1 pt

It looks like C code to me. That part should compile just fine with C or C++, but although the compiler gives you a warning these days it allows you to confuse assignments with comparisons. The expression will read the value from the left side of the assignment in the evaluation. Sometimes it's convenient to do that to get some things done (Python added the walrus operator to let you do it safely), but it's usually a mistake.

[–] 1 pt

> it allows you to confuse assignments with comparisons

I don't see a case where such "permission" could lead to any desirable outcome whatsoever, it's lame

[–] 1 pt

Yeah, it's considered bad form to use assignment operators in conditional statements. Even if you know what you're doing when you write the code it could cause confusion for the team that has to deal with it (or even the programmer who wrote once they've forgotten what they meant to do).

As far as I know they didn't design C with the intent of allowing programmers to write convenient but dangerous code, but it just happened to work out that way with the basic syntax they came up with. Later languages like Python reworked the rules so programmers would no longer be able to make that common mistake (or at least make it less likely to happen).

[–] 0 pt

>it's considered bad form to use assignment operators in conditional statements. Even if you know what you're doing when you write the code it could cause confusion for the team that has to deal with it

It also doesn't make much sense, logically speaking

If( myVar is equal to true ) <- self explaining

If( set myVar to true ) <- if what then? If the affectation is a success? What are we checking here?