Article # 137, added by Geoworks, historical record
| first | previous | index | next | last |

Why and when to use EC code.





You should use EC code in your geode at every available
opportunity. It will help you catch errors in your program more
quickly and find errors you wouldn't otherwise have caught. Here are
some questions and answers regarding when to use EC code:

Q: 
So what is the the theory behind EC code?  How much is good,
and how much is too much?

A: 
Put in as much EC code as possible.  It is great for catching bugs
now and in the future (when some other poor soul is maintaining the
code).  A good basic rule is to check all parameters coming into a 
function and all values returned from a function call. Also checking
global variables before passing them to a function is a good idea.

The non-EC version of EC routines are just stubs that immediately
return, so EC code will have minimal impact on your application's
performance.  Additionally, you can encapsulate EC routines in the
EC() macro, which will prevent even the stub from being called when
you compile for non-EC.


Q:
Almost every kernel routine (like MemAlloc, FileOpen) can "fail".  
Should I add EC routines to check for failure?

A:
No.  You always want your application to handle failures (can't
open the file or can't allocate memory) gracefully in both EC and 
non-EC versions.  Routines like ECCheckMemHandle or ECCheckFileHandle
should be used to check variables as they are passed around the 
system (when calling routines or messages).  This catches mistakes
like when other programmers accidentally call your routine with the
wrong parameters.