Searching \ for '[EE] Programming style' 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/microchip/devprogs.htm?key=programming
Search entire site for: 'Programming style'.

Exact match. Not showing close matches.
PICList Thread
'[EE] Programming style'
2005\12\04@134649 by Gerhard Fiedler

picon face
Hi,

I left recently a comment or two about programming style. I think that's a
really important subject. Good style conveys the intent of the code, much
more than anything else. Good style reduces the need for comments (which
can and often will get out of sync with the code). Good style makes
designing and debugging code a lot easier and reduces the probability of
errors. Good style is a tremendous time saver and helpful communication
tool.

There's no simple rule for good style, with the possible exception of this
one: it should be consistent. Among others, consistency makes spotting
errors a lot easier: if something is wrong in the code, there is a bigger
chance that it will also be "visually wrong". You can scan your newspaper
as fast as you can because it has a consistent layout. (There are better
and less good examples out there for this :)

So IMO the time you need to develop your own coding style is well spent.
This is something that can't be easily learned; it has to be developed.
It's more an art or a craft than a science.

A collection of some thoughts about style in C programming can be found
here http://www.doc.ic.ac.uk/lab/secondyear/cstyle/cstyle.html. It's rather
Unix-centric (no surprise when talking about C), but since this is not
about copying somebody's style, but rather about understanding what issues
people address with style and find one's own preferences how to most
efficiently address these issues, this is still helpful even for 8 bit
embedded C programming with a non-standard compiler.

And there's always the classic Code Complete by McConnell. Not really
targeted to any language or environment, it's one of the few really generic
classics about the part of programming that goes beyond churning out code.
The site for the (current) 2nd edition is http://www.cc2e.com/ (I can't
vouch for the 2nd edition; I only know the 1st. But there is no reason to
assume it be not at least as good.) It's probably beyond what is of
interest to the average hobbyist, but it's definitely recommended for
everyone who programs for a living.

Gerhard

2005\12\04@140601 by M Graff

flavicon
face
Gerhard Fiedler wrote:

> So IMO the time you need to develop your own coding style is well spent.
> This is something that can't be easily learned; it has to be developed.
> It's more an art or a craft than a science.

On the other hand, using a style that someone else uses (say, your
employeer :) may be helpful too.  I use the same style that NetBSD uses
(the latest of which is on
http://cvsweb.netbsd.org/bsdweb.cgi/src/share/misc/style?rev=HEAD&content-type=text/x-cvsweb-markup
and other places) and that seems to be fairly compatible with my
employeer's style, with some minor varances.  Of course, I helped set up
my employeer's style guide, so...

The importance of following strictly the style your employeer lays out
is that you probably won't be the only one working on your code, and
people have been reprimanded and/or let go because of their adamant
refusal to follow the style guide's major points.

Picking a style you like is useful, but BSD and/or GNU style works as
well, and is more likely to be compatible with someone else's style,
which is also important.

--Michael

2005\12\04@151420 by Gerhard Fiedler

picon face
M Graff wrote:

> The importance of following strictly the style your employeer lays out is
> that you probably won't be the only one working on your code, and people
> have been reprimanded and/or let go because of their adamant refusal to
> follow the style guide's major points.

I agree completely. My message was written with the view of someone who
follows various clients' styles, besides writing code under my own control
using my style.

Maybe there's another general rule (or is this a consequence of the
consistency rule): Never charge a style mid-stream. When changing or adding
to code, use the style that's already there, even if it isn't your
preference.

I still think that not only "learning" a style, be that BSD or GNU or
Microsoft, is the important thing, but rather understanding the rationale
behind every single rule. This is the part I meant with "developing your
own style". It is much easier following someone else's style if you
understand the reason and know about pros, cons and alternatives.

Gerhard

2005\12\05@093023 by Tony Smith

picon face
> I left recently a comment or two about programming style. I think that's a
> really important subject. Good style conveys the intent of the code, much
>
> So IMO the time you need to develop your own coding style is well spent.
> This is something that can't be easily learned; it has to be developed.
> It's more an art or a craft than a science.


Of course, there's no need to get carried away, most languages / dev stuff have certain 'rules' that people tend to follow, often
for a good reason (but occasionally just religion).

Anyway, I just finished a project (Microsoft Access) where the developer had his very own naming convention, bless his little cotton
socks.  Say you have a table with customers in it.  Most people would call the table tblCustomer, and the primary key CustomerID.
For Orders you have tblOrder, and OrderID.  I wonder what qryOrder would be?  Everyone does this, so it tends to be a no-brainer
figuring out stuff.  As it should be.  Not PWC, gotta justify the $$$.

Each table & field was prefixed with the abbreviation of the table name, so you had  cstCustomer and ordOrder.  Primary keys became
cstCustomerID and ordOrderID.  How this was helpful is beyond me.  But wait!  The order table needs CustomerID as the foreign key.
Most people use the same name, to make the link between the two obvious.  Not here, it was called ordCustomerID.  Hey, let's give
the keys different names!  Even better, the prefixes were inconsistant, Entity might be ent or ety.

Every time I had to do something, I had to look up the frigging name.  Gah.  Yes, I renamed everything.  The developer left his
name/company in the code comments (well, they were the only comments).  One day, I'll pay a visit to Wales.

Have a look at http://www.thedailywtf.com for more fun stuff people do.

Tony

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