Changes between Version 20 and Version 21 of MapGuideCodingStandards


Ignore:
Timestamp:
Jul 14, 2008, 1:35:17 PM (16 years ago)
Author:
jbirch
Comment:

Some of Walt's suggestions

Legend:

Unmodified
Added
Removed
Modified
  • MapGuideCodingStandards

    v20 v21  
    8787== Object Creation and Runtime Speed ==
    8888
    89 As with Java, unnecessary object creation is something you should avoid whenever possible.  Just be smart about it when you code.  For example, if a call to a method returns a new object and you call that method multiple times in the same context, then change your code to call this method only once and reuse the returned value.  Another example: use private helper objects when it makes sense to avoid unnecessary object creation.
     89As with Java, unnecessary object creation is something you should avoid whenever possible.  Just be smart about it when you code. 
     90
     91 * If a call to a method returns a new object and you call that method multiple times in the same context, then change your code to call this method only once and reuse the returned value. 
     92 * Use private helper objects when it makes sense to avoid unnecessary object creation.
     93
     94When you do need to create objects, check if it's possible to create them on the stack rather than on the heap.  Consider the following example:
     95{{{
     96#!cpp
     97Ptr<MgFoo> spFoo = new MgFoo(arg);
     98Bar(spFoo);
     99}}}
     100
     101In this case !MgFoo is a ref-counted object, and because of this you might think your only choice is call to new and assign the result to a smart pointer.  In fact, if the call to Bar does not add any references to the object then the following code which doesn't call new also works:
     102{{{
     103#!cpp
     104MgFoo foo(arg);
     105Bar(&foo);
     106}}}
     107
     108Of course the same stack vs. heap thinking applies to non-ref-counted objects.
    90109
    91110== Threading Guidelines ==
     
    295314=== Break and Goto ===
    296315
    297 Goto and break make the code very hard to read. I cannot believe that C# supports goto!!!
    298 The guideline is to avoid using break statements inside loops and to forbid the use of goto.
     316Goto and break make the code very hard to read.  The guideline is to avoid using break statements inside loops and to use goto sparingly (if at all).
    299317
    300318=== If, Else-If, Else Statements ===