Re:Does OO really match the way we think (1997) [pdf]
by nonsince on Saturday August 12, 2017 @06:34AM
(#14997357)
Rust is neither OO nor FP, it's procedural (like C and Fortran) but borrows concepts from OO and FP. OO requires data structures to support dynamic dispatch, and although you can have dynamic dispatch in Rust via trait objects your code is heavily gimped - no generics, you can only pass by reference, lifetimes have to be explicitly annotated, etc. It feels like OOP-emulating C code from back in the day. Likewise, if you try to do pure functional programming in Rust you're going to have a bad time. Closures don't share types, and doing dynamic dispatch on them creates the same problems as trying to emulate OOP. In reality it's its own beast, much closer to C with templates than a crossbreed of C++ and Haskell.
Re:Does OO really match the way we think (1997) [pdf]
by zaphar on Saturday August 12, 2017 @01:58PM
(#14999001)
I'm not sure where this meme on HN that Rust isn't OO comes from but it's based on a definition of OO that is almost never applied by day to day programmers and it's disagreed with by a fair number of language theory people.
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.
Re:Does OO really match the way we think (1997) [pdf]
by pjmlp on Saturday August 12, 2017 @09:49AM
(#14997876)
Contrary to mainstream knowledge there isn't one single truth of what OOP or FP actually are, rather multiple approaches of applying a set of abstract concepts.
Re:Does OO really match the way we think (1997) [pdf]
by boramalper on Saturday August 12, 2017 @10:13AM
(#14997942)
This, a million times. Any (meta) discussion on OOP without giving a precise definition of it is futile, for the devil lies precisely in those details that are omitted from the discussion.
Re:Does OO really match the way we think (1997) [pdf]
by dom0 on Saturday August 12, 2017 @12:01PM
(#14998387)
> it's procedural (like C and Fortran)
Wait... do you actually believe that? Tons of C software is OO through and through, has been since C existed.
Re:Does OO really match the way we think (1997) [pdf]
by ettoretorti on Saturday August 12, 2017 @07:35AM
(#14997501)
There's more to the everyday definition object oriented than having functions operating on in-memory data structures. Two other features that are commonly included are subtyping through inheritance and encapsulation.
If we stick to your definition C functions operating on structs qualify as OO, and I don't think many would agree with that.
Re:Does OO really match the way we think (1997) [pdf]
by seanmcdirmid on Saturday August 12, 2017 @10:34AM
(#14998013)
My first exposure to OOP was in C using structures to hold function pointers as a pattern. You can do OO in C without C being OO. There is a huge semantic difference between doing OO and a language at supports OO, the article is referring to the former rather than the latter.
Re:Does OO really match the way we think (1997) [pdf]
by tome on Saturday August 12, 2017 @11:41AM
(#14998281)
> Do they have in-memory data structures with attached functions
What do you mean by "attached function"?
Re:Does OO really match the way we think (1997) [pdf]
by jcelerier on Saturday August 12, 2017 @02:16PM
(#14999122)
I meant that a semantic value in the code (a variable for instance) "carries" functions with it, as methods.
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`.
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.