MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/8xqmpv/what_people_think_coding_is/e25ly52
r/ProgrammerHumor • u/Cirriliath • Jul 10 '18
398 comments sorted by
View all comments
Show parent comments
23
A good IDE would warn you about assignment inside an if condition
9 u/Albi_ze_RacistDragon Jul 11 '18 ‘if (a == b)’ vs ‘if (a === b)’ would probably be a better example 1 u/thestonedturtle Jul 11 '18 Now that is annoying lol 2 u/[deleted] Jul 11 '18 Sometimes you don't have a choice of what ide/language you have to work on, and the more unfamiliar you are with the languages (especially the tricky ones), the easier it is to make these mistakes.But it's what we do, so c'est la vie 😁 1 u/[deleted] Jul 11 '18 What about C?int c; if ((c = getchar()) != EOF) { ... } 1 u/thestonedturtle Jul 11 '18 Theres also a comparison in that condition though. 1 u/[deleted] Jul 11 '18 Yeah but it's not only legal, it's encouraged in K&R's C book, and they literally wrote the language. 2 u/thestonedturtle Jul 11 '18 I meant that since there is still a comparison the IDE should see that as a valid if condition, if there is no comparison it should warn you. 1 u/[deleted] Jul 11 '18 Ooooh ok I see 1 u/UnchainedMundane Jul 11 '18 The compiler will warn you if the assignment is not individually bracketed.i.e. if (c = getchar()) still throws a compiler warning -7 u/kodedemonmikalhanson Jul 10 '18 depends how old you are
9
‘if (a == b)’ vs ‘if (a === b)’ would probably be a better example
1 u/thestonedturtle Jul 11 '18 Now that is annoying lol
1
Now that is annoying lol
2
Sometimes you don't have a choice of what ide/language you have to work on, and the more unfamiliar you are with the languages (especially the tricky ones), the easier it is to make these mistakes.
But it's what we do, so c'est la vie 😁
What about C?
int c; if ((c = getchar()) != EOF) { ... }
1 u/thestonedturtle Jul 11 '18 Theres also a comparison in that condition though. 1 u/[deleted] Jul 11 '18 Yeah but it's not only legal, it's encouraged in K&R's C book, and they literally wrote the language. 2 u/thestonedturtle Jul 11 '18 I meant that since there is still a comparison the IDE should see that as a valid if condition, if there is no comparison it should warn you. 1 u/[deleted] Jul 11 '18 Ooooh ok I see 1 u/UnchainedMundane Jul 11 '18 The compiler will warn you if the assignment is not individually bracketed.i.e. if (c = getchar()) still throws a compiler warning
Theres also a comparison in that condition though.
1 u/[deleted] Jul 11 '18 Yeah but it's not only legal, it's encouraged in K&R's C book, and they literally wrote the language. 2 u/thestonedturtle Jul 11 '18 I meant that since there is still a comparison the IDE should see that as a valid if condition, if there is no comparison it should warn you. 1 u/[deleted] Jul 11 '18 Ooooh ok I see
Yeah but it's not only legal, it's encouraged in K&R's C book, and they literally wrote the language.
2 u/thestonedturtle Jul 11 '18 I meant that since there is still a comparison the IDE should see that as a valid if condition, if there is no comparison it should warn you. 1 u/[deleted] Jul 11 '18 Ooooh ok I see
I meant that since there is still a comparison the IDE should see that as a valid if condition, if there is no comparison it should warn you.
1 u/[deleted] Jul 11 '18 Ooooh ok I see
Ooooh ok I see
The compiler will warn you if the assignment is not individually bracketed.
i.e. if (c = getchar()) still throws a compiler warning
if (c = getchar())
-7
depends how old you are
23
u/thestonedturtle Jul 10 '18
A good IDE would warn you about assignment inside an if condition