A Ruby Scoping Gotcha?

Let’s take this basic class: class TestClass attr_accessor :one def my_method(branch=true) if branch puts "Do nothing to modify `one`" else puts "Modify `one` but it's a local variable" one = "test" end one # local variable end def my_non_modifying_method(branch=true) if branch puts "Do nothing to modify `one`" else puts "Do nothing to modify `one` either" end one #method call end end o = TestClass.new o.one = "Value" puts o.my_method => nil #might expect 'Value' if you're not paying attention puts o.my_non_modifying_method #expects "Value" => "Value" puts o.my_method(false) => "test" puts o.my_non_modifying_method(false) #expects "Value" => "Value" So remember, if you create any local variables anywhere in your method, even if they’re not called, they override the accessor methods and will give you results you’re not expecting. To get around it, make sure you always use self.accessor= to assign values when there is ambiguity.

August 27, 2010 · 1 min · Mark Simoneau

Optional Heirarchal Checkbox Selection with Nested Attributes in Rails

I had a process where I wanted users to fill out a survey which had hierarchal categories AND be able to specify some additional data for specific capabilities that the user had. Now, you could easily do this for a small subset and hand-code every item, but I wanted a flexible survey system that allowed true hierarchy and generalized code. Let’s start off with the basic survey and capabilities models and relationships: ...

June 4, 2010 · 4 min · Mark Simoneau

How and Why to Stop Multitasking - Peter Bregman - Harvard Business Review

A study showed that people distracted by incoming email and phone calls saw a 10-point fall in their IQs. What's the impact of a 10-point drop? The same as losing a night of sleep. More than twice the effect of smoking marijuana.Doing several things at once is a trick we play on ourselves, thinking we're getting more done. In reality, our productivity goes down by as much as 40%. We don't actually multitask. We switch-task, rapidly shifting from one thing to another, interrupting ourselves unproductively, and losing time in the process. ...

May 27, 2010 · 1 min · Mark Simoneau

9GAG - Making an iPad stand from its own packaging

9GAG - Making an iPad stand from its own packaging. Geeky and efficient. Couldn’t resist.

April 27, 2010 · 1 min · Mark Simoneau

Who Is A Good Tester?

A good software tester… Constantly asks, “What is the best test I can execute right now”. Can log unambiguous bugs with clear repro steps that make the main problem obvious with few words. Is not distracted by their understanding of developer decisions. Just because the tester may understand certain technology constraints motivating dev solutions, the tester’s mission is never to defend the AUT see my post, What We Can Learn From Dumb Testers. It is to communicate how the AUT currently works, in areas that matter right now. via Test This Blog - Eric Jacobson's Software Testing Blog: Who Is A Good Tester?.

April 14, 2010 · 1 min · Mark Simoneau

Rails Controller Specs with users, roles and nested routes

I’ve long put off testing my controllers because of user authentication and nested controllers, dealing with stubs, etc. But today, a fully working test! As background, Advertisers have many trackers and the routes look like this: ActionController::Routing::Routes.draw do |map| map.resources :advertisers do |advertisers| advertisers.resources :trackers end end To set everything up in the specs, I included all the files in the spec/support directory and used Mocha as my mock framework Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f} Spec::Runner.configure do |config| config.mock_with :mocha end Then I set up my factories (rather than fixtures) using Factory Girl ...

March 3, 2010 · 3 min · Mark Simoneau

An Interesting Way to Publish a Blog

Peepcode has a blog and it is managed in a very efficient and unique way. Everything is checked into git and pushed, no database involved–it’s kindof incredible. Check out the stack here: About this Blog | Free PeepCode Blog.

February 27, 2010 · 1 min · Mark Simoneau

Simplicity

I’ve read quite a bit lately about simplifying our lives–mostly from a personal perspective, i.e. having less stuff, doing fewer things, focusing on the right things. It made me wonder how that translates to the professional level. Apple, 37 Signals and many other companies make a living making software simple AND effective to use. That’s one way that it translates–on the macro level, but how about on the micro level? What is your absolute minimum work setup where you are free from distractions and free to do everything you need to do? Are there things that initially seem like “extras” that are actually a big deal? Are there things that you have in your workspace that you could easily do without now? ...

February 23, 2010 · 2 min · Mark Simoneau

Python vs. Ruby - A Fight To The Death

When you’re discussing efficiency, a lot of what comes up is the details. There is something to be said for the “beauty” of limitation and the “efficiency” of beautiful things–especially the efficiency of our brains processing it. A talk about the Zen of Python, monkey patching (several times), the Ruby community's reckless hastiness, the syntax of RSpec and cucumber, beauty and ugliness in languages and testing tools, the complexity of the languages' grammars, syntactic vs. semantic complexity, the relative taste of grasshoppers and tree bark, etc., etc. Python vs. Ruby: A Battle to The Death from Gary Bernhardt on Vimeo. ...

February 21, 2010 · 1 min · Mark Simoneau

"I need to talk to you about computers."

Nothing is simply black or white. Old Worlders are particularly sensitive to certain things that are simply non-issues to New Worlders. We learned about computers from the inside out. Many of us became interested in computers because they were hackable, open, and without restrictions. We worry that these New World devices are stifling the next generation of programmers. But can anyone point to evidence that that’s really happening? I don’t know about you, but I see more people carrying handheld computers than at any point in history. If even a small percentage of them are interested in “what makes this thing tick?” then we’ve got quite a few new programmers in the pipeline. ...

February 12, 2010 · 1 min · Mark Simoneau