News for hackers. Stuff that matters.
Re:Ruminations on D: An Interview with Walter Bright by jordigh on Tuesday August 30, 2016 @11:22AM (#12390946)

    We nailed it with arrays (Jan Knepper’s idea), the
    basic template design, compile-time function execution 
   (CTFE)
One of my favourite things about D is that it has a full compile-time D interpreter. You can do "template metaprogramming", so to speak, in the same language as D itself (it's probably a bit more fair to compare it to how lisp macros are "compile-time").

It's a bit sad that Rust is getting all of the attention in the spotlight, because D is a great, modern, safe language. If you've only heard about D 15 years ago and never tried it again, give it another look. The current D is really a new language, which was briefly called "D2" for a while.

Now, if Symantec could just fix the stupid licence of the reference compiler...

https://forum.dlang.org/thread/[email protected]...

Re:Ruminations on D: An Interview with Walter Bright by justin66 on Tuesday August 30, 2016 @02:42PM (#12392726)
To someone with only a passing interest, but a real interest nonetheless, D's position in the spotlight is a lot more comfortable than what's going on with rust. After a while, the way every thread about c, c++, systems programming, or operating systems draws the same predictable rust comments feels like being assaulted by a lunatic wielding a cheese grater.
Re:Ruminations on D: An Interview with Walter Bright by santaclaus on Tuesday August 30, 2016 @06:33PM (#12394503)
I've seen this phenomenon called 'Rustwins law' as it bears striking similarities to Godwin's law in its inevitability.
Re:Ruminations on D: An Interview with Walter Bright by stcredzero on Tuesday August 30, 2016 @07:42PM (#12394844)
If the law suggests that Rust wins, I'm sure the Rust community will not strenuously object.
Re:Ruminations on D: An Interview with Walter Bright by notriddle on Wednesday August 31, 2016 @12:06PM (#12399311)
If it's going to match Godwin's Law, then whoever mentions Rust automatically loses the argument...
Re:Ruminations on D: An Interview with Walter Bright by jordigh on Wednesday August 31, 2016 @12:10PM (#12399347)
Godwin's law isn't about losing the argument. It's just an observation that national socialism is going to be mentioned in the limit as the conversation grows without end.
Re:Ruminations on D: An Interview with Walter Bright by pcwalton on Tuesday August 30, 2016 @12:14PM (#12391406)
> It's a bit sad that Rust is getting all of the attention in the spotlight

This isn't a zero-sum game! D is a fine language.

Re:Ruminations on D: An Interview with Walter Bright by jordigh on Tuesday August 30, 2016 @01:03PM (#12391839)
There is a limited resource here, which is programmers' time and attention. If everyone is scrambling to Rust, they will probably not give D as much attention. Without attention, D will probably not have a healthy collection of 3rd party libraries and tools.
Re:Ruminations on D: An Interview with Walter Bright by lifthrasiir on Tuesday August 30, 2016 @08:50PM (#12395130)
I think D have been already given tons of attention, especially in its early years (just like other newer languages). That early-day reception defines the acceptance in, say, next decade---at which Rust has been relatively excelled than D, IMHO.
Re:Ruminations on D: An Interview with Walter Bright by gmfawcett on Tuesday August 30, 2016 @11:50AM (#12391194)
I agree! But the compile-time interpreter isn't really "full". For example, you can't do arbitrary I/O in a compile-time expression (by design). Non-portable casts and inline ASM are other exceptions. See [1] for the full story.

[1]: https://dlang.org/spec/function.html#interpretation

Re:Ruminations on D: An Interview with Walter Bright by Shoop on Tuesday August 30, 2016 @12:42PM (#12391658)
If inline asm or non-portable casts were allowed, D programs would compile inconsistently on different architectures. Compile time IO doesn't make much sense either. Not all limitations are shortcomings.
Re:Ruminations on D: An Interview with Walter Bright by Zardoz84 on Tuesday August 30, 2016 @12:58PM (#12391802)
Compile time read have sense. For example, reading a XML to build a GUI on complete time instead on runtime (I see you GTK builder).

Actually you can do this on CTFE on D, doing an import of a file and dumping it to an enum. The only big pitfall of this, is that enforces to read the whole file by the compiler.

Re:Ruminations on D: An Interview with Walter Bright by p0nce on Tuesday August 30, 2016 @06:34PM (#12394504)
> reading a XML to build a GUI on complete time instead on runtime

It can be done with:

    void[] ctData = import("file.xml");
For example, this feature is used in vibe.d to compile an HTML template language into more optimized code.
Re:Ruminations on D: An Interview with Walter Bright by Shoop on Tuesday August 30, 2016 @01:11PM (#12391914)
I withdraw my claim that compile time IO doesn't make any sense, but it is something I would be worried about. I wouldn't want the executable my build process produces to be changed by what files are laying around on the disk. Mixing in all of the state in the file system with something you want to be mostly stateless (your build process) seems like a dangerous idea to me.
Re:Ruminations on D: An Interview with Walter Bright by dansze on Tuesday August 30, 2016 @01:24PM (#12392022)
The compiler already depends on the state of the file system though, notably because it depends on the source code. In the above case, the xml is essentially just another source file that happens to not be in the same language.

An important difference is that the compiler doesn't know it's using that file ahead of time, which could have some unforeseen consequences, but I don't see anything immediately worrying about that fact since the compiler didn't know about the source either at it's own compile time.

Re:Ruminations on D: An Interview with Walter Bright by duaneb on Tuesday August 30, 2016 @02:51PM (#12392802)
How is it any different from, say, a makefile?
Re:Ruminations on D: An Interview with Walter Bright by stcredzero on Tuesday August 30, 2016 @07:48PM (#12394877)
Compile time read have sense.

Considering what we've known about the typical behavior of production programs for decades, why isn't there also an "Initialization Time" in addition to Compile Time and "runtime." (Steady State Time?)

Re:Ruminations on D: An Interview with Walter Bright by steveklabnik on Tuesday August 30, 2016 @08:22PM (#12395024)
Some languages do have a "life before main", but it's not always clear that it's a good thing. I don't have a link offhand, but I think it has a bad rap because it's often used to initialize some kind of global state, with all the cons global state brings.
Re:Ruminations on D: An Interview with Walter Bright by stcredzero on Wednesday August 31, 2016 @02:12PM (#12400273)
I remember a study of production Python servers that showed that past an "initialization period" the types of objects in variables settled down and essentially became static. It seems to me that this is a very common across many languages, and that this pattern could be exploited in a number of ways. (Compiling "dynamic" languages in the above case.)

I think it has a bad rap because it's often used to initialize some kind of global state, with all the cons global state brings.

So then what if the language didn't have global state, or only had immutable global state?

Re:Ruminations on D: An Interview with Walter Bright by ptman on Wednesday August 31, 2016 @06:47AM (#12397318)
Perl source filters
Re:Ruminations on D: An Interview with Walter Bright by steveklabnik on Tuesday August 30, 2016 @12:58PM (#12391798)

  > Compile time IO doesn't make much sense either.
While I agree with D's decision here, there are other languages which do allow anything at compile time. See Jai, for example.
Re:Ruminations on D: An Interview with Walter Bright by wtetzner on Tuesday August 30, 2016 @03:56PM (#12393341)
And Common Lisp, and Scheme, and Elixir, and Clojure, and I'm sure I'm missing a bunch :)
Re:Ruminations on D: An Interview with Walter Bright by lomnakkus on Wednesday August 31, 2016 @04:04PM (#12401078)
Even... Haskell! Dundundun! (I'm referring to Template Haskell.)

As it turns out (IME) referencing arbitrary data (such as a database schema queried from a 'live' database) is actually of quite limited value.

Where I actually agree that it makes sense is the 'read-a-checked-in-file-and-generate-code-at-compile-time-from-that'. Otherwise, you're mostly just looking at a lot of pain compared to just generating code (that you might check in).

Re:Ruminations on D: An Interview with Walter Bright by p0nce on Tuesday August 30, 2016 @06:35PM (#12394508)
Those come with the whole compiler at runtime.
Re:Ruminations on D: An Interview with Walter Bright by lucian1900 on Tuesday August 30, 2016 @12:10PM (#12391370)
> D is a great, modern, safe language

It's very nice, but it isn't memory safe.

Re:Ruminations on D: An Interview with Walter Bright by WalterBright on Tuesday August 30, 2016 @02:27PM (#12392610)
It's close, and we're working to close the remaining gaps.

Probably the biggest memory safety issue is buffer overflows, and D does a good job stopping that (array overflow checking).

Re:Ruminations on D: An Interview with Walter Bright by posterboy on Tuesday August 30, 2016 @12:40PM (#12391646)
I wonder, could a portable ownership model be implemented with the templates?
Re:Ruminations on D: An Interview with Walter Bright by pcwalton on Tuesday August 30, 2016 @01:52PM (#12392272)
Not soundly, no. The borrow check requires flow-sensitive analysis. The lifetime typechecker requires subtyping-aware extensions to Hindley-Milner.
Re:Ruminations on D: An Interview with Walter Bright by nialv7 on Wednesday August 31, 2016 @07:44PM (#12402284)
Can you going into some details about this? Like proofs?
Re:Ruminations on D: An Interview with Walter Bright by steveklabnik on Tuesday August 30, 2016 @12:57PM (#12391787)
I thought there was a DIP for this, but cannot seem to find it now.
Re:Ruminations on D: An Interview with Walter Bright by Shoop on Tuesday August 30, 2016 @12:46PM (#12391689)
When is D not memory safe?
Re:Ruminations on D: An Interview with Walter Bright by steveklabnik on Tuesday August 30, 2016 @12:51PM (#12391720)
It has been years since I have actively programed in D, so take this with a grain of salt, but my understanding is that D only guarantees memory safety in its @safe subset. See here: https://dlang.org/spec/memory-safe-d.html

Context: safe Rust is also a subset of unsafe Rust. But when people mention a language without qualifiers, they mean whatever the default is. D (appears) to default to a non-memory safe language, and Rust defaults to a memory-safe one. I believe this is what OP meant. (this also ignores the relative feature sets of the various sub/super-sets)

Re:Ruminations on D: An Interview with Walter Bright by qznc on Wednesday August 31, 2016 @07:22AM (#12397450)
Yes, Rust picked the better default and D is too mature to change it now, unfortunately. Likewise with "pure", "const", and maybe even "nothrow" and "nogc".

However, I don't think it is such a big deal, since you can patch it quite well. Mark your main function as @safe and you are force to make everything @safe (or @trusted as a workaround). The type checker will tell you where to look next.

It is interesting that Rust functions are not pure by default. I guess (did not follow the design discussions), because purity is too limiting. D came up with the concept of "weakly pure", which is useful and strong enough. Also you need transitive const to turn a weakly pure into really pure function.

Re:Ruminations on D: An Interview with Walter Bright by steveklabnik on Wednesday August 31, 2016 @10:20AM (#12398475)
Re:Ruminations on D: An Interview with Walter Bright by dansze on Tuesday August 30, 2016 @03:43PM (#12393247)
By default, D has no safeguards to prevent you from doing memory-unsafe things, and afaik no compile-time checks short of marking your main method as @safe. However, because the language is by default memory managed, it is fairly easy to stick to safe code without this by avoiding pointer/cast voodoo.
Re:Ruminations on D: An Interview with Walter Bright by p0nce on Tuesday August 30, 2016 @07:08PM (#12394690)
Fortunately with array bounds checks and default initialized variables, memory corruptions aren't very common in D.
Re:Ruminations on D: An Interview with Walter Bright by stonemetal on Tuesday August 30, 2016 @03:19PM (#12393049)
Always:

    import std.c.stdio;

    int main() {
	int x = 7;
	int* p = &x;
	 printf ("%d\n", *(p + 1));
	return 0;
    }
This compiles in D and violates memory safety.

If you prefer a documentation answer(https://dlang.org/spec/arrays.html#pointers) These are simple pointers to data, analogous to C pointers. Pointers are provided for interfacing with C and for specialized systems work. There is no length associated with it, and so there is no way for the compiler or runtime to do bounds checking, etc., on it.

Re:Ruminations on D: An Interview with Walter Bright by WalterBright on Tuesday August 30, 2016 @04:01PM (#12393378)
Add '@safe' to main()'s declaration and it will no longer compile.
Re:Ruminations on D: An Interview with Walter Bright by notriddle on Wednesday August 31, 2016 @12:08PM (#12399324)

    import std.stdio;

    @safe int f() {
      int* x = new int(6);
      delete x;  // !!
      return *x; // !!!!
    }

    @safe void main() {
      writeln(f());
    }
Re:Ruminations on D: An Interview with Walter Bright by nialv7 on Wednesday August 31, 2016 @07:46PM (#12402297)
'delete' is in the process of being deprecated: https://dlang.org/deprecate.html#delete