.

Solidarity From The ZenSpider

Polishing Ruby: as seen on IRC

16:05 srbaker : using < < self to replace the "duplication" in "def self."
16:05 srbaker : is like using method_missing to remove the duplication of leading a in
16:05 srbaker : apple and aardvark

This is very timely since I was just having this discussion yesterday.

To an outsider (aka non-coder) it may be incredibly difficult to imagine that there is much style or choice in coding. Nothing could be farther from the truty.

You can think about it in terms of prose - describing someone getting home from work can take a number of different paths depending on the description, pacing, and mood set by that prose.

A man comes home. He puts his keys on a table. He gets a beer from the fridge. He drinks it.

vs

He stolled in and casually threw his keys onto the counter and headed directly for the fridge. He furiously scanned its contents looking for his prize. He removed the beer carefully, and in a single motion twisted off its cap and poured it down his throat.

Now the point that is being made above is a lot more specific.

You can write code this way in Ruby:

class << self
  def find_all
    code_goes_here
  end  def destroy_all
    code_goes_here
  end
end

or you can write

def self.find_all
    code_goes_here
end
def self.destroy_all
    code_goes_here
end

Can you spot the difference?

Both pieces of code have the same behaviour. I’m pretty sure the first one is the more popular construct in the Ruby community. It turns out I prefer the second one.

Why?

Simple - I’m lazy. When I get to a method I prefer to know immediately if it is a class method (self.) or an instance method. By breaking that piece of info and putting it elsewhere in the file I have to go look for it to understand what is going on.

Is it a big deal? No. But a number of small style nits - I strongly perfer it one way over the other. Up until now I thought I was the only person who did (price of writing Ruby in an isolated community) - now I know I’m not alone.

For the curious - the other three that came up -

terinary operators - I love them - most people hate them - assuming they don’t get very long I prefer

def name
    self.obj ? self.obj.name : “”
end

or

def name
  if self.obj
    return self.obj.name
  end
  “”
end


unless
- I can never seem to read an unless statement in the first attempt - I have to substitute the phase “if not” in order to read it - I blame preference for this on Ruby’s Perl philisophical heritage)

protected/private
- that serve a small purpose in Ruby (mostly because you can always override them) But I personally don’t like it when people put the keyword in the file making all methods after that point private or protected. I prefer to use the alternate form where you put the keyword at the end of the class and list all methods that should be protected/private. It means you never accidentally make something private or protected and you don’t have to figure out if you are in a special part of the class to add a method. (This last one is probably silly)

Back in the days I wrote C,C++, PHP, and Perl - where you put the curly braces could be a serious argument.
Do you have a programming style preference? What style do you love? What drives you craze?


Another Word For You Vocabulary

Dr. Dobb’s | Dr. Dobb’s Agile Newsletter | July 24, 2006

In astronomy there is the concept of red-shifting and blue-shifting: red shifting occurs when a body is moving away from you (the wavelength of the light increases) and blue-shifting occurs when a body is moving towards you (the wavelength of the light decreases). This is useful input for determining the speed and direction of something. In software development we have green shifting which occurs when people rework the information contained in status reports to make them more politically palatable to their manager.

Basically this is where “spin” is applied to a project status to make it seem “green” - in this case that means go not evironmentally friendly.

I’ve seen this more that I care to admit in my career. Truth be told, it seems that the likelyhood that green shifting will occur is directly related to the importance of the project. Which is unfortunate, because it is those big expensive projects that you stand to lose the most when they fail. That failure is unlikely to be avoided by sweeping it under the carpet and avoiding sounding the alarm (it was a cliche two-fer).

This is actually one of the things I like about the agile projects I’ve worked on lately. The goal is to get the hardest most complicated stuff into play as fast as possible, so we can alert everyone involved if we’ve hit a problem.

“Bad news first, no suprises”


At BarCamp Texas in Austin

New venue - schedule is up - and now getting down to business!

IMG_7524.JPG

IMG_7522.JPG

IMG_7523.JPG

Site Too Wide!

(This has only been tested in Firefox - YMMV)

Have you ever been looking at a site and it was too wide? Kind of annoying. I stumbled into a simple solution -

if you put this in the address bar it will fix it:

javascript:void(document.body.style.width = "50em");

Now the fun part is create a new book mark - call it “Too Wide” - make the code above the location. Put the book mark in your tool bar. If you see a page that is too wide click it and you are one.

Simple and cool - I love it!

I got this from sverrejoh on reddit


Ask Pud: Japanese beer machine

Forwarded in by a Houston Contributor

Ask Pud: Japanese beer machine

Neat idea - the thing I find most commical is that instead of actually pouring it so you get a head - they actually generate the head from a seperate pour - I suppose takes some of the complexity out of it.


Big Technical Weekend

I’m going to do more of a wrap up than usual - mostly because there is a lot of ground to cover and none of them justify their own post. Once I get back in the groove I’m hoping I’ll be in shape to really crank out a good technical post or two (and who knows maybe even a movie review)
Let’s Start with the light stuff.
My camera didn’t make it back from Defcon in one piece

img_7575.jpg

I was seriously bumbed - I figured I was going to be shelling out for a new camera until I did some goggling and found this article
Basic with some elbow grease, and a $60 part - I get

img_7584.jpg

Seriously cool!

Windows XP - Permission Denied

I chose this weekend to re-install my windows workstation. Did I mention I hate working in Windows? It turns out that I’ve been struggling with permissions. I couldn’t wrap my brain around the fact that I could be administrator on a box and still not be able to read a frigging file. Which when you’re trying to copy around files from a previous install gets pretty frustrating. Well it turns out it’s all related to simple file sharing. As long as you have that turned on, you can’t see the permission tool. Once you turn it off - boom - you get full access - lesson learned - Simple != Better (In windows).

Is It Getting Hot In Here?

I’ve stumbled into a deep vat of new technology toys to play with in the last two days. The one that has the best eye candy appeal for the layman are Heat Maps.
Read The Definitive Guide
Basically this tech generates a transparent image you cal overlay on your website. It then allows you to see where users held their mouse or clicked. It basically gives you a cool visual guide to where your interface succeeds (and fails).

Back From The Dead?

I got the strangest email today - it was from the Mulberry News list - apparently Mulberry is alive again - well sort of - Learn more Here It’s free (as in beer - he’s trying to figure out if he is going open source). I was a huge fan of Mulberry! I’m not sure if I’m going to play with it now that I’ve broken away (even though truth be told I think Thunderbird and Evolution are nice but don’t handle my 500 mail box imap account half as well), but I have a feeling i won’t be able to resist the temptation.

Finally Released

I’ve been a heavy user of GnuCash for a number of years. 2.0 is now out there. It looks like it is already listed as an offical package in Edgy. We’ll see if I wait until Oct to run it when I upgrade to Edgy or if I recompile the package. For some reason I’m in no hurry to upgrade and break my accounting system.

Last Thing

Edgy Eft is the next release from Ubunutu. Don’t ask me what an Eft is - I have no idea. According to Edgy Release Schedule we can expect it in late Oct. This is one of the things I really love about Ubuntu. They continue to crank out big releases on a pretty much regular schedule. I don’t have to upgrade to Edgy - but it is nice to know I will be able to - especially since I use Dapper on my workstations and the desktop world just evolves a heck of lot faster than the server world (Rails being the exception)


Live From The Field

Wayne the ‘train’ Hancock at Casbeers

DirkPhoto020.jpg

Ad-Free Blogging

Ok I saw this linked to on a blog:

ad free blog *saying no to corporate advertising*

By using this icon on my website I am stating…

1. That I am opposed to the use of corporate advertising on blogs.

2. That I feel the use of corporate advertising on blogs devalues the medium.

3. That I do not accept money in return for advertising space on my blog.

signed,

the author

I currently don’t have ads that pay money - though I am working on that (now that Basecamp has a referral program). But I find this sort of thing funny. I think that if you don’t want ads on your blog that’s totally your right as the blog owner. I’m down with that. The idea that corporate advertising on blogs devalues the medium in the idea that really stands out as the odd statement in there.

#2 is the thing that really pulled this out for comment.

First of all, I think the whole of idea of any one thing underming the “medium” of blogging patently silly. The thing that does the most harm to the legitamacy of blogging are the trillions of blogs that have 1 post on them - My First Post - and nothing else - or the “Cheese Sandwich Blogs” - which are the ones that are so boring they have nothing more than what they ate recently.

Blogs as a “medium” have only gained in value - thanks in a large part to the role they play in the larger world of journalism and discussion. Some of those bloggers are paid to do what they do. I’m actually in favor of that. The revenue thing can probably cut both ways - meaning you end up being influenced by your advertisers but on the other hand it should prevent you from doing something stupid and shotty because it would impact your revenue.

I suppose the blogosphere is going through that phase that the rest of the internet handled with AOL first started letting it’s members on the Internet. That “golden” age ended - and for some the Internet would never be the same - thank god! The first time I saw a web browser I didn’t think it was much of an improvement over Gopher. Now look at it - more people - more stuff - hell I live on the Internet - it entertains , educates, and employees me.

That is basically what advertising does - it brings more people to the party by the shear fact that writing a blog takes time and effort. The posibility to make a little money in the process is good because it may convince voices to come out that other wise wouldn’t be here.

Besides - you might as well use ads to remind you that everything you read on the Internet could be a lie purpetrated by some far out political group - or some Spam generator hell bent on SOE


Mocha

Mocha

Mocha is a library for mocking and stubbing within tests using a syntax like that of JMock and SchMock.

Woohoo! - I finally found a mock tool that look like it can actually handle mocking out ActiveRecord classes on the fly! Truth be told, I haven’t had a chance to put this into production, but I hope to shortly.

I was incredibly frustrated with the way Rails handles mocks precisely because it doesn’t handle ActiveRecord mocking very well. Plus it handles both stubbing and mocks - with expectations. I may have finally found in Ruby what I had in PHP - I missed SimpleTest - it’s good to have a replacement.


Better Testing, Worse Testing

Quality Tree Software, Inc. - Better Testing, Worse Testing

This leads me to my next general conclusion: an isolated improvement in one aspect of a development process tends to be offset by declines in another, resulting in no overall improvement in the final result.

This is an interesting idea - both because I’ve spent a lot of time in the last few weeks teaching about how to use all the testing tools available to Rails developers so I’ve been thinking about all the different ways you can test.

But more importantly, I have experienced it myself. Once you start getting really good coverage from your unit tests and things really start cranking it can take a special amount of will to really sit down and add in all the Selenium tests that the system should have.

The last project I released had very few bugs. All of them were in areas where the testing was spotty or incomplete.
So remberer - test early and often - but also test from a variety of perspectives - or you will just push your bugs from one place in the code to another.


    You are currently browsing the Economy Size Geek weblog archives for August, 2006.
    Previous Entries »
    Categories
    Archives

    .