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 ... And what makes you think it's easier to read?
Umm...the fact that *he* finds it easier to read, perhaps? (Does an opinion
need a reason?) And I agree. For some reason (i have no idea why), I find
it much easier to quickly spot braces that are aligned vertically than a
closing brace matching the start of a line of text. So, for me, it's easier
to read.
On the other hand, my boss, who wrote the code I'm updating and maintaining,
likes it the other way. Must be why he's the boss. :-)
-Howard
"bart" <ba**@thatissec ret.nlm> wrote in message
news:3f******** *************** @news.xs4all.nl ... 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
I prefer your second style in functions only. If statement blocks like I
prefer to use the first. I just don't see the point in dedicating an ENTIRE
line to a measly '{'. I'd much rather write:
if (x == 10) {
}
than:
if (x == 10)
{
}
As long as my closing '}' is lined up DIRECTLY under the statement that
opened it, I find it easy to read.
bart wrote: 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 ; }
Pick a style any style and stick to it. Personally I prefer
function()
{
if (expression) {
statements;
}
}
but that is because it is our house style. Prior to my
current place I preferred another style, it doesn't matter a
jot, which you use. But if you are programming with others a
standard style is a great help. I can look over any piece of
code in the company and the layout is the same, it looks my
code, and my code looks like anyone else's. The standard
layout helps you to understand what is happening.
Occasionally we receive code from some outside source that
does not conform to our standard, and it is always
difficult to read. That doesn't mean that it is wrong, or a
bad style, its just that it isn't the one we are used to.
"bart" <ba**@thatissec ret.nlm> wrote in message news:<3f******* *************** *@news.xs4all.n l>... 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
Bart...I agree with the others. It's a matter of preference. I'm
pretty new to C++, and as I was getting started, I read several essays
on styles. I ended up using Bruce Eckel's book's style. eg:
function(){
implementations ;
}
I like this style because:
1) it takes up less space, vertically.
2) you read the function name, immediately see the open bracket, and
then look down to where the scope for that indentation ends.
My one minor exception to that I sometimes adopt is for if else
statements:
function(){
if(expression){
statement1;
statement2;
}else{
statement1;
statement2;
}
}
However, I also sometimes do single line if else if it fits nicely
onto one line.
function(){
if(expression) statement; else statement;
}
Tim Clacy wrote: ...and just to set the cat amongst the pigeons, I'm quite fond of this:
void fn() { while (...) { switch (...) { case : case : default : } } }
:-)
I'm fond of very short functions, and replacing switch statements with
virtual messages, so my bad-ass pidgeon is not alarmed by your silly
little cat.
--
Phlip
"J. Campbell" <ma**********@y ahoo.com> wrote in message
news:b9******** *************** ***@posting.goo gle.com...
<snip>
< However, I also sometimes do single line if else if it fits nicely
< onto one line.
<
< function(){
< if(expression) statement; else statement;
< }
I don't meant to be fickle (I think this is the first occasion of me using
that word :)
but if your expression and statements fit nicely on a single line, wouldn't
you be better off writing
expression ? true_statement : false_statement ;
That way, you dont have to write if, any brackets, an extra ; and the else.
Clive wrote: "J. Campbell" <ma**********@y ahoo.com> wrote in message news:b9******** *************** ***@posting.goo gle.com... <snip> < However, I also sometimes do single line if else if it fits nicely < onto one line. < < function(){ < if(expression) statement; else statement; < }
I don't meant to be fickle (I think this is the first occasion of me using that word :) but if your expression and statements fit nicely on a single line, wouldn't you be better off writing
expression ? true_statement : false_statement ;
That way, you dont have to write if, any brackets, an extra ; and the else.
The problem with both of these 'styles' is that you can't
put a simple breakpoint on any of the statements. The best
you can do is put a conditional breakpoint (based on
expression) on the line and then single step the expression.
With the tertiary expression both true_statement and
false_statement also have to be type compatible.
Phlip wrote: Tim Clacy wrote:
...and just to set the cat amongst the pigeons, I'm quite fond of this:
void fn() { while (...) { switch (...) { case : case : default : } } }
:-)
I'm fond of very short functions, and replacing switch statements with virtual messages, so my bad-ass pidgeon is not alarmed by your silly little cat.
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() { ... } };
"Clive" <cl***@clive.cl ive> wrote in message
news:bm******** **@enyo.uwa.edu .au... I don't meant to be fickle (I think this is the first occasion of me using that word :) but if your expression and statements fit nicely on a single line,
wouldn't you be better off writing
expression ? true_statement : false_statement ;
Statements are not allowed in expressions. You cannot
write, for instance ...
someFlag ? continue : break;
Also, if you used the syntactically correct form of...
expression ? true_expression : false_expressio n;
.... instead, it still must also be semantically correct so
that the types returned by the sub-expressions are
assignable to a common type (which then becomes the
type of the entire expression). This, for instance,
would be syntactically correct, but semantically illegal:
someFlag ? 123 : "";
IMO, it is always better to use the if(){}else{} instead
of the ?: operator in all contexts that allow a statement,
and use the conditional operator only when the context
*requires* (rather than just *allows*) an expression.
Cheers!
- Risto -
While it was 13/10/03 10:15 am throughout the UK, Risto Lankinen
sprinkled little black dots on a white screen, and they fell thus:
<snip> This, for instance, would be syntactically correct, but semantically illegal:
someFlag ? 123 : "";
But I've just tried
someFlag ? (void) 123 : (void) "";
and gcc/g++ accepts it.
IMO, it is always better to use the if(){}else{} instead of the ?: operator in all contexts that allow a statement, and use the conditional operator only when the context *requires* (rather than just *allows*) an expression.
Guess you're kind of right there.
But, which do most people prefer:
if(qwert > 100) {
yuiop = 50;
} else {
yuiop = 25;
}
or
yuiop = (qwert > 100) ? 50 : 25;
or even
yuiop = ((qwert > 100) + 1) * 25;
....?
Stewart.
--
My e-mail is valid but not my primary mailbox. Please keep replies on
on the 'group where everyone may benefit. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:
|
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 *
|
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
|
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...
|
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++)
{
| |
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...
|
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.
|
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
|
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
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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: 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: 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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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.
| |