Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

17
  • 8
    Very pithy ideology, but the fact remains that there's nothing wrong with assignment in conditionals. It's far preferable to early exit from a loop or duplicating code before and inside a loop. Commented Oct 29, 2016 at 20:31
  • 27
    @MilesRout There is. There is something wrong with any code having a side effect where you don't expect it, i.e. passing function arguments or evaluating conditionals. Not even mentionning that if (a=b) can easily be mistaken for if (a==b). Commented Oct 29, 2016 at 21:06
  • 13
    @Luke: "My IDE can clean up X, therefore it's not a problem" is rather unconvincing. If it's not a problem, why does the IDE make it so easy to "fix?" Commented Oct 30, 2016 at 5:32
  • 6
    @ArthurHavlicek I agree with your general point, but code with side effects in conditionals is really not so uncommon: while ((c = fgetc(file)) != EOF) as the first that comes to my mind. Commented Oct 30, 2016 at 5:59
  • 4
    +1 "Considering that debugging is twice as hard as writing a program in the first place, if you're as clever as you can be when you write it, how will you ever debug it?" B.W.Kernighan Commented Oct 31, 2016 at 20:24