[Rd] Object type name and class name
Fg Nu
fgnu32 at yahoo.com
Tue Dec 24 23:43:08 CET 2013
[Resending because HTML was scrubbed.]
Gabriel,
Thanks. Not trying to influence any changes, just trying to understand better what is going on when the term "object type" is used. From what you and the SO answer seem to suggest, it has little to do with OOP/classes at all. This would be fine if John Chambers weren't explicitly juxtaposing the two in the quote given in the original post.
Regards.
>On Wednesday, December 25, 2013 3:49 AM, Gabriel Becker <gmbecker at ucdavis.edu> wrote:
>
>It sounds like you're attempting to apply a version of object orientation (objects being instances of classes) which does not apply to R (in the S3 world anyway).
>>
>>That simply isn't how S3 classes work (in many ways S3 classes aren't really "classes" at all in the way you seem to be using the word, they are simply dispatch instructions) and that fact is AFAIK at the core of the language.
>>
>>I'm not a core developer of R, and so I don't speak for them, but the likelihood of that changes seems vanishingly small at this juncture. Whether it "should" work the way you describe is debatable (I am not convinced myself), but regardless of whether it should it almost surely isn't going to.
>>
>>~G
>>
>>
>>
>>
>>On Tue, Dec 24, 2013 at 1:57 PM, Fg Nu <fgnu32 at yahoo.com> wrote:
>>
>>
>>>
>>>Gabriel,
>>>
>>>
>>>[I understand that this is not about R development, but it seemed that this was a question about R internals that would be better answered on the R-devel list.]
>>>
>>>
>>>Thanks for your answer. Yes, this is what the person who answered on SO said as well.
>>>
>>>
>>>But my question is about terminology really. Why is the internal storage type called object type, which clashes with my understanding of an object being an instance of a class, and hence should share the same name? This is a purely technical notion, which should have nothing to do with the physical reality of C storage and types.
>>>
>>>
>>>Thanks.
>>>
>>>
>>>
>>>On Wednesday, December 25, 2013 3:02 AM, Gabriel Becker <gmbecker at ucdavis.edu> wrote:
>>>
>>>Fg,
>>>>
>>>>This is not really an r-devel question. It is more appropriate for r-help as far as I know. Please ask questions like it there in the future.
>>>>
>>>>Anyway, my understanding is that the type of an object has to do with how it is stored internally, whereas the class has to do with how it is dispatched on. For example, in the S3 system , it is entirely reasonable to do the following:
>>>>
>>>>
>>>>> x = 1:10
>>>>> class(x) = "myspecialint"
>>>>> x
>>>> [1] 1 2 3 4 5 6 7 8 9 10
>>>>attr(,"class")
>>>>[1] "myspecialint"
>>>>> print.myspecialint = function(x, ...) print(mean(x))
>>>>> print(x)
>>>>[1] 5.5
>>>>> typeof(x)
>>>>[1] "integer"
>>>>
>>>>As you can see, changing the "class" of x did not change how it was stored internally.
>>>>
>>>>
>>>>Another canonical example is the matrix class. Matrices in R are stored as vectors of the relevant type, with additional attributes indicating their dimension. So while there is a matrix class, there is no matrix type.
>>>>
>>>>
>>>>> x = matrix(1:10, nrow=2)
>>>>> x
>>>> [,1] [,2] [,3] [,4] [,5]
>>>>[1,] 1 3 5 7 9
>>>>[2,] 2 4 6 8 10
>>>>> typeof(x)
>>>>[1] "integer"
>>>>
>>>>
>>>>HTH,
>>>>~G
>>>>
>>>>
>>>>
>>>>
>>>>On Tue, Dec 24, 2013 at 12:26 PM, Fg Nu <fgnu32 at yahoo.com> wrote:
>>>>
>>>>
>>>>>
>>>>>
>>>>>I came across the distinction between the name of an object and the name of the class that it belongs to in an oblique way again today, which made me question my acceptance that it would be natural for them to differ.
>>>>>
>>>>>I asked a question on SO here:
>>>>>http://stackoverflow.com/questions/20762559/why-is-the-name-of-an-object-type-different-from-the-name-of-the-class-it-belong
>>>>>
>>>>>I wonder if anyone on the R-Devel list has a better explanation for why the class name of an object and the object type name of an object should differ?
>>>>>
>>>>>Happy holidays,
>>>>>
>>>>>fg
>>>>>
>>>>>______________________________________________
>>>>>R-devel at r-project.org mailing list
>>>>>https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>>
>>>>
>>>>
>>>>--
>>>>Gabriel Becker
>>>>Graduate Student
>>>>Statistics Department
>>>>University of California, Davis
>>>>
>>>>
>>>>
>>
>>
>>--
>>Gabriel Becker
>>Graduate Student
>>Statistics Department
>>University of California, Davis
>>
>>
>>
>
>
More information about the R-devel
mailing list