473,434 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

C elements of style

Hi all,

I was going through the book "C Elements of style" by steve oualline.
in this book many guidelines are given.

the following were seen in the book as rules

1) while(1) is preferred over for(;;)
2) use of const is preferred over #define
3) unless extreme efficiency is warranted, use printf instead of putc
& puts
now my question is

can anyone give examples for the justification of above rules ..????

OR
To what extent these rules are true..???
Apr 2 '08
55 2707
On Apr 3, 9:48*pm, Keith Thompson <ks...@mib.orgwrote:

Finally, the semicolon at the end of the macro definition defeats the
purpose of the do-while trick. *Is that really there in the book?

Okay you are correct. I accidentally put that semicolon at the end of
the macro
Apr 6 '08 #51
On Apr 3, 11:42 am, aark...@gmail.com wrote:
On Apr 2, 4:15 pm, aark...@gmail.com wrote:
On Apr 3, 12:58 am, Eric Sosman <Eric.Sos...@sun.comwrote:
Does this Rulemaker go on to
recommend pow(x,2) instead of x*x, or pow(2,6) instead of 64?
he gives many rules, some of them are as follows
4) always split a for statement into 3 lines
5) when splitting up a conditional clause(?:),write it on three lines:
the condition line,the true-value line, and the false-value
line.indent the last two lines an extra level
6)allow no more than 5 parameters to a function
7)avoid do/while use while and break instead.
8)use the comma operator inside a for statement only to put together
two statements. never use it to combine three statements
9)always put a break at the end of the last case in a switch statement

more rules fro the same book

10) do not use absolute paths in #include directives. let the -I
compile option do the work

11) begin all debug printfs with ##
ex:- printf("## state=%d",state);

12) the best indentation is 4 spaces

13) if a macro contains more than one statement, use a do while
structure to enclose the macro

ex:- #define ABORT \
do{ \
puts("abort"); \
exit(8); \
}while(0);
For Complete List of Oaulline Rules see:-

http://www.oualline.com/style/styleRULE.html
Apr 10 '08 #52
aa*****@gmail.com said:

<snip>
For Complete List of Oaulline Rules see:-

http://www.oualline.com/style/styleRULE.html
Why?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Apr 10 '08 #53
On 4 Apr, 08:20, Richard Heathfield <r...@see.sig.invalidwrote:
>
Secondly, let's take an example like this:

rc = myfunctioncall(arga,
argb,
argc);

which looks lovely with spaces.
Well, there is much debate about whether or not
that is lovely. Personally, I have never
liked that style. Much better (IMO) is:

rc = myfunctioncall(
arga,
argb,
argc
);

(With many variations on that theme.) The
notion of attempting to align all the arguments
to the first and anchoring the first argument
to the open paren is wrong-headed. If you
do like that, and still want to use tabs, you
can do things like:

rc = myfunctioncall( arga,
<tab to match indent of rc>/**/<spaces>argb,

The comment isn't necessary, but many
people (correctly) abhor mixing tabs and
spaces in indentation, and the emtpy comment
serves as a delimiter. But this particular
style (aligning arguments) is the only reason
to ever want to mix tabs and spaces, and (again
IMO) the correct solution is to abandon that
practice.
Apr 10 '08 #54
On Apr 10, 2:56 am, Richard Heathfield <r...@see.sig.invalidwrote:
aark...@gmail.com said:

<snip>
For Complete List of Oaulline Rules see:-
http://www.oualline.com/style/styleRULE.html

Why?
see this:- http://www.accu.informika.ru/accu/bo.../c/c000262.htm

Apr 10 '08 #55
aa*****@gmail.com said:
On Apr 10, 2:56 am, Richard Heathfield <r...@see.sig.invalidwrote:
>aark...@gmail.com said:

<snip>
For Complete List of Oaulline Rules see:-
>http://www.oualline.com/style/styleRULE.html

Why?

see this:-
http://www.accu.informika.ru/accu/bo.../c/c000262.htm

<shrugIt's a book review. Whilst I haven't read "C Elements of Style", I
did browse through "Practical C Programming" a few years ago, and was
rather disconcerted to find that it wasn't actually very good, despite
being recommended regularly in clc at the time (it isn't, any more). The
stuff you posted earlier about cleaning out program "muck" looked like
more of the same - i.e. not very impressive.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Apr 10 '08 #56

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rainer Kugeland | last post by:
Two problems regarding coordinates: a) When I click in the screen then I can easyly find the element on the current corrdinates. But is there a way to find the elements which are behind the fist...
13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
2
by: James | last post by:
Are there any style elements that work on select elements on Apple/IE? I want colored text, colored background, or just about anything colored in a select drop-down but can't seem to make it work...
23
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to...
4
by: omidmottaghi | last post by:
I need to disable/enable form elements in my form. the code i was developed works fine in FF, but in IE, its behaviour is very strange!! in the form, we have a lot of checkboxes, all of them...
2
by: misower | last post by:
var c = document.getElementById("PanelTree"); // PanelTree is a <div> element! var n = document.createElement("div"); n.setAttribute('id', 'nu'); n.setAttribute('style',...
5
by: Ed Jay | last post by:
I have a switch statement that controls which of several containers is displayed or not. It currently looks like: function showHelp(n) { show('vhelp'); //makes parent container visible switch...
3
by: David Golightly | last post by:
I'm taking a stab at making CSS sparklines - see http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001OR&topic_id=1&topic= <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC...
7
by: mavigozler | last post by:
IE7 does not appear to set an event on contained text inside SPAN elements whose 'onclick', 'onmouseover', and 'onmouseout' events, defying the HTML recommendation. Firefox appears to conform. ...
1
by: kidelectric | last post by:
The issue I am having is that I would like to be able to drag-and-drop div elements that have rounded corners.* Since these elements will be dynamically created (including background color), I could...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.