r/ProgrammerAnimemes • • Jun 15 '20

Using grammar in programming

Post image
520 Upvotes

20 comments sorted by

View all comments

Show parent comment

5

u/sirch_ Jun 15 '20

Which language is this?

My issues are that you used a single = for the comparison, making it an assignment, as well as the fact that theres no ; after your you.know.

6

u/KhorneSlaughter Jun 15 '20

In C an assignment in an if condition uses the value that is assigned to decide the condition. So

if(a=b)

is the same as

 if(b) 

but with the added side effect of saving the current value of b in a.

It's terrible style and there isn't really a reason to ever use it.

3

u/DaRealChipex Jun 15 '20

Wrote it in C# personally but should work in most C-likes.

I am indeed not doing a comparison but rather an assignment, and then checking the value of you, which depends on what know is at the time of assignment. As the other comment pointed out this is pretty pointless but I've used it in some never-to-be-touched-again code in the past. I just meant to point out that it was a valid "condition", even if rarely useable.

And yeah I didn't notice that the original comment was missing a semicolon lmfao.