NYCPHP Meetup

NYPHP.org

[nycphp-talk] Quality Code [was "Injection..."]

Elliotte Harold elharo at metalab.unc.edu
Tue Nov 13 18:24:01 EST 2007


Brian D. wrote:
> I'll grant you that using prepared statements rather than mysql_query
> isn't *that* much of a time difference, but unit testing, for example,
> does tend to take a little more time.
> 

I respectfully disagree. I am faster when I'm writing unit tests than 
when I'm not. I am *much* faster if the measurement is made to bug free 
code that actually solves the problem, rather than simply to code that 
compiled, but even if we're just accepting any old hack that gets the 
job done once, I am still faster when I write unit tests.

The more complicated and involved the problem the more true this is. I 
can't even begin to work on a sophisticated  sorting algorithm or a fast 
interpolated search without writing tests. However even with a problem 
as simple as a basic linear search, I get to the end faster with 
test-driven development than without.

> As Rusty pointed out, the biggest difference is "getting up-to-speed"
> with something that you're not familiar with, but when you're writing
> good code, in my experience at least, it's not as fast as throwing
> things together.

No, it's faster. :-)


> As an illustration, if you find yourself copying and pasting code,
> it's usually a better idea to create something reusable. But if you're
> just banging out some code, copying and pasting may be a little
> faster. The key is that it's only faster in the *short* run. In the
> long wrong, good code is always faster.


Well, as Fred Brooks said, "Plan to throw one away. You will anyway."

-- 
Elliotte Rusty Harold  elharo at metalab.unc.edu
Java I/O 2nd Edition Just Published!
http://www.cafeaulait.org/books/javaio2/
http://www.amazon.com/exec/obidos/ISBN=0596527500/ref=nosim/cafeaulaitA/



More information about the talk mailing list