Field hiding in OO-extensions

4 views
Skip to first unread message

Rasmus Knutsson

unread,
May 11, 2011, 6:32:06 AM5/11/11
to Compiler construction 2011
Hi everyone,

I don't think it is specified whether a local variable in a method
should be able to have the same name as a field in the same class--
correct me if I am wrong!

I don't really know what to think of this. Following Java it would of
course be natural to allow this, but on the other hand there would be
no way to access the field then, unless we add something like the
expression self->field.

Also there is the question of whether to allow naming a field with a
name that is already in use in a superclass. This too should perhaps
be allowed, but adds a little more mess to the implementation, since I
suppose the fields of the subclass would have to be renamed. Of
course, we could let the two fields be one and the same, but that
would mean allowing the subclass access to the superclass's field,
just by way of declaring it.

It would be nice to get a judgement on these matters!

Best regards,
Rasmus

Björn von Sydow

unread,
May 11, 2011, 6:51:49 AM5/11/11
to compiler-cons...@googlegroups.com
Hi!

You raise good questions, but I think I will refrain from commenting on them.

The main point here is that you actually have discovered the issue and that there is a choice to make. So think about it, the pros and cons of various options and then make a concious decision (which should preferrably be documented). Any reasonable decision, properly defended, will be accepted. There is no obvious correct answer to these questions, and going for what is simple to implement (and, of course, reasonable) is not a bad strategy.

Björn

Rasmus Knutsson

unread,
May 11, 2011, 7:02:08 AM5/11/11
to Compiler construction 2011
Ok, I will do that. Thanks! :)
Reply all
Reply to author
Forward
0 new messages