News for hackers. Stuff that matters.
Re:D 2.069.0 released, compiler automatically ported from C+... by amelius on Wednesday November 04, 2015 @06:15AM (#10505778)
I'm wondering, is there an advantage of using D over Rust?
Re:D 2.069.0 released, compiler automatically ported from C+... by logicchains on Wednesday November 04, 2015 @06:30AM (#10505831)
Some things D has that Rust doesn't: compiler-checked function purity annotations, higher-kinded types, variadic functions/generics, types parameterised by numbers, compile-time function evaluation, mixins, a fast compiler (the reference DMD compiler), powerful and convenient compile-time reflection (I think technically Rust can do anything D can at compile time, but it requires writing a syntax extension to do so). For better or worse, D also has classical OO inheritance, which Rust lacks.
Re:D 2.069.0 released, compiler automatically ported from C+... by steveklabnik on Wednesday November 04, 2015 @06:38AM (#10505845)
I would say this is fairly accurate, yeah. We got rid of purity in Rust, we didn't find it useful. HKT, variadic generics, and type-level integers are all things we want to do in the future.
Re:D 2.069.0 released, compiler automatically ported from C+... by logicchains on Wednesday November 04, 2015 @07:08AM (#10505935)
The ship's probably sailed on this, but is there any chance of Rust getting a module system like OCaml's (or Haskell's upcoming Backpack) in future? Or is there a way to provide module signatures with the current module system?
Re:D 2.069.0 released, compiler automatically ported from C+... by steveklabnik on Wednesday November 04, 2015 @07:11AM (#10505946)
Never say never, but I'm not aware of anyone who's even working on thinking about suggesting it. That'd be step one, creating an RFC which thinks through the design.
Re:D 2.069.0 released, compiler automatically ported from C+... by logicchains on Wednesday November 04, 2015 @07:22AM (#10505995)
There's this: https://internals.rust-lang.org/t/traits-ml-modules/272, but it didn't seem to get anywhere.
Re:D 2.069.0 released, compiler automatically ported from C+... by steveklabnik on Wednesday November 04, 2015 @07:27AM (#10506012)
Right, that was just a few posts, a long time ago, and never really came close to being a serious proposal.
Re:D 2.069.0 released, compiler automatically ported from C+... by sdegutis on Wednesday November 04, 2015 @09:23AM (#10506676)
Rust and D are both great. The difference is that Rust has a hugely powerful hype train, which happens to be operating at 1,000% capacity somehow since the beginning of Rust.
Re:D 2.069.0 released, compiler automatically ported from C+... by epoch1970 on Wednesday November 04, 2015 @12:38PM (#10508164)
Rust inherited the enthusiasm of some very prominent and outspoken members of the Ruby community. These ex-Rubyists honed the craft of projecting excitement with Ruby and RoR, and brought these skills and talents with them when they moved to the Rust camp. The D camp hasn't really had anyone like that join them.
Re:D 2.069.0 released, compiler automatically ported from C+... by jguegant on Wednesday November 04, 2015 @01:44PM (#10508580)
I have to agree on this. I was surprised to see that a majority of the Rust community actually comes from some web-development domains. Especially when comparing Ruby, a highly flexible dynamic language, to Rust a language full of constraints (for its own valid reasons).

Note that the a hype train is a two-edged sword, it will both bring a strong community and might also induce a cliff with the other communities (praising a single god is never a good thing).

Re:D 2.069.0 released, compiler automatically ported from C+... by kbenson on Wednesday November 04, 2015 @02:02PM (#10508732)
An alternative interpretation might be that rust has particular appeal to those that primarily use dynamic languages. It's probably both, but I will say that as someone that's busy getting stuff done in Perl[1] every day, rust looks appealing, and a lot of that has to do with guarantees. If I'm going to give up the convenience of Perl for a lower level language[2], I need to be sold. Rust's promise of provably correct memory management sounds really good in that situation.

1: I've used lower level languages, but for nothing large, and I haven't started a project in C, C++ or even Java in over a decade, and was never very enamored.

Re:D 2.069.0 released, compiler automatically ported from C+... by steveklabnik on Wednesday November 04, 2015 @05:07PM (#10510150)
As someone who fits this mould, for me, it's not exactly that. Yes, in my professional life, people know me for my Rails work, but I learned C at a very young age, and while my systems-level stuff was a bit out of practice, for me, Rust is a _return_ to the kind of stuff I used to do earlier in life.

Oh, and I'm not sure "majority" is really true. Yeah, maybe some of us have disproportionate impact, but a very large number of people in Rust-land really know their systems stuff. I am humbled to work alongside such talented people.

Re:D 2.069.0 released, compiler automatically ported from C+... by kbenson on Wednesday November 04, 2015 @11:57AM (#10507863)
As someone who's been following the hype, but not really jumped on yet, the difference (whether real or imagined) seems to be that rust is trying to do something new, and D looks to be (and I've seen it aggressively marketed as) C++ with some better choices and cool features. Personally, I'm not really interested in C++, but I am interested in getting for familiar with a systems language, so rust interests me.
Re:D 2.069.0 released, compiler automatically ported from C+... by sdegutis on Wednesday November 04, 2015 @12:30PM (#10508105)
From what I understand, the only new thing Rust is contributing is managed lifetimes. Everything else is, like in D, just borrowed from other languages and put together.

That said, I've mostly heard that lifetimes are still too young to be worth the trouble. So the one new thing Rust does bring to the table isn't really ready yet.

Re:D 2.069.0 released, compiler automatically ported from C+... by kbenson on Wednesday November 04, 2015 @12:58PM (#10508316)
I think of it like this: If I'm going to manually be managing memory, I might as well get some real gain for that effort. Provably correct memory management through an ownership system sounds like it might be worth the effort, especially if it might also help in situations with threading. I've had reason to use threads quite a bit in the past.
Re:D 2.069.0 released, compiler automatically ported from C+... by pcwalton on Wednesday November 04, 2015 @06:32PM (#10510575)
> That said, I've mostly heard that lifetimes are still too young to be worth the trouble. So the one new thing Rust does bring to the table isn't really ready yet.

Not in my experience. I wrote tons of safe Rust every day and I really enjoy not having to worry about difficult-to-debug crashes, undefined behavior, and security problems.

Re:D 2.069.0 released, compiler automatically ported from C+... by Manishearth on Wednesday November 04, 2015 @07:17PM (#10510750)
> just borrowed from other languages and put together.

Most of these things are new to the systems space, though. Things like algebraic data types, etc. Also usable affine types.

> lifetimes are still too young to be worth the trouble.

I've heard pretty much the opposite. Firstly, nobody who uses Rust calls the feature "lifetimes" (it's usually called borrowing or borrow checking). That's the name of the syntax, and while the syntax is new and somewhat confusing it doesn't pop up that much thanks to elision.

Borrowing has a learning curve, yes. But really, it's an equivalent set of principles to what you would do in C++ to keep your pointers safe. The difference is that you can write small C++ codebases without worrying about "C++ borrowing", whereas you need to think about these things off the bat in Rust.

Re:D 2.069.0 released, compiler automatically ported from C+... by detrino on Thursday November 05, 2015 @04:20AM (#10512405)
> it's an equivalent set of principles to what you would do in C++ to keep your pointers safe.

The things you can prove statically with the borrow checker are a subset of the things that wont trigger UB in C++.

Re:D 2.069.0 released, compiler automatically ported from C+... by Manishearth on Thursday November 05, 2015 @07:20AM (#10512890)
That doesn't contradict what I said.

My point was: If you're working on a large C++ codebase you will have to reason roughly about who owns what and where your pointery data is coming from. IME it amounts to (roughly) the same thing as Rust's borrowck rules, just that Rust forces you to think about this a priori, in a clean framework with clear rules, instead of wibbly wobbly, pointy-wointy, ... stuff.

The things you feel safe to do in Rust are often a superset of the things you feel safe to do in C++. Most large codebases often use lots of shared_ptr or equivalent, whereas in Rust Rc and RefCell are broken out only when necessary (when the compiler tells us there's no way to do it the borrow way).

So while C++ might let you write a larger variety of non-UB patterns in principle, Rust will let you write more non-UB patterns in practice. You feel safe playing fast and loose with the references, and dancing near the line of safe behavior since the compiler ensures you never cross it. I have a post illustrating an example of this here: http://manishearth.github.io/blog/2015/05/03/where-rust-real...

And, of course, if you really want to express one of those "things C++ lets you do" wrt pointers, you can always break out `unsafe`.

Re:D 2.069.0 released, compiler automatically ported from C+... by detrino on Thursday November 05, 2015 @03:46PM (#10515998)
Your comment has the structure of a well reasoned argument, but it's predicated on falsehoods.

Most large C++ projects do not unnecessarily use reference counting.

Most C++ programmers do not fear using references or pointers because of invalidation.

The Rust compiler does not tell you when it's impossible to satisfy your problem using borrows. In fact it often has false positives requiring borrow gymnastics because it is too primitive.

And your last line is a complete reversal of your previous attitude: Suddenly you are focusing on theory while ignoring that in practice you can not usually break out `unsafe` to solve your borrow problems. In fact it's Rust, not C++, that is more likely to reach for more heavyweight abstractions than necessary because it's not practical to litter unsafe throughout your codebase.

Re:D 2.069.0 released, compiler automatically ported from C+... by Manishearth on Thursday November 05, 2015 @04:16PM (#10516162)
> Most C++ programmers do not fear using references or pointers because of invalidation.

Compared to Rust? I doubt that. Like I said, Rust lets you dance near the line.

This is from experience in various large C++ codebases. I'm not saying people use refcounting a lot, I'm saying it gets used more than Rust.

YMMV though, so it does boil down to a matter of different experiences here. We'll probably have to agree to disagree.

> In fact it often has false positives requiring borrow gymnastics because it is too primitive.

Not really. Aside from non-lexical borrows and a couple other nice-to-have things (but not necessary), the borrow checker is pretty precise for what it tries to prove.

One might argue that the guarantees Rust tries to maintain (one writer or multiple readers for a piece of data) are too primitive. I don't think that's true. Doing a context-sensitive/flow-sensitive analysis might lead to more patterns being allowed but it's hard to scope guarantees when the analysis is interprocedural -- stopping at function boundaries makes sense to me.

> The Rust compiler does not tell you when it's impossible to satisfy your problem using borrows.

It sort of does. If you try to introduce borrows and listen to the suggestions the compiler gives you, and eventually end up nowhere, it's probably not possible to do it that way. It's not perfect, but it's good enough. And it's immune to further changes -- you don't need to design your pointer usage so that it's future-proof; design it however you want, and if a future refactoring introduces a possible use-after-free, fix the compile error.

> And your last line is a complete reversal of your previous attitude: Suddenly you are focusing on theory while ignoring that in practice you can not usually break out `unsafe` to solve your borrow problems.

No, it's not, I'm just pointing out the equivalence. My point was that "The things you can prove statically with the borrow checker are a subset of the things that wont trigger UB in C++." is irrelevant for two reasons -- (a) in practice IMO the things Rust makes you feel safe to do is a superset of what C++ lets you feel safe to do, and (b) if we're going to talk about "all possible things C++ theoretically allows you to do", then you should include unsafe -- you were comparing "safe Rust" with "all C++", which is unfair here, since the entities to be compared for what you're theoretically allowed to do are "all Rust" and "all C++". I focused on a different flaw in your argument, so of course the focus changed. I'm not saying you should use unsafe a lot, I'm saying "what C++ lets you do is equivalent to using unsafe a bit more often in Rust". I don't endorse it, but if you consider "C++ lets you do so many things Rust doesn't" to be a plus point of C++ (I don't), then you should at least be comparing the right things and allowing yourself to use unsafe in Rust too.

> more heavyweight abstractions than necessary

Examples?

Re:D 2.069.0 released, compiler automatically ported from C+... by detrino on Thursday November 05, 2015 @05:24PM (#10516570)
> Compared to Rust? I doubt that. Like I said, Rust lets you dance near the line.

Your problem is that you are trying to imagine what happens in the real world rather than just looking at it.

> This is from experience in various large C++ codebases. I'm not saying people use refcounting a lot, I'm saying it gets used more than Rust.

I count 56 imports of Arc and 37 of Rc in servo, would you wager the equivalent parts of chromium or firefox use more ref-counting?

> Not really. Aside from non-lexical borrows and a couple other nice-to-have things (but not necessary), the borrow checker is pretty precise for what it tries to prove.

The problem is that the borrow checker does not look at the function as a whole. You are a slave to the borrow checker, you can only consider other things when it has been satisfied, even if its trivially safe from a whole-function view. Some simple things aren't even expressible at all without non-lexical borrows, no matter what gymnastics you try.

> It sort of does. If you try to introduce borrows and listen to the suggestions the compiler gives you, and eventually end up nowhere, it's probably not possible to do it that way.

That sounds like a terrible workflow that I don't think Rust programmers use in the real world. I think they usually use shared ownership because they know they have shared ownership, not because they gave up on the borrow checker. Any instance of actually resorting to reference counting because of the inability to make the borrow checker happy actually counts against Rust, not for it.

> in practice IMO the things Rust makes you feel safe to do is a superset of what C++ lets you feel safe to do

People routinely do safe things in C++ that would be impossible to express in safe Rust code. You need to let go if this untruth.

> if we're going to talk about "all possible things C++ theoretically allows you to do", then you should include unsafe -- you were comparing "safe Rust" with "all C++", which is unfair here, since the entities to be compared for what you're theoretically allowed to do are "all Rust" and "all C++".

I focused on safe Rust because your argument was that safe Rust is just as powerful as C++, just proved safe statically. This is far from the truth and you refuse to accept the correction. Most people in the Rust community would probably say they accept the loss in power because they prefer absolute safety. This is a very defensive position. It's impressive just how little power Rust gives up in comparison to languages like C#/Java. But to pretend that you actually have more power in Rust due to psychological effects is just zealotry and doesn't reflect how people use C++ in the real world.

> Examples?

Any abstraction that uses dynamic checking that would be considered a bug to actually trigger. Some examples include borrowing a RefCell, random access of iterators, sequential access of certain kinds of iterator adaptors, etc.

Re:D 2.069.0 released, compiler automatically ported from C+... by Manishearth on Thursday November 05, 2015 @06:59PM (#10517000)
> your argument was that safe Rust is just as powerful as C++, just proved safe statically. This is far from the truth and you refuse to accept the correction.

No, it wasn't; sorry if you thought it was. My argument was that the cognitive overhead of satisfying the borrow checker isn't much different from the cognitive overhead in writing safe C++ code. Perhaps I shouldn't have used the word "equivalent", but that was my original point.

Then you said "The things you can prove statically with the borrow checker are a subset of the things that wont trigger UB in C++.", and I made the theory/in practice distinction, but at no point did I say that was wrong, I just said it wasn't relevant to my point.

Just to be clear, this is the set of things I believe:

- Rust lifetimes/borrowchk have little to no additional cognitive overhead as compared to writing safe code in C++

- Rust lets you approach problems without having to worry so much about safety, which lets you play more fast and loose with references (avoiding unnecessary refcounting, etc)

I agree with you that:

- C++ lets you do more patterns safely than safe Rust lets you compile; and some of these patterns are used often.

- Rust needs to work on improving on things like nonlexical borrows.

I disagree that the above two are major problems or come up often in practice whilst programming Rust. It could be that we've had different experiences whilst programming Rust, however.

> I count 56 imports of Arc and 37 of Rc in servo, would you wager the equivalent parts of chromium or firefox use more ref-counting?

Sure. Firefox has two garbage collectors. Not one. Two. (One of them is Spidermonkey's, which is expected, since Javascript is GCd. The other is for the DOM)

Firefox also has many different types of FooRefCounted base classes, which seem to be used all over the place.

Almost all the Arc is in the highly-parallel layout.

Note that "imports Rc" just means that it deals with an Rc'd value, not necessarily introduces a new Rc'd value. (On the other hand in C++ often you use base classes for Rc, which means that the derived class is Rcd everywhere)

For example, in all of the Servo DOM code, the Page is Rc'd (I forgot the reason, but we don't thrash the refcount too much there), and JS callbacks are Rcd (because of a sticky interaction with the JS runtime, to be expected of something like that), and nothing else. That itself accounts for 20 imports of Rc, even though it's just two kinds of things being Rcd. Arcs are used in code interfacing with the network or layout stack (I think, I haven't looked closely)

> People routinely do safe things in C++ that would be impossible to express in safe Rust code. You need to let go if this untruth.

I agree with this. That's not what I'm saying. I'm not refuting the existence of safe things C++ lets you do that Rust doesn't. I'm just saying that Rust lets you feel safer

> I don't think Rust programmers use in the real world.

Sure, that's not how we program. Because for the vast majority of cases since lifetime annotations exist it's pretty easy (for a Rust programmer) to figure out how to borrow things safely. But there are cases where you're unsure; and it takes very little time to try something out and see what happens.

> Any instance of actually resorting to reference counting because of the inability to make the borrow checker happy actually counts against Rust, not for it.

I don't see refcounting being used to "make the borrow checker happy"; I see it being used in cases where its necessary.

> Some simple things aren't even expressible at all without non-lexical borrows, no matter what gymnastics you try.

I disagree, in my experience it's very rare to hit a situation where you need nonlexical borrows.

> Some examples include borrowing a RefCell

Ah, right. I don't consider refcell too "heavyweight" (and often it can be replaced with the zero-cost Cell), but yes, it does get broken out more than necessary sometimes. I agree with you on that.

Re:D 2.069.0 released, compiler automatically ported from C+... by destructionator on Wednesday November 04, 2015 @06:21PM (#10510527)
D's new things have been more accidental than by design... and kinda subtle too. Like the compile time reflection. I'm sure someone else has done it somewhere before, but D makes it really easy.
Re:D 2.069.0 released, compiler automatically ported from C+... by steveklabnik on Wednesday November 04, 2015 @05:06PM (#10510143)

  > lifetimes are still too young
While some stuff is new, the core of the idea goes back to Cyclone in 2001.
Re:D 2.069.0 released, compiler automatically ported from C+... by wyldfire on Wednesday November 04, 2015 @02:21PM (#10508892)
I think I'm climbing aboard the hype train. The thing that made a difference for me was the lack of GC. I knew I could have an easier time selling that to my team than GC. As soon as they hear 'GC' they will probably start to think of unacceptable latencies and lump D in with Java, Python (et al).

That said, D's compatibility with C++ is a big plus.

Re:D 2.069.0 released, compiler automatically ported from C+... by srean on Wednesday November 04, 2015 @08:43AM (#10506356)
On the nontechnical side I would add that since D is a lot older, keeping up with changes is a whole lot less challenging. Its stable enough that one can put it near the money without worrying too much about breaking changes.
Re:D 2.069.0 released, compiler automatically ported from C+... by steveklabnik on Wednesday November 04, 2015 @09:04AM (#10506511)
Since 1.0 last May, we have a strong commitment to backwards compatibility as well. Stability should not be an issue any longer.
Re:D 2.069.0 released, compiler automatically ported from C+... by e12e on Wednesday November 04, 2015 @03:17PM (#10509331)
My impression is that things are settling down now, but I've encountered quite a few rust code bases that required "latest rust" (latest > 1.0) - and even "nightly".

Not to say that rust-the-language hasn't stabilized, but I think the point about D being (way) more mature still stands?

(Note, it's a good thing that people are writing code to test/work with/exercise latest rust/nightly etc -- but just because I can be fairly sure code I write today will compile tomorrow (which is good!) -- that doesn't mean "all of rust land" is stable).

Please don't take this of critique of all the hard work going into rust -- the only way this wouldn't be a thing was if rust core was a dead project.

[ed: To add to that - it might well be that all of the projects I've seen lately where I've had to wake up multirust[1] and do a little dance before my beautiful random code from random person on the Internet have been willing to compile -- have all been bad samples of rust code - but they're still part of the landscape of rust code one encounters in the wild.

[1] https://github.com/brson/multirust (eats a bit of space (~200MB per version of the compiler/toolchain) - but in my very limited testing works nicely!)]

Re:D 2.069.0 released, compiler automatically ported from C+... by Manishearth on Wednesday November 04, 2015 @07:06PM (#10510709)
> quite a few rust code bases that required "latest rust" (latest > 1.0) - and even "nightly".

In my experience most of these either use old features which have a stable counterpart, or use compile-time codegen (there are stable libraries to do this now, though they aren't as ergonomic as plugging into the compiler directly)

Re:D 2.069.0 released, compiler automatically ported from C+... by steveklabnik on Wednesday November 04, 2015 @05:05PM (#10510137)
Yeah, I mean, I don't take this as a critique, it's the same for basically every language. When you build a project with a new version, you might take advantage of the new features. Such is life. :)
Re:D 2.069.0 released, compiler automatically ported from C+... by kbenson on Wednesday November 04, 2015 @11:54AM (#10507831)
GP is actually the second post in a week I've seen where someone mentions tracking rust changes, but rust has been 1.0 for a while now. Have there actually any backwards incompatible changes since 1.0, or are people really complaining about a problem that's been fixed for close to six months and even then was specific to beta versions?
Re:D 2.069.0 released, compiler automatically ported from C+... by pcwalton on Wednesday November 04, 2015 @12:01PM (#10507898)
There haven't been backwards-incompatible changes in practice, no.

That is to say: there have been technically backwards-incompatible changes, but every compiler and language, including those of C++ and Java, make technically backwards-incompatible changes in point releases (e.g. defining new functions in the libraries and modifying undefined behavior). Rust doesn't make changes that violate the stability guarantee. It goes further than that, in fact—any change that is not breaking according to the public guidelines but is thought possibly breaking in practice is tested against crates.io and feedback is solicited from those who have any private crates that might be affected to make sure it doesn't break them either.

(Unfortunately this policy is often misunderstood—for example, it's been claimed that Rust will make breaking changes as long as they don't break anything on crates.io, which is very much not an accurate description of it.)

Re:D 2.069.0 released, compiler automatically ported from C+... by epoch1970 on Wednesday November 04, 2015 @12:36PM (#10508146)
Due to its erratic development and the much-delayed release of Rust 1.0, I fear that many people have associated Rust with frequent breaking changes, even if that is no longer the case. It's much like the "Java is slow" fallacy; it may have been true in Java's very early days, but it hasn't been the case for many, many years. Yet the misconception still persists, even to this day. This is the sort of taint that a language will find very hard to shake. The "Rust suffers from breaking changes" misconception is very ingrained in the minds of many programmers now.
Re:D 2.069.0 released, compiler automatically ported from C+... by pcwalton on Wednesday November 04, 2015 @11:53AM (#10507825)
> higher-kinded types

Well, not really. Higher-kinded type parameters are something that requires a kind (typeclass) system in the first place, which D intentionally doesn't have (as D's authors are opposed in principle).

Re:D 2.069.0 released, compiler automatically ported from C+... by kenko on Wednesday November 04, 2015 @04:48PM (#10510036)
kinds and typeclasses are rather different, are they not?
Re:D 2.069.0 released, compiler automatically ported from C+... by pcwalton on Wednesday November 04, 2015 @06:30PM (#10510564)
Yeah, I shouldn't have made it read like I was equating the two. What HKT means is that typeclasses, like Monad, can take parameters of higher kinds. But if you don't have typeclasses in the first place (like D doesn't), then you don't have HKT.
Re:D 2.069.0 released, compiler automatically ported from C+... by SamReidHughes on Thursday November 05, 2015 @12:17AM (#10511763)
Well this is completely wrong. HKT's have nothing to do with type classes.
Re:D 2.069.0 released, compiler automatically ported from C+... by pcwalton on Thursday November 05, 2015 @01:02PM (#10514971)
I'm referring to what people want when they say they want "higher-kinded types" in Rust. That is: the ability to have typeclasses with higher-kinded type parameters.

I'm well aware that the formal definition of an HKT is just a type with a higher kind, and that's irrelevant to this discussion.

Re:D 2.069.0 released, compiler automatically ported from C+... by SamReidHughes on Thursday November 05, 2015 @02:46PM (#10515697)
What certain Rust users want to do with HKT can already be done with D (maybe they're LKT's, loosely-kinded types -- you heard it here first!) or, for example, quite explicitly, C++, without type classes, so it's quite relevant.
Re:D 2.069.0 released, compiler automatically ported from C+... by pcwalton on Thursday November 05, 2015 @07:19PM (#10517083)
No, it's not relevant. When people say they want HKT, what they mean is that they want to create typeclasses that abstract over types of a higher kind and only those types, with a type system that can make those guarantees.

Saying C++ has HKT because it doesn't have typeclasses is like saying Python has all of Haskell's type system features because it doesn't have static types. There's a sort of vacuous sense in which it's true, but it's not a particularly meaningful or interesting thing to say.

Re:D 2.069.0 released, compiler automatically ported from C+... by SamReidHughes on Thursday November 05, 2015 @11:20PM (#10517820)
We have proof in this very thread that people don't use the term HKT that way. That makes sense, because that's not what the words "higher kinded types" mean.

> Saying C++ has HKT because it doesn't have typeclasses

I didn't say anything like that at all. C++ has HKT, and it doesn't have type classes.

Re:D 2.069.0 released, compiler automatically ported from C+... by Manishearth on Friday November 06, 2015 @06:09AM (#10518862)
If you consider `template<template ...>` to be HKT then Rust has this too. Rust macros can be used like C++ templates (minus autoinstantiation) and they can take other macros as parameters. It's not as nice as C++, but ... workable.

Patrick is talking about HKTs which can be typechecked at the source, similar to the rest of Rust generics, when he talks about "they want to create typeclasses that abstract over types of a higher kind and only those types". C++ templates get typechecked at use-time, not instantiation-time, like Rust macros. On the other hand, Rust forces you to constrain types in generics (a la C++ "concepts") so that it typechecks at the source (and then the contract for types being passed into the function is clear in the signature). We don't have higher kinded bounds, though.

HKT, after all, is a comment on bounds. What sort of things are you allowed to substitute for this generic or template parameter?

What seems to be happening here is a difference of opinion on what constitutes a "bound", in the C++ world a "structural" bound (i.e. type vs number vs template) is all you have. In the Rust world this isn't considered a bound, since the bound isn't type-safe. In the Rust world, Haskell world, and most other worlds where the word "kind" is used, a bound is a "type" (typeclass) bound and is type safe -- you can only do operations on the parameter which the bounds let you. Many Rust/Haskell people would consider C++ templates to be a particularly awesome macro system (but not a generics system); since they're structural-bound (like Rust macros); not type-safe.

Really a matter of terminology though.

Re:D 2.069.0 released, compiler automatically ported from C+... by pcwalton on Friday November 06, 2015 @02:05PM (#10521291)
Exactly. If C++/D have HKT, then so does Rust via its macro system.
Re:D 2.069.0 released, compiler automatically ported from C+... by SamReidHughes on Friday November 06, 2015 @02:15PM (#10521356)
C++ and D do it differently, I don't know why you're lumping them together. (Well, actually, I lied, I do know why.)
Re:D 2.069.0 released, compiler automatically ported from C+... by scardine on Wednesday November 04, 2015 @06:26AM (#10505818)
I guess D feels more like a better C++ and Rust like a better C, but I may be under the wrong impression.
Re:D 2.069.0 released, compiler automatically ported from C+... by humanrebar on Wednesday November 04, 2015 @06:57AM (#10505906)
Rust is more like the child of C and a functional language (OCaml).
Re:D 2.069.0 released, compiler automatically ported from C+... by acz on Wednesday November 04, 2015 @09:48AM (#10506905)
Still think that *ML syntax would fit Rust better.
Re:D 2.069.0 released, compiler automatically ported from C+... by bachmeier on Wednesday November 04, 2015 @08:48AM (#10506386)
I disagree. D is an improved C that does a lot of the same things as C++, but in order for it to be a better C++, it would need to start with C++ as a foundation and build on it. D has more of a scripting language feel to me.
Re:D 2.069.0 released, compiler automatically ported from C+... by Solarsail on Wednesday November 04, 2015 @10:35AM (#10507244)
> D has more of a scripting language feel to me.

I'm curious about this, although I don't think this is the first time I've heard D described as having a script-y feel to it. It sounds along the same lines as people describing Go as almost a scripting language, or comparing it to them. Neither Go nor D seem especially dynamic, both have compilers for reference implementations, both look more like C than Python. (To my eyes at least; I've never tried either one. Thus this question.)

Is it primarily the speed of the compilers? Both DMD and g6/g7/g8 boast very fast compiles, and Go uses somewhat script-y tools... but #!/usr/local/bin/tcc -run hasn't changed C's reputation. Fast compiling and memory safety, maybe?

Re:D 2.069.0 released, compiler automatically ported from C+... by EvenThisAcronym on Wednesday November 04, 2015 @03:34PM (#10509482)
People often say this because D has many features that allow it to be almost as flexible as the various scripting languages while still being compiled and statically typed. I don't bother with bash/cmd nowadays as D can easily fill that role, with the bonus of my small little scripts having all the power and scalability that D offers.

Also check out https://github.com/Abscissa/scriptlike

Re:D 2.069.0 released, compiler automatically ported from C+... by royjacobs on Wednesday November 04, 2015 @07:00AM (#10505913)
How would you consider Rust's generics as being part of a better C rather than a better C++?
Re:D 2.069.0 released, compiler automatically ported from C+... by pornel on Wednesday November 04, 2015 @07:43AM (#10506072)
C translates almost 1:1 to Rust, but when converting C++ to Rust you'll run into impedance mismatch between OO hierarchies and traits, and generics being narrower in functionality than templates.

In Rust you still can do "clever" things with generics to make them feel like C++, but the rest of the language is still closer to C: errors returned rather than thrown, no inheritance (but the "flat" OO and enums map well to what OO-like C programs do with "handles"), no constructors, etc.

Re:D 2.069.0 released, compiler automatically ported from C+... by thechao on Wednesday November 04, 2015 @08:06AM (#10506169)
Really? Now I have to go learn Rust.
Re:D 2.069.0 released, compiler automatically ported from C+... by knocte on Wednesday November 04, 2015 @11:01AM (#10507456)
> errors returned rather than thrown

WHATT??? did they do the same mistake as Go?

Re:D 2.069.0 released, compiler automatically ported from C+... by lucozade on Wednesday November 04, 2015 @11:26AM (#10507630)
It depends on what mistake you mean.

Having errors on return has merits. Particularly it make error handling more deterministic. What it tends to do though, in languages like C and Go, is be very verbose.

Rust largely mitigates that through judicious usage of some of its higher levels features. Specifically its try! macro wrap up the common case of passing errors up the call stack quite neatly. With that and the pervasive RAII, Rust does a pretty good job of making error management quite unobtrusive.

It also has quite a nice way of converting errors types using traits that, in my opinion at least, handles typed error propagation better than most exception mechanisms I am familiar with.

From a personal pov, I like the determinism and I like the type conversion. I probably prefer D's scope mechanism to RAII in general as I like thinks to be as explicit as possibly but without being too verbose. But I think Rust seems to have hit quite a nice balance.

Re:D 2.069.0 released, compiler automatically ported from C+... by steveklabnik on Wednesday November 04, 2015 @11:09AM (#10507507)
No. There's a few things that combine to make it different, but what it really boils down to are enums. Rust functions that can fail return a type, Result: http://doc.rust-lang.org/std/result/enum.Result.html

There's a number of things that make using this ergonomic: you can use the try! macro to convert it to a success value, returning an error value up the stack. You can use any of the combination methods on that page to chain various possibly-failing functions together into something that looks nice. Some people even use the word "monadic." We don't have if checks everywhere.

For more than you probably want to know on error handling in Rust, this guide just hit stable: https://doc.rust-lang.org/book/error-handling.html

Re:D 2.069.0 released, compiler automatically ported from C+... by johncolanduoni on Wednesday November 04, 2015 @07:28AM (#10506018)
I think it's more about Rust's approach to OO. In Rust, traits are usually used as interfaces for generics instead of dynamic dispatch. The generated code/performance is more like what you would get if you implemented them explicitly for each appropriate type in C, built around structs. You could do this with C++ templates, but it would be a huge pain in that language due to lack of template type safety.

This is a quite important part of Rust (IMHO) because it gives the language a performance profile closer to C than C++ in many instances.

Re:D 2.069.0 released, compiler automatically ported from C+... by royjacobs on Wednesday November 04, 2015 @08:05AM (#10506162)
Hmm, I see your point, but I've found that even in template-heavy code the compiler can produce code that's pretty optimal. Are you saying that with Rust it is easier to fall into the pit of success, as it were -- requiring less reasoning about how a compiler might convert the [templated|generic] code optimally?
Re:D 2.069.0 released, compiler automatically ported from C+... by johncolanduoni on Wednesday November 04, 2015 @08:12AM (#10506195)
My point was not that Rust creates better template code, but that a lot of things one uses dynamic dispatch for in C++ use templates instead. There are plenty of times when one knows the full derived type of a class in C++, but one throws away that information virtual calls are used anyway.

I think this is because Rust makes it far easier to use generics; they're type-safe and don't need to be pushed to header files. Also, the coding culture around Rust pushes one to use enums for dynamic dispatch instead of "trait objects" (Rust's equivalent of VFTs).

Re:D 2.069.0 released, compiler automatically ported from C+... by srean on Wednesday November 04, 2015 @08:56AM (#10506445)
> but one throws away the information ...

With the mythical smart enough compiler with god like devirtualizer it would be less of an issue but gratuitous use of virtuals annoys me no end. CRTP isn't that hard for the simple use cases but you are beholden to the god of compiler error messages when things go wrong. One great thing that clang has done (among others) is make g++ get their shit together. Contrary to the popular sentiment I personally find the current crop of g++ error messages more helpful.

Re:D 2.069.0 released, compiler automatically ported from C+... by johncolanduoni on Wednesday November 04, 2015 @09:09AM (#10506565)
Another big part of the barrier here is the nature of compiled binaries. When you define a public generic function in Rust, the compiler ensures that it keeps enough information in the resulting binary so that the generic can be instantiated. Unless you wanted to massively balloon your headers and compile times, achieving the same with C++ is simply impossible across executables and libraries, and very hard even across object files.
Re:D 2.069.0 released, compiler automatically ported from C+... by scardine on Wednesday November 04, 2015 @07:29AM (#10506021)
While OOP is perfectly possible in Rust, IMHO it is a lot more like doing OOP in C than in C++ (despite nice features like traits and generics).

Rust is marketed as a "general-purpose, multi-paradigm, compiled programming language" and D "originated as a re-engineering of C++", so may be I'm biased by my interpretation of the goals from both language designers.

Re:D 2.069.0 released, compiler automatically ported from C+... by fithisux on Wednesday November 04, 2015 @07:19AM (#10505976)
I wish the ObjC was supported for Windows x86 (>= 7) for linking with Gnustep.

In any case, congratulations.

I wonder if the C++ to D translator could be used in other codebases, like Fltk for example.

Re:D 2.069.0 released, compiler automatically ported from C+... by qznc on Wednesday November 04, 2015 @09:24AM (#10506683)
You could use it as a starting point, but it was never intended to be a generic tool. For example, the C++ code was changed in some places to make the job for the translator easier.
Re:D 2.069.0 released, compiler automatically ported from C+... by EvenThisAcronym on Wednesday November 04, 2015 @03:31PM (#10509456)
D is what you get if C married Python and the resulting baby was adopted and raised by Lisp and C#.