Checking out frogmetrics.com and thinking it is really cool, but reminds me...
How many times have you seen a survey with the answer being from 1-10 or 1-5 stars? Every time I come across one of these I always wonder how in the world they aggregate these responses in a meaningful way. A very level person will answer most things close to the center (every thing is a 4-6) where a excitable personality tends to hit the extremes. They both likely meant the same thing by their feedback. The same thing goes with netflix movie rankings for example, and then they try and give me recommendations based off of what other users felt. Problem being is that the level heads and the excited are all mixed in together.
So is there a way you could get a sense of what personality they are to help classifier their answers? What if you asked a single question somewhere in the survey that was a "primer" question. Something that has a decent emotional response, like how would winning 100 dollars make you feel 1-10?
Monday, August 18, 2008
Friday, August 15, 2008
Named Parameters in Ruby
Ever forget whether the name or email parameter is first on a method like this?
Named parameters can help out so that you don't have to remember the order of parameters. As a fringe benefit the code can read a bit nicer and you can add in new optional parameters without breaking existing code.
Ruby as a language doesn't support named parameters to functions. But it does support converting named pairs into a hash if you provide an argument for it.
This takes a little more work on the function declaration but it's not too bad. Now we can call the function like this:
Suppose you wanted your name parameter to be optional and default to the email parameter. You can easily set default values for one or more of your expected parameters:
With named parameters it often behooves you to do a bit more parameter checking.
To make all parameters optional, set a default value for your parameter to {}.
signup(name,email)
Named parameters can help out so that you don't have to remember the order of parameters. As a fringe benefit the code can read a bit nicer and you can add in new optional parameters without breaking existing code.
Ruby as a language doesn't support named parameters to functions. But it does support converting named pairs into a hash if you provide an argument for it.
def signup(params)
name=params[:name]
email=params[:email]
...
end
This takes a little more work on the function declaration but it's not too bad. Now we can call the function like this:
signup(:name=>'Me', :email=>'me@net.com')
Suppose you wanted your name parameter to be optional and default to the email parameter. You can easily set default values for one or more of your expected parameters:
def signup(params)
email=params[:email]
name=params[:name]||email
...
end
With named parameters it often behooves you to do a bit more parameter checking.
def signup(params)
email=params[:email] || raise("email parameter is required!")
name=params[:name]||email
...
end
To make all parameters optional, set a default value for your parameter to {}.
def optional(params={})
Subscribe to:
Posts (Atom)