April 26, 2023

On Tuesday, 25 April 2023 at 20:15:39 UTC, ryuukk_ wrote:

>

void set_connected()
{
network_connect_state = NetworkConnectState.CONNECTED
}

MySuperLongNameFlag flag = MySuperLongNameFlag.A | MySuperLongNameFlag.B | MySuperLongNameFlag.C | MySuperLongNameFlag.D;

set_flags(MySuperLongNameFlag.A | MySuperLongNameFlag.B | MySuperLongNameFlag.C | MySuperLongNameFlag.D)

Okay, I understand this is sometimes really annoying, but in this example, why can't you just:

import std.stdio;

enum MySuperLongNameFlag : int
{
    A = 0b0001,
    B = 0b0010,
    C = 0b0100,
    D = 0b1000,
}

void set_flags(MySuperLongNameFlag f) {}

void main()
{
    with (MySuperLongNameFlag)
    {
        auto flag = A | B | C | D;
        set_flags(A | B | C | D);

        writefln("%04b", flag);
    }
}

April 26, 2023

On Wednesday, 26 April 2023 at 11:52:31 UTC, Jacob Shtokolov wrote:

>

On Tuesday, 25 April 2023 at 20:15:39 UTC, ryuukk_ wrote:

>

void set_connected()
{
network_connect_state = NetworkConnectState.CONNECTED
}

MySuperLongNameFlag flag = MySuperLongNameFlag.A | MySuperLongNameFlag.B | MySuperLongNameFlag.C | MySuperLongNameFlag.D;

set_flags(MySuperLongNameFlag.A | MySuperLongNameFlag.B | MySuperLongNameFlag.C | MySuperLongNameFlag.D)

Okay, I understand this is sometimes really annoying, but in this example, why can't you just:

Many other solutions were provided as well, including but not limited to

  • Using shorter names
  • Using alias
  • Using an IDE with autocomplete
  • Using copy and paste
April 26, 2023

On Tuesday, 25 April 2023 at 04:54:43 UTC, Mike Parker wrote:

>

I submitted DIP1044, "Enum Type Inference", to Walter and Atila on April 1. I received the final decision from them on April 18. They have decided not to accept this proposal.

This was the right decision, but it would have been nice to include as one of the reasons that it would have made it harder for new users.

April 26, 2023

On Tuesday, 25 April 2023 at 04:54:43 UTC, Mike Parker wrote:

>

I submitted DIP1044, "Enum Type Inference", to Walter and Atila on April 1. I received the final decision from them on April 18. They have decided not to accept this proposal.
[...]

While I was rather "pro" I think that D lacked an absolute necessity for that. As explained earlier on IRC, enum type inference is also very intersting when the language has a bitfield type based on an enum, like the Set Of pascal construct, which makes enum member something really commonly used, much more than in D.

April 26, 2023

On Wednesday, 26 April 2023 at 12:50:32 UTC, bachmeier wrote:

>

Many other solutions were provided as well, including but not limited to

  • Using shorter names
  • Using alias
  • Using an IDE with autocomplete
  • Using copy and paste

While aliases and shorter names are always good options, autocomplete and copy/paste really aren't as the end user of the code is either yourself or another developer, so reading the mess produced with copy/paste makes life much more miserable :)

I wish the with() operator would also be an expression, so you could do something like:

auto f = with(Flags) A | B | C |D;

But that breaks backwards compatibility ¯_(ツ)_/¯

April 26, 2023

On Wednesday, 26 April 2023 at 13:08:22 UTC, Jacob Shtokolov wrote:

>

On Wednesday, 26 April 2023 at 12:50:32 UTC, bachmeier wrote:

>

Many other solutions were provided as well, including but not limited to

  • Using shorter names
  • Using alias
  • Using an IDE with autocomplete
  • Using copy and paste

While aliases and shorter names are always good options, autocomplete and copy/paste really aren't as the end user of the code is either yourself or another developer, so reading the mess produced with copy/paste makes life much more miserable :)

I wish the with() operator would also be an expression, so you could do something like:

auto f = with(Flags) A | B | C |D;

But that breaks backwards compatibility ¯_(ツ)_/¯

https://github.com/dlang/dmd/pull/13776

April 26, 2023

On Wednesday, 26 April 2023 at 11:52:31 UTC, Jacob Shtokolov wrote:

>

On Tuesday, 25 April 2023 at 20:15:39 UTC, ryuukk_ wrote:

>

void set_connected()
{
network_connect_state = NetworkConnectState.CONNECTED
}

MySuperLongNameFlag flag = MySuperLongNameFlag.A | MySuperLongNameFlag.B | MySuperLongNameFlag.C | MySuperLongNameFlag.D;

set_flags(MySuperLongNameFlag.A | MySuperLongNameFlag.B | MySuperLongNameFlag.C | MySuperLongNameFlag.D)

Okay, I understand this is sometimes really annoying, but in this example, why can't you just:

import std.stdio;

enum MySuperLongNameFlag : int
{
    A = 0b0001,
    B = 0b0010,
    C = 0b0100,
    D = 0b1000,
}

void set_flags(MySuperLongNameFlag f) {}

void main()
{
    with (MySuperLongNameFlag)
    {
        auto flag = A | B | C | D;
        set_flags(A | B | C | D);

        writefln("%04b", flag);
    }
}

No, what about this:

 import std.stdio;

 enum MySuperLongNameFlag : int
 {
     A = 0b0001,
     B = 0b0010,
     C = 0b0100,
     D = 0b1000,
 }

 void set_flags(MySuperLongNameFlag f) {}

 void main()
 {
    MySuperLongNameFlag flag = A | B | C | D;
    set_flags(A | B | C | D);

    writefln("%04b", flag);
 }

No bloat, no extra indentation, no auto, you know what you are using

April 26, 2023

On Wednesday, 26 April 2023 at 10:48:21 UTC, Greggor wrote:

>

On Tuesday, 25 April 2023 at 04:54:43 UTC, Mike Parker wrote:

>

I submitted DIP1044, "Enum Type Inference", to Walter and Atila on April 1. I received the final decision from them on April 18. They have decided not to accept this proposal.

[...]

I’m going to contribute to the peanut gallery, and say I support the rejection of the dip and the reasoning given is solid.

I do like the suggestion of with final switch and I also like the even shorter enumswitch as a new keyword, it would be a nice bit of syntactic sugar.

Regardless of this dip being added or not, I'm not going to be dramatic about it, its not the end of the world or of D :^)

That's not contribution

with final switch what kind of Java is that? or is it D? i'm getting lost for a moment, not sure!

April 26, 2023

On Wednesday, 26 April 2023 at 12:50:32 UTC, bachmeier wrote:

>

On Wednesday, 26 April 2023 at 11:52:31 UTC, Jacob Shtokolov wrote:

>

On Tuesday, 25 April 2023 at 20:15:39 UTC, ryuukk_ wrote:

>

void set_connected()
{
network_connect_state = NetworkConnectState.CONNECTED
}

MySuperLongNameFlag flag = MySuperLongNameFlag.A | MySuperLongNameFlag.B | MySuperLongNameFlag.C | MySuperLongNameFlag.D;

set_flags(MySuperLongNameFlag.A | MySuperLongNameFlag.B | MySuperLongNameFlag.C | MySuperLongNameFlag.D)

Okay, I understand this is sometimes really annoying, but in this example, why can't you just:

Many other solutions were provided as well, including but not limited to

  • Using shorter names

Why make your code harder to read ?


// just use short name, duh
enum CState
{
   CON, DC, WT
}

void on_con()
{
    st = CState.CON;
}



// no, let me take advantage of the robust type system
enum NetworkConnectionState
{
    CONNECTED, DISCONNECTED, WAITING
}


void on_connecte()
{
    network_state = .CONNECTED;
}
>
  • Using alias

Now you have multiple symbols doing the same thing, that's a maintenance downgrade, "refactor? ohhh i forgot to refactor the multiple aliases"

>
  • Using an IDE with autocomplete

Now i need an IDE to code, nice

>
  • Using copy and paste

Now introduce duplicates that are hard to manage during refactors, wich copy pasta is the right one?

Again, all of this was covered and argumented during the DIP discussion

The goal is to improve the language, not find excuses or workarounds, don't defend obfuscation, move forward

April 26, 2023

On Wednesday, 26 April 2023 at 13:08:22 UTC, Jacob Shtokolov wrote:

>

On Wednesday, 26 April 2023 at 12:50:32 UTC, bachmeier wrote:

>

Many other solutions were provided as well, including but not limited to

  • Using shorter names
  • Using alias
  • Using an IDE with autocomplete
  • Using copy and paste

While aliases and shorter names are always good options, autocomplete and copy/paste really aren't as the end user of the code is either yourself or another developer, so reading the mess produced with copy/paste makes life much more miserable :)

Unless you're using incredibly long names (which is not a reason to change the language) I find the explicit approach to be more readable. If I have to parse the code and do inference, it's a lot more work, and in some cases, more error-prone.

We've had proposals to drop the semicolon requirement. I would hate that. It's easier to read code when I don't have to figure out where the lines end.

>

I wish the with() operator would also be an expression, so you could do something like:

auto f = with(Flags) A | B | C |D;

This would be great, but it goes against the spirit of this DIP, since you have to explicitly type out with(Flags).