www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - New D coding convention style guide

reply Walter Bright <newshound digitalmars.com> writes:
http://thc.segfault.net/root/phun/unmaintain.html
Aug 19 2006
next sibling parent kris <foo bar.com> writes:
Walter Bright wrote:
 
 http://thc.segfault.net/root/phun/unmaintain.html

Some good advice on tab-usage there: "Never underestimate how much havoc you can create by indenting with tabs instead of spaces, especially when there is no corporate standard on how much indenting a tab represents. Embed tabs inside string literals, or use a tool to convert spaces to tabs that will do that for you."
Aug 19 2006
prev sibling next sibling parent "Chris Miller" <chris dprogramming.com> writes:
On Sat, 19 Aug 2006 20:03:35 -0400, Walter Bright  
<newshound digitalmars.com> wrote:
 http://thc.segfault.net/root/phun/unmaintain.html

I'll begin converting my code...
Aug 20 2006
prev sibling parent reply Bruno Medeiros <brunodomedeiros+spam com.gmail> writes:
Walter Bright wrote:
 
 http://thc.segfault.net/root/phun/unmaintain.html
  From - Mon

Speaking of which (but seriously), we may not get a consensus on tabs, and maybe justifiedly so, but one other thing with DMD's coding convention that troubles me is the braces formatting: if (b) { dg(); return true; } ... whoa :/ . Where did that come from? It's unusual (I personally have never seen C-family code formatted that way), and seems awkward to me. How about: // BSD/Allman style if (b) { dg(); return true; } or (my preference) : // K&R style if (b) { dg(); return true; } ?
Aug 21 2006
next sibling parent Ivan Senji <ivan.senji_REMOVE_ _THIS__gmail.com> writes:
Bruno Medeiros wrote:
 Walter Bright wrote:
 http://thc.segfault.net/root/phun/unmaintain.html
  From - Mon

Speaking of which (but seriously), we may not get a consensus on tabs, and maybe justifiedly so, but one other thing with DMD's coding convention that troubles me is the braces formatting: if (b) { dg(); return true; } .... whoa :/ . Where did that come from? It's unusual

It sure is!
 (I personally have 
 never seen C-family code formatted that way), and seems awkward to me. 
 How about:
 
     // BSD/Allman style
     if (b)
     {
     dg();
     return true;
     }
 
 or (my preference) :
     // K&R style
     if (b) {
         dg();
         return true;
     }
 ?

No, No! Everyone knows it should really be: if(b) { dg(); return true; } ;) :P
Aug 21 2006
prev sibling next sibling parent reply Walter Bright <newshound digitalmars.com> writes:
Bruno Medeiros wrote:
 Walter Bright wrote:
 http://thc.segfault.net/root/phun/unmaintain.html
  From - Mon

Speaking of which (but seriously), we may not get a consensus on tabs, and maybe justifiedly so, but one other thing with DMD's coding convention that troubles me is the braces formatting: if (b) { dg(); return true; } ... whoa :/ . Where did that come from? It's unusual (I personally have never seen C-family code formatted that way), and seems awkward to me.

It's just: if (b) { dg(); return true; } compressed to save precious vertical screen space.
Aug 21 2006
next sibling parent reply kris <foo bar.com> writes:
Walter Bright wrote:
 Bruno Medeiros wrote:
 
 Walter Bright wrote:

 http://thc.segfault.net/root/phun/unmaintain.html
  From - Mon

Speaking of which (but seriously), we may not get a consensus on tabs, and maybe justifiedly so, but one other thing with DMD's coding convention that troubles me is the braces formatting: if (b) { dg(); return true; } ... whoa :/ . Where did that come from? It's unusual (I personally have never seen C-family code formatted that way), and seems awkward to me.

It's just: if (b) { dg(); return true; } compressed to save precious vertical screen space.

... get a flat-panel that can be rotated into portrait mode. The 24" Dell displays more lines of code (in portrait orientation) than you can shake a stick at :)
Aug 21 2006
next sibling parent reply Walter Bright <newshound digitalmars.com> writes:
kris wrote:
  ... get a flat-panel that can be rotated into portrait mode. The 24" 
 Dell displays more lines of code (in portrait orientation) than you can 
 shake a stick at :)

There's never enough screen real estate (but I now can't imagine working on 24 line displays like I used to).
Aug 21 2006
next sibling parent kris <foo bar.com> writes:
Walter Bright wrote:
 kris wrote:
 
  ... get a flat-panel that can be rotated into portrait mode. The 24" 
 Dell displays more lines of code (in portrait orientation) than you 
 can shake a stick at :)

There's never enough screen real estate (but I now can't imagine working on 24 line displays like I used to).

likewise
Aug 21 2006
prev sibling parent reply Don Clugston <dac nospam.com.au> writes:
Walter Bright wrote:
 kris wrote:
  ... get a flat-panel that can be rotated into portrait mode. The 24" 
 Dell displays more lines of code (in portrait orientation) than you 
 can shake a stick at :)

There's never enough screen real estate (but I now can't imagine working on 24 line displays like I used to).

Amen. I used to print my source code out and do most of my programming on paper, partly for that reason. Actually, I think that's what most of the {} formatting wars are about. Anyone who feels their screen isn't big enough is never going to be happy with one of the styles that uses lots of vertical space. Kris, with your coding style, I always suspected your screen was much bigger than mine <g>.
Aug 22 2006
parent kris <foo bar.com> writes:
Don Clugston wrote:
 Walter Bright wrote:
 
 kris wrote:

  ... get a flat-panel that can be rotated into portrait mode. The 24" 
 Dell displays more lines of code (in portrait orientation) than you 
 can shake a stick at :)

There's never enough screen real estate (but I now can't imagine working on 24 line displays like I used to).

Amen. I used to print my source code out and do most of my programming on paper, partly for that reason. Actually, I think that's what most of the {} formatting wars are about. Anyone who feels their screen isn't big enough is never going to be happy with one of the styles that uses lots of vertical space. Kris, with your coding style, I always suspected your screen was much bigger than mine <g>.

*blush* It's funny, but that style was initially adopted on a vt52. Old habits die hard. Years later (1989) when I convinced a corporation to splash out on /secondary/ monitors with *gasp* a full-length Hercules card supporting 50 lines of text, the engineering team bought me beers for weeks afterward. Those were appreciated more than stock options :)
Aug 22 2006
prev sibling parent reply Richard Koch <dr.richard.koch t-online.de> writes:
this all is need, super and thanx walter, - but any chance to get the 
html help as a printable pdf or like wise?

rko
Aug 21 2006
parent reply Walter Bright <newshound digitalmars.com> writes:
Richard Koch wrote:
 this all is need, super and thanx walter, - but any chance to get the 
 html help as a printable pdf or like wise?

I have no experience with creating pdf's, I have no idea what is involved. Frank is looking at creating Latex output.
Aug 21 2006
next sibling parent "Unknown W. Brackets" <unknown simplemachines.org> writes:
There are libraries, like pdflib.  I've worked with that one, but I 
think there are others.

A quick Google found me:

http://www.rustyparts.com/pdf.php
http://www.tufat.com/script19.htm

And if the data could be semantically parsed, it wouldn't be hard to 
just write it out using pdflib and not have the header/footer.  But 
maybe it's easier to use an existing tool like the above.

That said, I wouldn't personally prefer a pdf.  I'd prefer a chm, if 
anything, since that can be integrated into various editors... and I'm 
told there are Linux CHM viewers (but don't know personally since I only 
use Linux for servers.)

CHMs are also easy.  They're like zip files of html, with an index. 
It's a little more complicated, but not much.

-[Unknown]


 Richard Koch wrote:
 this all is need, super and thanx walter, - but any chance to get the 
 html help as a printable pdf or like wise?

I have no experience with creating pdf's, I have no idea what is involved. Frank is looking at creating Latex output.

Aug 21 2006
prev sibling next sibling parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Walter Bright wrote:

 this all is need, super and thanx walter, - but any chance to get the 
 html help as a printable pdf or like wise?

I have no experience with creating pdf's, I have no idea what is involved. Frank is looking at creating Latex output.

I posted a script that created PDF from the HTML using "htmldoc", and the output wasn't exactly pretty - but readable and printable. http://www.easysw.com/htmldoc/ Haven't tried it with the updated documentation though, and it was over 350 pages long so I guess you would have to have a good printer :-) Ddoc probably needs some PDF output capabilities... ? --anders
Aug 22 2006
prev sibling parent Markus Dangl <danglm in.tum.de> writes:
Walter Bright schrieb:
 Richard Koch wrote:
 this all is need, super and thanx walter, - but any chance to get the 
 html help as a printable pdf or like wise?

I have no experience with creating pdf's, I have no idea what is involved. Frank is looking at creating Latex output.

I don't have the time atm, but if we had XML-DDoc i could easily write a CHM and a PDF Export which could then be customized. I already had PDF output: I wrote an XML output for DDoc, which was then formatted with Apache FOP and a decent XSL-FO Stylesheet. But i didn't maintain it as i'm stuck knee-deep in some other projects.
Aug 22 2006
prev sibling parent Bruno Medeiros <brunodomedeiros+spam com.gmail> writes:
Walter Bright wrote:
 Bruno Medeiros wrote:
 Walter Bright wrote:
 http://thc.segfault.net/root/phun/unmaintain.html
  From - Mon

Speaking of which (but seriously), we may not get a consensus on tabs, and maybe justifiedly so, but one other thing with DMD's coding convention that troubles me is the braces formatting: if (b) { dg(); return true; } ... whoa :/ . Where did that come from? It's unusual (I personally have never seen C-family code formatted that way), and seems awkward to me.

It's just: if (b) { dg(); return true; } compressed to save precious vertical screen space.

Then how about K&R style?
Aug 22 2006
prev sibling parent reply Charles D Hixson <charleshixsn earthlink.net> writes:
Bruno Medeiros wrote:
 Walter Bright wrote:
 http://thc.segfault.net/root/phun/unmaintain.html
  From - Mon

Speaking of which (but seriously), we may not get a consensus on tabs, and maybe justifiedly so, but one other thing with DMD's coding convention that troubles me is the braces formatting: if (b) { dg(); return true; } ... ?

My personal preference is: if (b) { dg(); return true; } with all the indentations managed by tabs, so you can decide how much indenting you find useful. (I normally choose 3 spaces...but there are times when I compress it down to two, and I used to usually use 4 spaces.) I'd be surprised if this was the most common choice, however.
Aug 22 2006
parent reply Kristian <kjkilpi gmail.com> writes:
On Wed, 23 Aug 2006 04:41:01 +0300, Charles D Hixson  
<charleshixsn earthlink.net> wrote:

 Bruno Medeiros wrote:
 Walter Bright wrote:
 http://thc.segfault.net/root/phun/unmaintain.html
  From - Mon

and maybe justifiedly so, but one other thing with DMD's coding convention that troubles me is the braces formatting: if (b) { dg(); return true; } ... ?

My personal preference is: if (b) { dg(); return true; } with all the indentations managed by tabs, so you can decide how much indenting you find useful. (I normally choose 3 spaces...but there are times when I compress it down to two, and I used to usually use 4 spaces.) I'd be surprised if this was the most common choice, however.

That one I haven't seen yet. :) Well, if you like to see an uncommon case (I think), here's a one, heheh. It's the one I prefer: if(b) { dg(); return true; } Before you feel sorry for me, there is a point for using it, and it is cases where you don't use brackets. For example, compare the following cases: //case 1 if(b) { doX(); doY(); } else { doY(); doZ(); } //case 2 if(b) doX(); else doY(); //case 1 + 2 if(b) { doX(); doY(); } else doY(); See how similar the cases are, and how they fit together. Indention tells where a block or single line statement starts. And where it ends, you may ask? Well, of course, it ends before the next one starts. (Code will look like there were a caption and paragraph(s), a caption and paragraph(s), etc.) I know any syntax can look weird, until you get accustomed to it. And you can get accustomed to a lot of things.
Aug 23 2006
parent Charles D Hixson <charleshixsn earthlink.net> writes:
Kristian wrote:
 On Wed, 23 Aug 2006 04:41:01 +0300, Charles D Hixson 
 <charleshixsn earthlink.net> wrote:
 
 Bruno Medeiros wrote:
 Walter Bright wrote:
 ...



Well, if you like to see an uncommon case (I think), here's a one, heheh. It's the one I prefer: if(b) { dg(); return true; } Before you feel sorry for me, there is a point for using it, and it is ...

taste (though I couldn't use yours). The point of my system is "brackets should line up vertically!". I'll admit, however, that I can't quite figure out how switch/case statements should be handled using my preferred approach. I dither between at least two choices. (Partially because I don't use them very often.
Aug 23 2006