CodeHappy

February 19, 2009

Codehappy is now Hackify

Filed under: Uncategorized — pwrighta @ 7:41 pm

I’ve decided to move the blog. After this post, there’ll be no more posts on CodeHappy. Instead head on over to Hackify.com to get the lowdown on what’s going on.

Basically the move was a decision to first migrate to a platform that would let me monetize the mass of traffic I get in some small way (I’m not likely to retire off the proceeds, but it sure would be nice to see something for the time I spend working on content. Second, I want to start over in some ways, to really focus on getting some good content up on blog and I just felt a change of environment would be a good step to take.

Thanks for reading, and please be sure to head on over to Hackify.


February 9, 2009

RSpec and Shoulda

Filed under: General Programming, Ruby On Rails — pwrighta @ 11:40 pm
Tags: , , , , ,

I introduced the dev team at Izea (then only 2 people – me and Dray) to RSpec pretty much as soon as it became available. It looked interesting, but I have to admit that it’s not something that caught on with me immediately. I’ve been a big fan of Test Driven Development for many years, but the switch to Behavior Driven just felt a little odd. I still don’t think I’ve fully gotten the ‘thinking’ behind the paradigm shift down, but I did start to pay more attention to RSpec again recently.

RSpec 1.1.12 now works with the Shoulda macros, and that single fact now has me as a convert to the world of RSpec for all the work I’m doing in Ruby (which, it may surprise you, is quite a lot lately).

From the Shoulda website

The Shoulda gem makes it easy to write elegant, understandable, and maintainable Ruby tests. Shoulda consists of test macros, assertions, and helpers added on to the Test::Unit framework. It’s fully compatible with your existing tests, and requires no retooling to use.

  • Helpers – context and should give you rSpec like test blocks. In addition, you get nested contexts and a much more readable syntax.
  • Macros – Generate many ActionController and ActiveRecord tests with helpful error messages. They get you started quickly, and can help you ensure that your application is conforming to best practices.
  • Assertions – Many common Rails testing idioms have been distilled into a set of useful assertions.

Within the project I’m working on, we needed to get a set of tests built that just made sure required validations were on an underlying model. There’s an argument that says you don’t need to do that, that you should just let ActiveRecord do what it does while you get on with testing your app, but we really needed to have some tests in place just to make sure over time that required validations don’t magically disappear. However, I do tend to agree with the counter argument, and the amount of code required to write the RSpec tests really didn’t help at all.

With Shoulda, it became very simple. For example, here’s a full set of RSpec specifications (?) using Shoulda to check that uniqueness constraints are still applied to a basic User model.

describe "To keep the User table clean," do
  before(:each) { create_user() }
  subject { User.new }
  it {should validate_uniqueness_of(:login)}
  it {should validate_uniqueness_of(:name)}
  it {should validate_uniqueness_of(:email)}
end

“validate_uniqueness_of” is one of many Shoulda macros. It requires a record to already be in the database and then goes ahead and tries to create a new one with the specified field set to the same value as previously to check that the specification still holds.

The “before” block calls a method to create a simple user record before each “it” block runs. The “subject” block returns the object that each Shoulda macro works with. Simple huh. The macros also output nice and legibly in specdoc format.

To keep the User table clean,
- should require case sensitive unique value for login
- should require case sensitive unique value for name
- should require case sensitive unique value for email

Here’s another set of tests on the same model, this time checking data formats using the Shoulda macros.

describe "New users" do
  subject{ User.new }

  # Presence tests - login, email and name all need to be present
  it {should validate_presence_of(:login)}
  it {should validate_presence_of(:email)}
  it {should validate_presence_of(:name)}

  # Length tests - there are length constraints on login and name
  it {should ensure_length_of(:login).is_at_least(3).is_at_most(40)}
  it {should ensure_length_of(:name).is_at_most(100)}

  # Format tests - login and email both need to comply to a format.
  %w(test 1234 test23 a1.-_@).each do |value|
    it {should allow_value(value).for(:login)}
  end
  %w(test@test.com me_test@test.com test@sub.test.com).each do |value|
    it {should allow_value(value).for(:email)}
  end
end

In the case of these tests, we don’t need a pre-existing record for the Shoulda macros to work their magic.

Setting the whole thing up in an existing Rails project was quite easy, but it did take me a little while to figure out which gem to use etc. Here’s the process.

sudo gem install thoughtbot-shoulda --source=http://gems.github.com
rake gems:install
rake gems:unpack

I also had to add a line to environment.rb

config.gem "thoughtbot-shoulda", :lib => "shoulda", :source => "http://gems.github.com"

I’m sure part of the argument against testing such basic functionality of a model stems from the fact that RSpec code can be so horribly verbose and time consuming to produce. Shoulda makes it a snap though and having tests ensure that these basic validations are in place, no matter what refactorings happen over time, is a safety net I’m glad to have.

Shoulda also lets you produce your own macros with a similar feel, but I haven’t dived into that just yet.

January 17, 2009

Busy busy

Filed under: Uncategorized — pwrighta @ 1:41 pm

Sorry no posts of late – I’ve been pretty busy with the new job and stuff in general. I’ve got a couple I’m working on, but it’s going to be a week or so before they go up. Monday is a holiday for me (not for Meagan …moohahahah) so I’m planning on jumping on the new bike for the day. Just gotta figure out where to go – St. Augustine? Tampa? Who knows.

January 4, 2009

MacRabbit deliver Expresso Beta

Filed under: Uncategorized — pwrighta @ 12:03 am
Tags: , ,

If there’s one thing that I truly enjoy about the Mac, it’s the third party developers. There are so many tiny development shops out there making a living by delivering compelling applications for the platform and, unlike Windows, Mac OS is not yet saturated with complete crap.

One such developer is MacRabbit, makers of the phenomenal CSSEdit tool. MacRabbit have made available a free public Beta of their latest tool, and all encompassing development environment called Expresso.

ShotPreview.jpg

Just like CSSEdit, Expresso is a joy to look at. It’s also very powerful indeed. MacRabbit are undoubtedly going after the legions of devoted TextMate fans with this one, since they are also pushing the fact that Expresso is fully extensible, but also building on the shortcomings of TextMate with full preview modes for things like CSS and HTML.

This will be a tool to watch in 2009.

January 2, 2009

2009’s hot ‘new’ programming language

Filed under: Tech Opinion — pwrighta @ 10:26 pm
Technorati Tags: ,,,,

This is the time of year when many passionate programmers start thinking about learning new languages to code in. The trick, of course, is to choose something marketable, and valuable. Ideally, it should be something you can get in at the ground floor with, some emerging new market.

So, what’s it going to be? Perhaps a functional programming language like Scala, Erlang, Clojure or even Microsoft’s F#? That would be great if you’re working somewhere that needs that kind of processing power. I work somewhere with the sort of data volumes that almost demand one of those languages, but none of them are on my to-learn list for 2009.

How about a scripting language coupled with a rapid development framework, something like Ruby and Rails, Python and Django, maybe even Coldfusion and Wheels? Nope – been there done that. Rails is so 2007 anyway.

No, I’ve already started hitting the books on my hot new language of choice. Want to know what it is? I’ll tell you – Java.

My new years resolution didn’t involve substituting crack cocaine for nicotine, I am in fact deadly serious. The language that I predict to be the hottest ticket out there this coming year is none other than James Gosling’s 13 year old ugly love child.

Over the past two years Objective-C experienced something of a resurgence. A rapid uptake of Mac OS X among developers everywhere lead them into the world of Mac programming and of course iPhone development. The language of choice in those environments is the previously unheard of, but really quite long in the tooth, Objective-C. Prior to that it was the turn of redheaded Java stepchild C# as developers flocked in droves to the now ubiquitous .NET platform with dreams of web services, cross device compatibility and of course rapid web development.

The catalyst for Java then is none other than Google’s open, Linux based, operating system, Android. It’s the Google juice that powers T-Mobile’s G1 phone, the same motion lotion that is set to power no less than 5 other phones due to hit the market in the next 12 months, and the magic fairy dust that looks very likely to be powering the increasingly popular Netbook before the end of 2009.

There have been plenty of competitors to Android (Symbian, Blackberry’s OS, Palm OS, Windows CE), but Android has a couple of things going for it that those other platforms don’t.

First, the openness. There is no barrier to entry to writing Android apps. Just download the SDK and Eclipse and away you go. You don’t need to buy a developer license, you don’t need to make a large outlay on development tools.

Second, the marketplace. Google took a leaf out of Apple’s book with the Android Market. Android developers have a central venue to get noticed and even make money, and it’s integrated with all Android devices. Every single person that owns a G1 phone has access to the Android Market to discover, download and try out applications today. That’s compelling.

Finally, the Google factor. Windows CE was backed by the largest software development shop on the planet, but ultimately the platform was an island. Android is heavily integrated with Google’s own services. Email, Calendar, Contacts, RSS Reader – all of Google’s online services are either tied into rich applications on the device, or work on the device through the browser. That alone makes Android devices very appealing to the millions of Google users out there, but also opens up a lot of possibilities for developers. It’s also something that’s never been done properly on a mobile device before. Sure we’ve had mail clients, calendars and so on on other devices but these are Googles -some of the most popular online services available today.

Android is going to be huge in 2009. It’s going to be everywhere. Android is actually the operating system that will finally realize the dream of Linux on the desktop (all be it very small desktops). Java powers Android, and so if you want to be on the leading edge for 2009 you’re going to have to get very intimate with a language that many people wrote off just a few years ago.

January 1, 2009

Apple really need to consolidate their peripherals now

Filed under: Tech Opinion — pwrighta @ 5:14 pm
Tags: , ,

Apple have worked hard at consolidating their computer product line. These days you have just iMac, MacBook, MacBook Pro and Mac Pro. All share common product design aesthetics, and this is really nowhere more apparent than when comparing MacBook to MacBook Pro. Both those lines look identical now, and you really need to dig underneath the hood to find out just what makes one of them ‘pro’ (and hence worthy of the significant price jump).

I went to the local Apple Store today to get an adapter to connect my new MacBook Pro to both a DVI monitor and a VGA adapter. Now, while the product lines themselves have been nicely tidied up, their peripheral line hasn’t.

The MacBook Pro doesn’t have a ’standard’ video out port. It’s got a ‘DisplayPort’ instead. The older MacBook Pro’s have DVI, the older MacBook’s have Mini DVI, the MacBook Air’s have ‘Micro DVI’. The end result is that can spend a very long time staring at a bunch of packages in store which all actually look exactly the same, but which all have different prices and very specific applications. To make matters worse, the staff in the store also seemed lost as to just which one to get.

In the end, we did find one person in the store that understood all the differences and 29.99 later I walked out with a handy Display Port to DVI adapter for the new machine.

Really though Apple – you’ve done such a good job on the rest of the product line surely it makes sense to at least brand these accessories better. When I walk into my local Harley Davidson dealership I know that the things that fit my bike are on the shelf labelled Sportster/XL. My friends know to look at the shelves labelled Road King. Why not just, at the very least label up the shelves in the store as “Old MacBook”, “MacBook Pro/New MacBook”, “MacBook Air” or something similar. I hate buying stuff and then worrying about whether or not I got the right thing and will have to trudge back later to change it.

G1 owners to get a new battery

Filed under: Uncategorized — pwrighta @ 11:06 am
Tags: , ,

When I talked about my experiences with the G1 the one and only gripe I had with the device was the abysmal battery life.

T-Mobile have listened to all the complaints and, according to Mike Martin, will be sending everyone a new super powerful battery within a month or so, for free.

According to Mike…

T-Mobile is reported to be sending a new extended life battery plus the compatible back cover within a month to all T-Mobile G1 owners.

Since the reported T-Mobile plan included a back cover then perhaps its the 2400mAh battery providing over twice the current battery life and needing a seperate back cover

Excellent customer service T-Mobile.

December 24, 2008

AboutScrum.com launches!

Filed under: General Programming, Product News — pwrighta @ 12:13 pm
Tags: , ,

SCRUM is rapidly gaining traction as an acceptable agile development method, helped along in part by some very large names in software development adopting it as their in-house method. Strangely though, it’s been quite hard to find a single definitive source of information about the process.

aboutscrum.jpg

All that looks set to change with the launch of AboutScrum.com. The site has a few articles in place already, as well as a 10 minute introductory video to the process. From what I gather, the plans are to expand the site into the definitive online resource for everything Scrum and scrum process related.

Pigs and chickens of the world rejoice!

Pragmatic Programmers launch Android book

Filed under: Uncategorized — pwrighta @ 11:43 am
Tags: , ,

The Pragmatic Programmers announced the release of “Hello Android” today, their first book covering development on the Google Android phone.

eband.jpg

From the news release…

We released twenty-two (22) new titles this year, including the last title for 2008: Hello, Android. The Android books are leaving the printer today, so we’ll be shipping them out right around New Year’s or so

At 200 pages, the book is quite small, a lot smaller than I expect, but it is aimed at developers wanting to migrate to Googles open phone platform. With that in mind then, you can assume the author (who is also the owner of Planet Android skips the fluff and background of just how to write code and dives straight into the meat of what it takes to write an Android application.

$22 for the PDF, available for download now, $44 or so for the PDF and paper book, which ships next week.

December 23, 2008

Mass iPhone-phoria unfairly taints the G1

Filed under: Product News, Tech Opinion — pwrighta @ 7:57 pm
Tags: ,

I thought I knew what I was getting into when I picked up my G1 “Google phone” at the weekend. I’d read that it didn’t have wireless network support, Bluetooth, a headphone jack and only 1 gig of memory, but I didn’t care. It’s an open platform with a huge amount of potential and that’s what I was most interested in.

large_g1.jpg

The surprise came when I got the G1 home and started to really play with it. I think the world at large is suffering some kind of iPhone-phoria, a condition that obviously makes people badly report on the capabilities of any device that’s not an iPhone.

The G1 does have Bluetooth. It does have wireless network support. It doesn’t have a built in headphone jack, but it does come with one (a micro-usb style cable supplied with the phone supplies the requisite headphone hole). It does have 1 gig of memory sure, but it’s also got a card slot built in making the storage potential virtually limitless.

In use, the G1 is everything I expected it to be. It’s fast, it doesn’t crash, and the ability to run more than one application at a time is awesome. For example you could easily log into the 4 main I.M platforms, Twitter, Facebook and get updates in realtime from any of them no matter what else you are doing on the phone.

Sure, flicking out the keyboard to get messages typed takes a bit of getting used to, but the keyboard is good and so much faster than pressing air on a glass surface (in my opinion).

All in all then, the G1 is nowhere near the limited piece of crap many people are reporting it to be, and most of the negative points about the phone that have been reported are simply untruths. The only problem I have with the device at all is that the battery life is weak, but I’m sure a third party battery will solve that in a month or two.

I love my G1 and have a bunch of app ideas for it that I may start exploring over the Christmas break.

Next Page »

Blog at WordPress.com.