Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any situations where a side effect on a "get" or "calculate" operation is legitimate?

I've just finished a six hour debugging session for a weird UI effect where I found that my favorite framework's implementation of an interface function called "getVisibleRegion" disabled some UI feature (and apparently forgot to restore it).

I've filed a bug with the framework, but this made me think about proper design: under what conditions is it legitimate to have any side-effects on an operation with a name that implies a mere calculation/getting operation?

For those interested in the actual details: I had a report on a bug where my plug-in kept breaking Eclipse's code folding so that the folding bar disappeared and it was impossible to "unfold" or see folded code . I traced it down to a call to getVisibleRegion() on an ITextViewer whose type represents a source code viewer. Now, ITextViewer's documentation does state that "Viewers implementing ITextViewerExtension5 may be forced to change the fractions of the input document that are shown, in order to fulfill this contract". The actual implementation, however, took this a little too liberally and just disabled projection (folding) permanently, never to bring it back.

like image 415
Uri Avatar asked Dec 17 '22 09:12

Uri


1 Answers

The biggest reason I can think of is caching results.

like image 179
grepsedawk Avatar answered May 16 '23 07:05

grepsedawk