473,750 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

matching { } syntax style

Why is it that everybody likes the follwowing curly braces syntax

function() {
implementations ;
}

I find the following much better to read (C style)

function()
{
implementations ;
}

kind regards,
Bart
Jul 19 '05
31 2507
In order to avoid these kind of "religious" matters, I was looking for a
tool enabling each developper to have his own style.

Found "C++ SourceStyler" from OchreSoftware
(http://www.sourcestyler.com/) but it is expensive and not available on
Unix/Linux.

Does anybody know of a FREE "C++ styler" available on Unix/Linux ?
Please don't answer with "indent".

Marc

Jul 19 '05 #21
Marc Ferry wrote:
In order to avoid these kind of "religious" matters, I was looking for a
tool enabling each developper to have his own style.


Do you mean each developer reformats everything at check-out time?

That will fill the source control system up with irrelevant changes. I have
heard this suggested before; has anyone ever actually done it?

Developers should share a team style, and all code should match it. One can
support the style electronically, but the common style should support team
bonding. Developers can find more productive ways to be individualistic .

--
Phlip
Jul 19 '05 #22
> The shorter the function, the more the relative waste of space the braces
become; so where so you put your braces in your 'very short functions'? How about:


struct
A
{
virtual void fn0() { ... }
virtual void fn1() { ... }
virtual void fn2() { ... }
};

There. A is in the first column. 'struct', being less important, is out of
the first column, and the braces parallel each other.

The functions are so short that the next stiff breeze will make them
collapse into something using even less lines of code.

--
Phlip
http://www.c2.com/cgi/wiki?TestFirstUserInterfaces
Jul 19 '05 #23
Phlip wrote:
Marc Ferry wrote:

In order to avoid these kind of "religious" matters, I was looking for a
tool enabling each developper to have his own style.

Do you mean each developer reformats everything at check-out time?

That will fill the source control system up with irrelevant changes. I have
heard this suggested before; has anyone ever actually done it?


Have a look at "SourceStyl er C++" at http://www.sourcestyler.com/
Source file doesn't seem to be reformated.
Marc

Jul 19 '05 #24
Marc Ferry wrote:
Phlip wrote:
Marc Ferry wrote:

In order to avoid these kind of "religious" matters, I was looking for a
tool enabling each developper to have his own style.


Do you mean each developer reformats everything at check-out time?

That will fill the source control system up with irrelevant changes. I
have
heard this suggested before; has anyone ever actually done it?

Have a look at "SourceStyl er C++" at http://www.sourcestyler.com/
Source file doesn't seem to be reformated.
Marc


Actually it is reformatted:
http://www.ochresoftware.com/sourcestyler-gui.html

I emailed the link to colleagues and you could tell when
they had opened it by the laughter.

A coding style contains much more than where you place a
brace or how many spaces you indent. It will have rulings on
language constructs to be avoided, naming schemes for
variables, classes, and functions etc, lots of stuff that
reformatting just doesn't address.

If you are going to adopt a coding style you need to pick
one have a meeting to discuss any contentious issues, and
have someone who is in a position to make a final ruling.
Then adopt and enforce the scheme, no one should be exempt
from the adopted style.

Jul 19 '05 #25
lilburne wrote:
Actually it is reformatted:
http://www.ochresoftware.com/sourcestyler-gui.html

I emailed the link to colleagues and you could tell when
they had opened it by the laughter.

A coding style contains much more than where you place a
brace or how many spaces you indent. It will have rulings on
language constructs to be avoided, naming schemes for
variables, classes, and functions etc, lots of stuff that
reformatting just doesn't address.

If you are going to adopt a coding style you need to pick
one have a meeting to discuss any contentious issues, and
have someone who is in a position to make a final ruling.
Then adopt and enforce the scheme, no one should be exempt
from the adopted style.


If you are going to adopt coding styles, start by defining your terms.
There are two kinds - esthetic and technical. The OP asked about an
esthetic guideline.

You list technical things. The two guidelines should be democratic and
meritocratic, respectively. If we declare a technical guideline, and
you find a way to exceed it, you may simply tell us what the actual
technology is. (Tip: Fighting on USENET helps teach us how to defend
our principles ;)

For example, suppose we agree on camelCase for identifiers, and on
"complete words without excess abbreviations". But if you want to
write a big identifier, like camelCaseWithFu llPack, you are allowed to
write and defend "camelCase_with FullPack". You added a _ for major
breaks in identifiers, and this has merit.

--
Phlip
Jul 19 '05 #26
Phlip wrote:
lilburne wrote:

If you are going to adopt a coding style you need to pick
one have a meeting to discuss any contentious issues, and
have someone who is in a position to make a final ruling.
Then adopt and enforce the scheme, no one should be exempt
from the adopted style.

If you are going to adopt coding styles, start by defining your terms.
There are two kinds - esthetic and technical. The OP asked about an
esthetic guideline.

The poster to this sub-thread was talking about a standard
layout that wasn't a standard layout, something about not
having a religious war over brace style and such. I've yet
to see an in-house style that didn't combine the aesthetic
and the technical.

But consider for the moment what was being proposed:

"In order to avoid these kind of "religious" matters,
I was looking for a tool enabling each developper to
have his own style."

the idea is that when the file is extracted from the
repository it is formatted into the devvies prefered style,
then when it is returned to the repository it is converted
into house style. This presupposes there is a "house style"
or common layout, but the motivating factor for doing this
is that there isn't "each developer to have his own style".
If this group of developers can agree a common layout format
why can't they adopt it as *the* style?

Now think about what happens when two devvies are working
together, joint debugging, or extreme programming session,
or whatever. Whose layout style are they going to use?

I hope the company that produces this software makes a lot
of money from it, I pray that all my industry competitors
adopt it too.

You list technical things. The two guidelines should be democratic and
meritocratic, respectively. If we declare a technical guideline, and
you find a way to exceed it, you may simply tell us what the actual
technology is. (Tip: Fighting on USENET helps teach us how to defend
our principles ;)

For example, suppose we agree on camelCase for identifiers, and on
"complete words without excess abbreviations". But if you want to
write a big identifier, like camelCaseWithFu llPack, you are allowed to
write and defend "camelCase_with FullPack". You added a _ for major
breaks in identifiers, and this has merit.


Of course, the standard will be revised from time to time
and there ought to be a way of managing that. What you don't
want is ad hoc changes or worse yet someone taking the
attitude that they are not bound by it. Practically all of
the in-house style will have some technical basis even the
aesthetic ones.

Jul 19 '05 #27
"Phlip" <ph*******@yaho o.com> wrote in message news:<Ab******* **********@news svr16.news.prod igy.com>...
Marc Ferry wrote:
In order to avoid these kind of "religious" matters, I was looking for a
tool enabling each developper to have his own style.


Do you mean each developer reformats everything at check-out time?

That will fill the source control system up with irrelevant changes. I have
heard this suggested before; has anyone ever actually done it?

Developers should share a team style, and all code should match it. One can
support the style electronically, but the common style should support team
bonding. Developers can find more productive ways to be individualistic .


I've done that. But I didn't check in that reformatted version.
Instead, I would run vdiff (a function from an old version of PVCS) to
determine what really changed and then make those same changes in a
fresh copy of the code. I'd then vdiff the two modified versions
again to make sure I'd copied in all of my changes before checking the
code back in. That way I could format the code in whatever way best
suited my understanding, and the resulting code didn't overburden the
source control system.
Jul 19 '05 #28
bart wrote:
Why is it that everybody likes the following curly braces syntax

void function(void) {
implementations ;
}


Style is a very subjective and personal consideration.
C and C++ programmers develop or adopt a style
in order to make their code easier for themselves
and other programmers to read, understand and maintain.
If you are developing your own style, there are no rules
except that you should try to be consistent.
Otherwise, you should try to adopt a style
with which other C and C++ programmers are comfortable,
familiar or that they will at least recognize.
Personally, I try to use the same punctuation rules
that are used for ordinary (mathematical) typesetting.
Here are my recommendations :

Terminators always follow immediately after an expression

x@ for all @ in {?, :, ,, ;}

and are followed by at least one white space.
Write

x? y: z

instead of

x ? y : z

or

x?y:z

and write

void f(int, int, int); void g(double);

instead of

void f(int,int,int); void g(double);

for example.

There is no space
between some binary operators and their operands

x@y for all @ in {::, ., ->, .*, ->*, *, /, %, &, ^, |}

but there is always a space
between other binary operators and their operands

x @ y for all @ in {+, -, <<, >>;, <, <=, >, >=, ==, !=,
&&, ||, =, *=, /=, %=, +=, -=, <<=, >>=, &=, |=, ^=}

except when expressions appear as subscripts.
Write

x + y

instead of

x+y
and

x*y

instead of

x * y

for example.
But you may wish to write

A[i+1][j-1]

instead of

A[i + 1][j - 1]

for example to subscript array A.
Most unary prefix operators never have any whitespace
between themselves and their operands

@x for all @ in {::, ++, --, ~, !, -, +, &, *}

but others do

@ x for all @ in {sizeof, new, delete, delete [], throw}

No unary postfix operators

x@ for all @ in {[], (), ++, --}

ever have any whitespace between themselves and their operands.

Use the normal typesetting rules for parentheses (),
square brackets [], angle brackets <> and curly brackets {}.
No space after (, [, < or { and no space before ), ], > or }.
Write

(x)

instead of

( x )

or

(x )

or

( x)

and write

[x]

instead of

[ x ]

or

[x ]

or

[ x]

for example.
There are, of course, exceptions
where extra white space helps to make your code more readable:

double A[2][3] = {{ 1, -1, 0},
{-10, 11, -21}};
Don't give identifiers cryptic, mangled names.
Use ordinary, meaningful words, conventional symbols
or abbreviations with annotations.
Write

double distance, velocity, acceleration, mass, Force;

Force = mass*accelerati on;

or

double x; // distance
double v; // velocity
double a; // acceleration
double m; // mass
double F; // force

F = m*a;

for example.

Don't rely on defaults. Make declarations explicit.
Write

int i = 1;

instead of

i = 1;

to declare and initialize integer i and write

class X {
private:
// Representation
int I;
public:
// Constructors
// ...
};

instead of

class X {
// Representation
int I;
public:
// Constructors
// ...
};

to define the private data members of class X for example.
Use indentation to emphasize scope.
Everybody is comfortable with standard indentation:

void f()
{
// indent
}

But I indent curly brackets to the scope of the function body:

void f()
{
// indent
}

And I include the open curly bracket with the function heading:

void f() {
// indent
}

to save a line of code.

I always indent just two spaces at a time and
I place just one statement on each line so that
there is usually room for a comment at the end of each line
beginning in column 33 or 41.

Write

if (condition) {
// statements
}

instead of

if(condition) {
// statements
}

and

while (condition) {
// statements
}

instead of

while(condition ) {
// statements
}

to distinguish flow control structures from function calls.

I use

// comment

for comments in C++ and I reserve

/*
a = b;
// comment
b = c;
*/

to comment out code which may include comments.
If you find yourself in an environment
that requires you to conform to style rules with which you are not
comfortable,
consider investing a little time and effort in a program like astyle

Artistic Style
http://astyle.sourceforge.net/

which changes the appearance of C or C++ programs
by inserting or deleting whitespace.

Write

constant == variable

instead of

variable == constant

when comparing a variable to a constant for equality
so that if you write

constant = variable

by mistake, the compiler will detect the error.

I always write

x < y

or

x <= y

instead of

y > x

or

y >= x

when comparing two values so that the expression is true
when the left hand side is to the left of the right hand side
on the real number line.

Jul 19 '05 #29
In article <3F************ **@jpl.nasa.gov >,
E. Robert Tisdale <E.************ **@jpl.nasa.gov > wrote:

Is there a hyphen in anal(-?)retentive?
Jul 19 '05 #30

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

Similar topics

24
2712
by: Andrew Koenig | last post by:
PEP 315 suggests that a statement such as do: x = foo() while x != 0: bar(x) be equivalent to while True:
2
2585
by: Peter Fein | last post by:
I'm trying to use pyparsing write a screenscraper. I've got some arbitrary HTML text I define as opener & closer. In between is the HTML data I want to extract. However, the data may contain the same characters as used in the closer (but not the exact same text, obviously). I'd like to get the *minimal* amount of data between these. Here's an example (whitespace may differ): from pyparsing import *
9
3217
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images files from gif # format to png format. Now you need to change the # html code to use the .png files. So, essentially
1
3487
by: Stephen | last post by:
I am unable to get intelligent font matching to work. I used a @font-face with a Panose-1 descriptor. I tried it with both Internet Explorer 6 and Firefox on Windows 98 SE. The Panose numbers are from the Windows Registry key HKEY_LOCAL_MACHINE\Software\Microsoft\Shared Tools\Panose. I am unsure if I made a coding error, or if the browsers do not support intelligent font matching, or if there is some other cause. In the example shown...
18
1771
by: Chris Mantoulidis | last post by:
There is a LARGE number of syntax styles in most (if not all) programming languages. For example, one syntax style (my current one): .... int main() { for (int i = 0; i < 50; i++) {
4
7619
by: Bob hotmail.com> | last post by:
Everyone I have been spending weeks looking on the web for a good tutorial on how to use regular expressions and other methods to satisfy my craving for learning how to do FAST c-style syntax highlighting in C# but I have yet to find anything useful I know there are people at MS that know this stuff like the front of their hand and I know there are many people out on the web that are proficient in doing this as well but it seems nobody...
8
2243
by: Xah Lee | last post by:
the Python regex documentation is available at: http://xahlee.org/perl-python/python_re-write/lib/module-re.html Note that, i've just made the terms of use clear. Also, can anyone answer what is the precise terms of license of the official python documentation? The official python.org doc site is not clear. Note also, that the regex syntax used by Perl is the same as Python.
3
2358
by: Magnus.Moraberg | last post by:
multipleSpaces = re.compile(u'\\h+') importantTextString = '\n \n \n \t\t ' importantTextString = multipleSpaces.sub("M", importantTextString) I would have expected consecutive spaces and tabs to be replaced by M but nothing is being replaced. If I try the following, then I'm left only with M, as expected - multipleSpaces = re.compile(u'\\s+') # both vertical and horizontal
21
2455
by: REH | last post by:
It it permissible to use the constructor style cast with primitives such as "unsigned long"? One of my compilers accepts this syntax, the other does not. The failing one chokes on the fact that the type is not a single identifier or keyword. Which one is correct? For example: unsigned long x = unsigned long(y); REH
0
8838
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,...
1
9339
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8260
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, 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...
0
6081
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();...
0
4713
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...
0
4887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
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
2
2804
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2225
bsmnconsultancy
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...

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.