FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Coding style
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic     Forum Index -> DDL - D Dynamic Libraries
View previous topic :: View next topic  
Author Message
pragma



Joined: 28 May 2004
Posts: 607
Location: Washington, DC

PostPosted: Mon Jan 09, 2006 5:03 am    Post subject: Reply with quote

(Don, it looks like PHPBB ate your indents. You might want to try a [code] block instead. Wink)

Cool, I never knew these had names. That almost felt like a personality test.

Personally, I fell into that particular style simply becuase it lets me read the code without necessarily reading the brackets: they become more like window-dressing, with the indentation more directly supporting the nesting of statments. Then along came Java, which influenced my style to what you see today. ($0.02)

Personal bias aside, I think we've been doing very well with the current fusion of styles within DDL. If everyone involved wants to converge on a common bracket style along with the 4-spc indent we've compromised on, then we should do so quickly - I just want to be fair. Otherwise, I don't think we loose much by staying the course and continuing as we have already.

That having been said, I think we should look into this, and similar cosmetic treatments to existing code, as more of a code-cleanup activity which would be more appropriate for the V1.0 milestone.
_________________
-- !Eric.t.Anderton at gmail
Back to top
View user's profile Send private message Yahoo Messenger
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Mon Jan 09, 2006 9:55 am    Post subject: Re: Brace placement - catalogue of options Reply with quote

As pragma mentioned, using "code" blocks makes your point more clear.

Don Clugston wrote:

BSD or Allman style (I don't know where that name comes from).

Code:
class A
{
  int func (int x)
  {
    if (x==2)
    {
       return x*3;
    }
    else
    {
       return x*4;
    }
  }
}



Stroustrup (http://public.research.att.com/~bs/bs_faq2.html)
Functions are on a line by themselves

Code:
class A {
  int func (int x)
  {
    if (x==2) {
       return x*3;
    }
    else {
       return x*4;
    }
  }
}


-------------
Java (http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html)

Code:
class A {
  int func (int x) {
    if (x==2) {
       return x*3;
    } else {
       return x*4;
    }
  }
}


-------------
Eckel (http://www.camtp.uni-mb.si/books/Thinking-in-C++/TIC2Vone-distribution/html/AppendixA.html)

Code:
class A {
  int func (int x) {
    if (x==2) {
       return x*3;
    }
    else {
       return x*4;
    }
  }
}


-------------
Is this Alignment on Brackets (AoB)?

Code:
class A
   {
   int func (int x)
       {
       if (x==2)
          {
          return x*3;
          }
       else
          {
          return x*4;
          }
       }
    }


--------------
Pig's Breakfast
Different every time.
Code:
class A
{
  int func (int x)  {
       if (x==2)
          {
          return x*3;
          }
       else {  return( x*4 );    }
       }
}
Back to top
View user's profile Send private message AIM Address
larsivi
Site Admin


Joined: 27 Mar 2004
Posts: 453
Location: Trondheim, Norway

PostPosted: Mon Jan 09, 2006 10:05 am    Post subject: Reply with quote

If we are to choose a bracket style, I would vote for Stroustroup.

As for spacing in if's and such, I'm most used to

<code>
if (foo) {

}
elseif (foo == 3) {

}
</code>

That is space before and after paranthesis, and around operators in the expression.

Oh, and I find "return(3);" strange compared to "return 3;"

Anyway, as long as we don't use tabs, I won't fight over these Wink
Back to top
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Mon Jan 09, 2006 12:30 pm    Post subject: Reply with quote

I like BSD style and use something similar to it.

But, I'd be willing to compromise on this, if people here were to agree on a system to use for common projects.

-JJR
Back to top
View user's profile Send private message
larsivi
Site Admin


Joined: 27 Mar 2004
Posts: 453
Location: Trondheim, Norway

PostPosted: Mon Jan 09, 2006 12:33 pm    Post subject: Reply with quote

JJR wrote:

But, I'd be willing to compromise on this, if people here were to agree on a system to use for common projects.

-JJR


Now you're pushing it Wink I think some agreement might be possible within a project, but for several projects? Shocked
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Mon Jan 09, 2006 12:39 pm    Post subject: Reply with quote

larsivi wrote:
JJR wrote:

But, I'd be willing to compromise on this, if people here were to agree on a system to use for common projects.

-JJR


Now you're pushing it Wink I think some agreement might be possible within a project, but for several projects? Shocked


*cough* *splutter* Shocked

There is but one true path of alignment ~ the Steve will announce it tomorrow AM ...
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Mon Jan 09, 2006 1:41 pm    Post subject: Re: Brace placement - catalogue of options Reply with quote

jcc7 wrote:
As pragma mentioned, using "code" blocks makes your point more clear.

Don Clugston wrote:

BSD or Allman style (I don't know where that name comes from).

Code:
class A
{
  int func (int x)
  {
    if (x==2)
    {
       return x*3;
    }
    else
    {
       return x*4;
    }
  }
}


I didn't know that BSD style even existed!

Nice to see it, since it does have that "code block" flavour to it. The style used by mango (AoB) is very close to BSD style, with a twist: key constructs using parenthesis cause the following code (and braces) to align correspondingly. Thus, keywords while, for, foreach, if, else, switch et. al. cause following code to indent up to the opening paren.

There are a couple of specific exclusions (such as function declarations) where paren alignment would not add anything of value to the clarity of code-blocks. In such cases, formatting reverts to BSD style.

AoB look like this:

Code:
class Class
{
        void foo (bool blah)
        {
               if (blah)
                  {
                  // do something regarding blah
                  writefln ("blah is true");
                  blah = false;
                  }
               else
                  {
                  // do something else
                  writefln ("blah is false");
                  }

               foreach (char line[]; lines)
                       {
                       line ~= "\n";
                       writef (line);
                       }
        }
}

The distinction is that "container" constructs (like classes, structs, and function declarations) follow BSD, whereas the code proper has further emphasis upon the block aspect, to make the controlling keyword jump out at you. I find the braces tend to disappear using this approach within the code (or at least emphasize the block aspects), whereas they are highlighted by the contrasting BSD aspects. I like this, as it causes the "container" constructs to stand out somewhat against the code ~ a bit like background colouring?

Regardless, code formatting can be a notoriously personal thing: like religion in some respects, or like one's favourite editor program Smile
Back to top
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Mon Jan 09, 2006 2:46 pm    Post subject: Reply with quote

larsivi wrote:
JJR wrote:

But, I'd be willing to compromise on this, if people here were to agree on a system to use for common projects.

-JJR


Now you're pushing it Wink I think some agreement might be possible within a project, but for several projects? Shocked


Oh dear... I made that sound somewhat ambiguous, didn't I? I did say common projects, though. Smile

I just mean any project that a group of individuals are working on together. Not all projects at dsource need follow the same path.

-JJR
Back to top
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Mon Jan 09, 2006 2:52 pm    Post subject: Reply with quote

kris wrote:
There is but one true path of alignment ~ the Steve will announce it tomorrow AM ...


That he will... and I'm kind of curious to know what he's got up his sleeve this time. Whatever it is, I bet his RDF will be set to maximum tomorrow. Wink

I've been very close to being suckered in the past... and I'm not so sure I can hold out for much longer...

-JJR
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Mon Jan 09, 2006 3:04 pm    Post subject: OT - MacWorld Reply with quote

JJR wrote:
kris wrote:
There is but one true path of alignment ~ the Steve will announce it tomorrow AM ...


That he will... and I'm kind of curious to know what he's got up his sleeve this time. Whatever it is, I bet his RDF will be set to maximum tomorrow. Wink

I've been very close to being suckered in the past... and I'm not so sure I can hold out for much longer...

Last Mac I bought was an original 128KB Macintosh, modified to 512KB with a 10MB hard-dive (and has all the engineers sigs inside it). The next machine for me will likely be a VIIV oriented MacMini ~ dual-boot to Win32, and attached to Dell's recent LCD release (the 30" one is easier to work with than two 21's, and has the same resolution). Naturally, I'm hoping the new MacMini will have dual-DVI support to drive the 2560x1600 display, and will be as completely silent as their current siblings. Hook that up to some NAS, and you've got a wicked recording-studio slash development machine slash household media server Wink
Back to top
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Mon Jan 09, 2006 3:24 pm    Post subject: Re: OT - MacWorld Reply with quote

kris wrote:
Last Mac I bought was an original 128KB Macintosh, modified to 512KB with a 10MB hard-dive (and has all the engineers sigs inside it). The next machine for me will likely be a VIIV oriented MacMini ~ dual-boot to Win32, and attached to Dell's recent LCD release (the 30" one is easier to work with than two 21's, and has the same resolution). Naturally, I'm hoping the new MacMini will have dual-DVI support to drive the 2560x1600 display, and will be as completely silent as their current siblings. Hook that up to some NAS, and you've got a wicked recording-studio slash development machine slash household media server Wink


I could never have afforded the 128K Mac when it first came out. Smile I was about 6 or 7 when my folks bought it, and I literally grew up using it: learned to type, play games, do schol work... etc. They never replaced it for many years, even though it became horribly out of date. It was a monstrous spend for them since they didn't have much money at the time. They eventually bought a huge dud of a powerpc mac later; it worked barely, but now sits unused in basement storage.

I've been very interested in getting a mac for some time... but haven't been quite convinced it was worth the spend. When they move to intel (this month?)... I may just bite... because as you mention, I can probably dual boot Mac OS X and Windows (Vista?). Mac mini will be the easiest to transition into, but I'm doubting it will have dual DVI out. I would love to be pleasantly surprised, though.

Ohhh... the 30" Dell screen. I've heard about that. I just bought a Dell 21" LCD display for a good price from Dell; I love it. They make good screens. I'm not so impressed with dual-DVI... though. I wish those big screens just used one. But I guess it's better than using two LCDs.

Now look what you did, Kris! You made us get off topic... for shame! Laughing
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Tue Jan 10, 2006 11:36 am    Post subject: Re: OT - MacWorld Reply with quote

JJR wrote:
Now look what you did, Kris! You made us get off topic... for shame!

Sorry about that Smile

Just thought I'd note that the HyperMacMini didn't make it to the show Crying or Very sad
Back to top
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Tue Jan 10, 2006 12:04 pm    Post subject: Re: OT - MacWorld Reply with quote

kris wrote:
Just thought I'd note that the HyperMacMini didn't make it to the show Crying or Very sad

That's too bad. I've been searching for an excuse to get a Mac Mini for home Wink We've got a G4 Cube that goes largely unused however, and I'm trying to convince the wife to resurrect it as a dedicated server.

On the topic of formatting--I've always used the BSD style, though I tend to space my parenthesis differently. I have a bit of a love-hate affair with this method:
Code:

if( a == b )
{
    fn( a, b );
}
else if( x + y == 10 &&
         y - 2 > 5 )
{
    fn( x, y );
}

I find it's more readable in the general case, but it can be a bit irritating for complex expressions if you're determined to fit everything on one line.
Back to top
View user's profile Send private message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Mon Jul 31, 2006 8:28 pm    Post subject: Reply with quote

BSD style and tab characters for life. And spaces around operands and after commas.

Anyone notice Walter's coding "style"? Have a look at DMD/Phobos source. Hmm.. it indents four spaces, but when you get to two indents, it puts a tab.. then four more spaces, then two tabs. And code on the same line as braces like

Code:
if(foo)
{   int x = 4;
    blah blah
}


I.. I can't get my head around it.
Back to top
View user's profile Send private message
pragma



Joined: 28 May 2004
Posts: 607
Location: Washington, DC

PostPosted: Mon Jul 31, 2006 8:58 pm    Post subject: Reply with quote

JarrettBillingsley wrote:
I.. I can't get my head around it.


I don't know if anyone else has managed to cultivate this "skill", but I've learned to read code and get a feeling for how many people have touched it just by the mish-mash of coding styles present.

Walter's code reads as though it was written by at least two people, but since we know its most likely just him, this leads me to the conclusion that it has more to do with him patching his work by using a few keystrokes as possible. Not that there's anything wrong with that. I've changed some of my habits at least twice since I started coding D - and who knows how many times before that.

But yea... its a wierd style.
_________________
-- !Eric.t.Anderton at gmail
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DDL - D Dynamic Libraries All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group