Author Topic: Programming Style, C#  (Read 5588 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Programming Style, C#
« Reply #15 on: April 21, 2011, 09:23:50 AM »
I purchased 'The Elements of C# Style' a few years ago and it's an excellent book - I generally live by it when writing C# code.

As far as this discussion is concerned, Rule No. 12 is invoked (this is an extract) - 'Always use Block Statements in Control Flow Constructs' to avoid the 'dangling else' problem ...

I forgot about that book; good example too. Thanks Glenn. :)

I find when going over code I haven't worked on in a while, its easy to skip right over a single line of unbraced "else" code when there is a large block of "if-positive" code right above it.  For internal consistency I only omit the braces where both are single-statements.  If either require multiple lines they both get braced.

Solid approach, thanks dgorsman. :)

Hi, Michael
I have read in "Best code practice" article , don't remember where is it, but written by one of the giants  ( I think by Petzold, not sure about )
"Better yet to use the brackets always"

Following sage Petzold advice could never be a bad thing (very much enjoy his writing too). :)

Bottom line ... whatever scheme one employs ... do it consistently.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst