WelcomeUser Guide
ToSPrivacyCanary
DonateBugsLicense

©2025 Poal.co

(post is archived)

[–] 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?

[–] 1 pt

It basically boils down to if(expression != 0) do_this();

It's up to the programmer to come up with a sensible expression. It's common to use

'while(true) { do_stuff(); if(condition) break; }`

The expressions will be zero (false) or non-zero (true). Usually you wouldn't want a constant expression in a conditional statement, but there are exceptions (to force code to run for debugging purposes for instance).

They do keep working on ways to keep programmers from doing stupid things; but with C it's kind of like you're following policies that were set before OSHA came into being. The scaffolding lets you get where you need to go, but you need to be careful not to fall off while you're working.

[–] 1 pt (edited )

The expressions will be zero (false) or non-zero (true).

Yeah ok, so, "if(myVar = true)" essentially means "if(true)", in C/C++... Or any other language allowing such stunts. Makes sense. And at the same time it makes no sense whatsoever; the conditional check becomes an affectation, so it's not a conditional check it's just lame

...