5 ms·
In what way is the Linux kernel or my router firmware object-oriented? Linus Torvalds has even gone on record to express his distaste for C++ and OOP.
by willtim 9y ago
In what way is the Linux kernel or my router firmware object-oriented?
Linus Torvalds has even gone on record to express his distaste for C++ and OOP.
- jcelerier 9y agoObject-oriented design patterns in the kernel, part 1: https://lwn.net/Articles/444910/ https://lwn.net/Articles/444910/ I'd go as far as to say that every time you have a C API that looks like struct some_struct { ... }; void my_api_foo(some_struct*, param1, param2); int my_api_bar(some_struct*); float my_api_baz(some_struct*, float**, int n); it's OO. And the kernel is full of this (just like many C APIs). Also, Linus's arguments are about C++ usage in kernel. His diving software Subsurface was ported from GTK / C to Qt / C++ for instance. (and even GTK with GObject* everywhere is fairly OO).
- willtim 9y agoPassing a common struct into one or more procedures is absolutely not what is commonly understood as object-oriented programming. This is what people did (and are still doing) long before OOP existed. I also do it all the time in Haskell. Similarly that article is wrong to imply that all these techniques are unique to OOP.
- mpweiher 9y agoIt absolutely is. OOP languages formalized this pattern and made it easy to use.
- wfunction 9y agoNo, it absolutely is not. OOP has lots of well-known unique characteristics such as inheritance, dynamic dispatch, polymorphism, encapsulation, etc... as well other less-frequently-noticed semantic differences like the fact that the message-passing follows a subroutine model (which may be more difficult to appreciate if that's the only thing you're used to). Yes, you can do OOP in C, but just making a struct and defining procedures to operate on it doesn't imply any OOP.
- jcelerier 9y ago> OOP has lots of well-known unique characteristics such as inheritance, dynamic dispatch, polymorphism, encapsulation, etc... OO just means that you have a semantic entity, the object, which contains data and to which you associate code. Your main tool to work with is this object; just like in FP your main tool to work with is the function to which you associate data through closures and currying. Likewise, in logic programming your main tool is the constraint. And these aren't relevant to the language. You can do both OO and FP in most mainstream languages. > dynamic dispatch is just allowing to associate a different implementation to the same function name. Every languages that have some kind of function pointer allow this. > polymorphism is in almost every language, including FP. data Tree a = Empty | Node a (Tree a) (Tree a) is polymorphism. C++ templates are polymorphism. Rust traits are polymorphism. > message-passing is only relevant if you adhere to Alan Kay's vision of objects. I personally don't (even if the guy coined the term).
- wfunction 9y agoA lot of misunderstanding in what you wrote, but to comment on two parts: > Every languages that have some kind of function pointer allow this. It doesn't seem like you're reading the discussion. The claim the parent made was that "every time you do {X}, it is OOP". My reply was "yes, you can do OOP in C, but OOP implies far more than just {X} (it implies {Y}, etc.); merely {X} does not imply OOP". You reply with "languages that have function pointers allow {Y}". Well yes, they do allow {Y}. Most/all of them in fact probably allow OOP in full. Nobody suggested such languages don't allow OOP (in fact I said the opposite about C). What does that have to do with the entire discussion and argument? Your argument isn't even wrong... it doesn't even compile. > message-passing is only relevant if you adhere to Alan Kay's vision of objects. I personally don't (even if the guy coined the term). This 100% completely misses the point of what I said. Replace it with "procedural call" if you're allergic to "message passing". The point I was making was we're talking about subroutine calls: you call a procedure and wait for it to produce a single value as the resulting output before proceeding. Again: if you're not used to other paradigms then that might be why you're missing my point here and adversely reacting to superficial things like the nomenclature. Whether you dress it as message passing or anything else has nothing to do with the issue.
- tome 9y agoOOP languages formalized the pattern of passing data structures into procedures?!
- xorcist 9y agoA definition of OO trivial enough to make everything OO isn't very useful. That's why inheritance, encapsulation etc. are often included, to mark the difference against what was before.
- jcelerier 9y agoBut there is an infinite spectrum of languages that mix and match various features of what you call "OO" at diverse degrees, making it meaningless to include all of these in the definition. The most famous ones tended to bundle them all which led to the misappropriation but really, there's no problem with simple concepts. We don't have to find names for everything: it's much clearer to say "language Foobar makes immutable values first-class and allows interface inheritance and delegation" than "language Foobar is FP/OO/whatever seems to be most predominant when looking at the hello world in such language".