My first D module - Critiques welcome.

Xinok xinok at live.com
Mon Dec 23 16:46:37 PST 2013


On Monday, 23 December 2013 at 21:34:34 UTC, John Carter wrote:
> So I resolved to learn D, and try code as idiomatically as I 
> could.
>
> So here is a trivial module that encodes and decodes roman 
> numerals.
>
> https://bitbucket.org/JohnCarter/roman/src/9ec5b36b9973426f35b0ab9dfd595cb3b305e39e/roman.d?at=default
>
> I also attempted to do it in "Best Practice Test Driven 
> Development" form
> with commits on every change.
>
> So you can see the blow by blow history of how it grew.
>
> I would welcome any critique, advice, flames, recommendations, 
> etc. etc.
>
> Thanks for your help and patience with various stupid newbie 
> questions I
> asked in the process!

Overall, I say it's not bad. I just have a few comments on your 
coding style.


Be consistent with your opening braces. Personally, I always 
place it on the next line, regardless if it's a function or 
something else.

unittest
{
}

instead of:

unittest {
}


The standard in Phobos is that 1 tab = 4 spaces. Otherwise, when 
using spaces to align code, make sure it's consistent and 
everything lines up. (lines 145-155)


There are a series of unittests which could be merged together. 
Keep the line comments to keep different tests separate, but 
there's no need to have multiple unittests which contain nothing 
more than a few simple asserts. Or as bearophile suggested, use 
an in-out table. Besides for grouping things together and making 
your code more organized, it's better for those of us who use 
IDEs, so we can collapse the unittest with a single click.


More information about the Digitalmars-d-learn mailing list