www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Seeking advice on programming style

reply Victor Porton <porton narod.ru> writes:
I have (in D bindings of a C library, which I am writing):

module rdf.raptor.uri;

struct URIWithoutFinalize {
   // ...
}

struct URI {
   // ...
    property URIWithoutFinalize base() { /* ... */ }
   alias base this;
}

(in fact, these structs are created by a system of template 
mixins).

The two structs differ mainly by their destructor behavior.

What can you advice to put non-member functions?

1. module scope (but then they may need to have long names to 
disambiguate with other modules).
2. as statics in URIWithoutFinalize (but then the full name of 
the functions would contain WithoutFinalize what is not quite 
about what they are).
3. as statics in URI (but then they are in a logically derived 
struct, while may belong logically to the base that is to 
URIWithoutFinalize)
4. in a new struct specifically created to hold static function 
(but then how to name it?)
Dec 31 2018
next sibling parent Neia Neutuladh <neia ikeran.org> writes:
On Mon, 31 Dec 2018 21:51:11 +0000, Victor Porton wrote:
 What can you advice to put non-member functions?
 
 1. module scope (but then they may need to have long names to
 disambiguate with other modules).
Module scope, short convenient names, and use renamed imports to disambiguate if you need to: import uri = rdf.raptor.uri; auto docURI = uri.parse(uriString);
Dec 31
prev sibling parent Andre Pany <andre s-e-a-p.de> writes:
On Monday, 31 December 2018 at 21:51:11 UTC, Victor Porton wrote:
 I have (in D bindings of a C library, which I am writing):

 module rdf.raptor.uri;

 struct URIWithoutFinalize {
   // ...
 }

 struct URI {
   // ...
    property URIWithoutFinalize base() { /* ... */ }
   alias base this;
 }

 (in fact, these structs are created by a system of template 
 mixins).

 The two structs differ mainly by their destructor behavior.

 What can you advice to put non-member functions?

 1. module scope (but then they may need to have long names to 
 disambiguate with other modules).
 2. as statics in URIWithoutFinalize (but then the full name of 
 the functions would contain WithoutFinalize what is not quite 
 about what they are).
 3. as statics in URI (but then they are in a logically derived 
 struct, while may belong logically to the base that is to 
 URIWithoutFinalize)
 4. in a new struct specifically created to hold static function 
 (but then how to name it?)
Little bit off topic. Curl now exposes its URL api. It would be great if it could be added to Phobos:) https://daniel.haxx.se/blog/2018/09/09/libcurl-gets-a-url-api/ Kind regards Andre
Jan 01