It is very, very easy to confuse = and == (and ===, oh my). The use of a naked assignment where everyone expects to see == is not a good coding practice.
For one thing, in a large project someone will helpfully "debug" it for you every time, changing the behavior of the code. In the C world there is a convention for use in such situations: if (($results = $this->getResults())) The idea being that the extra set of parens calls attention to the code. (It also causes some compilers to stop flagging the situation as dangerous and unwise.) But I much prefer your refactoring. Yes, it is a little more verbose, but it is infinitely less likely to lead to confusion and bugs down the road. It's worth it. On Tue, Dec 15, 2009 at 2:40 PM, Davide Borsatto <[email protected]> wrote: > With "assignment in condition" you mean something like > > if ($results = $this->getResults()) > { > // ... > } > > ? > > If so, then I think it's not about coding standards. Those standards > define the way you indent code, where you put brackets and stuff like > this. > By the way the refactored code above would be look like this: > > $results = $this->getResults(); > if ($results) > { > // ... > } > > Which brings honestly only un-necessary verbosity to the code, without > actually improving quality. Plus as you say, that is a perfectly legal > statement, and I don't know where it could lead to problems compared > to getting the assignment out of the condition. I know this is a > simple example, but the concept of the problem is that it's your > editor's problem :) > > Of course, IMHO. > > On Dec 15, 5:46 pm, Alexandru-Emil Lupu <[email protected]> wrote: >> HI! >> I would like to ask you / tell you about a coding standard present in >> the symfony. >> I am using Zend Studio 7 and my "error" tab shows me a lot of symfony >> problems that i guess it is not ok to be there. >> The most present error met is the "Assignment in condition", which, i >> think is really a problem, because will not let the devs solve or will >> hide their project problems. >> I know that this kind of statement is perfectly legal, but it might >> hide some problems generated by the devs... Unfortunately not all the >> devs are using TDD or have their code "test covered" >> >> Let me know what opinion do you have about this request / enhancement . >> >> Alecs >> >> -- >> Have a nice day! >> Alecs >> >> As programmers create bigger & better idiot proof programs, so the >> universe creates bigger & better idiots! >> I am on web: http://www.alecslupu.ro/ >> I am on twitter:http://twitter.com/alecslupu >> I am on linkedIn:http://www.linkedin.com/in/alecslupu >> Tel: (+4)0748.543.798 > > -- > > You received this message because you are subscribed to the Google Groups > "symfony developers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/symfony-devs?hl=en. > > > -- Tom Boutell P'unk Avenue 215 755 1330 punkave.com window.punkave.com -- You received this message because you are subscribed to the Google Groups "symfony developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/symfony-devs?hl=en.
