Re: passing enum value as an argument



> Yes, but then you made blanket statements which didn't state that you
> were essentially working in a non-typesafe way. You can't expect type
> safety at all (at compile time) when you've got option strict turned
> off. Do you actually write much code without option strict on?

The issue at hand in this particular question is whether you could possibly
call a value from an Enum without qualifying the value, the discussion is not
about type safety. Anytime you assign a type of any kind to any variable you
get type safety, there is no argument there. It was the other reply that
introduced type safety into this thread. By the way, I ALWAYS code with
Option Strict ON.

Yes, if you cast it. In what way does that diminish the usefulness of
> having compile-time type safety when you're *not* deliberately trying
> to break things?

Again. Not talking about type safety here.

> You seem to think that the sole purpose of enums is to force the
> developer into fully qualifying names. I think that's a pretty narrow
> idea of the purpose - for me, it's mostly to provide a typesafe way of
> having a collection of values which map to primitive values.
>
> By your idea of the purpose of enums, yes, the OP's solution would
> indeed defeat the purpose. I think you'll find you're in the minority
> when it comes to that idea.

This may sound silly but.... For you to get the benefits of an Enum, you
have to USE the Enum, don't you think?... lol, no disrespect there. Consider
this:

Enum Juan
One
Two
End Enum

Dim SomeVariable as Juan
When you call it: SomeVariable = Juan.One

There you are limiting the value of SomeVariable to a limited range (the
Enum). Now, This is what the owner of this post proposes:

Enum Juan
One = 0
Two = 1
End Enum
Dim SomeVariable as Juan
When you call it: SomeVariable = One

First of all, how will the compiler be able to resolve this variable? It
will not be able to, because in this scope there is no such variable. There
is a reference however to Juan.One .
If the user wants to not qualify the name (which you can never do), wouldnt
it be the same as doing this?:

Dim SomeVariable as Juan
Dim One as integer = 0
When you call it: SomeVariable = One

The only difference would be that the enum would limit you to a defined
range. Other than that, this is the same, so IT DOES defeat the purpose of
having an Enum, which is why Enums exist, otherwise the language creators
wouldnt have bothered, don't you think?

Thank you.

--
Juan Romero
-----------------------------------------
The successful person has the habit of doing the things failures don't like
to do.
E.M. Gray


"Jon Skeet [C# MVP]" wrote:

> Madestro <me_no_like_spam_juanDOTromero@bowneDOTcom> wrote:
> > Well, if you read the thread carefully you will see that I DID mention
> > Option Strict before.
>
> Yes, but then you made blanket statements which didn't state that you
> were essentially working in a non-typesafe way. You can't expect type
> safety at all (at compile time) when you've got option strict turned
> off. Do you actually write much code without option strict on?
>
> > But even with Option Strict ON you can still pass a
> > value from another Enum if you cast it.
>
> Yes, if you cast it. In what way does that diminish the usefulness of
> having compile-time type safety when you're *not* deliberately trying
> to break things?
>
> > Nevertheless, because of all these comments, we are drifting away from the
> > point of this question, and I still stand on my ground: Refering to Enum
> > options without fully qualifying them defeats the purpose of having an Enum.
>
> You seem to think that the sole purpose of enums is to force the
> developer into fully qualifying names. I think that's a pretty narrow
> idea of the purpose - for me, it's mostly to provide a typesafe way of
> having a collection of values which map to primitive values.
>
> By your idea of the purpose of enums, yes, the OP's solution would
> indeed defeat the purpose. I think you'll find you're in the minority
> when it comes to that idea.
>
> > You might as well declare variables or constants if you dont want to go
> > through the trouble of qualifying names.
>
> Except then you lose the type safety, and could accidentally end up
> using (say) an HTTP response code where you should actually be using a
> file share mode.
>
> --
> Jon Skeet - <skeet@xxxxxxxxx>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too
>
.



Relevant Pages

  • Re: passing enum value as an argument
    ... safety at all when you've got option strict turned ... and I still stand on my ground: Refering to Enum ... > options without fully qualifying them defeats the purpose of having an Enum. ...
    (microsoft.public.dotnet.general)
  • Re: passing enum value as an argument
    ... Option Strict before. ... and I still stand on my ground: Refering to Enum ... > | It may not be the case in the language you are using, ... > |> SecondEnum with values Fred, George, Harry, and two methods: ...
    (microsoft.public.dotnet.general)
  • RE: passing enum value as an argument
    ... Not with option strict on. ... Public Enum FirstEnum ... Shared Sub TakeSecondEnum ...
    (microsoft.public.dotnet.general)
  • RE: passing enum value as an argument
    ... > hours after your only previous reference to Option Strict? ... indeed you would have an Enum, and you WOULD have to use the same type on the ... the compiler would force you to ... >> Public sub New ...
    (microsoft.public.dotnet.general)
  • RE: passing enum value as an argument
    ... I did talk about Option Strict. ... > I clearly stated that you could CAST to the Enum type. ... > Public sub New ... > Juan Romero ...
    (microsoft.public.dotnet.general)