Style question

Namespace rswhite4 at googlemail.com
Thu Jul 11 13:15:51 PDT 2013


> The whole situation looks strange. If you can change both 
> files, than it is unclear what made you to write such 
> inconsistent code. If you can change only one of them, then it 
> should be adjusted to another (meaning importing external file 
> and using that enum instead of trying to define different type 
> and passing it).

Besides the problem of changing existing API:
If you change only one of those modules and use the enum from the 
other file, every user have to look into the file which declares 
the enum, to see which member the enum has.

> Judging by "MyStaticClass.test2(this._a)" it seems that the 
> first imports the second which is also suspicious - you are 
> importing module which contains main function. From where does 
> the code come from?
It's my example of his problem. Only example code.

> It would be good to clarify which file cannot be modified, 
> although it does not really matter - just use one version of 
> enum.
That would be the best, I agree.

> This is almost same as direct cast in #2. Instead of making 
> test2() accept B or (u)int consider making it static void test2 
> (MyClass.A a) and wipe out enum B entirely.

That's the problem I tried to describe above.
If you have those two modules as in my example code, the one file 
without the enum depends on the one with the enum. Isn't that a 
bad situation?
A possible solution would be to change one of those functions 
which accepts different enums, that it accept an uint - nothing 
else is an enum (in this case).



More information about the Digitalmars-d-learn mailing list