www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - '!' and naming conventions

reply "cym13" <mystiro gmail.com> writes:
Hello,

I see a lot of functions and other stuff with a '!' in the name
such as 'bitfields!' or 'ctRegex!'. What does it mean exactly? In
scheme, we use such a convention to warn that a function is not
pure, but I don't see the point of using it that way in D as
there are other way to express it.

Moreover, I'm looking for a style guide of D, something like the
PEP8 for python. Is there anything like that?

Thanks!
Jun 18 2014
next sibling parent reply "Brad Anderson" <eco gnuk.net> writes:
On Wednesday, 18 June 2014 at 20:55:36 UTC, cym13 wrote:
 Hello,

 I see a lot of functions and other stuff with a '!' in the name
 such as 'bitfields!' or 'ctRegex!'. What does it mean exactly? 
 In
 scheme, we use such a convention to warn that a function is not
 pure, but I don't see the point of using it that way in D as
 there are other way to express it.

 Moreover, I'm looking for a style guide of D, something like the
 PEP8 for python. Is there anything like that?

 Thanks!
The ! specifies that a template argument list follows. auto fun(T)(T a, T b) { return a * b; } void main() { // fun can be called using several different ways: fun!(int)(1, 2); // Specifying the template arguments fun!int(1, 2); // If there is only one template argument the // parens can be omitted fun(1, 2); // IFTI can be used to figure out the types for you } There is a style guide on the website: http://dlang.org/dstyle.html Personally I just consider this a Phobos contributor style guide and not like a PEP8 style guideline.
Jun 18 2014
parent reply Jonathan M Davis via Digitalmars-d-learn writes:
 Sent: Wednesday, June 18, 2014 at 11:02 PM
 From: "Brad Anderson via Digitalmars-d-learn"
<digitalmars-d-learn puremagic.com>
 To: digitalmars-d-learn puremagic.com
 Subject: Re: '!' and naming conventions

 There is a style guide on the website: 
 http://dlang.org/dstyle.html
 
 Personally I just consider this a Phobos contributor style guide 
 and not like a PEP8 style guideline.
It was written with the hope that it would be generally followed by the D community, and that's part of the reason that it specifically focuses on the API and not the formatting of the code itself. So, ideally, most D projects would follow it (particularly if they're being distributed publicly) so that we have consistency across the community (particularly with regards to how things are captitalized and whatnot), but by no means is it required that every D project follow it. It's up to every developer to choose how they want to go about writing their APIs. We're not fascists and don't require that all code out there be formatted in a specific way or that all APIs follow exact naming rules (we couldn't enforce that anyway). But still, I would hope that most public D librares would follow the naming guidelines in the D style guide. Now, for Phobos, it's required, and there are even a couple of formatting rules added to the end specifically for Phobos, but outside of official D projects, it's up to the developers of those projects to choose what they want to do. - Jonathan M Davis
Jun 18 2014
parent "Brad Anderson" <eco gnuk.net> writes:
On Wednesday, 18 June 2014 at 21:58:48 UTC, Jonathan M Davis via 
Digitalmars-d-learn wrote:
 Sent: Wednesday, June 18, 2014 at 11:02 PM
 From: "Brad Anderson via Digitalmars-d-learn" 
 <digitalmars-d-learn puremagic.com>
 To: digitalmars-d-learn puremagic.com
 Subject: Re: '!' and naming conventions

 There is a style guide on the website: 
 http://dlang.org/dstyle.html
 
 Personally I just consider this a Phobos contributor style 
 guide and not like a PEP8 style guideline.
It was written with the hope that it would be generally followed by the D community, and that's part of the reason that it specifically focuses on the API and not the formatting of the code itself. So, ideally, most D projects would follow it (particularly if they're being distributed publicly) so that we have consistency across the community (particularly with regards to how things are captitalized and whatnot), but by no means is it required that every D project follow it. It's up to every developer to choose how they want to go about writing their APIs. We're not fascists and don't require that all code out there be formatted in a specific way or that all APIs follow exact naming rules (we couldn't enforce that anyway). But still, I would hope that most public D librares would follow the naming guidelines in the D style guide. Now, for Phobos, it's required, and there are even a couple of formatting rules added to the end specifically for Phobos, but outside of official D projects, it's up to the developers of those projects to choose what they want to do. - Jonathan M Davis
I think it's a pretty good basic style guide overall and I follow it quite a bit, mostly due to coincidence (it overlaps with my own style I've developed over the years quite a bit). Really, the main thing I do differently is I use all lowercase, underscored names for variables instead of camelcasing. I don't care for the look of camelcase so I only use it for globals and other infrequently used things where I want it to stand out a bit from my regular variables. What we really need is a D Idiom Guide but that's a much more difficult and controversial subject.
Jun 18 2014
prev sibling next sibling parent "w0rp" <devw0rp gmail.com> writes:
On Wednesday, 18 June 2014 at 20:55:36 UTC, cym13 wrote:
 Hello,

 I see a lot of functions and other stuff with a '!' in the name
 such as 'bitfields!' or 'ctRegex!'. What does it mean exactly? 
 In
 scheme, we use such a convention to warn that a function is not
 pure, but I don't see the point of using it that way in D as
 there are other way to express it.

 Moreover, I'm looking for a style guide of D, something like the
 PEP8 for python. Is there anything like that?

 Thanks!
! is actually the way in D of passing compile time arguments. So take for example the 'to' function. double foo = 3.14; // Convert a double to a string. string bar = foo.to!string; // Same as the above, written a little differently. bar = to!(string)(foo); // How C++ and friends would write it. // bar = to<string>(foo);
Jun 18 2014
prev sibling parent "Gary Willoughby" <dev nomad.so> writes:
On Wednesday, 18 June 2014 at 20:55:36 UTC, cym13 wrote:
 Hello,

 I see a lot of functions and other stuff with a '!' in the name
 such as 'bitfields!' or 'ctRegex!'. What does it mean exactly?
I think this will be helpful: http://nomad.so/2013/07/templates-in-d-explained/
Jun 18 2014