by jcelerier · 9y ago · 0 comments
Both are 100% object-orientated (and in the case of Rust, also 100% FP is reachable I'd say. Not knowledgeable enough in C# to say). Do they have in-memory data structures with attached functions that do useful work with this object's state (not necessarily mutating it) ? Yes. Then OO.
Rust has encapsulation, message passing in the smalltalk/OO sense, and polymorphism. It does this through objects with attached methods, and traits. In every way that actually matters to a working programmer Rust is OO.
Wait... do you actually believe that? Tons of C software is OO through and through, has been since C existed.
If we stick to your definition C functions operating on structs qualify as OO, and I don't think many would agree with that.
What do you mean by "attached function"?
e.g. in a C API:
struct foo {
// dispatch
void (*do_stuff)(int);
int (*get_stuff)(const char*, void* context);
};
// attached functions
void foo_do_operation1(foo*);
int foo_do_operation2(foo*, int);
or C++ which allow to conflate both forms but restricts the first with inheritance struct foo {
virtual void do_stuff() = 0;
virtual int get_stuff(std::string, a_better_type_than_void_ptr&) = 0;
void do_operation1();
int do_operation2(int);
};
or JS where everything can change whether you want it or not var v = new Object;
v.do_stuff = function() { ... }
v.get_stuff = function(str, something) { ... }
v.do_operation1 = function() { /* v is available in the closure */ }
etc...
or OCaml modules: module foo =
struct
let do_operation1 = ...
let do_operation2 x = ...
end
in every case, some state is mentioned first, and then some code is bound to this state; then, the language (except in C where it is only a convention... even though some people can get fairly "creative" with macros) provides a way to call the code with a given variable of type `foo`.