五种我认为值得掌握的现代编程语言:
我刻意剔除了三种语言:
你认同么?我认同,并且我认为学校教了C语言之后,应该直接教Rust,而不要教C++了。学校教Java和C#也不能培养出优秀的有计算机学科特质的程序员,我们没办法面面俱到,只求有独到之处。
Linuar Type: https://en.wikipedia.org/wiki/Substructural_type_system
Linear types corresponds to linear logic and ensures that objects are used exactly once, allowing the system to safely deallocate an object after its use.
To many people, polymorphism is synonymous with inheritance. But it’s actually a more general concept that refers to code that can work with data of multiple types. For inheritance, those types are generally subclasses.
Rust instead uses generics to abstract over different possible types and trait bounds to impose constraints on what those types must provide. This is sometimes called bounded parametric polymorphism.
其中,传统OO里多态是运行时多态,常规的实现是通过继承来达成的:Inheritance as a Type System and as Code Sharing ,但是继承共享代码一般会导致两种问题:
从C++的模版编程+Concept概念开始,泛型+萃取这种编译期,通过两种不同的抽象维度来实现多态,叫做:bounded parametric polymorphism.
Rust在OO编程上的选择,采用的正是完备的编译期OO+多态设计:
struct Data{}
impl Data{ fn method(){} }
pub struct Data{ pub no: u32}
impl Data{ pub fn new()->Data{Data{no:0}}
fn test<T>(t:T){}
trait Echo{ fn echo();}
impl Echo for Data{ fn echo(){}}
fn test<T>(t:T) where T:Echo {}
// TODO: 拷贝行为
https://book.async.rs/introduction.html
在当前Executor里发起一个异步任务
use std::task;
task::spawn(async move {
});
在一个线程里发起异步任务
use std::thread;
thread::spawn(move ||{
task::block_on(async { {
});
})
[1] 给Java/C#/C++程序员的Rust介绍,这种教程风格是我最喜欢的,通过Diff,Step By Step引入概念设计上的不同:https://fasterthanli.me/articles/i-am-a-java-csharp-c-or-cplusplus-dev-time-to-do-some-rust
[2] 作者学习Rust遇到的一个个怪(阻挠,Frustrat),但是作者一步步打怪升级,把概念吃的很透彻:https://fasterthanli.me/articles/frustrated-its-not-you-its-rust
原文:https://www.cnblogs.com/math/p/rust.html