
03.06.2015, 21:02
|
 |
Быдлокодер;)
|
|
Регистрация: 19.11.2010
Сообщений: 4,338
|
|
Да, уже понял  Модеры, забаньте его поскорее 
|
|

03.06.2015, 23:52
|
 |
Профессор
|
|
Регистрация: 23.12.2013
Сообщений: 1,856
|
|
kobezzza,
Цитата:
|
Модеры, забаньте его поскорее
|
уже.
Я в Расте пока не продолжал разбираться, но на первый взгляд там довольно удобное ООП. Просто оно немного непривычное.
|
|

07.06.2015, 13:59
|
Интересующийся
|
|
Регистрация: 07.06.2015
Сообщений: 26
|
|
Сообщение от indeterm
|
Вот это говно чтоли ты называешь ООП?
trait Animal {
// Static method signature; `Self` refers to the implementor type
fn new(name: &'static str) -> Self;
// Instance methods, only signatures
fn name(&self) -> &'static str;
fn noise(&self) -> &'static str;
// A trait can provide default method definitions
fn talk(&self) {
// These definitions can access other methods declared in the same
// trait
println!("{} says {}", self.name(), self.noise());
}
}
struct Dog { name: &'static str }
impl Dog {
fn wag_tail(&self) {
println!("{} wags tail", self.name);
}
}
// Implement the `Animal` trait for `Dog`
impl Animal for Dog {
// Replace `Self` with the implementor type: `Dog`
fn new(name: &'static str) -> Dog {
Dog { name: name }
}
fn name(&self) -> &'static str {
self.name
}
fn noise(&self) -> &'static str {
"woof!"
}
// Default trait methods can be overridden
fn talk(&self) {
// Traits methods can access the implementor methods
self.wag_tail();
println!("{} says {}", self.name, self.noise());
}
}
struct Sheep { naked: bool, name: &'static str }
impl Sheep {
fn is_naked(&self) -> bool {
self.naked
}
fn shear(&mut self) {
if self.is_naked() {
// Implementor methods can use the implementor's trait methods
println!("{} is already naked!", self.name());
} else {
println!("{} gets a haircut", self.name);
self.talk();
self.naked = true;
}
}
}
impl Animal for Sheep {
fn new(name: &'static str) -> Sheep {
Sheep { name: name, naked: false }
}
fn name(&self) -> &'static str {
self.name
}
fn noise(&self) -> &'static str {
if self.is_naked() {
"baaah"
} else {
"baaaaaaaaaaaah"
}
}
}
fn main() {
// Type annotation is necessary in this case
let mut dolly: Sheep = Animal::new("Dolly");
let spike: Dog = Animal::new("Spike");
// TODO ^ Try removing the type annotations
dolly.shear();
spike.talk();
dolly.talk();
}
|
На *языке программирования* это выглядело бы примерно так:
Animal := Object clone do(
name ::= ""
talk := method((name .. " says " .. noise) println)
)
Dog := Animal clone do(noise := "woof")
Sheep := Animal clone do(
naked ::= false
shear := method(
if(naked, (name .. " is already naked") println, (name .. " gets a haircut") println)
)
noise := method(
if(naked, "baaah", "baaaaaaaaaaah")
)
)
spike := Dog clone setName("Spike")
dolly := Sheep clone setName("Dolly")
spike talk
dolly talk
dolly shear
|
|

07.06.2015, 14:08
|
Интересующийся
|
|
Регистрация: 07.06.2015
Сообщений: 26
|
|
Сообщение от Safort
|
Я в Расте пока не продолжал разбираться, но на первый взгляд там довольно удобное ООП. Просто оно немного непривычное.
|
Почитал Ваши посты в треде. Это весьма странно выглядит: Вы вовсю пиарите язык, с которым толком даже не ознакомились.
|
|

07.06.2015, 17:56
|
 |
Профессор
|
|
Регистрация: 23.12.2013
Сообщений: 1,856
|
|
pornoborets,
а что, плохое знание языка должно как-то мешать мне пиарить его?)
|
|

25.06.2015, 21:24
|
 |
Профессор
|
|
Регистрация: 23.12.2013
Сообщений: 1,856
|
|
|
|

13.07.2015, 23:49
|
 |
Быдлокодер;)
|
|
Регистрация: 19.11.2010
Сообщений: 4,338
|
|
|
|

14.07.2015, 01:27
|
 |
Быдлокодер;)
|
|
Регистрация: 19.11.2010
Сообщений: 4,338
|
|
|
|

14.07.2015, 13:54
|
Аспирант
|
|
Регистрация: 23.06.2015
Сообщений: 53
|
|
Цитата:
|
после всех мучений, у меня наконец получился проект, который вы можете увидеть в снапшоте на github.
|
Получившийся "проект" -- это два квадратика. Отличная реклама языку.
|
|
|
|