A discussion about code, data structure, objects

Shu: I need your opinion on something related to code. Maybe the other person, with which I discussed,  is right. But still something I feel is not ok.

Ri: Ok. Tell me more.

Shu: I need to pass to the UI a list of address types. For example address type of home, or address type of work,… My initial idea was to send a simple collection with key value pairs. Something like:

           new Dictionary<int, string>{{ 1, “Work” }, { 2, “Home” }}

           or

           new List<AddressType>{AddressType.Home, AddressType.Work}

           where AddressType is an enum type

And then the UI would know what to do.

Ri: Ok

Shu: My problem is that at a code review I was being told that I should return “a list of objects”. And each “object” should contain the same 2 data. Something like:

           List<AddresTypeData>{new AddresTypeData{Id= 1, Name=”Work”}, new AddresTypeData{Id=2, Name=”Home”}}

Why the latter is better than the first?

Ri: It’s not. Conceptually are the same thing. Ok, we can speak of some advantages regarding reading the code, or what happens at runtime. But, I think that something else needs to be clarified tough.

Shu: What?

Ri: The reviewer said “object”?

Shu: Yes

RI: What he proposed is an object?

Shu: Yes

Ri: Look …<<a sigh>>… is a big difference between a data structure and an object. Maybe what he wanted to say is that he wanted to represent the idea of Address type in a different data structure, this is a different thing.

Shu: I do not understand what you are trying to explain.

Ri: Look, objects are like biologic cells(1). Cells which communicates between them to do something. Those cells have a sense in an ensemble of connecting cells, ensemble which tries to do a certain thing. What cell send to another cell is a message. (For example, for neuro cells from the brain that message is an electrical signal. This electrical signal jumps from a cell to another, is not continuous. This message flows via synapses. ). Those messages can have their own structure, but there are still messages. A cell will not do the work of another cell, and the cell will know to whom to send the message. An object you’ll see it truly only in the connection with the other objects, which as a whole try to solve something.

Shu: What do you want to say?

Ri: Semantics matters, and for me it was a sign of confusion of what objects and OOP mean. And I wanted to underline this. You were speaking about data structure of a message not objects, which are a different thing.


(1) Alan Kay, “Dr. Alan Kay  on the meaning of “object-oriented programming””, https://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/doc_kay_oop_de



Leave a Reply

Your email address will not be published. Required fields are marked *