Re: enum options

new topic     » goto parent     » topic index » view thread      » older message » newer message
CChris said...
Matt Lewis said...

This suggestion assumes that the most common usage of enums will be for wrapping C code. I doubt this to be the case. And I care more for making euphoria easier for euphoria programmers than for theoretical users coming from another language. They know that they're using a different language. Since we're actually programming in euphoria, we should follow euphoria conventions, and starting at 1 is much more useful. It's really not that difficult to add in the "= 0" to the first enum, if that's the requirement.

If you only need to tweak one or two enums in a program, this approuach is correct. If you have scores of them, it is not correct at all. At least terrbly unpractical.

It's not as bad as you say. Most of the time, you can cut and paste from C source, and do some find and replace. I think I've done as much of this as anyone has, and it's somewhat of a pain, but the reality is that you're most commonly dealing with simple macros, not enums, so you have to go back and add equals signs, commas and change from C-style hex (0xdeadbeef) to euphoria style (#DEADBEEF). Has anyone ever actually had to convert scores of enums? Even so, it's the addition of a single = 0 to each one. And, it's a one-time cost.

Bottom line, there is no practical way to convert large amounts of code from another language.

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.

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.

CChris said...

And much more tedious to code. I cannot see how the example Shawn posted is not clear. Could you elaborate? By the ay, 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

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

Search



Quick Links

User menu

Not signed in.

Misc Menu