From: Arnout E. <no...@bz...> - 2011-04-15 16:52:46
|
On Tue, Apr 12, 2011 at 09:28:51AM -0400, Etan Reisner wrote: > I think renaming to "super" is a pointless idea. Either you know what type > the parent is, in which case typing its name instead of super isn't a big > deal; or you don't, in which case you can't use super anyway since you > can't know what to cast it to. Indeed it is not useful when writing code, but imho it is useful when reading code. > It also doesn't tell you anything useful, since the immediate super > relationship isn't particularly helpful whereas the type of the member > actually is (especially if you are simply passing it to another function > which expects a certain type). > > Consider: > WScreen *scr=current_screen(); > mplex_switch_next(&(scr->mplex)); > versus > WScreen *scr=current_screen(); > mplex_switch_next(&(scr->super)); > > Which one tells you immediately that you've gotten the argument type to > mplex_switch_next right and which one leaves you having to remember and or > guess? In this case, when reading this code, I actually do think the second variation is more readable: you know the code compiles, you can easily guess 'mplex_switch_next' will take an mplex argument, and the 'super' tells you you're calling 'mplex_switch_next' on the screen itself instead of on some mplex property of the screen. > Also consider your given example. In what way is > > 'rw->scr.super.super.win=None;' > superior to > > 'rw->scr.mplex.win.win=None;' > ? > > The super version reads less well (to me), gives me less information, and > at that point I would really want a cast (or cast macro) or something to > hide it (you probably want that in either case really). Again, while I agree '.super.super' does not look very elegant, you *can* see at a glance that 'win' is a property of the screen itself (via superclasses) rather than a property of a property of a property of the screen. The types of the superclasses in the second variation add confusion rather than information imho. I think I would prefer 'normal' casts over glib-style macro-casts, but both of these throw the static typechecking out of the window, which the use of members (named 'super' or otherwise) avoids. Kind regards, Arnout |