My first D module - Critiques welcome.

Gary Willoughby dev at nomad.so
Mon Dec 23 14:46:23 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!

I like it and it seems you are grasping D well. I wonder if the 
entire implementation could be done using templates and all done 
at compile time? It would be interesting to explore.

int year    = fromRoman!("DXLIX");
string year = toRoman!(2013);

Very similar to how [octal][1] is implemented;

[1]: http://dlang.org/phobos/std_conv.html#.octal


More information about the Digitalmars-d-learn mailing list