Naming Conventions and Descriptive but Long Names

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Naming Conventions and Descriptive but Long Names

Post 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.
Last edited by Ambush Commander on Tue Nov 15, 2005 9:55 pm, edited 1 time in total.
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post by sweatje »

Looks pretty good to me :) :lol: 8)

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() {}
}
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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...
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Yea I've recently shifted to the Camel hump.. I find it much more readable 8)
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post by Nathaniel »

I CamelHump class names, camelHumpWithTheFirstWordLowercase method names, and underscore variables...
User avatar
trukfixer
Forum Contributor
Posts: 174
Joined: Fri May 21, 2004 3:14 pm
Location: Miami, Florida, USA

Post by trukfixer »

Hmm with all the Humping going on around this thread, I'm surprised it's not been rated X ;)
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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.
Post Reply