codehints

stuff about programming

prefixes: using a consistent nomenclature system

I use prefixes for everything that I can: variables, constants, classes, files, methods, etc.

Typically, programmers use multiple nomenclature protocols:
1.  MyBlah       … camel casing
2.  myBlah       … camel casing, with the first-word exception
3.  MY_BLAH   … all-caps, which necessitates the inconsistent usage of an underscore
4.  _myBlah     … preceeding underscore
5.  myBlah_mc … suffix
etc.


On the other hand, here’s a code example that uses only prefix’s:
//———— actionscript ————————————-
package pkg_blah
  { // ‘pkg’ stands for ‘package’
    //     I’m a bit unhappy about using a multi-letter abbreviation for one-word
    //     nevertheless, using a prefix for packages helps to organize your work directory also.

    public class ec_blah
      { // ‘ec’ stands for ‘external class’
        //     from the flash point of view, classes are external;
        //     maybe simply using a ‘c’ is better for other development environments.

        private    var pvi_blah  : Number = 1.234 ; // ‘pv’ stands for ‘property variable’;
                                                                    // ‘i’ derived from integer, now I use it for any numerical type.

        private    var pvn_blah  : String = “Joe”   ; // ‘pv’ stands for ‘property variable’;
                                                                    // ‘n’ for ‘name’ … names are a uniquely special string sub-type
                                                                    //     maybe this is a bad exception, but for me it’s ok.

        private const pks_blah : String                ; // ‘pk’ stands for ‘property constant’; ‘s’ for ‘string’.


        private function om_blah ( args_blah : String ) : Boolean
          {
            // ‘om’ stands for ‘object method’
            //     I should probably use ‘pf’ for ‘property function’ instead.

            // ‘arg’ stands for ‘argument’; ‘s’ for ‘string’.

            const lko_blah : Object = { pva_blah : [ 0 , 1 , 2 ] } ;
            // ‘lk’ stands for ‘local constant’; ‘o’ for ‘object’.
            // ‘a’ for ‘array’

            var lvb_blah : Boolean ;
            // ‘lv’ stands for ‘local variable’; ‘b’ for ‘boolean’.

            lvb_blah = ( args_blah == “A” ) ? true : false ;

            return lvb_blah ;
        }
      }
  }
//—————————————————————–

I like the info that I can quickly get from prefixes; and I like the consistency of using only one nomenclature system: only prefixes.

I admit that I am inconsistent with my prefix system; however all of the inconsistencies DO FIT into one nomenclature protocol; here are some of my inconsistencies:
1. pkg_blah – I used a 3-letter abbreviation for ‘package’ ( ‘pkg’ ) instead of a 1-letter;
2. pvi_blah – I used an ‘i’ for numbers, which comes from the word ‘integer’
                    clearly 1.234 is not an integer, but I use the ‘n’ for ‘names’
                    so I had to figure out something different for ‘numbers’;
3. pvn_blah – I use an ‘n’ for ‘names’, even though it is a ‘string’, simply because names are used so often
                      in coding that it seems as if they are practically their own special data type.
4. om_blah – 2 bad things happen here: the ‘o’ here refers directly to the class/object,
                      but I did not include an ‘o’ in my class properties;
                      and I did not use a ‘p’ to denote that ‘om_blah’ is a ‘property’;
                      so technically I should call this ‘pm_blah’, but old habits die hard;
                      or I could have used ‘pf…’ which would probably be the best:
                      ‘property function’ which by definition is a ‘method’.
5. notice that I do not have a way of distinguishing private properties vs. public or protected; or static props, etc.

I am not suggesting that my prefix system is the perfect prefix system; but rather I am suggesting that using a single prefix system is better than using multiple systems. You might develop a prefix system that is cleaner than my prefix system.

Also, note that I like underscores. A lot of developers dislike underscores; I once used a system combining prefix’s with camel casing, and that worked pretty good … but be thorough with the camel casing if you do use it – no first-word exceptions and what not.



Here’s a javascript example:
<script type=’javascript’>
function gf_blah ( argas_blah )
  { // ‘gf’ = ‘global function’
    // ‘argas’ = ‘argument, array of strings’
    // etc
  }
</script>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: