Saturday, March 10, 2012

We Are Not Software Engineers

The other day it came to my attention, after years of thinking of and calling myself a ‘Software Engineer’, I was not in fact one. Not only that, but many of my talented tech friends were not either. We had all been committing a fraud, if only unknowingly.

Worse still companies advertising to hire a ‘Software Engineer’ were also clueless since that was not what they were actually seeking to higher. Ok, so what am I talking about?

Well I have found that, legally speaking, most us cannot call ourselves ‘Software Engineers’. In order to be a licensed professional engineer one is required to:

  • Have the legal authority to use an engineering title without restriction.
  • Can offer engineering services.


Most states in the US prohibit the unlicensed ‘practice of engineering’. To offer engineering work without a license is actually illegal. Licensing laws exist to maintain a certain level of professionalism and competency of the term ‘engineer’ so as to ensure public safety.

One can, though, legally use the term engineer in their title under certain conditions:

  • One only practices engineering for their full time employer.
  • One’s practice is limited to their employer’s facilities and products.
  • One does not use the title outside of their company.
  • One does not claim that they are qualified to offer engineering services to another party.


So how can one become a licensed software engineer? Well, in the state of Texas one would need to have the following:

  1. Possession of an engineering, a computer science, or other high-level math or science degree.
  2. At least 16 years creditable experience performing engineering work.
  3. References from at least nine people, five of whom are licensed engineers.
  4. Required educational and other credentials.



So from now on, we’re all just software developers. Also, feel free to report all those claiming to be ‘domestic engineers’. That’s just annoying.:)


Friday, March 9, 2012

The Levels of Foo

I found an article on the web site of the Internet Engineering Task Force (IETF) today which gives the etymology of the word 'foo' and defines the different levels of foo. They are:

foo
bar
baz
qux
quux
corge
grault
garply
waldo
fred
plugh
xyzzy
thud

Now let's see how many levels we can refer to in our example code. Ha


   foo /foo/

   1. interj.  Term of disgust.

   2. Used very generally as a sample name for absolutely anything, esp.
      programs and files (esp. scratch files).

   3. First on the standard list of metasyntactic variables used in
      syntax examples (bar, baz, qux, quux, corge, grault, garply,
      waldo, fred, plugh, xyzzy, thud). [JARGON]

      When used in connection with `bar' it is generally traced to the
      WW II era Army slang acronym FUBAR (`Fucked Up Beyond All
      Repair'), later modified to foobar.  Early versions of the Jargon
      File [JARGON] interpreted this change as a post-war
      bowdlerization, but it now seems more likely that FUBAR was itself
      a derivative of `foo' perhaps influenced by German `furchtbar'
      (terrible) - `foobar' may actually have been the original form.

http://www.ietf.org/rfc/rfc3092.txt

Saturday, June 26, 2010

Using Object#tap

Object#tap is new to Ruby 1.9. This new method will allow us to modify the object its called upon and, after the block finishes, will return to us the original object.

We can use this feature to make our specs a bit more concise.

Here is an example using this spec...


describe Array do
   before(:all) do
    @array = Array.new
    @array << 1
   end
   
   it "should have a length of 1" do
    @array.should have(1).element
   end   
end

We change it so.

describe Array do
   before(:all) {@array = Array.new.tap{|me| me << 1}}
   
   it "should have a length of 1" do
    @array.should have(1).element
   end   
end

This code says "create a new instance of class Array, pass it to the 'tap' block, modify it, and return the original now modified object."

@array = Array.new.tap{|me| me << 1}

Some Ruby Built In Global Variables

These maybe helpful to know:


$0 --- Returns the name of the file that ruby is executing
$: --- Returns the directories Ruby searches to load external files
$$ --- Returns the process id of the Ruby process

Friday, June 25, 2010

let, its, and subject

We're going to refactor a spec to a more concise size.


First here is our starting point:


describe Foobar do
   before(:each) do
      @foobar = Foobar.new
   end
   
   it "should not be nil"
      @foobar.should_not be_nil
   end
   
   describe "#length" do
      before(:each) do
         @length = @foobar.length
      end
    
      it "should == 10" do
         @length.should == 10
      end
   end
end


The above example uses 15 lines of code. Lets see if we can do better.


First we're going to replace the 'before' blocks with 'let' blocks.
The 'let' block returns an evaluated block. It really helps you define
players in your spec.


describe Foobar do
   let(:foobar) {Foobar.new}
   
   it "should not be nil"
      foobar.should_not be_nil
   end
   
   describe "#length" do
      let(:length) {foobar.length}
    
      it "should == 10" do
         length.should == 10
      end
   end
end


That's a bit better. We are now at 11 lines of code.
But, we can do better.

We're going to use 'subject' block. This allows us to call
'should' right within the block. We're also going to use an 'its' block.
The 'its' block will return to us the value of the message retrieved represented
by the symbol we passed to it.


describe Foobar do
   subject {Foobar.new}
   
   it {should_not be_nil}
   its(:length) {should == 10}
end


Very good. We have brought it down to 5 lines.

What does the specdoc output look like?

Here it is:


Foobar
- should not be nil
Foobar length
- should == 10

Modifying an Existing Ruby Class

First example is reopening the class and adding methods to it.


First, the original class:


class OriginalGangsta
   def shoot
      puts 'bang!' 
   end

   def flee
      puts 'run muther###'
   end
end


Now, we modify the class:


#load the original class
require 'original_gangsta'

#add some new methods
class OriginalGangsta
   def lie
      puts "he dunnit"
   end

   def dance
      puts "I'm a dancin' fool"
   end
end


We can also just modify an instance of the class:


og = OriginalGangsta.new

class << og
   def cry
      puts "I never had a good home!"
   end
end

or we can do it this way:

og = OriginalGangsta.new

def og.cry
   puts "I never had a good home!"
end