Re: switch




"James Curran" <jamescurran@xxxxxxxx> wrote in message
news:exKlDDQKGHA.1192@xxxxxxxxxxxxxxxxxxxxxxx
"Michael S" <no@xxxxxxxx> wrote in message
news:OdmcFt2JGHA.2248@xxxxxxxxxxxxxxxxxxxxxxx
I hate when VB does stuff better than C#. I wonder why switch is so
limited
in C#, anyone knows why?

You're looking at it from the wrong point of view. When C was being
designed (in the 1970's), they added if() to the language, but they wanted
a
way to do something which could not be easily done with nested if()s,
specifically, a jump table (and other optimizations). So, they created
the
switch statement. When C begat C++ and when C++ begat C#, the syntax was
carried forward, but more importantly, the functionality was also carried
forward.

Years later, the VB designers though C's switch statement looked cool,
and decided to add it to VB (renaming it Select) (actually I think it
entered the language in the MSDOS/QuickBasic era). However, it is purely
cosmetic --- VB's Select does *nothing* that nested IFs don't do -- It
probably even compiles to identical code.

One would think that a clever compiler designer would be able to dream up a
switch that can do either, they've already added string support to the C#
version which isn't quite a jump table(it does use a hashtable at some point
I think) and multiple labels. Allowing range shortcuts, if not whole
expressions, at some acceptable level of performance shouldn't be impossible
in the modern day.


.



Relevant Pages

  • Re: OT: Requesting C advice
    ... language designers made the language ... Every compiler I've used compiles C to native machine code for the ... libraries was not pleasant. ...
    (Fedora)
  • Re: Speculative Design Hypothesis (with predictions) 2nd draft
    ... intelligence of their designers. ... I'm not saying that DNA is a language ... evidence you have is that other mammals have forelimbs that look like ... So how did these two similar bills or two completely ...
    (talk.origins)
  • Re: [LONG] C# too sharp for me
    ... much more about you than the language. ... or that you think the language designers didn't understand ... OTOH, I do a lot of VB.Net work, and VB programmers are always asking me ... this morning I bought a copy of Programming Ruby! ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Speculative Design Hypothesis (with predictions) 2nd draft
    ... intelligence of their designers. ... I'm not saying that DNA is a language ... evidence you have is that other mammals have forelimbs that look like ... Because bat forelimbs and other mammalian forelimbs are similar does not ...
    (talk.origins)
  • Re: Python syntax in Lisp and Scheme
    ... is not Lisp is a domain-specific language for ... You say that's because Lisp can be used ... > designers have found the best language feature for any task that might ... So, umm, how does Lisp handle shared memory? ...
    (comp.lang.lisp)