Re: "Reader Q&A: ?Will C++ remain indispensable???" by Herb Sutter
On Sat, 21 Sep 2013 18:17:53 +0200
Melzzzzz <mel@zzzzz.com> wrote:
On Wed, 18 Sep 2013 07:42:00 +0200
Melzzzzz <mel@zzzzz.com> wrote:
On Sat, 14 Sep 2013 14:53:28 +0000 (UTC)
Tobias M=C3=BCller <troplin@bluewin.ch> wrote:
Jorgen Grahn <grahn+nntp@snipabacken.se> wrote:
Never mind speed -- what other mainstream languages are
C-compatible but suck less than C? What other mainstream
languages are high-level, yet provide static typing?
I hope that Rust will eventually fill that hole. It's not mature
yet, but evolving quickly.
Rust vtable implementation is currently broken and does not work.
It works without inheritance, but with inheritance, it must
impose run time cost as dynamically finding proper table
for particular method enforces dynamic cast whenever method
is called.
Actually language does not need trait(interface) inheritance
at all. It can be simulated in following way and perfectly
works:
bmaxa@maxa:~/examples/rust$ cat trait.rs
// trait.rs
#[link(name = "testtrait")];
fn create<T:'static+TestTrait>()->@TestTrait
{
let a:T = TestTrait::new();
@a as @TestTrait
}
=09
trait TestTrait{
fn doo(&self);
fn doo1(&self);
fn new()->Self;
}
=09
impl Derived for @TestTrait{
fn doo(&self)
{
println("TestTrait D doo");
self.doo();
}
fn doo1(&self)
{
println("TestTrait D doo1");
self.doo1();
}
}
=09
impl Base for @TestTrait{
fn doo(&self)
{
println("TestTrait B doo");
self.doo();
}
}
=09
trait Derived{
fn doo(&self);
fn doo1(&self);
}
=09
impl Base for @Derived{
fn doo(&self)
{
println("Derived B doo");
self.doo();
}
}
trait Base{
fn doo(&self);
}
bmaxa@maxa:~/examples/rust$ cat maintrait.rs
extern mod testtrait;
use testtrait::*;
fn main()
{
let s = create::<S>();
let d = @s as @Derived;
let c = @s as @Base;
let b = @d as @Base;
s.doo();
s.doo1();
=09
d.doo();
d.doo1();
c.doo();
=09
b.doo();
}
impl TestTrait for S{
fn new()->S{
return S;
}
fn doo(&self)
{
println("doo S");
}
fn doo1(&self)
{
println("doo1 S");
}
}
struct S;
bmaxa@maxa:~/examples/rust$ rustc --lib trait.rs -Z debug-info
warning: missing crate link meta `vers`, using `0.0` as default
bmaxa@maxa:~/examples/rust$ rustc maintrait.rs -L . -Z debug-info
bmaxa@maxa:~/examples/rust$ ./maintrait
doo S
doo1 S
TestTrait D doo
doo S
TestTrait D doo1
doo1 S
TestTrait B doo
doo S
Derived B doo
TestTrait D doo
doo S
All in all language is really promising and interresting ;)
--
Sig.