What style to choose?

M

maths_fan

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?
 
M

Malcolm

maths_fan said:
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.
 
R

Richard Heathfield

Irrwahn said:
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.
 
M

Mathew Hendry

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top