Thread overview
[phobos] phobos commit, revision 1851
Aug 14, 2010
dsource.org
Aug 14, 2010
Adam Ruppe
Aug 14, 2010
Adam Ruppe
August 14, 2010
phobos commit, revision 1851


user: adr

msg:
commiting my first attempt at network support in the File interface.

http://www.dsource.org/projects/phobos/changeset/1851

August 14, 2010
You might remember my posts quite a while ago where I talked about making network access work through the phobos File interface.

It depends on C's FILE* internally, but the external interface is what matters. I've been using it in some quick projects already, and it works well enough for me, so I finally decided to commit it to phobos so everyone can use it.
August 14, 2010
Great work! A few nits:

* Generally the prevalent Phobos (and I hope D) style is to declare local values as late as possible. This is pretty much ubiquitous in today's style guides for all languages (Code Complete, C++ Coding Standards etc.) Even C99 caved in and allows declarations intermixed with statements.

* In D, use of auto is recommended unless you want to make a specific point by mentioning the type. So, a suggested rewrite:

sock.hostent* h;
sock.sockaddr_in addr;
h = sock.gethostbyname(std.string.toStringz(host));

=>

auto h = sock.gethostbyname(std.string.toStringz(host));
// Define addr upon first use

* The pattern if (cond) throw new X(args) is best encoded with enforce:

if(h is null)
     throw new StdioException("gethostbyname");

=>

enforce(h !is null, new StdioException("gethostbyname"));

enforce() has a special overload that detects the presence of a Throwable in the second position and does what it should do.

* Phobos currently uses full bracing after if, while etc. I've tried to follow that but on occasion I slip. I'm not sure whether we should enforce such rules; this might be a good time to discuss that.

* Generally I encourage economy of vertical space, e.g.

auto imp = new File.Impl(fp, 1, host ~ ":" ~ to!string(port));
f.p = imp;

=>

f.p = new File.Impl(fp, 1, host ~ ":" ~ to!string(port));

This is an awesome development. I'll play with the code today.


Andrei

On 08/14/2010 12:12 PM, dsource.org wrote:
> phobos commit, revision 1851
>
>
> user: adr
>
> msg:
> commiting my first attempt at network support in the File interface.
>
> http://www.dsource.org/projects/phobos/changeset/1851
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
August 14, 2010
Indeed, the style here shows its roots: copy/paste from a very old C function. (I think I've written network connect code maybe twice over the years. I just copy/paste the same thing when I need it again.) Then I switch to a more D style near the end since that's the newer code.

Anyway, I switched it to general Phobos style and recommitted. I even changed my beloved tabs to your vile spaces :)

Interestingly, enforce replaced /all/ the if statements in there.


>  Phobos currently uses full bracing after if, while etc.
> I've tried to follow that but on occasion I slip.
> I'm not sure whether we should enforce such rules;
> this might be a good time to discuss that.

I'm pretty meh oh that, the braces take up a chunk of space and don't offer much in return IMO. But, I messed up some code by adding a second line after an if before, so I'd agree there is a small benefit. I'm just not so sure if it outweighs the space usage.

But if that's the Phobos style, I'll use it.