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. 31 2021
Christopher Benson-Manica <at***@nospam.c yberspace.org> scribbled the following: 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 { ... }
Make those if( cond ) thingies if (cond), and you've got my style
pretty much spot-on.
Another possibility (I don't use it in C) is
if( cond ) { ... } else if( blah ) { ... } ...
--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"'So called' means: 'There is a long explanation for this, but I have no
time to explain it here.'"
- JIPsoft
Joona I Palaste <pa*****@cc.hel sinki.fi> spoke thus: Make those if( cond ) thingies if (cond), and you've got my style pretty much spot-on.
That's a house rule. If I were a style Nazi I would have committed
seppuku my first week ;)
--
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.
"Christophe r Benson-Manica" <at***@nospam.c yberspace.org> wrote in message
news:bv******** **@chessie.cirr .com... How about your if/else if/else constructs? Being nitpicky like any good C programmer, I'm in the process of transforming code [...]
Why do you need to transform code from one style to another? If you use
any source-control system, it may lead to too many differences that aren't.
FWIW, my prefered style is similar to yours, except that I use:
if (cond)
{
...
}
else if (some_other_con d)
{
...
}
else
{
...
}
The opening brace sits on its own line, just like the closing one, and the
two indent the same. There is a space before the opening parenthesis and
voluntary space after the closing one, but never the other way round. Now,
this is The Only True Style, so stick to it! :-)
Peter
Christopher Benson-Manica wrote: How about your if/else if/else constructs? Being [anal] like any good C programmer, I'm in the process of transforming code written like
[snip]
I prefer:
if (cond) {
...
}
else
if (some_other_con d) {
...
}
else
if(explode_with _pretty_colors) {
/* explode with pretty colors */
}
else {
...
}
But like I said
Get a C reformatter program like indent: http://www.gnu.org/software/indent/indent.html
so that you can convert
from one format to another automatically.
Christopher Benson-Manica wrote: 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
<snip>> to my preferred style:
<snip> Another possibility (I don't use it in C) is
if( cond ) { ... } else if( blah ) { ... } ...
If you're going for consistency, why not just run all your code through
a C beautifier and just accept whatever it spits out? As long as all the
code's consistent in style, the actual style selected doesn't matter a
whole lot.
FWIW the UNIX tool "cb -s" (K&R mode) spits out your boss's preferred
style for case statements and the final style above for if...else.
Without the "-s" it still prefers your boss's case style but doesn't
appear to do anything useful with "if...else" .
Ed.
Peter Pichler <pi*****@pobox. sk> spoke thus: Why do you need to transform code from one style to another? If you use any source-control system, it may lead to too many differences that aren't.
Well, there is that, of course, but I figure that since MY style is
the "One Style," it's justified. One style to rule them all...
--
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 <at***@nospam.c yberspace.org> scribbled the following: Joona I Palaste <pa*****@cc.hel sinki.fi> spoke thus: Make those if( cond ) thingies if (cond), and you've got my style pretty much spot-on.
That's a house rule. If I were a style Nazi I would have committed seppuku my first week ;)
Can you please ask whoever came up with that rule what they were
smoking? =)
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:
- Indents are 2 spaces
- Braces K&R style: opening brace on the same line, closing on its own
line, one space before the opening brace
- Always 1 space after every comma and every semicolon, otherwise
1 space around every "important" operator or no spaces at all if it's
not "important"
- Always 1 space between *keywords* (if, for, while, etc) and the
opening paren, never any space between a function or a macro name and
the opening paren
- Two blank lines between each function, one blank line separating
conceptual groups of statements
That's pretty much the important stuff.
--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Normal is what everyone else is, and you're not."
- Dr. Tolian Soran
Ed Morton <mo****@lsupcae mnt.com> scribbled the following: If you're going for consistency, why not just run all your code through a C beautifier and just accept whatever it spits out? As long as all the code's consistent in style, the actual style selected doesn't matter a whole lot.
FWIW the UNIX tool "cb -s" (K&R mode) spits out your boss's preferred style for case statements and the final style above for if...else. Without the "-s" it still prefers your boss's case style but doesn't appear to do anything useful with "if...else" .
Can the C beautifier also beautify Java?
--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I am lying."
- Anon
Joona I Palaste <pa*****@cc.hel sinki.fi> spoke thus: Can you please ask whoever came up with that rule what they were smoking? =)
Will do! :)
- Indents are 2 spaces
Ours are five. I count on the pain to wake me up on Monday morning.
It isn't as bad as our <ot>HTML, however - indentation is essentially
random, making editing tables and scripts a joy. I've spent several
days just reformatting it, never mind fixing actual errors...</ot>
- Braces K&R style: opening brace on the same line, closing on its own line, one space before the opening brace
I'm a former separate-line'r who's been beaten into submission...
- Two blank lines between each function, one blank line separating conceptual groups of statements
That's another bad thing - there is space between initial declarations
and code, but blank lines elsewhere within functions are frowned upon.
Heavens knows why...
--
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. 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: 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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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: 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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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...
| |