From: Robert Klemme Date: 2006-12-20T01:45:08+09:00 Subject: Re: Discovering the number of return arguments requested. On 19.12.2006 16:49, Brad Phelan wrote: > Robert Klemme wrote: >> IMHO you are worrying too much about this: if a method has a >> meaningful return value it should be documented and returned no matter >> what the caller does. If he chooses to ignore it that's his choice. >> My 0.02EUR. > > I'm only curious about this due to performance issues not interface > issues. I am sure everybody has seen _Why's Markaby builder. On each > nested element called a fragment object is returned though very rarely > used. > > The fragment objects are used for rarely encountered events that > are outside of the standard Markaby pattern and can be used to > rewind the stream and pull out chunks that were already > inserted. > > mab = Markaby::Builder.new > > mab.html do > div do > div do > p do > "cat" + br + "dog" + br + "cow" > end > end > end > end > > generates > > >
>
>

> cat
dog
cow >

>
>
> > > The html, div, p and br methods all return fragment > objects. However only the fragment objects from the br > calls actually get used. The fragment objects from the > other calls are just thrown away. I can see your point. You could change the code and test it out or create some test suite of your own. Then you *know* whether this will actually yield speed improvements - and how large they are. And if they are negligible - you do not have to worry any more. When it comes to rendering HTML IO and fetching the data to display is usually slower than the HTML rendering (assuming some persistent backend storage). > In the case of Markaby I suspect there would be some > performance increase ( small maybe ) by changing the > Markaby code to do something different if it knew > beforehand that the fragment object was never required > instead of generating one and giving it straight to > the garbage collector. Actually it is not immediately GC'ed. And when Ruby runs on a JVM then short lived objects are definitively nothing to worry about. Read here for example: http://www-128.ibm.com/developerworks/library/j-jtp01274.html?ca=dnt-54 Kind regards robert