While doing the code inspection of one of the project, I have come across that Resharper is giving "Assignment in conditional expression" warning for a code block similar to below:
if (this.pnlSummary.Visible = isValid)
{
//do something
}
else
{
// do something
}
While I agree that this compromises readability to some extent.. but apart from that I dont think there are any disadvantages of using this as far as code execution is concerned.
Could anyone please suggest what could be the potential consequences of writing assignments in conditional expressions?
Based on that, I will instruct developers to avoid writing such code.
Any advice on this will be much appreciated.
A good programmer is a programmer who writes code that his coworkers understand not the one who writes code that computers understand.
There you are. This is absolutely a good reason to prevent programmers from writing code like this. Also when you can write better code with just few keystrokes then what is the reason behind doing something harmful?
you see? just some keys and few dots. Auto-complete is awesome!