incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "marios@redhat.com" <mandr...@redhat.com>
Subject Re: [PATCH] Introduces blob metadata - Adds ability to specify arbitrary user metadata (KEY-VALUE) for S3, Cloudfiles and Azure, during blob creation
Date Mon, 31 Jan 2011 20:52:52 GMT
Ok, I have changed the code to use .inject - its a new toy and its 
pretty cool. I will let this sit till tomorrow and if there are no other 
objections I will commit this code (aka I *aint* sendin out another 
patch unless someone asks me nicely).

> Very good example of how to use .inject can be found here:
>
> http://blog.jayfields.com/2008/03/ruby-inject.html

  ^^ This site does a *really* good job of explaining .inject ^^

>
> Yes, actually it's http://rubybestpractices.com ;-) There is an article
> about functional programming, which describes this.

This site is a ruby book (pdf) -  by article i assume you meant 
chapter... i tried searching but only thing I could find was a 
comparison of using .inject vs using recursion. However its a pretty big 
book so I may well have missed the relevant bit.

That got me curious; what *actually* is the advantage of using .inject. 
Don't get me wrong, I still think its pretty cool and elegant in its 
concise expressiveness, but most search results seem to suggest that 
.inject is actually slower (for this case, it makes no difference, since 
the input will never really be a HUGE structure; we are talking about 
key:value pairs for blob metadata). The way I understood it, if you are 
handling large data structures, the resultant object is returned at each 
'loop' of the inner code block, making it expensive.

>
> Anyway, it's not a blocker, just small hint (I found myself .inject very
> useful when I was doing some meta programming in client library. It saves
> variables and lines of code (and it's better for garbage collecting)).

In this particular case it doesn't save variables ( I assume you're 
referring to the instantiation of the resulting structure, 'user_meta' 
in this case). Do you have a reference/article/explanation for the 
'better for garbage collecting' (aka, please give me a reason to use 
.inject rather than .each, since the former is clearly much cooler),

marios


Mime
View raw message