Hacker News new | past | comments | ask | show | jobs | submit login
Object-oriented design patterns in the Linux kernel (2011) (lwn.net)
149 points by zwliew on Nov 10, 2018 | hide | past | favorite | 10 comments



This is part 2 for data inheritance: https://lwn.net/Articles/446317/


This is a great article. So many programmers (including me) start with a language that does OO stuff for them. But it's really important to understand that it's not really magic and that a lower level language gives you more flexibility in which methods to use.

The difference between C and Lisp is that the latter allows you to extend the language in a way that essentially documents your technique in the same way C++ extends C to document its chosen techniques. If you saw the code in the article without having read this article and without suitable comments in the code, it would be really unclear what the programmer is actually doing.


Perl's OO is interesting in this regard. They use a function called bless() to mark something as an object of a specific class. No magic keywords, methods are just functions in a specific namespace/package, etc.

So, while it has it's warts, OO in Perl is very easy to follow.


Didn't most perl5 OOP move to the Moose library, that set a bunch of standard method names and hid all the bless'ing stuff in its internals?


I recently wrote an article about objects / classes in Perl 5 and Perl 6, which also touches on Moose: https://opensource.com/article/18/11/how-make-perl-more-clas...


Your article does a pretty good job of showing what I meant. The Perl 5 example is more verbose, but easy to follow how OO is implemented. Perl 6 hides it. Not arguing Perl 5's approach as better. Just that it makes OO easy to understand for a procedural developer.


Thank you. FWIW, I like to work with things that do what I want, without having to precisely understand how they do it.


It didn't move per se. You can use Moose as an abstraction if you want. But Moose is just a pure Perl module using bless at the bottom.

Edit: Maybe not pure Perl anymore? Would be VERY surprised if bless wasn't at the bottom though.


I seem to recall that most of Moose is XS now?


While I didn't start with an OO language, being young and self-taught I hadn't given much thought about how OO was actually implemented. And I hadn't thought about this possibility until I tried to use the Independent JPEG Group's JPEG library from my language of choice.

After filling in the function pointers for reading and writing data, it suddenly dawned on me "hey, this is OO, but in C!".

It was a very influential moment and after that I've always tried to gain a deeper understanding of what's under the hood, so to speak.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: