Assorted quick thoughts

Posted 2021-10-11

Terminal password read function, dchar.init musings, tracking email rant, tip on struct ctor that checks all values present.

Core D Development Statistics

In the community

Community announcements

See more at the announce forum.

Tip of the Week

I just added this to a struct:

this(typeof(this.tupleof) args) {
        this.tupleof = args;
}

Why? Because now the compiler will require that I pass all the arguments and thus initialize all members when constructing the struct. This is to prevent any NaN accidents like I had in last week's dconf stream.

What Adam is working on

Someone asked if there was an easy function to do a password prompt. The Linux glibc function is deprecated, so I decided to make my own and add it to terminal.d. Already on master if you wanna try yourself:

import arsd.terminal;

void main() {
        auto terminal = Terminal(ConsoleOutputType.linear);
        auto pwd = terminal.getline("Password: ", '*');
        terminal.writeln(pwd);
}

The second argument is now the echo char. Default argument means normal echo, passing 0 means no echo at all (like most unix password prompts), or you can do another character like the star seen here to give partial but masked user feedback.

Should we change dchar.init?

I think we should change float.init and char.init (and friends) away from their current values to zeroes to better match the way init values are actually used in the real world.

However... I actually use char.init kinda a lot. For example, in the new password function I just showed, it actually uses dchar.init as the "no special behavior" special value, distinct from 0, which is the "don't echo anything" special value. Changing that I fear would be fairly significant code breakage.

Perhaps worth it though, since it could be transitioned fairly easily from dchar.init to dchar.invalid perhaps, or just plain 0xffffffff or whatever it actually is explicitly. (I like dchar.invalid.)

Another rant

Tracking emails should be banned. I often get emails that say things like "are you receiving our emails? We notice you haven't noticed one for a long time."

Well, I do receive them, and I actually read them too. I just don't let your thing phone home to track me. The fact that I subscribed to your list and haven't unsubscribed nor is the message bouncing ought to tell you I'm happy enough with it.

But nope more tracking nonsense. Ugh.