11-04-2010 03:36 PM
In the driver development guide, it says
Choose a text ring to represent values that do not have clear two state values (recommanded).
Is ring preferred over enum in this case? If so, why is that? Does that mean I should use a ring if I have more than 2 values?
If I have 0, 1, 2, 3, 4, why could it be recommaded to use a ring instead of enum? It seems like a enum would work pretty well. What are the pros and cons in this case?
Yik
11-04-2010 03:45 PM
Enum is a type def and can be connected to a Case structure where you'll see the enum names. Rings are a value array and can be changed in run time. Rings can also be given any value, whereas Enums automatically number from 1-X in step 1.
Just recently i've used Rings in a calibration program where i fill the list with nominal values and give the choices their actual value. What's the benefit? Choosing 120V in the text ring sends 120 as output from the control.
Enums make for prettier code, but not being able to change it in run time is a big drawback.
So, enums are a better choice if the program allows it, i'd say.
/Y
11-04-2010 03:48 PM
Yeah, I agree that enum is a better choice, but why does the guideline prefer a ring instead?
11-04-2010 04:47 PM
@jyang72211 wrote:
Yeah, I agree that enum is a better choice, but why does the guideline prefer a ring instead?
Enum is enumerated type and good choice in cases such as building state machines or in situations with "fixed cases". Usually enum used in connection with typedef. You can't modify enum in run-time. Ring is good in situation when items not defined or should be changed at runtime - you can do almost anything:
Andrey.
11-04-2010 05:19 PM
I guess we should narrow down the use case to the driver level, otherwise we just repeate the endless comparissons between enum and ring.
At a driver level, there are two points I'd throw in for the ring:
* The advantage of propagating changes in the code via a type def'ed enums can be ignored, as you release a finished driver for your product (most likley encapsulating a finished dll).
* Other languages support 'enums' that aren't sequential. So it's easier to work with rings to map to values as 0, 1275, 14567. As an example look at the Excel ActiveX interface.
My personally prefered solution is to have a type-cast vi thats converting the enum to the numbers required by the dll/ActiveX/...
This adds an abstraction layer (operation/parameter->numerical code), which I think is good.
But another issue to have in mind, you can 'merge' such string-based rings:
Lets say:
OpA -> 1
OpB -> 2
OpC -> 22
where developed for module X (1,2) and Y (22), when you now come up with module Z that reuses (2, 22)...
Felix
11-04-2010 11:27 PM
Thanks!