17 August 2008

Code Can Be Poetic

While learning RSpec (a testing framework for Ruby), my girlfriend was sitting next to me on our couch asking me what color of yarn she should knit some socks in. While she asked me questions, I came up with these to snippits of code that "tested" if a particular yarn type was correct. Not very useful, but fun!

sock.rb:
class Sock
attr_accessor :colors

def initialize
@colors = [:teal, :olive, :green, :blue, :purple]
end

def machine_washable?
true
end
end

sock_spec.rb:
require "sock"

describe "Socks that Kevin would like" do

before :each do
@sock = Sock.new
end

it "should not have pink in it" do
@sock.colors.include?(:pink).should_not == true
end

it "should not have purple in it" do
@sock.colors.include?(:purple).should_not == true
end

it "should be machine washable" do
@sock.should be_machine_washable
end

it "should not have grey in it" do
@sock.colors.include?(:grey).should_not == true
end

it "should have multiple colors" do
@sock.colors.length.should > 1
end

end

14 August 2008

Programming at a High Level

Jeff Atwood (of the Coding Horror blog) this week pointed out that there are many new high-level JavaScript libraries that allow you to ignore the lower-level JavaScript incompatibilities between browsers. I have used JQuery and can also vouch that using JQuery is incredibly fun and easy to program with.

This is more broadly applicable to other programming languages and libraries, too: Use the highest-level interface that you are able to use to accomplish your task. For example, don't use C when you can use C++. Don't use JavaScript when you can use JQuery. Don't use C++ when you can use C#. Don't use Perl when you can use Ruby.

References:
  1. Secrets of the Scripting Ninjas (Coding Horror blog post)

13 August 2008

Ruby Compiler Project

In my spare time (that is, apart from all the other hobbies I have), I have started work on a new programming project. My goal is to write an interpreter/compiler for a new programming language. I have no great ambitions, this project is purely for my own enjoyment and to hopefully teach myself something new.

Goals/Plans:
  1. Develop in Mac OS X
  2. Implement the compiler in Ruby
  3. Use test driven development and the agile process

24 April 2008

Test Driven Development

We have started using Test Driven Development at work, which is an entirely new way to program. This goes along with our existing use of Agile Development, so we are totally embracing the latest and (hopefully) greatest in programming philosophy.

14 August 2007

JavaScript Retardedness

I just discovered after dealing with an annoying bug for over an hour, that in JavaScript, this evaluates to true:

0 == ''

Thankfully, in the newer browsers, they added the === operator to deal with this.

15 July 2007

Mac OS

I've been using Mac for about a year now, so I thought it was time to give a quick review comparing and contrasting the benefits of Mac (compared to my previous experience with Windows).

Things I like about Mac:
  • Invisibility of the operating system -- It really does "just work" as Apple claims. Unless you need to do something very advanced, you could get away with never configuring anything in the OS.
  • Visual appeal -- the OS looks very slick while still being functional
  • Application availability -- there are many applications available (obviously less than Windows, though), and the quality of each application is very high
  • Application switching -- the application switching features are incredible and very useful
Things I don't like about Mac:
  • The WiFi applet responds slowly to user feedback, about a 5-10 second lag between clicks sometimes.
  • Most applications can't be maximized
  • Lack of Visual Studio -- Microsoft's Visual Studio development tool is the most user-friendly development tool I've ever used, but it's not available on Mac... Eclipse is a fairly good alternative once you get used to it.
Overall what I've noticed during my switch is how the rise of Internet applications has made it which operating system I use less important. I use Google Calendar, Gmail, Google Reader, and Firefox, which works on every platform. Internet based blogs constitute much of my writing. As internet apps get more powerful, this trend will only continue, making the OS you use nearly meaningless.

24 May 2007

Functional Languages on the Horizon

The usefulness of functional languages is really starting to go mainstream now. In the past, I've learned Haskell, Scheme, and Ruby, and I'm studying Scheme again now. Trying to learn every technology is impossible so I'm going to stick with Scheme right now because of the great books that are available for learning it.

Practical reasons for learning some functional languages:

Scala
Haskell
Scheme/Lisp
  • Great books: "Lisp in Small Pieces", "The Scheme Programming Language" (by Kent Dybvig), and "The Structure and Interpretation of Computer Programs".
  • Good, cross-platform IDE: DrScheme
  • Ability to leverage knowledge for Arc (Paul Graham's language which will almost certainly have a large following due to his popularity)

18 May 2007

PLT Scheme

I'm learning Scheme right now in my spare time to expand my programming ability and hopefully find use for it at work. PLT Scheme seems to be a good implementation: it has a large library, and a good cross-platform IDE. Also, the PLT Scheme user community is large and active compared to many other Scheme implementations.

There are also some cool extensions for it:
And some other good links:

Hello, World!

No better way to start a blog about computer programming than with the immortal words of every programmer's first foray into a new programming language. This blog will mostly be for my own benefit and future reference, but if someone finds it useful, all the better!