Re: Programming style...
- From: "David J. Craig" <SeniorDriversWriter@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 30 May 2005 23:16:27 -0700
Here is a freebie for those trying to do error checking and avoiding goto's.
K&R say the only legal 'DO ONCE' is done using the for command.
for( ; ; )
{
break; // If OE or ??? warps this, it should be four lines
with this line indented.
}
You can then do tests and do a 'continue' or a 'break' as needed to exit or
restart the loop. You will forget the terminating break especially when
beginning, but it is legal and works. You can add a __finally to handle
terminating cleanup, but I just usually initialize all locals and return
variables before the 'for' block. Then a test and the appropriate cleanup
can be done to free memory, close handles, etc. after exiting the block or
before returning.
If you can't code it clean and easy to follow, you need to go back to school
or find something other than a programming job. No one will live forever,
much less stay in the same job, so be nice to those who follow and write
maintainable code. You can add comments to the 'for' loop to tell anyone
looking that this is a 'do once' block and not to get confused.
"Robert Marquardt" <marquardt@xxxxxxxxxxxxx> wrote in message
news:%23TSRLUaZFHA.3732@xxxxxxxxxxxxxxxxxxxxxxx
> Wan-Hi wrote:
>
>> 2) error checking:
>> SetupDiGetClassDevs and many other functions return a specific value if
>> they fail. so should i check for failure although such case is
>> impossible? e.g. SetupDiGetClassDevs with GUID_DEVINTERFACE_VOLUME should
>> never fail. i ask because useless failure checks make the code
>> unreadable.
>
> The error checks only make the code unreadable because MS prefers a
> *really* bad style. Excessive return and goto is about as bad as it can
> get. A clean if else style and a proper indentation solves that.
.
- Follow-Ups:
- Re: Programming style...
- From: Mark Roddy
- Re: Programming style...
- From: Wan-Hi
- Re: Programming style...
- References:
- Programming style...
- From: Wan-Hi
- Re: Programming style...
- From: Robert Marquardt
- Programming style...
- Prev by Date: Re: Programming style...
- Next by Date: Re: Bug in Scsiport.sys on AMD64?
- Previous by thread: Re: Programming style...
- Next by thread: Re: Programming style...
- Index(es):
Relevant Pages
|
Loading