Originally posted by tuuker
View Post
Announcement
Collapse
No announcement yet.
ToaruOS With Kernel Written From Scratch Is Still In Development
Collapse
X
-
Originally posted by Hi-Angel View PostWell, Rust would break quite a number of his arguments. It's not object-oriented, it doesn't have exceptions, and it would solve a number of common C errors.
Now that said is Rust a language designed to help you operate in OOP paradigms? Yes, actually. Its type system is a mutable graph as opposed to a static hierarchy, but talk is cheap... let's see some code (Note that I haven't checked to make sure any of this will compile or run, but the principles are there):
Code://rust trait Animal{ fn speak(&self) -> String; fn move(&self); } struct Dog{ } struct Cat{ } impl Dog{ fn New() ->Dog{ Dog{} } } impl Animal for Dog{ fn speak(&self) -> String{ "bark" } fn move(&self) { } } impl Cat{ fn New() -> Cat{ Cat{} } } impl Animal for Cat{ fn speak(&Self) -> String { "meow" } fn move(&Self){ } }
Code://C# public interface Animal{ String speak(); void move(); } public class Dog{ public Dog() { } public String speak() { return "Bark"; } public void Move() { } } public class Cat{ public Cat() { } public String speak() { return "meow"; } public void Move() { } }
Code:struct GermanShepherd{ _dog:Dog } impl GermanShepherd{ fn New() -> GermanShepherd{ GermanShepherd{ _dog : Dog::New()} } impl Animal for GermanShepherd{ fn Speak () -> String{ "WOOF" } fn Move(){ _dog.Move(); } }
Code:trait Canine{ fn dig(&Self); } impl Canine for Dog{ fn dig(&Self) { println!("Digging a big old hole"); } } impl Canine for GermanShepherd { fn dig(&Self) { _dog.Dig(); } } fn DogFunction<T>(&dog: T) Where T: Animal + Canine{ println!(dog.Speak()); }
[1] Yes all programs are "simply algorithms" but it's a methodology difference
- Likes 1
Comment
-
Originally posted by debianxfce View PostIf it so hard not to create memory leaks, do not develop any software. Think of old home computers like C64, os and games were programmed with assembler and what a huge success. There is also newer os that is programmed with assembler.
Comment
-
Phoronix. The site where the article never gives any interesting details (what is special about this OS? Why should we care? How does it perform compared to others?), and where every last discussion is immediately hijacked to become a rust-ad.
Comment
-
Object Oriented Programming languages generally, but aren't required to, support the following three features: Inheritance (Either through a class system or composable structures, or whatever), Polymorphism (Which in Modern OOP is basically always handled as relating to interfaces, which Traits are), and Encapsulation in a manner that is easily accessible to the developer. Javascript however is an example of an object oriented programming language that doesn't support encapsulation or the concept of polymorphism really, but it is entirely feasible to write Javascript in an object oriented manner (I certainly have), and well... you're playing around with a Document Object Model.
The only legitimate concern over OOP that I've ever seen, as opposed to "Waaaaah Newbies suck" is that OOP is very much big design up front. So for what would procedurally be a very small project can be substantially larger in the OOP paradigm when done right. However for large projects I've certainly found that rewriting procedural code into an OOP paradigm actually reduces the size and even if it doesn't reduce the size it absolutely reduces the complexity because it get's split into smaller more tightly defined code units. However even if we're talking a small project that would be much smaller done procedurally than OOP, if you intend to keep it around, there's a very strong argument that you should just go all the way from the beginning... the whole MVC enchilada because it'll make maintenance and extension easier later. It makes me quite happy when I can reduce the number of places I have to touch in code to be able to extend it down to 1 or 2 places (preferably loose coupled enough to be the main function and the configurator factory).
- Likes 1
Comment
-
Comment