-
Hidden enum values?
In VB5 and VB6 I've frequently used hidden enum values by making use of the
way names with leading underscores are not shown. For example:
Public Enum CarMakes
Chevrolet=1
Ford=2
Isuzu=3
[_MaxCarMake]=3
End Enum
Public Sub SelectMake(ByVal MakeChoice As CarMakes)
If MakeChoice>0 And MakeChoice<=[_MaxCarMake] Then ...
The idea being that if additional entries are added to the enum is is almost
impossible not to see and adjust the "max" value. With VB.Net the leading
underscore no longer hides the name so this trick is dead unless there is an
alternative. Does anybody know of an attribute or other alternative that
accomplishes the same end?
The fallback will probably be a private constant defined outside the enum
but I find that more prone to being overlooked when changes are made.
-
Re: Hidden enum values?
You don't need that design pattern any more. Instead, use...
Public Sub SelectMake(ByVal MakeChoice As CarMakes)
If Enum.IsDefined( GetType(CarMakes), MakeChoice) Then
--
Jonathan Allen
"Bob Butler" <butlerbob@earthlink.net> wrote in message
news:3aace806@news.devx.com...
> In VB5 and VB6 I've frequently used hidden enum values by making use of
the
> way names with leading underscores are not shown. For example:
>
> Public Enum CarMakes
> Chevrolet=1
> Ford=2
> Isuzu=3
> [_MaxCarMake]=3
> End Enum
>
> Public Sub SelectMake(ByVal MakeChoice As CarMakes)
> If MakeChoice>0 And MakeChoice<=[_MaxCarMake] Then ...
>
>
> The idea being that if additional entries are added to the enum is is
almost
> impossible not to see and adjust the "max" value. With VB.Net the leading
> underscore no longer hides the name so this trick is dead unless there is
an
> alternative. Does anybody know of an attribute or other alternative that
> accomplishes the same end?
>
> The fallback will probably be a private constant defined outside the enum
> but I find that more prone to being overlooked when changes are made.
>
>
>
-
Re: Hidden enum values?
"Jonathan Allen" <greywolf@cts.com> wrote in message
news:3aad070a@news.devx.com...
> You don't need that design pattern any more. Instead, use...
>
> Public Sub SelectMake(ByVal MakeChoice As CarMakes)
> If Enum.IsDefined( GetType(CarMakes), MakeChoice) Then
You are right that I should stop trying to locate an equivalent in VB.Net
for a lot of things. Thanks.
IMO, however, that line obfuscates the intent and increases the maintenance
burden.
-
Re: Hidden enum values?
Not really, I think "Enum.IsDefined" is a perfect method name for defining
what's going on. Furthermore, with hidden "Min" and "Max" values, you can
only work with a contiguous set of enum values. What if I have the following:
APIErrNoFile = 2
APIErrFileExists = 43
APIErrCantCreateFile = 82
In this case working with Min and Max values won't work, but Enum.IsDefined
works perfectly and is not obfuscating at all. Once you get used to the everything-is-an-object-call
style, it looks natural.
-Rob
"Bob Butler" <butlerbob@earthlink.net> wrote:
>
>IMO, however, that line obfuscates the intent and increases the maintenance
>burden.
>
>
-
Re: Hidden enum values?
"Rob Teixeira" <RobTeixeira@@msn.com> wrote in message
news:3aad2053$1@news.devx.com...
>
> Not really, I think "Enum.IsDefined" is a perfect method name for defining
> what's going on. Furthermore, with hidden "Min" and "Max" values, you can
> only work with a contiguous set of enum values. What if I have the
following:
>
> APIErrNoFile = 2
> APIErrFileExists = 43
> APIErrCantCreateFile = 82
>
> In this case working with Min and Max values won't work, but
Enum.IsDefined
> works perfectly and is not obfuscating at all. Once you get used to the
everything-is-an-object-call
> style, it looks natural.
I think in C# it looks fine. The more I look at VB.Net the more discouraged
and disgusted I get with it.
-
Re: Hidden enum values?
"Bob Butler" <butlerbob@earthlink.net> wrote:
>
>"Jonathan Allen" <greywolf@cts.com> wrote in message
>news:3aad070a@news.devx.com...
>> You don't need that design pattern any more. Instead, use...
>>
>> Public Sub SelectMake(ByVal MakeChoice As CarMakes)
>> If Enum.IsDefined( GetType(CarMakes), MakeChoice) Then
>
>You are right that I should stop trying to locate an equivalent in VB.Net
>for a lot of things.
Is anyone keeping keeping a list of things like this? I can volunteer to
be the one, but don't want to duplicate someone else's efforts.
- Jim
-
Re: Hidden enum values?
"Jonathan Allen" <greywolf@cts.com> wrote in message <news:3aad070a@news.devx.com>...
> You don't need that design pattern any more. Instead, use...
>
> Public Sub SelectMake(ByVal MakeChoice As CarMakes)
> If Enum.IsDefined( GetType(CarMakes), MakeChoice) Then
Might be nicer if it was GetType(MakeChoice) or even MakeChoice.IsDefined,
since IsDefined is a member of Enum anyway.
--
Joe Foster <mailto:jfoster@ricochet.net> Space Cooties! <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above They're coming to
because my cats have apparently learned to type. take me away, ha ha!
-
Re: Hidden enum values?
"Bob Butler" <butlerbob@earthlink.net> wrote in message <news:3aad0f7d$1@news.devx.com>...
>
> "Jonathan Allen" <greywolf@cts.com> wrote in message
> news:3aad070a@news.devx.com...
> > You don't need that design pattern any more. Instead, use...
> >
> > Public Sub SelectMake(ByVal MakeChoice As CarMakes)
> > If Enum.IsDefined( GetType(CarMakes), MakeChoice) Then
>
> You are right that I should stop trying to locate an equivalent in VB.Net
> for a lot of things. Thanks.
>
> IMO, however, that line obfuscates the intent and increases the maintenance
> burden.
MakeChoice.IsDefined() would be fine, though. If all enums are subtypes
of Enum, IsDefined with no arguments could be overridable, and surely
the compiler has all the information necessary to generate IsDefined
automagically.
--
Joe Foster <mailto:jfoster@ricochet.net> "Regged" again? <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above They're coming to
because my cats have apparently learned to type. take me away, ha ha!
-
Re: Hidden enum values?
"Jim Pragit" <NoSpam@NoSpam.com> wrote in message
news:3aad4adf$1@news.devx.com...
>
> "Bob Butler" <butlerbob@earthlink.net> wrote:
> >
> >"Jonathan Allen" <greywolf@cts.com> wrote in message
> >news:3aad070a@news.devx.com...
> >> You don't need that design pattern any more. Instead, use...
> >>
> >> Public Sub SelectMake(ByVal MakeChoice As CarMakes)
> >> If Enum.IsDefined( GetType(CarMakes), MakeChoice) Then
> >
> >You are right that I should stop trying to locate an equivalent in VB.Net
> >for a lot of things.
>
> Is anyone keeping keeping a list of things like this? I can volunteer to
> be the one, but don't want to duplicate someone else's efforts.
I had started but it's simply impossible to keep up with the number of
issues.
VB.Net is, IMO, a major mistake. I hear constantly how great it is that
we'll have multiple languages that all have almost exactly the same
capabilities and speed and differ only in surface syntax. The question I
keep coming back to is why is that considered a good thing and who wanted
it? Even calling it Visual Fred leaves open the question of why should MS
develop and support two separate languages that accomplish the same goals
and how long before they decide it makes no sense to continue the investment
of resources.
There's a great deal that I like about the dotnet platform and I see a lot
of potential for development in C# and/or MSIL but hammering the round VB
peg into the square dotnet hole is ludicrous. I guess the only consolation
is that Cobol.Net may look even worse.
-
Re: Hidden enum values?
> Might be nicer if it was GetType(MakeChoice) or even MakeChoice.IsDefined,
> since IsDefined is a member of Enum anyway.
I would certainly prefer it that way.
--
Jonathan Allen
"Joe "Nuke Me Xemu" Foster" <joe@bftsi0.UUCP> wrote in message
news:3aad4f04@news.devx.com...
> "Jonathan Allen" <greywolf@cts.com> wrote in message
<news:3aad070a@news.devx.com>...
>
> > You don't need that design pattern any more. Instead, use...
> >
> > Public Sub SelectMake(ByVal MakeChoice As CarMakes)
>
> > If Enum.IsDefined( GetType(CarMakes), MakeChoice) Then
>
> Might be nicer if it was GetType(MakeChoice) or even MakeChoice.IsDefined,
> since IsDefined is a member of Enum anyway.
>
> --
> Joe Foster <mailto:jfoster@ricochet.net> Space Cooties!
<http://www.xenu.net/>
> WARNING: I cannot be held responsible for the above They're
coming to
> because my cats have apparently learned to type. take me away,
ha ha!
>
>
-
Re: Hidden enum values?
Yep, I never understood why the compiler wasn't capable of determining whether
the passed value was one of the valid entries (in the first place) since (by
declaring the parameter as an eNum) you've indicated that only certain values
"should" be acceptable. But perhaps this is less technical and more discussion
since it's unlikely to change...
"Joe "Nuke Me Xemu" Foster" <joe@bftsi0.UUCP> wrote in message
news:3aad4f04@news.devx.com...
> Might be nicer if it was GetType(MakeChoice) or even MakeChoice.IsDefined,
> since IsDefined is a member of Enum anyway.
-
Re: Hidden enum values?
Two reasons...
1. Bitflags, where valid values are combinations of named values
2. Performance
Personally, I think we should be able to apply an attribute to a parameter
that says, "Hey compiler! Make sure this value is valid.".
--
Jonathan Allen
"Larry Triezenberg" <ltriezenberg@pathsys.com> wrote in message
news:3aae0726@news.devx.com...
> Yep, I never understood why the compiler wasn't capable of determining
whether
> the passed value was one of the valid entries (in the first place) since
(by
> declaring the parameter as an eNum) you've indicated that only certain
values
> "should" be acceptable. But perhaps this is less technical and more
discussion
> since it's unlikely to change...
>
> "Joe "Nuke Me Xemu" Foster" <joe@bftsi0.UUCP> wrote in message
> news:3aad4f04@news.devx.com...
> > Might be nicer if it was GetType(MakeChoice) or even
MakeChoice.IsDefined,
> > since IsDefined is a member of Enum anyway.
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks