TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Rust's Object System

106 点作者 justauser大约 13 年前

6 条评论

comex大约 13 年前
C++, of course, has the same choice between virtual methods and templates, "interfaces", inline and external method implementation syntax, etc, although the separate vtables are a nice trick and traits look interesting. So I'm curious about one thing (which would be obvious if I'd used Rust, but isn't apparent on Google):<p>What's the compilation speed like?<p>C++'s tendency to stick template functions in header files is a curse on compilation speed compared to C. Rust's solution is apparently to compile all modules in a crate together, which at least avoids instantiating the same templates more than once when compiling from scratch, but sounds like it would make incremental compilation times even worse. I am interested in Rust, but slow compilation drives me crazy.<p>(And what are the rules for importing classes between crates - how do template functions work, are there any guarantees for changes to a class that won't prevent code that was compiled with an old version from working?)
评论 #3826188 未加载
kombine大约 13 年前
Looks interesting, but to be honest there is nothing new here. If you take a look at D, it also has both runtime and compile time polymorphism for a long time. The former is implemented with Java-style interfaces, while the latter is done through templates. Traits are also possible via template mixins: you define a template like so: template ExtraStuff { int someData; void someMethod() { someDate = 5; } }<p>and then you mix it into the class in question: class SomeClass { mixin ExtraStuff; }<p>It also gives you a lot more flexibility: you can mix it not only in classes but in structs(in D those are different types), to the global scope and even inside the functions(in that case someData becomes a local variable and someMethod() an inner function).
评论 #3827908 未加载
sthatipamala大约 13 年前
I haven't read up a lot on Rust but I feel that it is similar to Go and perhaps Ceylon. Can someone explain why there is a sudden "renaissance" in such memory-managed systems programming languages?<p>Edit: Oh, and also the D programming language. There are quite a few of these!
评论 #3825892 未加载
评论 #3826752 未加载
oconnor0大约 13 年前
Interesting, I think they had an object system that they removed in favor of type classes, but objects have returned.
riffraff大约 13 年前
does anyone else have the feeling the idiosyncratic keywords in rust ("iface"? really?) are there to distract the casual reader from talking about the important stuff?
评论 #3826987 未加载
Ralith大约 13 年前
So, they reinvented existential types?