Robert Dober
5/22/2009 11:42:00 AM
On Fri, May 22, 2009 at 1:10 PM, Balint Erdi <balint.erdi@gmail.com> wrote:
> Hi,
>
> Deleting (vs. just fetching) the hash key from an options hash that
> was passed in as an argument to the method seems prevalent.
I strongly disagree.
> I saw it
> in several high-quality OS projects (e.g DataMapper, Rails)
Rails high-quality? On what basis?
Please do not take this as a provocation, it is just the first time I
have heard this claim (well maybe DHH said something similar once, but
do not quote me, please;)
>
> For example:
>
> unless options.delete(:only_path)
> =A0 =A0 =A0 =A0url << (options.delete(:protocol) || 'http')
> =A0 =A0 =A0 =A0url << '://' unless url.match("://")
> =A0 =A0 =A0 =A0...
> end
>
> I wonder what advantage the above snippet has instead of writing:
I would say that context is king. If the author of the above snippet
deletes values from the hash she has probably a (good) reason.
It is not very difficult to imagine some reasons, e.g. checking later
for the same values again (but please see below).
I would however take another look at the whole setup of the thing, if
I were e.g. a code reviewer. This seems not a case I would mute
objects a priori, thus I too would be intrigued by the rationale
behind this.
If you are too, which I have understood from your post, than you might
just want to follow the lifetime of options in the code to
understand/approve/disapprove about this code.
HTH
Robert