Re: Programming style...



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.


.



Relevant Pages

  • Re: Programming style...
    ... >> school or find something other than a programming job. ... A clean if else style and a proper indentation solves that. ... > I vote for single/entrance single/exit coding style every time. ...
    (microsoft.public.development.device.drivers)
  • Re: Where does str class represent its data?
    ... The "flat is better than nested" philosophy suggests that clean should ... But this is an abuse of the str class if you intend to populate your ... UserString instead of just str. ...
    (comp.lang.python)
  • Re: Where does str class represent its data?
    ... def clean: ... I understand that I could just remove the clean function from the ... The python standard library make this easy with the UserString class and the ability to add custom methods to its subclasses: ...
    (comp.lang.python)
  • Re: Evo Engine Temp Sensors - 4 in 8 years?
    ... IIRC, that will screw it up, but cleaning it fixes ... not the Throttle Position Sensor. ... The TPS's are sealed and you cain't clean shit off'a 'em. ... fail from just a plain was on a cold engine (which I HIGHLY recommend doing, ...
    (rec.motorcycles.harley)
  • missing library: intl.6
    ... Gimp and fetchmail). ... Both fail when they can't find "intl.6". ... 'make clean' for good measure) and I still can't get past it. ...
    (comp.unix.bsd.freebsd.misc)

Loading