digitalmars.dip.ideas - Remove `default` as a keyword
- Ogion (16/16) Mar 10 In D, `default` is reserved as a keyword, but the only case (no
- Dejan Lekic (2/4) Mar 10 You can argue the same for `version`, right? :)
- Dennis (11/13) Mar 10 I often see problems with `in`, `out`, and `version` being
- Serg Gini (3/5) Mar 10 Yes, in/out are popular names for function arguments.
- Paul Backus (4/8) Mar 10 What if we made `default` reserved as a label, but allowed as a
- Atila Neves (3/11) Mar 11 I think this would be a better proposal, but I'm not sure it's
- user1234 (25/41) Mar 10 Yes but the default-case is not necessarily at the bottom. That
- Kagamin (13/13) Mar 11 I saw a proposal for a loop fallthrough handler
- Kagamin (11/11) Mar 12 ```d
In D, `default` is reserved as a keyword, but the only case (no
pun intended) where it is used is the `switch` statement. It
could be substituted with `else`:
```D
bool isEven(int x) {
// wish there was an easier way to do this...
switch (x) {
case 2, 4, 6, 8:
return true;
else:
return false;
}
}
```
Removing this keyword will allow users to freely use the word
`default` for naming things.
Mar 10
On Tuesday, 10 March 2026 at 11:23:49 UTC, Ogion wrote:Removing this keyword will allow users to freely use the word `default` for naming things.You can argue the same for `version`, right? :)
Mar 10
On Tuesday, 10 March 2026 at 11:23:49 UTC, Ogion wrote:Removing this keyword will allow users to freely use the word `default` for naming things.I often see problems with `in`, `out`, and `version` being reserved in D when translating code from other languages, but `default` is reserved as a keyword for switch statements in C, to it being reserved. For D to deviate from common switch syntax would make it harder to learn. Also consider that `goto default;` then needs to be replaced with `goto else;` which can be confusing when it's inside an if-statement, since it might look like it would go to the `else` statements from that `if` instead of the `switch`.
Mar 10
On Tuesday, 10 March 2026 at 13:52:32 UTC, Dennis wrote:I often see problems with `in`, `out`, and `version` being reserved in D when translating code from other languages, butYes, in/out are popular names for function arguments. I had some issues with C lib that used them :(
Mar 10
On Tuesday, 10 March 2026 at 13:52:32 UTC, Dennis wrote:Also consider that `goto default;` then needs to be replaced with `goto else;` which can be confusing when it's inside an if-statement, since it might look like it would go to the `else` statements from that `if` instead of the `switch`.What if we made `default` reserved as a label, but allowed as a normal identifier in other contexts? This would preserve the existing behavior of `default:` and `goto default;`.
Mar 10
On Tuesday, 10 March 2026 at 16:55:00 UTC, Paul Backus wrote:On Tuesday, 10 March 2026 at 13:52:32 UTC, Dennis wrote:I think this would be a better proposal, but I'm not sure it's worth the effort.Also consider that `goto default;` then needs to be replaced with `goto else;` which can be confusing when it's inside an if-statement, since it might look like it would go to the `else` statements from that `if` instead of the `switch`.What if we made `default` reserved as a label, but allowed as a normal identifier in other contexts? This would preserve the existing behavior of `default:` and `goto default;`.
Mar 11
On Tuesday, 10 March 2026 at 11:23:49 UTC, Ogion wrote:
In D, `default` is reserved as a keyword, but the only case (no
pun intended) where it is used is the `switch` statement. It
could be substituted with `else`:
```D
bool isEven(int x) {
// wish there was an easier way to do this...
switch (x) {
case 2, 4, 6, 8:
return true;
else:
return false;
}
}
```
Removing this keyword will allow users to freely use the word
`default` for naming things.
Yes but the default-case is not necessarily at the bottom. That
would be strange to have
```d
switch (a)
{
else : break;
case 0 : break;
}
```
Now to be honest I've never seen a default-case not declared at
the bottom.
Then there's another problem. The D switch allows random
statement within the body, including else-statements:
```d
switch (x)
{
if (true)
default: break;
else {}
}
```
still possible to change the keyword but this affects a bit the
parser as you have to figure out if `else` is for the `if` or for
the default-case.
Mar 10
I saw a proposal for a loop fallthrough handler
```d
foreach(a;b)
{
if(found)return 0;
}
default
{
puts("not found");
}
```
I think it was `else`, but that's ambiguous, `default` might be
more idiomatic.
Mar 11
```d
bool isEven(int x) {
// wish there was an easier way to do this...
switch (x) {
case 2, 4, 6, 8:
return true;
case:
return false;
}
}
```
Mar 12
On Thursday, 12 March 2026 at 13:20:30 UTC, Kagamin wrote:
```d
bool isEven(int x) {
// wish there was an easier way to do this...
switch (x) {
case 2, 4, 6, 8:
return true;
case:
return false;
}
}
```
yes, that's a bit better toward the previous comment about
ordering of the default-case.
Mar 12
On Thursday, 12 March 2026 at 14:09:27 UTC, user1234 wrote:yes, that's a bit better toward the previous comment about ordering of the default-case.How do you distinguish `goto case;` and `goto default;` then?
Mar 12
On Thursday, 12 March 2026 at 14:53:02 UTC, Dennis wrote:On Thursday, 12 March 2026 at 14:09:27 UTC, user1234 wrote:Indeed, one step forward, on step back.yes, that's a bit better toward the previous comment about ordering of the default-case.How do you distinguish `goto case;` and `goto default;` then?
Mar 12









Dejan Lekic <dejan.lekic gmail.com> 