Re: switch case - to require the break statements seems strange to me

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Sep 12, 2008, at 4:27 PM, Robert Cummings wrote:

On Fri, 2008-09-12 at 16:11 -0400, Eric Gorr wrote:
On Sep 12, 2008, at 3:44 PM, Robert Cummings wrote:

I don't see how that in any way makes an argument for or against. Once
still must spend client's money wasting time on code that has
questionable merit. Yes, some debugging code is a great boon in any
application, but littered everywhere to fulfill someone's subjective
philosophical ideal when sometimes it's just plain unnecessary...
wasteful IMHO.

As far as I know, no one has yet come up with a proof showing when
debugging code is and/or is not necessary.

The simple fact is that bugs can popup anywhere and spending a
client's time and money by spending a few minutes writing all of the
simple test cases throughout an application can be well worth it as it
can save far more of the client's time and money by not wasting it on
tracking down bugs that could have been easily caught.

It is impractical to include debugging code for every conditional in a
program.

I have yet to see any evidence that it is impractical, especially after one has gotten into the habit. After all, for switch statements, adding in a default case takes mere seconds.

Now, for a large project that has already been written, it may be impractical but only because it is unlikely anyone will be willing to spend the time or money to go back and put the stuff back in...

Doubly impractical to do so in PHP unless you have some way to
prevent said debugging code from running in production.

It isn't hard to prevent a code path from running in a production environment and allowing it to run in a development environment. Just one example, in PHP, would be globally defining something like PRODUCTION and then testing to see if it has a value of 1 or 0 and then writing an if statement to test the value before executing some code. Of course, there may be other clever solutions that aren't popping into my head at the moment. I'm sure you could come up with something better.

Furthermore, the whole point of these test cases is for those parts of the code which are never supposed to be executed to begin with, so that alone will aid in preventing said debugging code from executing in production...and if said debugging code does run in production, would that be such a bad thing (assuming it doesn't interfere with the user)? After all, because it (like the default switch case) was executed, it immediately implies there was a problem...

Maybe you're
confusing debugging code with unit tests. As I said earlier, it is far
more practical to do so for complex conditions where a reader might
easily get lost. Rather useless for simplistic cases.

Until one finds it has saved hours because a problem was caught, I can understand why some would think that it is rather useless.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux