[Grace-core] On numbers and objects
Michael Kölling
M.Kolling at kent.ac.uk
Mon Nov 8 08:47:45 PST 2010
Where are Strings in this? Do they have constructors? I.e. can I have two different String objects representing the String "equality is mysterious"?
Michael
On 8 Nov 2010, at 07:37, Kim Bruce wrote:
> Hi Michael,
>
> Thanks for your very complete comments. The distinction you make is indeed an interesting one. I have always found Java strings difficult to teach to novices as they don't quite fit into any of the 4 categories. In particular, they are pre-existing/built-in, yet one can write "new String("hello")" and get a distinct object from that represented by just "hello". Our "egal" notion of equality will help here, but locating String entirely within pre-existing/built-in will also help.
>
> I do like the idea of adding enums to the language, probably with a built-in "toString" method, possibly one that can be overridden as well.
>
> I'm not quite sure what might lie in the constructed/built-in category.
>
> Kim
>
>
>
> On Nov 7, 2010, at 11:40 AM, Michael Kölling wrote:
>
>> I am slowly reading through the GraceNotes - apologies for the multiple postings. I'll keep it down to a few a day... :-)
>>
>> Regarding the note on Basic Types, I have a few questions and thoughts.
>>
>> It seems intended (implicit in the text, I think, but not explicitly stated), that all data are objects, including the basic types - right? I think that's good. But it leaves a few questions. One is: where do these objects come from?
>>
>> (Please stop me if I have the completely wrong end of the stick here. But I'll just go ahead and write my thoughts...)
>>
>> I guess one view is to say that there are some pre-existing objects (such as numbers and strings), which just "are". They pre-exist in the Grace universe, and literals (1 or "Hello") are just constant references to these pre-existing objects.
>>
>> That's okay.
>>
>> There cannot be constructors for classes of this kind, otherwise you could have two 1-objects, which would wreak havoc with equality.
>>
>> Then there are other object types (such a user defined classes), where objects don't pre-exist, but instead we are given a constructor. So we have two kinds of objects: pre-existing and constructor-created. (That's a much nicer distinction that the Java "primitive vs object".)
>>
>> (Was that the idea here? Or have I got this completely wrong?)
>>
>> Then there is another dimension: built-in types (the ones that the Grace system implicitly needs to know to operate, e.g. Boolean, Number) and user-defined (any class that is made by the user or explicitly imported from a library). This distinction is somewhat orthogonal to the creation question.
>>
>> So, can we have all four combinations?
>>
>> pre-existing / built-in: Boolean, Number, String, ...
>> constructed / built-in: ??? (anything that is "just there" without import from libraries?)
>> pre-existing / user defined: interesting case. Maybe enums?
>> constructed / user defined: of course. standard classes.
>>
>> The "pre-existing / user defined" case looks interesting: Can I have a class where I enumerate the objects, instead of providing a constructor? After all, that's the model (as I see it) for Boolean or String.
>>
>> Michael
>> _______________________________________________
>> Grace-core mailing list
>> Grace-core at cecs.pdx.edu
>> https://mailhost.cecs.pdx.edu/mailman/listinfo/grace-core
>
More information about the Grace-core
mailing list