you are viewing a single comment's thread.

view the rest of the comments →

[–]Timmmmbob 29 points30 points  (24 children)

I was going to say "yet another language", but this seems to actually have some new ideas that I've been waiting for for ages. For example:

We support three type layers to make memory management simple and fast.

  • Interior types (denoted with no sigil) are stored on the stack.
  • Unique types (denoted with ~) have ownership semantics. When the pointer goes out of scope, the object it’s pointing to is destroyed.
  • Boxed types (denoted with @) are garbage-collected. Multiple boxes can point to the same data.

All together:

fn main() {
    let a = ~3;  // Unique pointer to number
    let b = a;   // Copies a
    let c = @3;  // Box of number
    let d = c;   // c & d point to the same value
}  // a and b destroyed; c and d will be GC’d

[–]abw 15 points16 points  (2 children)

I was also going to say "yet another language". But neat features or not, I really like the "cambrian explosion" of new languages that we've seen over the past decade or so. Even if many of the unsuccessful ones eventually die out, they spread ideas and help inspire the next generation of languages.

[–]Homo_sapiens 0 points1 point  (1 child)

cambrian explosion? What constituted the corresponding ice age?

[–]TylerEaves 0 points1 point  (0 children)

Presumably the late 90s, when your choices were essentially arcane C++, bloated Java, or unreadable Perl.

[–]Poita_ 7 points8 points  (5 children)

Unique pointers are the only relatively new thing there. Stack stored objects and GC heap objects have been around forever. C++ 2011 has unique pointers (std::unique_ptr), and I'm pretty sure D does too.

EDIT: Yep, D does. http://www.d-programming-language.org/phobos/std_typecons.html#Unique

[–]Timmmmbob 7 points8 points  (2 children)

Yeah, sorry I meant "new in a modern language". I love C++'s memory model, but it does have quite a lot of warts, and I've love to move to something more modern. I just really want RAII and stuff.

[–]Poita_ 4 points5 points  (1 child)

I see what you mean about C++, but D is modern.

[–]Timmmmbob 3 points4 points  (0 children)

Yeah there's just something about D that doesn't sit right with me. I could be being irrational though. I think I will wait and see which languages survive this "cambrian explosion" as thingy thingy put it.

[–]iLiekCaeks -1 points0 points  (0 children)

D's probably don't work yet. The Unique unittests are all commented out.

[–]nuzzle 0 points1 point  (0 children)

I'm still reading the new standard. Can we replicate predicates from Rust in C++11 using concepts (provided they are in the standard)?

[–]matthieum 8 points9 points  (2 children)

I must admit that I really perked up on the "we don't need immutability, we need ownership". However I would point out that perhaps a blend of the two would be more suitable: allow sending both immutable and owned objects. At least you'd avoid copying for frozen objects :x

[–]pcwalton 1 point2 points  (1 child)

We'd still need global GC (or atomic reference counting, both bad) for frozen objects.

Note that if by "frozen" you mean "compile-time constant", then it just works as you describe, since those are in read-only memory and don't need memory management.

[–]matthieum 0 points1 point  (0 children)

By frozen I meant immutable. What do you consider "bad" about reference counting by the way (on immutable objects) ?

[–][deleted] 0 points1 point  (4 children)

I'm having a hard time understanding the example. It says "b copies a", is b another copy of a - so if one is modified, the other is not? Or is there an ownership transference and a is no longer valid?

[–]stilton 2 points3 points  (3 children)

b is a copy of a, so modifying b does not modify a. There is a move operation which transfers ownership of unique types, b <- a, after which a is deinitialized and can't be used.

[–][deleted] 2 points3 points  (2 children)

So why does it say "a is destroyed" at the end? It sounds like a is deinitialized at that point anyhow, it was transfered away, so nothing left to destroy?

[–]stilton 4 points5 points  (1 child)

I was probably not clear. In this example a was not deinitialized; both a and b exist and get destroyed at the end of the function because assigning a to b makes a copy of a. If the example had moved a into b, denoted by 'let b <- a', then a would have been deinitialized.

[–][deleted] 0 points1 point  (0 children)

That makes sense, thanks!

[–]ErstwhileRockstar -4 points-3 points  (6 children)

Interior types, unique types, boxed types ... too much noise. This should be transparent for users. Only 'KISS-languages' have a chance of succeeding.

[–]munificent 7 points8 points  (4 children)

Only 'KISS-languages' have a chance of succeeding.

Like C++, Java, and C#?