Jump to page: 1 2
Thread overview
[phobos] excessive vertical spacing?
Jan 28, 2013
Jacob Carlborg
Jan 28, 2013
Brad Roberts
Jan 28, 2013
Jonathan M Davis
Jan 28, 2013
Jacob Carlborg
Jan 28, 2013
Jonathan M Davis
Jan 28, 2013
Dmitry Olshansky
January 27, 2013
There's been sporadic discussion every now and then about recommended style etc. Time to add to it :o).

I've noticed excessive empty lines in a few Phobos modules. For example:

        @property SysTime timeLastModified()
        {
            _ensureStatDone();

            return SysTime(unixTimeToStdTime(_statBuf.st_mtime));
        }

And so on for functions of 2-5 lines, and there's a bunch of them. It would be difficult to argue that the vertical space adds to clarity as the whole thing is just there.

Can we agree to be a bit more sparing with empty lines? If there's one resource that's not abundant to all of us, that must be vertical space.


Thanks,

Andrei
_______________________________________________
phobos mailing list
phobos@puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos

January 28, 2013

On Jan 27, 2013, at 09:11 PM, Andrei Alexandrescu <andrei@erdani.com> wrote:

> There's been sporadic discussion every now and then about recommended style etc. Time to add to it :o).
>
> I've noticed excessive empty lines in a few Phobos modules. For example:
>
> @property SysTime timeLastModified()
> {
> _ensureStatDone();
>
> return SysTime(unixTimeToStdTime(_statBuf.st_mtime));
> }
>
> And so on for functions of 2-5 lines, and there's a bunch of them. It would be difficult to argue that the vertical space adds to clarity as the whole thing is just there.
>
> Can we agree to be a bit more sparing with empty lines? If there's one resource that's not abundant to all of us, that must be vertical space.

It don't understand the obsession in cutting down on vertical space. Are you afraid you're going to run out. It's not like we're writing on a physical piece of paper.

I think it adds clarity. Not using a few empty newlines here and there is like writing a piece of text without any paragraphs. It just makes it harder to read.

This particular example you give would make no difference with or without the empty newline.

--
/Jacob Carlborg

January 28, 2013
On 1/28/13 3:45 AM, Jacob Carlborg wrote:
> It don't understand the obsession in cutting down on vertical space. Are
> you afraid you're going to run out. It's not like we're writing on a
> physical piece of paper.

"Obsession" would overstate it. Gratuitous empty lines reduce the amount of information one can absorb off of any given screen.

> I think it adds clarity. Not using a few empty newlines here and there
> is like writing a piece of text without any paragraphs. It just makes it
> harder to read.
>
> This particular example you give would make no difference with or
> without the empty newline.

Great. Then let's not do it.


Thanks,

Andrei

_______________________________________________
phobos mailing list
phobos@puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos

January 28, 2013
On 1/27/2013 12:11 PM, Andrei Alexandrescu wrote:
> There's been sporadic discussion every now and then about recommended style etc. Time to add to it :o).
> 
> I've noticed excessive empty lines in a few Phobos modules. For example:
> 
>         @property SysTime timeLastModified()
>         {
>             _ensureStatDone();
> 
>             return SysTime(unixTimeToStdTime(_statBuf.st_mtime));
>         }
> 
> And so on for functions of 2-5 lines, and there's a bunch of them. It would be difficult to argue that the vertical space adds to clarity as the whole thing is just there.
> 
> Can we agree to be a bit more sparing with empty lines? If there's one resource that's not abundant to all of us, that must be vertical space.
> 
> 
> Thanks,
> 
> Andrei

I actually prefer the blank line.  For me, blank lines separate logically separate parts of code.  If a set of lines have no separating vertical white space it indicates that they're directly related.  In a two line example like this, it matters a little less, but it does still matter.

If functions are so long that they can't be displayed as a whole, it's not the vertical white space that's at issue, it's the amount of code as a whole.. time to split up.

I acknowledge that a lot of this boils down to style and screen and font sizes.  My typical editor session is about 120 cols, 80 rows, two side by side on a 24" monitor.  Occasionally another pair of those on the second monitor (though that's usually browser + mail client).

So, no, I don't agree, but not passionately.

My 2 cents,
Brad

_______________________________________________
phobos mailing list
phobos@puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos

January 28, 2013
On 1/28/13 9:46 AM, Brad Roberts wrote:
> I actually prefer the blank line.

I'm surprised, but it's a good lesson to learn. I honestly believed nobody would prefer that.

Andrei
_______________________________________________
phobos mailing list
phobos@puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos

January 28, 2013
On Monday, January 28, 2013 10:50:10 Andrei Alexandrescu wrote:
> On 1/28/13 9:46 AM, Brad Roberts wrote:
> > I actually prefer the blank line.
> 
> I'm surprised, but it's a good lesson to learn. I honestly believed nobody would prefer that.

I pretty much always put a blank line before return statements precisely so that they're visibly separate from the rest of the code. It's the same reason why I pretty much always have a blank line after vairable declarations or before or after if blocks or loops. It's less of a big deal in this particular case, because there's only one line of code above it, but I pretty much agree with Brad's reasoning on this. Blank lines are good for logically separating out sections of code, and I use them for that quite a bit.

- Jonathan M Davis
_______________________________________________
phobos mailing list
phobos@puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos

January 28, 2013
On 28 jan 2013, at 21:04, Jonathan M Davis <jmdavisProg@gmx.com> wrote:

> On Monday, January 28, 2013 10:50:10 Andrei Alexandrescu wrote:
>> On 1/28/13 9:46 AM, Brad Roberts wrote:
>>> I actually prefer the blank line.
>> 
>> I'm surprised, but it's a good lesson to learn. I honestly believed nobody would prefer that.
> 
> I pretty much always put a blank line before return statements precisely so that they're visibly separate from the rest of the code. It's the same reason why I pretty much always have a blank line after vairable declarations or before or after if blocks or loops. It's less of a big deal in this particular case, because there's only one line of code above it, but I pretty much agree with Brad's reasoning on this. Blank lines are good for logically separating out sections of code, and I use them for that quite a bit.


I agree. I always put a blank line between expressions and statements:

int a = 3;
int b = 4 + b;

foreach (i ; a .. b)
{
}

b = 3;

-- 
/Jacob Carlborg

_______________________________________________
phobos mailing list
phobos@puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos

January 29, 2013
29-Jan-2013 00:04, Jonathan M Davis пишет:
> On Monday, January 28, 2013 10:50:10 Andrei Alexandrescu wrote:
>> On 1/28/13 9:46 AM, Brad Roberts wrote:
>>> I actually prefer the blank line.
>> I'm surprised, but it's a good lesson to learn. I honestly believed
>> nobody would prefer that.
> I pretty much always put a blank line before return statements precisely so
> that they're visibly separate from the rest of the code. It's the same reason
> why I pretty much always have a blank line after vairable declarations or
> before or after if blocks or loops. It's less of a big deal in this
> particular case, because there's only one line of code above it, but I pretty
> much agree with Brad's reasoning on this. Blank lines are good for logically
> separating out sections of code, and I use them for that quite a bit.
And obligatory view from the other side of the fence.

I hate empty lines after "variable declarations or before or after if blocks".
D isn't Fortran and variables typically get defined right before being used
and go out of scope as soon as possible. Distinguishing if statements is
frankly strange in general, as fonts and editors provide enough of control
to make these stand out.

Same goes for putting a line before return statement - the return keyword is already
highlighted, and pretty much always expected. Most of the time (YMMV) it's either
an early return as (if+return) or the good old return at the end of function.

I'd say saved vertical space adds more clarity especially with modern wide-screen laptops ;)
And quite a lot of it is already wasted since we have "brace on its own line" as a style guideline.

I don't mind (and in fact like) empty lines that indicate semantic blocks or steps inside of a function.
I'd even put a comment in such a case. One of examples is the exception-safe code as there
is always a line between the stuff that may fail with exception (action)
and the stuff that shall never do (commit).

-- 
Dmitry Olshansky

_______________________________________________
phobos mailing list
phobos@puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos
January 28, 2013
On 1/28/13 3:51 PM, Dmitry Olshansky wrote:
> I hate empty lines after "variable declarations or before or after if
> blocks".
> D isn't Fortran and variables typically get defined right before being used
> and go out of scope as soon as possible.

I agree and was about to submit a similar protest but gave up on that.

> Distinguishing if statements is
> frankly strange in general, as fonts and editors provide enough of control
> to make these stand out.
> Same goes for putting a line before return statement - the return
> keyword is already
> highlighted, and pretty much always expected. Most of the time (YMMV)
> it's either
> an early return as (if+return) or the good old return at the end of
> function.
>
> I'd say saved vertical space adds more clarity especially with modern
> wide-screen laptops ;)
> And quite a lot of it is already wasted since we have "brace on its own
> line" as a style guideline.
>
> I don't mind (and in fact like) empty lines that indicate semantic
> blocks or steps inside of a function.
> I'd even put a comment in such a case. One of examples is the
> exception-safe code as there
> is always a line between the stuff that may fail with exception (action)
> and the stuff that shall never do (commit).

I agree with all of the above. Let me add that the need for vertical blank lines may sometimes reveal the opportunity of refactoring into smaller functions.


Andrei
_______________________________________________
phobos mailing list
phobos@puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos

January 28, 2013
On 1/28/13 3:26 PM, Jacob Carlborg wrote:
> I agree. I always put a blank line between expressions and statements:

To restate what Dmitry said: I think this is a Pascal-ism that we need to actively move away from. It is actually damaging.

Andrei
_______________________________________________
phobos mailing list
phobos@puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos

« First   ‹ Prev
1 2