|
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 
|
|
|
|
|
The compiler doesn't care. Neither do I.
|
|
|
|
|
You're not writing for the compiler.
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 usually do. The compiler is only one who really cares, and analyzes my writings thoroughly!
|
|
|
|
|
Well, the compiler doesn't care if you use hungarian notation, but this is how office wars start.
There is only one Vera Farmiga and Salma Hayek is her prophet!
Advertise here – minimum three posts per day are guaranteed.
|
|
|
|
|
First, always. The single "{" hanging in the air - taken to the extreme becomes:
if (...)
{
..
}
else
{
..
}
versus
if () {
..
} else {
..
}
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
The first style is usually called "K&R", while the second is often named Allman. There are countless variations based on indentation of the following code body. I started out using K&R when I learned 'C' from, er, the K&R. When I learned C# where the convention leans hard toward Allman, I found I preferred Allman braces.
I have significant visual problems: myopia, astigmatism, presbyopia, and glaucoma in the left eye, and the right one is made of plastic. Did I mention the cataract forming in the left eye?
Allman adds white-space and highlights braces, both of which improve readability greatly for me.
One good thing about venerable VS2008 still being an active tool in our shop is that I have a Visual Studio editor macro that converts K&R style to Allman. I don't like the reformatters in later editions of Visual Studio.
Software Zen: delete this;
|
|
|
|
|
I'm totally K&R, but I upvoted this anyway just because you're cool. #no_shame
Jeremy Falcon
|
|
|
|
|
Thanks Jeremy. Glad to see you coming around here again!
Software Zen: delete this;
|
|
|
|
|
I generally prefer the latter but it depends ... = [](){ return on my mood + on the number of enclosed statements + on the kind of those statements e.g. for some reason I like lambda 's all in one line + on the complexity of those statements + on whatever surprises the automatic formatting of IDEA has in store for me; }();
|
|
|
|
|
This is the only correct way:
void AFunc() {
}
Embrace it. Join the dark side.
Jeremy Falcon
|
|
|
|
|
Not what's usually done on leaving (9)
"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!
|
|
|
|
|
Departing ?
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
|
|
|
|
|
Nope!
"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!
|
|
|
|
|
Departure ?
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
|
|
|
|
|
You are up tomorrow!
Sorry about rejecting "DEPARTING", but it didn't quite fit the first part of the clue.
"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!
|
|
|
|
|
No worries I thought it was one or the other - I just chose the wrong one first.
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
|
|
|
|
|
Explanation, please?
Happiness will never come to those who fail to appreciate what they already have. -Anon
|
|
|
|
|
Not what's usually done DEPARTURE - as in "departure from our usual procedures".
on leaving DEPARTURE - as in "use the departure terminal on leaving the country"
"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!
|
|
|
|
|
Thank you
Happiness will never come to those who fail to appreciate what they already have. -Anon
|
|
|
|
|
You're welcome!
"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!
|
|
|
|
|
Wordle 541 4/6
⬛🟨🟨⬛⬛
⬛⬛⬛🟨🟨
⬛🟨⬛🟩🟩
🟩🟩🟩🟩🟩
|
|
|
|