Thread overview | |||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 28, 2002 switch default | ||||
---|---|---|---|---|
| ||||
In debug build I got a "switch default" runtime error! Is this true, that you *must* provide a default case, and that a switch without a matching case is an error? I dislike the idea of having to provide an explicit default which does nothing, but there may be other reasons for this (safety I guess) Lotta little things to get used to in D. ;) Sean |
May 28, 2002 Re: switch default | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | >
> Is this true, that you *must* provide a default case, and that a switch without a matching case is an error? I dislike the idea of having to provide an explicit default which does nothing, but there may be other reasons for this (safety I guess)
>
it makes no sense to have a default in every switch. it would be like having an else in every single if.
|
May 28, 2002 Re: switch default | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos | "Carlos" <carlos8294@msn.com> wrote in message news:acurl4$g05$1@digitaldaemon.com... > > Is this true, that you *must* provide a default case, and that a switch without a matching case is an error? I dislike the idea of having to provide an explicit default which does nothing, but there may be other reasons for this (safety I guess) > > > it makes no sense to have a default in every switch. it would be like having > an else in every single if. Not really so. It helps to resolve problems like when you add a new member to an enum, and forget to add the appropriate case for it. And besides, is a single "default:" at the end of case so hard to type? |
May 28, 2002 Re: switch default | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | > And besides, is a single "default:" at the end of case so hard to type?
>
it is if you see it under one of 2 (or more) points of view:
1) under logical eyes (already explained)
2) under the eyes of a common C programmer
|
May 28, 2002 Re: switch default | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | "Pavel Minayev" <evilone@omen.ru> wrote in message news:acuuif$kq6$1@digitaldaemon.com... > "Carlos" <carlos8294@msn.com> wrote in message news:acurl4$g05$1@digitaldaemon.com... <Snip> > And besides, is a single "default:" at the end of case so hard to type? 1. The less code often makes things quicker to read (compare reading point for to an essay). 2. Allowing optional components don't make things much more difficult. 3. If you can shave 10% of typing in a program, that's 10% more time to spend elsewhere. I agree that a language needs to be strongly typed, but something like not using "default:" isn't going to cause that many more errors. |
May 28, 2002 Re: switch default | ||||
---|---|---|---|---|
| ||||
Posted in reply to anderson | "anderson" <anderson@firestar.com.au> wrote in message news:acv659$tb5$1@digitaldaemon.com... > 1. The less code often makes things quicker to read (compare reading point > for to an essay). > 2. Allowing optional components don't make things much more difficult. > 3. If you can shave 10% of typing in a program, that's 10% more time to > spend elsewhere. > > I agree that a language needs to be strongly typed, but something like not using "default:" isn't going to cause that many more errors. In general, I agree with you. I just told the "official explanation" for this feature. |
May 28, 2002 Re: switch default | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | And before we start another war with the bracket clan :) As long as the language is much better then C++ these things are really very insignficant. PS - I wonder if they had the same arguments when inventing A,B,C, C++ and C#? "Pavel Minayev" <evilone@omen.ru> wrote in message news:ad0218$27n0$1@digitaldaemon.com... > "anderson" <anderson@firestar.com.au> wrote in message news:acv659$tb5$1@digitaldaemon.com... > > > 1. The less code often makes things quicker to read (compare reading point > > for to an essay). > > 2. Allowing optional components don't make things much more difficult. > > 3. If you can shave 10% of typing in a program, that's 10% more time to > > spend elsewhere. > > > > I agree that a language needs to be strongly typed, but something like not > > using "default:" isn't going to cause that many more errors. > > In general, I agree with you. I just told the "official explanation" for > this > feature. |
May 28, 2002 language features | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | Hey, A quick question. I like C#'s implementation of reflection. Does D do reflection? Also, Does D do variable parameters? C# has a good convention for variable parameters using the params keyword like this: void Print(params string stuffToPrint[]) { foreach(oneThing in stuffToPrint) System.Console.WriteLn(oneThing); } Then you would call it like this: Print("Printing ", "variable ", "parameters"); I know it seems like I'm bragging on C#, but I'm not really. I would never use it since I do a lot of scientific applications that are too computationally intensive for an interpreted language. C# is too slow. I've used it. I do think that C# has beautiful syntax, though. Thanks, Craig |
May 28, 2002 Re: switch default | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | "Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:acurhn$foq$1@digitaldaemon.com... > In debug build I got a "switch default" runtime error! > Is this true, that you *must* provide a default case, and that a switch > without a matching case is an error? Correct. > I dislike the idea of having to > provide an explicit default which does nothing, but there may be other > reasons for this (safety I guess) The reason for it is all the bugs I've had over the years where I add another value to something, and forget to add a case for it in a corresponding switch somewhere in the code. It means one must be explicit about ignoring the default case. > Lotta little things to get used to in D. ;) Yup <g>. D doesn't have one killer feature, it is more the aggregate of a lot of little things. |
May 28, 2002 Re: language features | ||||
---|---|---|---|---|
| ||||
Posted in reply to cblack01 | "cblack01" <cblack01@cox.net> wrote in message news:ad0rbq$88q$1@digitaldaemon.com... > A quick question. I like C#'s implementation of reflection. Does D do reflection? Only partially, via the .classinfo property. > Also, Does D do variable parameters? C# has a good convention for variable > parameters using the params keyword like this: > > void Print(params string stuffToPrint[]) > { > foreach(oneThing in stuffToPrint) System.Console.WriteLn(oneThing); > } > > Then you would call it like this: > > Print("Printing ", "variable ", "parameters"); D does variable parameter lists exactly like C does. While not typesafe, it is efficient. |
Copyright © 1999-2021 by the D Language Foundation