Discussion:
Empty lines after local variable declarations
Leif Hedstrom
2018-11-11 22:44:18 UTC
Permalink
This might sound petty, but I really much prefer that we consistently put empty lines after local variable declarations. We do so much of the time, but definitely not consistently. Besides looking cleaner, doing this consistently really helps making clang-format not indent code stupidly.

For example, without the empty line we get

if (auto it = g_records_ht.find(name); it != g_records_ht.end()) {
RecRecord *r = it->second;
*buf = (char *)ats_malloc(sizeof(char) * 1024);



Note how clang-format will align the =’s, even though they really aren’t related. Whereas with the empty line, it looks a lot nicer as

if (auto it = g_records_ht.find(name); it != g_records_ht.end()) {
RecRecord *r = it->second;

*buf = (char *)ats_malloc(sizeof(char) * 1024);



My $0.01 of the day.

— Leif
Walt Karas
2018-11-12 15:59:59 UTC
Permalink
I'm more with the crowd that says you should keep the declaration as
close as possible to the first use.
Post by Leif Hedstrom
This might sound petty, but I really much prefer that we consistently put empty lines after local variable declarations. We do so much of the time, but definitely not consistently. Besides looking cleaner, doing this consistently really helps making clang-format not indent code stupidly.
For example, without the empty line we get
if (auto it = g_records_ht.find(name); it != g_records_ht.end()) {
RecRecord *r = it->second;
*buf = (char *)ats_malloc(sizeof(char) * 1024);
Note how clang-format will align the =’s, even though they really aren’t related. Whereas with the empty line, it looks a lot nicer as
if (auto it = g_records_ht.find(name); it != g_records_ht.end()) {
RecRecord *r = it->second;
*buf = (char *)ats_malloc(sizeof(char) * 1024);
My $0.01 of the day.
— Leif
Alan Carroll
2018-11-12 16:43:10 UTC
Permalink
I don't see the conflict.
Post by Walt Karas
I'm more with the crowd that says you should keep the declaration as
close as possible to the first use.
Post by Leif Hedstrom
This might sound petty, but I really much prefer that we consistently
put empty lines after local variable declarations. We do so much of the
time, but definitely not consistently. Besides looking cleaner, doing this
consistently really helps making clang-format not indent code stupidly.
Post by Leif Hedstrom
For example, without the empty line we get
if (auto it = g_records_ht.find(name); it != g_records_ht.end()) {
RecRecord *r = it->second;
*buf = (char *)ats_malloc(sizeof(char) * 1024);
Note how clang-format will align the =’s, even though they really aren’t
related. Whereas with the empty line, it looks a lot nicer as
Post by Leif Hedstrom
if (auto it = g_records_ht.find(name); it != g_records_ht.end()) {
RecRecord *r = it->second;
*buf = (char *)ats_malloc(sizeof(char) * 1024);
My $0.01 of the day.
— Leif
--
*Beware the fisherman who's casting out his line in to a dried up riverbed.*
*Oh don't try to tell him 'cause he won't believe. Throw some bread to the
ducks instead.*
*It's easier that way. *- Genesis : Duke : VI 25-28
Walt Karas
2018-11-12 16:46:04 UTC
Permalink
When you talk about a space after the declarations that seems to imply
doing the C-like thing of putting all the declarations first.
Post by Alan Carroll
I don't see the conflict.
Post by Walt Karas
I'm more with the crowd that says you should keep the declaration as
close as possible to the first use.
Post by Leif Hedstrom
This might sound petty, but I really much prefer that we consistently put empty lines after local variable declarations. We do so much of the time, but definitely not consistently. Besides looking cleaner, doing this consistently really helps making clang-format not indent code stupidly.
For example, without the empty line we get
if (auto it = g_records_ht.find(name); it != g_records_ht.end()) {
RecRecord *r = it->second;
*buf = (char *)ats_malloc(sizeof(char) * 1024);
Note how clang-format will align the =’s, even though they really aren’t related. Whereas with the empty line, it looks a lot nicer as
if (auto it = g_records_ht.find(name); it != g_records_ht.end()) {
RecRecord *r = it->second;
*buf = (char *)ats_malloc(sizeof(char) * 1024);
My $0.01 of the day.
— Leif
--
Beware the fisherman who's casting out his line in to a dried up riverbed.
Oh don't try to tell him 'cause he won't believe. Throw some bread to the ducks instead.
It's easier that way. - Genesis : Duke : VI 25-28
Leif Hedstrom
2018-11-12 22:46:45 UTC
Permalink
Post by Walt Karas
When you talk about a space after the declarations that seems to imply
doing the C-like thing of putting all the declarations first.
No. Just an empty line after the last declaration in that scope and before other code.

— Leif
Post by Walt Karas
Post by Alan Carroll
I don't see the conflict.
Post by Walt Karas
I'm more with the crowd that says you should keep the declaration as
close as possible to the first use.
Post by Leif Hedstrom
This might sound petty, but I really much prefer that we consistently put empty lines after local variable declarations. We do so much of the time, but definitely not consistently. Besides looking cleaner, doing this consistently really helps making clang-format not indent code stupidly.
For example, without the empty line we get
if (auto it = g_records_ht.find(name); it != g_records_ht.end()) {
RecRecord *r = it->second;
*buf = (char *)ats_malloc(sizeof(char) * 1024);
Note how clang-format will align the =’s, even though they really aren’t related. Whereas with the empty line, it looks a lot nicer as
if (auto it = g_records_ht.find(name); it != g_records_ht.end()) {
RecRecord *r = it->second;
*buf = (char *)ats_malloc(sizeof(char) * 1024);
My $0.01 of the day.
— Leif
--
Beware the fisherman who's casting out his line in to a dried up riverbed.
Oh don't try to tell him 'cause he won't believe. Throw some bread to the ducks instead.
It's easier that way. - Genesis : Duke : VI 25-28
Walt Karas
2018-11-12 22:51:47 UTC
Permalink
this -------------------------->
my head
Post by Leif Hedstrom
Post by Walt Karas
When you talk about a space after the declarations that seems to imply
doing the C-like thing of putting all the declarations first.
No. Just an empty line after the last declaration in that scope and before other code.
— Leif
Post by Walt Karas
Post by Alan Carroll
I don't see the conflict.
Post by Walt Karas
I'm more with the crowd that says you should keep the declaration as
close as possible to the first use.
Post by Leif Hedstrom
This might sound petty, but I really much prefer that we consistently put empty lines after local variable declarations. We do so much of the time, but definitely not consistently. Besides looking cleaner, doing this consistently really helps making clang-format not indent code stupidly.
For example, without the empty line we get
if (auto it = g_records_ht.find(name); it != g_records_ht.end()) {
RecRecord *r = it->second;
*buf = (char *)ats_malloc(sizeof(char) * 1024);
Note how clang-format will align the =’s, even though they really aren’t related. Whereas with the empty line, it looks a lot nicer as
if (auto it = g_records_ht.find(name); it != g_records_ht.end()) {
RecRecord *r = it->second;
*buf = (char *)ats_malloc(sizeof(char) * 1024);
My $0.01 of the day.
— Leif
--
Beware the fisherman who's casting out his line in to a dried up riverbed.
Oh don't try to tell him 'cause he won't believe. Throw some bread to the ducks instead.
It's easier that way. - Genesis : Duke : VI 25-28
Loading...