Re: enum options

new topic     » goto parent     » topic index » view thread      » older message » newer message

<snipped the practicality part, Irv is more qualified to comment on it/>

Matt Lewis said...
CChris said...
Matt Lewis said...

Further, I think that the "with base=n" will lead to difficult to maintain code. I think that if you need some weirdness, it's better to explicitly declare it.

Isn't "with base n" explicit? I don't understand. It will also help Basic users, who have an Options Base n directive as well.

It's explicit wherever that statement is, which is not necessarily where the enum is declared.

Another scale issue.
If you have a couple enums to tweak, it is not neeeded. If you have a lot of them, then chances are that all of them are to be tweaked. And then the need to be explicit disappears, as all enums would be treated the same.

Don't get me wrong. I prefer the (from start_value ...) form. But your point was I think not much justified.

Matt Lewis said...
CChris said...
Matt Lewis said...

If you're creating a set of bit flags, don't use enums. Use constants. It will be much clearer for everyone reading the code.

Why?

Because then it's more obvious what they're for. That's just my opinion. The values really stand out.

If the explicit values matter, then indeed use plain constants, whether for flags or anything else. If they don't, use enums for flags or anything else. Relevant names are often the best way out of the problem. They are part of the commenting.

Matt Lewis said...
CChris said...

And much more tedious to code. I cannot see how the example Shawn posted is not clear. Could you elaborate? By the way, nothing prevents you from adding comment marks with an explicit value to the enum.

Comments have a precise purpose in the (any) language: tell reader things a machine doesn't need to know, or in a different way. The language constructs do not need to duplicate one another's functionality, and this applies to coments just as well.

It's adding complication to something for basically zero benefit. If I'm going to put comments in, why would I use an enum? The only place I could see using a comment for an enum value is within a long list, in order to be able to figure out which value was which, but even then, it would only be every 5 or 10, or something similar. Doing this for bit flags would be as inane as:

    i +=1 -- increase i by one 

Matt

Since there is less code to convey the same semantics, it brings more simplicity rather than complexity. I agree with your last point about comments. But I see it buttressing my position more than yours.

CChris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu