Searching \ for 'C syntax' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/language/index.htm?key=c
Search entire site for: 'C syntax'.

Truncated match.
PICList Thread
'C syntax'
2003\01\08@125200 by Grant Beattie

flavicon
face
Dare I introduce the following?

if(blah)
   {
   code ...
   code...
   }
else
   {
   code...
   code...
   }

GB

{Original Message removed}

2003\01\08@130021 by Shawn Mulligan

picon face
Grant Beattie wrote:
>Dare I introduce the following?
>
>if(blah)
>     {
>     code ...
>     code...
>     }
>else
>     {
>     code...
>     code...
>     }
>
Now that's just uncalled-for! ;-)

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*
http://join.msn.com/?page=features/virus

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\08@130816 by Brian Aase

picon face
> Dare I introduce the following?
>
> if(blah)
>     {
>     code ...
>     code...
>     }
> else
>     {
>     code...
>     code...
>     }
>
> GB

Grant, you've just made my day!
My co-workers constantly criticize this style (which I adopted
for myself long ago) as being "anti-K&R" and too beginner-like.
Well, *I* like it and intend to stay with it.  Just seems the
clearest choice for my own mental parser.

Brian Aase

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\08@134208 by Fredrik Axtelius

picon face
> Dare I introduce the following?
>
> if(blah)
>     {
>     code ...
>     code...
>     }
> else
>     {
>     code...
>     code...
>     }

My version

if(blah) {
   code...
   code...
} else {
   code...
   code...
}


From 10 to 7 lines, tight and easy to read.
I like tight code.

/frax

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\08@142358 by stanton54

picon face
Fredrik Axtelius wrote:
>
>
> My version
>
> if(blah) {
>     code...
>     code...
> } else {
>     code...
>     code...
> }
>
> >From 10 to 7 lines, tight and easy to read.
> I like tight code.
>
> /frax

This is my favourite for long if-else if-else blocks; it makes them
easier to read. They're still kinda ugly but sometimes you just can't
use switch.

Or maybe I'm just too lazy to press Enter too many times... strangely,
for single if statements, I prefer the extra line break between the if()
and {.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\08@144054 by Brent Brown

picon face
{Quote hidden}

Hey, I like that second one! Even though I'm a K&R kind of guy. The
indentation follows the code nicer than other ways.

--
Brent Brown, Electronic Design Solutions
16 English Street, Hamilton, New Zealand
Ph/fax: +64 7 849 0069
Mobile/txt: 025 334 069
eMail:  spam_OUTbrent.brownTakeThisOuTspamclear.net.nz

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\08@145925 by Mike Mansheim

flavicon
face
> if(blah) {
>     code...
>     code...
> } else {
>     code...
>     code...
> }

> From 10 to 7 lines, tight and easy to read.
> I like tight code.

Well, I still disagree with "easy to read".
Also, I like tight code too, but I always assumed it referred to the
compiled code.  The size of the C code has no direct relationship to the
compiled size.  I've seen amazing amounts of code packed into a single C
line that doesn't compile any better than the same code spread out so it
is readable.  And with the packed version it can be very difficult to
determine what exactly it is supposed to do (kind of a macho thing, I
guess).  But I seem to be digressing...

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\08@163129 by Spehro Pefhany

picon face
At 10:08 AM 1/8/03 -0800, you wrote:
{Quote hidden}

This is the one that makes sense to me, too (maybe with one or two
less spaces for the indent).

But as long as it is well-written code, and consistent, who really cares?

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
.....speffKILLspamspam@spam@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\08@170022 by William Chops Westfield

face picon face
> if(blah)
 *
>     {
>     code ...
>     code...
>     }
 *
> else
 *
>     {
>     code...
>     code...
>     }

The standard here is (and has been for a long time)
       if (blah) {
           code...
       } else {
           code...
       }

I'm a bit pressed to provide reasons I dislike the alternate forms, but I
think it has to do with the open brace "needing" to be associated with the
matching if/etc statement to quickly given an indication of whether a single
statement follows, or a compound statement.  I use indentation more for
visual distinction, and emacs finds matching braces for me.  In addition,
the alternate format provides several places (marked with "*" above) where
you can easilly accidentally insert statements, causing dramatic errors.
Code where your visual clues don't match the actual syntax is just NASTY to
find:
       for (i=0; i <10; i++);
       {
           j = myfunc(i);
           printf("\n%d", j);
       }

BillW

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\08@170024 by Wouter van Ooijen

face picon face
> But as long as it is well-written code, and consistent, who
> really cares?

I think there is some merit in choosing a 'style' that fits your own
mental processes best, but it is not worth the fuss that is often made
about it. When you modify code, stick to the existing style. When you
write new code for yourself, use your favourite syle. When reading, you
will have to cope with all styles, and the big problem will be with code
that does not follow a style at all! And for realy big fun google for
osbfucated C contests.

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\08@173429 by Shawn Mulligan

picon face
Along these lines, what is your favourite naming convention/style for
variables?  Say you're referring to the maximum temperature read from
channel 1 of the internal ADC. Would you choose:

1) float max_temperature
2) float MaximumTemperature
3) float MT
4) float mtAD1
5) float T
  or
6)
  typedef float temperature_type_floating_point

  //*** Variable Declaration ***
  //variable to represent the maximum temperature read on
  //Channel 1 (PIN 20, 16F877 QFP, 10-bit, internal RC)
  //based on <typedef float temperature_type_floating_point>
  //See block header for more detail

  temperature_type_floating_point Maximum_Temperature_Channel_1;
  Maximum_Temperature_Channel_1 = 0; //set to 0 (Zero)
??

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE*
http://join.msn.com/?page=features/virus

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\08@174054 by Spehro Pefhany

picon face
At 03:34 PM 1/8/03 -0700, you wrote:
>Along these lines, what is your favourite naming convention/style for
>variables?  Say you're referring to the maximum temperature read from
>channel 1 of the internal ADC. Would you choose:
>
>1) float max_temperature
>2) float MaximumTemperature
>3) float MT
>4) float mtAD1
>5) float T
>   or
>6)

Err, well, I'd try to avoid using floats to begin with. ;-)

Best regadrs,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
speffspamKILLspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\08@174706 by Peter L. Peres

picon face
Imho it's about time soneone put the indent.exe program somewhere where
any1 can download it without also getting a huge development environment
(djgpp, cygnus etc).

indent covers all the styles discussed here, it's a matter of giving it
the right option(s).

Peter

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\08@174708 by Shawn Mulligan

picon face
Spehro Pefhany wrote:
>Err, well, I'd try to avoid using floats to begin with. ;-)

Nice dodge!

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\08@192531 by Bill Couture

picon face
On Wed, 8 Jan 2003, Grant Beattie wrote:

> Dare I introduce the following?
>
> if(blah)
>     {
>     code ...
>     code...
>     }
> else
>     {
>     code...
>     code...
>     }
>

It is close, but not quite the one true coding style.

You're indenting too far.  Cannonical usage is
  if (foo)
     {
     bar1();
     bar2();
     }
  else
     {
     bar3();
     bar4();
     }

Bill

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\08@214326 by Jim Korman

flavicon
face
>
>
><snip>
>
>It is close, but not quite the one true coding style.
>
>You're indenting too far.  Cannonical usage is
>   if (foo)
>      {
>      bar1();
>      bar2();
>      }
>   else
>      {
>      bar3();
>      bar4();
>      }
>
>Bill
>
I thought no religion here! ;-)

Jim

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\09@012016 by Wouter van Ooijen

face picon face
> It is close, but not quite the one true coding style.
> You're indenting too far.  Cannonical usage is

Who's cannon? NB no ;) in sight...

As to choosing 'the' right style (for indenting, object naming, or most
other styling issues): where do people get the wrong idea that there is
one best style? Programmers' abilities vary from let's say my little
son's driving skills (he can sit on a plastic car and sort of walk, and
has a vuague notion that the steering wheel is important) up to Michael
Schumacher and other racing dare-devils. What's good for one can be pure
evil for the other.

A style should target the audience, and help with the weakest link that
particualr audience has in writing, or (more important) reading code.
This weakest point can vary, from syntactical issues for the very
beginner:
-   whow, this } ends a then-body, let's put empty lines around it and a
two-line comment after that!
-   blimey, a macro-defined constant is not the same as a typed
constant. Let's put all macro names in uppercase!
-   I don't know where the shift key is, so let's use lowercase
exclusively.
-   I have trouble distinguishing constant, type declarations and
variable declarations. Let's put them in different sections with a
10-line comment block inbetween.
to more problem-area related fields
-   I use both integers and floats for my calculation, let's distinguish
them by the first l better of the name.
-   The properties of these 3 different measurement devices are
important. Let's gather all declarations for a device in one place.

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\01\09@054548 by Andy Kunz

flavicon
face
At 09:50 AM 1/8/03 -0800, you wrote:
>Dare I introduce the following?
>
>if(blah)
>    {
>    code ...
>    code...
>    }
>else
>    {
>    code...
>    code...
>    }

This is the format I've been using for 20 years.  It has the symmetry that
makes things easy to read, and adding a line of code at any point, even to
extend an if(), is intuitive.  Far and away the best format, imho.

Like others have pointed out, consistency is important.  Always use TABS
for all indentation.  Set your editor to match the tab positions.  I prefer
tabs every 4 characters.

Andy

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\01\09@055842 by Andy Kunz

flavicon
face
At 07:26 PM 1/8/03 -0500, you wrote:
>On Wed, 8 Jan 2003, Grant Beattie wrote:
>
>> Dare I introduce the following?
>>
>> if(blah)
>It is close, but not quite the one true coding style.
>
>You're indenting too far.  Cannonical usage is
>   if (foo)

The "Truly Important Thing" is really the space between the if and the (.

Set your tabs with your editor and it won't matter what the other guy used.

Just USE HARD TABS everywhere!

Andy

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\01\09@095241 by Dave Tweed

face
flavicon
face
Bill Couture <.....bcoutureKILLspamspam.....CRIS.COM> wrote:
> It is close, but not quite the one true coding style.
>
> You're indenting too far.  Cannonical usage is
>    if (foo)
>       {
>       bar1();
>       bar2();
>       }
>    else
>       {
>       bar3();
>       bar4();
>       }

Be careful of your terminology. The "One True Brace Style", or 1TBS,
is the original K&R style, used in the Unix kernel:

   if (foo) {
       bar1();
       bar2();
   } else {
       bar3();
       bar4();
   }

Look it up in the Jargon File.

-- Dave Tweed

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...