Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > What style to choose?

Reply
Thread Tools

What style to choose?

 
 
maths_fan
Guest
Posts: n/a
 
      10-19-2003
What style do you prefer? Where to place brackets? How to name
variables, functions, constants, etc. How do you format your source
code? Do you write comments?
 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      10-19-2003
"maths_fan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> What style do you prefer?


Clear and readable.

> Where to place brackets?


Such that they contribute to the above.

>How to name
> variables, functions, constants, etc.


Such that they express their purpose.

> How do you format your source
> code?


Such that it's clear and readable.

> Do you write comments?


Yes, when they aid readability, otherwise not.

-Mike


 
Reply With Quote
 
 
 
 
Irrwahn Grausewitz
Guest
Posts: n/a
 
      10-19-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (maths_fan) wrote:

>What style do you prefer?

Baroque.

>Where to place brackets?

On the wall.

>How to name
>variables, functions, constants, etc.

Pick random scrabble pieces out of a bag.

>How do you format your source
>code?

With an editor.

>Do you write comments?

No. The purpose of writing comments is to confuse the reader.
They're only useful in military strength code.

--
Irrwahn
((E-Mail Removed))
 
Reply With Quote
 
Malcolm
Guest
Posts: n/a
 
      10-19-2003

"maths_fan" <(E-Mail Removed)> wrote in message
> What style do you prefer?
> Where to place brackets?

I always place brackets one above the other, and always have a bracket as
the only entry on its line.
> How to name variables, functions, constants, etc.

Generally I think one should use mathematical conventions - eg i for a loop
counter, x for a general real and y for a dependent one, N for a count etc.
An angle would be theta.
You do have problems with namespace collisions in C.
> How do you format your source code?

Without tabs, 2 spaces of indents.
>Do you write comments?

A function needs a comment to expalin what it does, what parameters it
takes, and what it returns. Usually heavy commenting of the function body
should be unnecessary because the function should be simple enough for
another programmer to see what is going on.


 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      10-19-2003
Irrwahn Grausewitz wrote:

> (E-Mail Removed) (maths_fan) wrote:
>
>>Do you write comments?

> No. The purpose of writing comments is to confuse the reader.


That is merely an unfortunate side-effect of badly-written or
poorly-maintained comments.

> They're only useful in military strength code.


All code should be "military" strength.

I know you're just winding the guy up, but it's fairly obvious that /he/
doesn't know that - hence this clarification.

--
Richard Heathfield : (E-Mail Removed)
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
 
Reply With Quote
 
Mathew Hendry
Guest
Posts: n/a
 
      10-19-2003
On 19 Oct 2003 06:43:51 -0700, (E-Mail Removed) (maths_fan) wrote:

>What style do you prefer?


The one true style, obviously.

>Where to place brackets?


Cuddled except for function definitions, where they go one line under.

>How to name variables


By function.

>functions


By variable.

>constants


Constantly.

>How do you format your source code?


As I go... (seriously: adjusting formatting after the fact tends to confuse
version control systems).

>Do you write comments?


/* FIXME: broken */

(Yes, direct quote I'm afraid

Serious answer: simple, undertandable, consistent.

-- Mat.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid header style inconsistent with sortable column style cedoucette@alum.rpi.edu ASP .Net 0 10-14-2005 12:13 AM
All style tags after the first 30 style tags on an HTML page are not applied in Internet Explorer Rob Nicholson ASP .Net 3 05-28-2005 03:11 PM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM
Javascript Style Switcher that remebers current site style in use Hardeep Rakhra HTML 8 01-15-2004 08:00 PM
Style sheets, include one style within another (not inheritance) foldface@yahoo.co.uk HTML 1 11-24-2003 01:37 PM



Advertisments