Thread overview
Re: A small style tip
Jan 01, 2012
Jonathan M Davis
Jan 01, 2012
Mail Mantis
Jan 02, 2012
Jonathan M Davis
Jan 02, 2012
Derek
Jan 03, 2012
Jesse Phillips
January 01, 2012
On Monday, January 02, 2012 00:16:18 Mail Mantis wrote:
> Just a small tip for those people, who use following code style:
> 
> if( cond ) {
>   body
> } else {
>   body
> }
> 
> I've found it very convenient to "attach" unittest block to my function declatarions in a same way:
> 
> private int find_pos_divisor( int first, int second ) {
>     int temp;
>     while( second ) {
>         temp = second;
>         second = first % second;
>         first = temp;
>     }
>     return abs( first );
> } unittest {
>     assert( find_pos_divisor ( 10, 20 ) == 10 );
>     assert( find_pos_divisor ( 10, 0 ) == 10 );
>     assert( find_pos_divisor ( 9, 6 ) == 3 );
>     assert( find_pos_divisor ( 10, 3 ) == 1 );
> }
> 
> Looks as a natural extension to the declaration, and helps to keep all related code in one place. Did anyone found out any more convenient D-specific conventions?

And I find that style to be seriously harming readability (braces should always be on their own line IMHO), but I guess that if you like it, it makes sense.

- Jonathan M Davis
January 01, 2012
2012/1/2 Jonathan M Davis <jmdavisProg@gmx.com>

>
> And I find that style to be seriously harming readability (braces should
> always
> be on their own line IMHO), but I guess that if you like it, it makes
> sense.
>
> - Jonathan M Davis
>

I understand your point, but don't share it - since tabulation outlines the code structure pretty well, I suppose it's only a matter of personal preference.


January 02, 2012
On Monday, January 02, 2012 01:40:30 Mail Mantis wrote:
> 2012/1/2 Jonathan M Davis <jmdavisProg@gmx.com>
> 
> > And I find that style to be seriously harming readability (braces should
> > always
> > be on their own line IMHO), but I guess that if you like it, it makes
> > sense.
> > 
> > - Jonathan M Davis
> 
> I understand your point, but don't share it - since tabulation outlines the code structure pretty well, I suppose it's only a matter of personal preference.

The placement of braces is very much a matter of personal preference.

- Jonathan M Davis
January 02, 2012
On Mon, 02 Jan 2012 12:20:36 +1100, Jonathan M Davis <jmdavisProg@gmx.com> wrote:


> The placement of braces is very much a matter of personal preference.

I suspect that any given piece of source code is read far more often by people that didn't write it. So personal code writing preferences can affect the future maintainability of code.

-- 
Derek Parnell
Melbourne, Australia
January 03, 2012
On Monday, 2 January 2012 at 03:35:25 UTC, Derek wrote:
> On Mon, 02 Jan 2012 12:20:36 +1100, Jonathan M Davis <jmdavisProg@gmx.com> wrote:
>
>
>> The placement of braces is very much a matter of personal preference.
>
> I suspect that any given piece of source code is read far more often by people that didn't write it. So personal code writing preferences can affect the future maintainability of code.

But I find this particular code style easy to read. Though I can't say the other style is harder to read, I can say it is hard for me to write.