Sudoku Py / C++11 / D?

maarten van damme maartenvd1994 at gmail.com
Fri Aug 24 15:58:51 PDT 2012


> Some suggestions about the code:
Thank you very much for your criticism, there are indeed a lot of
points where I have to improve on.

> - Put a space before and after operators, after a commas and semicolon,
> around "..", etc.
> - Compile with "-wi -property";
> - Try to add pure/const/nothrow/immutable where possible;

I realize the usefullness of keywords like these but having to type
them over and over again tends to become rather annoying. There are
functions where the implementation is shorter than it's declaration...
Is there a special reason I should use them in little programs like these?

> - Minimize the need of cast();
> - Sometimes it's useful to localize the imports (stdio e datetime are used
> just by the main);
> - Minimize the usage of magical constants like 0b10_0000_0000, possibly
> define it only once. And often adding underscores inside long numbers is
> handy (here I have put them every 4 digits because it's binary);
> - Repeating things like "short[81]" in many function signatures is quite
> bad. Better to define a global type with alias (or someday better with
> std.typecons.Typedef when it will work), and then use it;
> - Generally it's better to use unsigned values for array indexes;
> - If you look for performance and your program is single thread, then it's
> better to annotate global variables with __gshared;

I'm not all that familiar with __gshared, why does it increase performance?

>
> - This:
>     ubyte[81] taken = false;
> is better than this:
>     ubyte[81] taken;
>     taken[] = false;

I know and I think I can even leave false out because the default
value of ubyte is 0 => false. I had a big in my code and it took me a
long time to find it. That line is a leftover of a desperate attempt
at finding it :) (as is line 101)

I even tried using array!bool but even instantiating failed so I gave
up. Would performance increase be noticeable? I guess not.
>
>
> This is your code modified, it's also a little faster:
> http://dpaste.dzfl.pl/06510dcd
>

Thank you. I see you also used contracts, looks better now :)
(using contracts is really something I should start doing...)

> I will try to replace the int[] of cachedBitsetToRange with something more
> static, to reduce indirection.
>
> Bye,
> bearophile


I should also add a little check to see if every value I put is indeed
numerical.


More information about the Digitalmars-d-learn mailing list