How about your if/else if/else constructs? Being nitpicky like any
good C programmer, I'm in the process of transforming code written
like
if( cond ) {
...
} else
if( some_other_cond ) {
...
} else
if( explode_with_pr etty_colors) {
/* explode with pretty colors */
}
else {
...
}
to my preferred style:
if( cond ) {
...
}
else if( some_other_cond ) {
...
}
else if( explode_with_pr etty_colors ) {
/* explode! */
}
else {
...
}
Another possibility (I don't use it in C) is
if( cond ) {
...
} else if( blah ) {
...
}
....
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Nov 14 '05
31 2022
Joona I Palaste <pa*****@cc.hel sinki.fi> spoke thus: Christopher originally wrote "nitpicky", not "anal". It's fun to see what Trollsdale will alter *my* message to. =)
Well, in this case at least it's fairly benign - one might call it
un-euphemizing my choice of words ;)
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Christopher Benson-Manica wrote: How about your if/else if/else constructs?
if (cond) { /* brace can be here... */
/* ... */
}
else
if (cond) /* ...or line below... */
{ /* (depending on what looks best at the time) */
/* ... */
}
else /* ...but never after final else */
{
/* ... */
}
--
|_ CJSonnack <Ch***@Sonnack. com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ _______________ ____| Call: 1-800-DEV-NULL |
|______________ _______________ _______________ _|_____________ __________|
In <bv**********@o ravannahka.hels inki.fi> Joona I Palaste <pa*****@cc.hel sinki.fi> writes: Personally I'm a bit of a style Nazi myself. Whenever I have to edit code someone else wrote, I take time to format it to "readable" style first. Which means:
Which means that you've never been involved in some open/free source
code collaboration, where the ability to produce and read *meaningful*
diffs is essential. Any stylistical changes to the code are a major
source of "noise" and the rest of the collaboration would promptly
kick you out.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
In <40************ ***@yahoo.com> CBFalconer <cb********@yah oo.com> writes: Richard Heathfield wrote: Thomas Stegen CES2000 wrote: > Joona I Palaste wrote: > > I think I would object if someone told me to code like this though: > a=b+c*3; > I think a = b + c * 3; is much better.
And I prefer
a = c * 3 + b;
YMMV.
Definitely MV. I can even find cases where I want different emphasis, and would write:
a = 3*c + b; or dsq = b*b - 4*a*c;
although normally I would not suppress the blanks.
As a beginner, I would not insert any space that was not required by the
language. A habit inherited from FORTRAN programming on punched cards,
where you really wanted to avoid continuation cards. Then, one day I was
bitten by
i=-1;
being parsed as
i =- 1;
by a VAX C compiler (=- was the anachronic form of -=, but some
pre-ANSI compilers still supported it). After that, I always left one
space between operators and operands, just to be on the safe side. This
kind of bugs (the compiler parses the code differently than the human) is
just too difficult to spot, so it pays the "effort" needed to avoid it.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Dan Pop <Da*****@cern.c h> scribbled the following: In <bv**********@o ravannahka.hels inki.fi> Joona I Palaste <pa*****@cc.hel sinki.fi> writes:Personally I'm a bit of a style Nazi myself. Whenever I have to edit code someone else wrote, I take time to format it to "readable" style first. Which means:
Which means that you've never been involved in some open/free source code collaboration, where the ability to produce and read *meaningful* diffs is essential. Any stylistical changes to the code are a major source of "noise" and the rest of the collaboration would promptly kick you out.
You guessed right. The only "real" programming I've ever done is for
university exercises and an actual commercial job. With both of these,
a change that does nothing else than make the code more readable is
accepted.
--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The truth is out there, man! Way out there!"
- Professor Ashfield
On 5 Feb 2004 18:02:56 GMT, in comp.lang.c , Joona I Palaste
<pa*****@cc.hel sinki.fi> wrote: Dan Pop <Da*****@cern.c h> scribbled the following: In <bv**********@o ravannahka.hels inki.fi> Joona I Palaste <pa*****@cc.hel sinki.fi> writes:Personally I'm a bit of a style Nazi myself. Whenever I have to edit code someone else wrote, I take time to format it to "readable" style first. Which means:
Which means that you've never been involved in some open/free source code collaboration, where the ability to produce and read *meaningful* diffs is essential. Any stylistical changes to the code are a major source of "noise" and the rest of the collaboration would promptly kick you out.
You guessed right. The only "real" programming I've ever done is for university exercises and an actual commercial job. With both of these, a change that does nothing else than make the code more readable is accepted.
Its also worth noting that any code diff or version control tool that
takes meaningless whitespace into account should be abandoned. It
should always be possible to beautify dense code without aggravation.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Mark McIntyre <ma**********@s pamcop.net> spoke thus: Its also worth noting that any code diff or version control tool that takes meaningless whitespace into account should be abandoned. It should always be possible to beautify dense code without aggravation.
Believe me, if it were in my power to use something other than
Microsoft's Visual Sourcesafe at my employment docimile, I certainly
would.
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
In <bv**********@o ravannahka.hels inki.fi> Joona I Palaste <pa*****@cc.hel sinki.fi> writes: You guessed right. The only "real" programming I've ever done is for university exercises and an actual commercial job. With both of these, a change that does nothing else than make the code more readable is accepted.
Keep in mind that readability is in the eye of the beholder. What's
more readable to you may be less readable to the person who wrote the
code in the first place. We had plenty of threads proving this, in this
very newsgroup.
The only consensus is that some form of indentation is better than
no indentation at all and that identifiers with meaningful names are
better than identifiers of the form oo0o00oo and l111ll1ll.
But once we start comparing the merits of different kinds of indentations
or identifier naming conventions, the Pandora's box is open...
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
On Fri, 6 Feb 2004 02:18:06 +0000 (UTC), in comp.lang.c , Christopher
Benson-Manica <at***@nospam.c yberspace.org> wrote: Mark McIntyre <ma**********@s pamcop.net> spoke thus:
Its also worth noting that any code diff or version control tool that takes meaningless whitespace into account should be abandoned. It should always be possible to beautify dense code without aggravation.
Believe me, if it were in my power to use something other than Microsoft's Visual Sourcesafe at my employment docimile, I certainly would.
the vesion of vss that I last used actually had an option to ignore
whitespace. STR that it didn't actually work as such tho....
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Dan Pop wrote: In <bv**********@o ravannahka.hels inki.fi> Joona I Palaste <pa*****@cc.hel sinki.fi> writes:
You guessed right. The only "real" programming I've ever done is for university exercises and an actual commercial job. With both of these, a change that does nothing else than make the code more readable is accepted.
Keep in mind that readability is in the eye of the beholder. What's more readable to you may be less readable to the person who wrote the code in the first place. We had plenty of threads proving this, in this very newsgroup.
The only consensus is that some form of indentation is better than no indentation at all and that identifiers with meaningful names are better than identifiers of the form oo0o00oo and l111ll1ll.
But once we start comparing the merits of different kinds of indentations or identifier naming conventions, the Pandora's box is open...
Dan -- Dan Pop DESY Zeuthen, RZ group Email: Da*****@ifh.de
I think it's possible to develop reasonably objective, nonrandom
standards of readbility. But some things done in the name of readability
fly in the face of prohibitions against early return, some formatting
conventions.
--
Les Cargill This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: HolaGoogle |
last post by:
hi there,
i've 2 questions for you guys....
1: is there any way to "force" a session_onend(), session timeout or
at least call my logout method when a user leaves the application
window without logging out? i.e: using the "X" in the right corner???
i'd like to reset to their default all my variables session?? is this
possible???
2: I've succesfully been able to ask the user to confirm whether he
wants to extend his session before it...
|
by: CMAR |
last post by:
I have the following markup. The problem is that the browser, e.g., IE6,
inserts several lines of blank space between the <div> and the following
table. Is there a way to minimize that vertical spacing?
Thanks, CMA
<div class="vlgray">Condition</div>
<table cellpadding="0" cellspacing="0">
|
by: andy.dreistadt |
last post by:
Hi all,
I came across another problem that is probably pretty easy but, again,
due to my rusty-ness with C, I'm a little stumped.
I have a struct that looks like this:
/* Instrument Data structure */
struct instrument_info
{
|
by: Calan |
last post by:
Mike,
Your code on the dynamic input checking was excellent and very well
explained. (The only thing I had to do was change the test for text input to
be "1 > len of text", instead or "0 > length of text", and add a line to
store the result for use on the server). Thank you very much!
I have a related issue that you might have some ideas on. In some cases, I
have a select box where one of the selections may require an additional
input...
|
by: Terry Olson |
last post by:
I'm trying to build a table on an output page based on text input by the
user. And what I am trying to do is create 4 table data boxes on a row, then
start a new row on the 5th one. But I can't quite get it right, the code I
got here will start a new line on odd numbers like 9, 29, 16, etc.What am I
doing wrong?
(ignore any unbalanced braces or the referance to "i", since this is juat a
small snippet.)
if(!isNaN(mxfld) && mxfld != 0) {...
| |
by: Sebastian Hiller |
last post by:
Hello,
i'm new to .Net (i'm using VB as language and i'm working in the
code-behind mode) and i can't solve the following problem:
I have a WebForm and want to Add a UserControl
(classname:QuestionControl) as many times as there are rows in a
DataTable (also named Questions) in a DataSet. But this UserControl is
,for reasons of structuring, not a member of the WebForm Object in
which it should be displayed, it is member of another class...
|
by: Jon Paal [MSMD] |
last post by:
This "show-hide" works in IE7 but fails in FF2 -
Error in FF: "this.children is not a function"
Can someone help ?
<DIV id=sect style="display:block;" onclick="javascript:if
(this.children(0).style.display=='none'){this.children(0).style.display='block'}else{this.children(0).style.display='none'}">
<Table>
<TR>
|
by: sagar |
last post by:
Hi,
I have a C file(add.c) in which i have a function called add.now
i want to call the same add function from another file sub.c .Can any1
tell how to do that...
Thanks in advance
Mark
|
by: sheldonlg |
last post by:
I am looking for a clean solution to a problem that I solved in, what I
call, a "dirty" way.
Here is what I want to do. I have a dropdown list. Clicking on an item
in the dropdown list invokes an AJAX call that gets data which populates
the entire lower part of my screen. It does this with an innerHTML for
the div tag that holds all of this. This works fine.
I also have an "Edit" button that I want to show next to dropdown list,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |