Huh, invariant() {...} ?
Ary Manzana
ary at esperanto.org.ar
Mon Jun 18 11:51:53 PDT 2007
This can only be a win!
1. If the invariant keyword will be left with those two meaning, than
for consistency unit tests should be written:
unittest() {
}
Which leaves the possibility to specify something between the parens:
unittest("List adds correctly an element") {
}
and then when an assert fails within a unittest, that message could also
be displayed.
Also a string could be specified in a class invariant, with the same
purpose.
2. If one of the invariant keyword will be changed by another
(classinvariant) or (immutable), that everything will be clearer.
:)
Kristian Kilpi escribió:
>
> This is a small detail, but I found myself wondering why the class
> invariant declarations have now parenthesis (in 2.0, that is).
>
> I mean, you cannot write something like this:
>
> invariant {
> int* p; //invariant int* p;
> }
>
> Or can you?
>
>
> The class invariant declarations are no longer consistent with other
> class blocks, which is a shame.
>
> class A {
> invariant() { //hmmm, should I put parens here or not?
> ...
> }
> unittest { //how about here?
> ...
> }
> }
>
>
> It may be clearer anyway to use different keyword for the class
> invariants, 'classinvariant' or something.
>
> Or change the new 'invariant' keyword to 'invar'...
>
> const int* p1;
> invar int* p2;
>
> (Less typing, and then both the keywords would be 5 chars long (a little
> bonus).)
More information about the Digitalmars-d
mailing list