Page 1 of 1
Naming Conventions and Descriptive but Long Names
Posted: Tue Nov 15, 2005 8:39 pm
by Ambush Commander
Check this out.
Code: Select all
$key_0 = 0; $value_0 = 'Value #0';
$key_1 = 1; $value_1 = 'Value #1';
$array = array($key_0 => $value_0, $key_1 => $value_1);
$this->sketch =& new ArraySketch();
$this->sketch->setTarget($array);
$this->assertSketchHasNoErrors();
$this->assertSketchHasNoMissingKeys();
$this->assertSketchErrorsAtAre($key_0, null);
$this->assertSketchErrorsAtAre($key_1, null);
$this->assertSketchUnknownMissingKeyAt($key_0);
$this->assertSketchUnknownMissingKeyAt($key_1);
$this->assertSketchAlienKeysAre(array($key_0, $key_1));
Absolutely no noodling with the actual object. Just some pure sentence constructions. It would be great if I could methods like assertSketch($sketch)ErrorsAt($index)Are($errors) (sentences with substitutions), this looks absolutely great for documentation. You know exactly how the class should behave in these conditions. Whoo!
Perhaps it would not be such a good idea to use on real classes... but this is absolutely delicious.
Posted: Tue Nov 15, 2005 9:28 pm
by sweatje
Looks pretty good to me
Here is the API for a test case I wrote in my book:
Code: Select all
class ValueObjTestCase extends UnitTestCase {
function testDollar() {}
function testDollarDivideEasy() {}
function testDollarDivideReturnsArrayOfDivisorSize() {}
function <span style='color:red;text-decoration:blink' title='Alert a moderator!'>grilled spam</span>() {}
function testDollarDivideImmuneToRoundingErrors() {}
}
Posted: Tue Nov 15, 2005 9:32 pm
by Roja
The surgeon general warns that CamelHumpsNaming can be hazardous to your programming health. Reports indicate that regular use of the underscore can prevent insanity.
Posted: Tue Nov 15, 2005 9:37 pm
by Ambush Commander
So let's talk about naming conventions.
I tend to shy away from underscores in method names because it seems like everyone camelcaps method names (sorta like the norm) while global functions use underscores. Besides:
Code: Select all
$this->assertSketchUnknownMissingKeyAt($key_0);
//becomes
$this->assert_sketch_unknown_missing_key_at($key_0);
Personally, I think the first looks nicer...
Posted: Tue Nov 15, 2005 9:42 pm
by John Cartwright
Yea I've recently shifted to the Camel hump.. I find it much more readable

Posted: Tue Nov 15, 2005 9:52 pm
by Nathaniel
I CamelHump class names, camelHumpWithTheFirstWordLowercase method names, and underscore variables...
Posted: Tue Nov 15, 2005 9:59 pm
by trukfixer
Hmm with all the Humping going on around this thread, I'm surprised it's not been rated X

Posted: Tue Nov 15, 2005 10:04 pm
by Roja
Ambush Commander wrote:I tend to shy away from underscores in method names because it seems like everyone camelcaps method names (sorta like the norm) while global functions use underscores.
Funny, virtually every function name in php uses underscores, so I'd say, it seems like everyone (at least on the php team) underscores function names (thats the norm).
But yes, its a matter of personal taste.
Posted: Tue Nov 15, 2005 10:06 pm
by redmonkey
I use CamelCase for class names and underscores for everything else, I find it diffivult to distingiush word breaks in long descriptive CamelCased strings. And when you consider this.....
Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn’t mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and lsat ltteer be at the rghit pclae. The rset can be a total mses and you can sitll raed it wouthit porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe. Amzanig huh?
..it kind of makes sense to show some sort of easily indetifyable word boundary. (well, for me at least)
Posted: Tue Nov 15, 2005 10:10 pm
by Ambush Commander
However, it turns out that this only applies to commonly used/short words. Astubeolly otospipe (actually opposite) when it comes to longer and rarer words. Don't try this with Vernacular, kids.
Schlossanagle makes the case that easily identifiable word boundraries makes things easier on developers whose main language is not English: if they see a word they don't know, it is far easier to look up when it is seperated by underscores.
Posted: Wed Nov 16, 2005 3:10 am
by Maugrim_The_Reaper
Possibly the best case for it I've seen yet...
I still use it - but usually I mix it with underscores for horrifically long method names. I find it useful in similar method name to separate the common sections from the unique sections with an underscore.
Code: Select all
function testDollarDivide_Easy() {}
function testDollarDivide_ReturnsArrayOfDivisorSize() {}
function testDollarDivide_<span style='color:red;text-decoration:blink' title='Alert a moderator!'>grilled spam</span>() {}
function testDollarDivide_ImmuneToRoundingErrors() {}
Kinda make more sense this way - I can now see the unique purpose of each a lot faster.