On Wed, Dec 09, 2015 at 10:10:42AM +0100, Jean-Marc Lasgouttes wrote: > Le 09/12/2015 06:54, Scott Kostyshak a écrit : > >Regarding the following code: > > > >----- > >void Text::selectWord(Cursor & cur, word_location loc) > >{ > > LBUFERR(this == cur.text()); > > CursorSlice from = cur.top(); > > CursorSlice to = cur.top(); > > getWord(from, to, loc); > >----- > > > >It is not easy to know whether "to" and "from" are equal to each other > >because > >cur.top() might return something different the second time. For readability > >purposes, I would prefer either > > I do not really see why this confuses you actually.
Well, since I have a bad memory I always try to write code imagining "what if I did not have any inside information". A newcommer does not know that the initializations of 'to' and 'from' are useless (neither would he under my proposal). A newcommer also does not know what top() does. Maybe it pops off something, and thus changes the underlying list so that the second call to it returns something different. My proposal at least clarifies this. I don't care that much. I was just curious what others thought. This was a poor example. I should have cut off the "getWord" call in my quote so as just to focus on what the reader would think of 'from' and 'to'. Scott
signature.asc
Description: PGP signature