Laugh Test
Ruby The Roobster
michaeleverestc79 at gmail.com
Thu Sep 24 20:41:30 UTC 2020
On Thursday, 24 September 2020 at 19:54:40 UTC, mipri wrote:
>
> There are parts of that I don't understand at all, like the
> sorted_point logic, and this.next_move, so that limits what I
> can suggest.
>
> But you might prefer writing this with an eye on
>
> https://dlang.org/spec/arrays.html#array-operations
> https://dlang.org/phobos/std_exception.html#enforce
>
> ex:
>
> struct Mobile {
> int[3] pos, delta;
>
> void step() {
> import std.exception : enforce;
>
> pos[] += delta[];
> enforce(pos[] < [666, 666, 666], "example position
> violation");
> }
> }
>
> unittest {
> import std.stdio : writeln;
>
> auto m1 = Mobile([0, 0, 0], [5, 0, -1]);
> m1.step;
> m1.step;
> m1.step;
> writeln(m1);
> }
>
> unittest {
> import std.exception : assertThrown;
>
> auto m1 = Mobile([0, 0, 0], [1000, 1000, 1000]);
> m1.step.assertThrown; // position violation
> }
Even if I did something similar to what you suggested, the code
would still be confusing, just because of how many checks have to
be done in this function. I can't really improve the way the
checks look. Also, implementing that would be a huge pain because
I use position(the struct) like this(not with a lot of checks but
the .x = .x,.y = .y,etc. thing) in basically any function
involving position of the shape.
More information about the Digitalmars-d
mailing list