|
I've been spoiled for years by being in a situation where I set the standards and control the direction on account of my experience.
That said, I understand where you are coming from, but I don't envy you your coworkers. It sounds like you don't have enough written coding standards.
If you all wanted to increase your productivity and reduce problems, you'd have linting and formatting scripts for this if the project is significant enough in size. Or at least that's what I'd do, as it tends to pay for itself in terms of more legible and consistent code, and shorter code reviews.
To err is human. Fortune favors the monsters.
|
|
|
|
|
I'm in the correct camp:
void AFunc()
{
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Indented braces ?
Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
Yep. It's called "Whitesmiths": Indentation style - Wikipedia[^]
It's more consistent than Allman.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
That would depend on whether you consider the braces to be a part of the content or the header.
If your answer is neither you should consider GNU style.
|
|
|
|
|
pkfox wrote: I'm in the second I second you.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
I distinctly remember a similar post on this site about 12 years ago.
The replies were all the same then as they are today.
|
|
|
|
|
The later, is easier for me to follow.
PartsBin an Electronics Part Organizer - An updated version available!
JaxCoder.com
|
|
|
|
|
First: Java, Javascript, PHP
Second: C, C++, C#
Who needs braces: Python
|
|
|
|
|
Richard MacCutchan wrote: Who needs braces: Python
FTFY!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Come on!! What's next? Tabs vs spaces?
Mircea
|
|
|
|
|
A POX upon Tabs.
I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.
|
|
|
|
|
Please don't go there! One unwinnable debate is enough
We all have our ways of setting braces and indenting which we know to be right and we'll quash the unbelievers who dare to have a different opinion. We've done that since the time of the first crusade
Mircea
|
|
|
|
|
I f-f-fart in the general direction of spaces. I had to work on code where some dev used a single space, some two, some 3 and some idiot 8.
As a result it was completely unindented. With tabs there wouldn't have been any issue.
GCS/GE d--(d) s-/+ a C+++ U+++ P-- L+@ E-- W+++ N+ o+ K- w+++ O? M-- V? PS+ PE Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
I reject the premise of the question.
|
|
|
|
|
I prefer the first one in javascript/typescript and the second one in C#.
___ ___ ___
|__ |_| |\ | | |_| \ /
__| | | | \| |__| | | /
|
|
|
|
|
The first one wasn't invented for clarity or ease of reading, but for squeezing more text onto paper.
|
|
|
|
|
I used to be in the first camp, I had to adapt to MISRA rules and now I prefer the second. It's way easier to find missing braces, move braced code and reindent it, even with powerful syntax highlighting - which is not a given in most IDEs for embedded development.
GCS/GE d--(d) s-/+ a C+++ U+++ P-- L+@ E-- W+++ N+ o+ K- w+++ O? M-- V? PS+ PE Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
exactly.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I'm in this camp
void AFunc()
{
}
And for short/inline statements in this one:
void AFunc() {}
I never mix them.
There is only one Vera Farmiga and Salma Hayek is her prophet!
Advertise here – minimum three posts per day are guaranteed.
|
|
|
|
|
In the second one, even when an If has only one command to be executed.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
modified 12-Dec-22 10:28am.
|
|
|
|
|
The only sane format is:
void Afunc()
{
}
Why #1:
Because half the non-curly scoped languages out there use words or other symbols for marking scope, and BEGIN just doesn't look right at the end of the line!
Why #2:
Java version 1.1 (the first language I used and learned that trailed the curly brace in books) was so horrible, it gave me one more thing to hate!
Why #3:
Other than using some automated reformatting that kicks lines to the right or left, I find it very difficult to find missing curly braces in some logic. Matched ones line up very clearly. If they trail the line, when things get a few indents deep, the code becomes hard to read and finding that one line you inserted outside of them takes more time than just begin clear the first time. So, always on its own line!
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
|
|
|
|
|
I'd add that a number of us were influenced by K&R C, where you had
int foo(str, y)
char *str;
int y;
{
}
So an opening curly bracket at the beginning of a function made sense. But then we have:
if(a == b ){
} ditto for while , for , etc. Yes, it is inconsistent between functions and every other compound block of code, but blessed by Kernighan and Ritchie, so who am I to argue. So maybe that's Why #4.
Keep Calm and Carry On
|
|
|
|
|
godfetish wrote: BEGIN just doesn't look right at the end of the line! I really love 'It just ain't done!' arguments!
BEGIN is perfectly fine at the end of the line. In my Pascal days, that was the established standard. Note that Pascal switch statements - CASE value OF - uses the OF keyword to start the case list. I never saw anyone put OF on a separate line. It is matched by an END, just like BEGIN. So why would there be a difference between BEGIN ... END and CASE OF ... END? Or would you write Pascal code as
CASE i
OF
0 : Write('zero');
1 : Write('one');
2 : Write('two');
3,4,5,6,7,8,9,10: Write('?')
END; Note that if you put BEGIN and OF at separate lines, they are still at the end of the line
|
|
|
|