News for hackers. Stuff that matters.
Re:Data-oriented design or why you might shoot yourself in t... by bccdee on Monday June 28, 2021 @01:09PM (#27664490)
Those aren't exclusive to OO, though.

C, for all its faults, has encapsulation at a module level: any functions you don't define in your header file aren't exported and are thus private. Go and rust do the same thing.

Abstraction is even more common. Functions are abstractions. And any language with typeclasses (like haskell) or function overriding (like Julia) uses a form of polymorphism

Really, the only essentially object-oriented things here are inheritance and (by extension) inheritance-based polymorphism.

Re:Data-oriented design or why you might shoot yourself in t... by rsj_hn on Monday June 28, 2021 @01:26PM (#27664733)
> C, for all its faults, has encapsulation at a module level:

No language that supports memory access for the entire address space of the currently running program can ever support something like encapsulation: you can pass pointers to objects and functions outside the currently running module, or you could somehow derive this info from outside the module and so access functions and objects that were not declared in header files. Thus the language cannot give you the isolation guarantees that memory managed languages can. What it can do, is put up some roadblocks or barriers that require effort to cross. But there is a big difference between correctness guarantees and roadblocks.

There really is a qualitative change when you are working in a memory managed language as that allows the language to assign fine grained control over which memory addresses are available to which data structures, which is something that you cannot do with C.

Re:Data-oriented design or why you might shoot yourself in t... by corty on Monday June 28, 2021 @02:37PM (#27665808)
Well then, C++ doesn't have encapsulation, therefore C++ isn't OO. Hell, even Java isn't OO if you allow JNI.
Re:Data-oriented design or why you might shoot yourself in t... by rsj_hn on Monday June 28, 2021 @09:51PM (#27670748)
I don't want to get into a debate defining what language is OO and what is not. My point was rebutting the notion that C has private data structures by pointing out only languages in which memory is managed by the runtime (e.g. VM) can offer isolation guarantees. Attempts to switch the topic to OS level memory protections are not really what we're talking about here, as the OS doesn't provide language level protections. So yes, if your code leaves the VM then you lose those VM protections.
Re:Data-oriented design or why you might shoot yourself in t... by bccdee on Monday June 28, 2021 @10:18PM (#27670950)
> I don't want to get into a debate defining what language is OO and what is not

I mean, that is the discussion we were having. We weren't talking about language VMs.

Re:Data-oriented design or why you might shoot yourself in t... by rsj_hn on Thursday July 01, 2021 @01:42PM (#27701968)
I was replying to a statement that C had isolation and I pointed out that it didn't. The response was a non-sequitur: "So then even C++ isn't OO", and I responded that the question is not whether C++ is OO but whether it's memory is managed. Not sure how any of this is hard to follow or why these arguments should trip you up.
Re:Data-oriented design or why you might shoot yourself in t... by bccdee on Friday July 02, 2021 @06:24PM (#27717676)
The statement was specifically that C had encapsulation, within the context of a discussion about whether OOP should be defined as "encapsulation, abstraction, polymorphism, and inheritance."

You interpreted that as meaning memory isolation for some reason (even though plenty of clearly-OOP languages do not implement that), and when someone asked you how that definition of encapsulation squared with the fact that C++ is generally considered object-oriented, you said you didn't want to have that conversation.

It's not hard to follow and it didn't trip anyone up; you just changed the subject out of nowhere and for no discernible reason by injecting a contextually-inappropriate definition of "encapsulation."

Re:Data-oriented design or why you might shoot yourself in t... by bccdee on Monday June 28, 2021 @04:02PM (#27667137)
If we're talking about making guarantees about blocking the programmer's ability to modify parts of the address space, we're no longer discussing programming paradigms. We're discussing security proofs. The MMU does not play a core role in object-oriented programming.
Re:Data-oriented design or why you might shoot yourself in t... by corty on Monday June 28, 2021 @04:37PM (#27667735)
Historically, this is not entirely correct. Segmented MMUs (as opposed to the more common, currently used concept of paged MMUs) were intended to provide the hardware support for the protection levels and the data/code mixture in OOP. I.e. each object would have executable, readable, r/w and inaccessible parts. Protected by the MMU, depending on the currently accessing context, that is, a subclass, friend class, other class, etc. But creating a segment descriptor for each object or even just each class was, of course, far too expensive in the end.
Re:Data-oriented design or why you might shoot yourself in t... by bccdee on Monday June 28, 2021 @10:15PM (#27670924)
That's actually really interesting, I hadn't heard of that.
Re:Data-oriented design or why you might shoot yourself in t... by rsj_hn on Monday June 28, 2021 @09:49PM (#27670727)
We're not talking about the programmer doing something, but about the code doing something, which is absolutely all about security proofs. And while the OS protects an address space, the OO runtime protects memory within that runtime, so a private variable isn't available to code running outside the class while the same cannot be said for C code. That's the benefit of offloading memory management in interpreted languages.
Re:Data-oriented design or why you might shoot yourself in t... by mytailorisrich on Monday June 28, 2021 @01:45PM (#27664990)
OOP is a set of principles. C is a language. These are not the same things.
Re:Data-oriented design or why you might shoot yourself in t... by corty on Monday June 28, 2021 @02:39PM (#27665837)
Then OOP is no true scotsman, because no language implements all the principles.

Or in other terms, without an implementation, OOP isn't even usable, it isn't even real. Just maybe a desirable ideal somewhere.

Re:Data-oriented design or why you might shoot yourself in t... by bccdee on Monday June 28, 2021 @03:54PM (#27667003)
"Abstraction" as a principle is something we've been doing since we came up with function calls. Encapsulation as a principle is something we do when writing C code. The only one of the listed OO principles which is in any sense exclusive to OOP is inheritance.
Re:Data-oriented design or why you might shoot yourself in t... by mytailorisrich on Monday June 28, 2021 @04:09PM (#27667260)
> Encapsulation as a principle is something we do when writing idiomatic C code.

That's clearly not the case. C obviously does not enforce encapsulation, and it's extremely common for devs not to follow this principle, in fact it's pretty much the default not to and it takes discipline to enforce it.

"Encapsulation at module level", as you wrote earlier, is not encapsulation. If you implement your object as a struct (which is really what objects are) then encapsulation means not accessing the content of that struct/object directly.

Re:Data-oriented design or why you might shoot yourself in t... by bccdee on Monday June 28, 2021 @10:14PM (#27670915)
Encapsulation is information hiding, where the internal components of a unit of code are inaccessible to its consumers (by fiat or by convention — see python's _private methods). This includes hiding procedures, fields and types. Context objects are a form of data encapsulation, for instance, because their contents are meant to be inaccessible, and they're not uncommon in C.

I also gave the examples of rust and go, which have private struct fields but are not really object-oriented, and encapsulate at the module level. Point is, OOP does not by any stretch have a monopoly on encapsulation, and OOP should not be defined in terms of it.

Re:Data-oriented design or why you might shoot yourself in t... by mytailorisrich on Tuesday June 29, 2021 @03:19AM (#27672850)
Sorry but I no longer understand what you are arguing about, nor do I understand your point.

Encapsulation in the context of OOP means effectively hiding the data within an object from the external world and not allowing direct access to these data.

OOP may not have a monopoly on this but this is indeed a defining feature of OOP (which you know very well if you ever took a programming 101 course): You may have encapsulation without OOP, but in OOP you must have encapsulation. It's not OOP if there's no encapsulation.

Encapsulation is not something enforced by C (access to struct's fields is free for all). And this is not a principle generally followed in C code (most C code does directly access fields within whatever struct). Hence my rebuke to your claim of the contrary.

Now, obviously this can be done in C, this is a matter of choice. OOP can be done in any language. There seems to be confusion in many comments between OOP and specific languages.

Lastly OOP are a set of principles. Principles are rarely followed in their entirety and indeed many languages pick and choose which, if any, principles they implement and how they implement them. It's the same when 'practising' OOP in a language where you have to do everything "by hand", like C: You pick and choose as needed.

I'm out.

Re:Data-oriented design or why you might shoot yourself in t... by bccdee on Tuesday June 29, 2021 @01:35PM (#27679158)
> this is indeed a defining feature of OOP (which you know very well if you ever took a programming 101 course)

Setting aside the fact that any 101 course is necessarily reductive and inaccurate, "encapsulation + abstraction + polymorphism + inheritance = OOP" is something that gets regurgitated a lot without ever really being argued in favour of.

Since the first 3 of those 4 points are not at all limited to OOP, it really doesn't make sense for them to constitute ¾ of the definition. Are they really OOP principles if basically every modern language follows them? And now that we largely agree composition > inheritance, OOP often ignores that fourth principle too.

I know you hate C as an example here, so let's use rust instead. If a rust codebase can exercise encapsulation, polymorphism, and "abstraction" (still the vaguest and weakest criterion imo), and OOP code is discouraged now from using inheritance anyway, what stops it from being OOP? Most of the rust I've seen hasn't fit with any conventional notion of OOP, but it still technically matches the definition. Doesn't that make it a bad definition?

Re:Data-oriented design or why you might shoot yourself in t... by wtetzner on Monday June 28, 2021 @05:25PM (#27668377)
ML supports encapsulation via modules and abstract types.