Re: Normalized Numbers

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

 



# neuhauser@xxxxxxxxxx / 2007-01-12 14:40:04 +0000:
> # jochem@xxxxxxxxxxxxx / 2007-01-12 13:39:59 +0100:
> > Roman Neuhauser wrote:
> > > # jochem@xxxxxxxxxxxxx / 2007-01-12 01:57:27 +0100:
> > >> Brian P. Giroux wrote:
> > >>> If anyone can help me out with that or provide any other advice about
> > >>> the rest of it, I'd be grateful.
> > >>> The file can be found at http://www.senecal.ca/normnums.php.txt
> > > 
> > >> keep commenting all your code to that extent! you do us proud :-)
> > > 
> > > I find the *inline* comments superfluous and cluttering the code. They
> > > don't add any insight, they simply repeat what the code already says very
> > > succintly:
> > 
> > it is anything but superfluous imho - the comment describes what the line of
> > code *should* be doing - given that the code itself maybe changed (and
> > possibly broken)
> 
> That's exactly one of the things that make comments dangerous: they can easily
> diverge from the code!
> 
> Use lots of small functions, well named, with well defined tasks.
> It's easy to see where the code lies about itself then.
> Use automated tests. You won't need to check whether the code actually
> does what a comment says: the test either succeeded or failed.

I converted the original "tests" (they don't evaluate the results,
that's up to the user) into a few Testilence-based test cases, and then
modified the code a bit. I removed almost all inline comments to let the
code come forward and speak for itself, and then reduced the code to
speak more clearly. It's not something I'd consider finished, but you
get the idea.

Regarding the digit_sum() "bug", I don't understand why you just don't
strrev() the input string. You'll need to swap the weights as well if
the string consists of an even number of characters. There's a test case
showing this as well.

The tests are really straight conversions of the old ones. I don't think
they're good, tests should IMO represent boolean questions about the
code, and provide answers to them. The old tests didn't ask any clear
questions, this is carried over to the new ones.

You can see my version at http://codex.sigpipe.cz/tmp/normnums.phps,
Testilence is at http://www.testilence.org/.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE.             http://bash.org/?255991

-- 
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