Re: Programming style...
- From: "David J. Craig" <SeniorDriversWriter@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 31 May 2005 08:55:06 -0700
On another issue, thanks for the ddkbuild system. I had my own
implementation and have mostly switched to yours. SlickEdit tends to run
some stuff auto-magically that cause the bscmake option to not work. I had
to add some help to my batch file that undoes it. They seem to call setenv
themselves if you set up the project based upon the DDK/IFS Kit.
"Mark Roddy" <markr@xxxxxxxxxxxxxx> wrote in message
news:usiBxbdZFHA.2076@xxxxxxxxxxxxxxxxxxxxxxx
> David J. Craig wrote:
>> 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.
>>
>>
>>
> or:
>
> do {
>
> error = stuff();
> if (error) {
> ...
> break;
> }
>
> error = morestuff;
> if (error) {
> ...
> break;
> }
> } while(0);
>
>
> or the try/finally/leave stuff, although it has overhead.
> The for and while one pass models break down (pun intended) over the
> semantics of 'break'.
>
>
> I vote for single/entrance single/exit coding style every time.
>
> --
>
> =====================
> Mark Roddy DDK MVP
> Windows 2003/XP/2000 Consulting
> Hollis Technology Solutions 603-321-1032
> www.hollistech.com
.
- References:
- Programming style...
- From: Wan-Hi
- Re: Programming style...
- From: Robert Marquardt
- Re: Programming style...
- From: David J. Craig
- Re: Programming style...
- From: Mark Roddy
- Programming style...
- Prev by Date: Re: user unable to print on windows 2000 cluster via port monitor.
- Next by Date: temporarly power down disk drive ASAP
- Previous by thread: Re: Programming style...
- Next by thread: Re: Programming style...
- Index(es):