Categories
Business Technology

Investing in the Learning Curve

We have a concept of what the learning curve represents, and unfortunately, the same thing can represent 2 opposite concepts. What makes more sense to me is looking at a learning curve from a classical labour cost perspective and more keenly towards labour productivity. In this sense, the learning curve is interpreted, broadly, as: the more you work with something, the more productive (cheaper, better, faster, more knowledgeable) you become. And one can recognise that sentiment when it’s expressed variously with respect to success, specialization, expertise, productivity, quality or minimizing costs. So where’s the investment?

Programming technology changes rapidly, and sometimes to the detriment of programming and business, sometimes not, but also to the advantage of progress and for the sake of technology itself. But changes are also forced to be incremental in order to be successfully adopted, since any radical departure will result in a prohibitively expensive learning curve where the economic costs outweigh the advantages of the change. Similarly, you also cannot force change too frequently, even if it’s small enough, since you never get to break even or realise a profit from the previous change. I think this last point might also be reflected in the current developer attitudes towards the “next big Microsoft thing” and the ubiquitous jading of old hats. Everyone seems to hanging five for a bit before moving forward. Or maybe Douglas Adam’s theory is kicking in?

At the same time though, you need to keep moving forward. So where do you invest your next generation of development so as to minimize the costs of the learning curve if you want to remain marketable and competitive across:
* web development
* mobile application development
* backend systems
* any platform (platform agnostic)

C++, C, C#, VB, Perl, PHP, Python, Ruby… ?

All these languages have their pro’s and con’s and more importantly, costs. As an example, I recently looked at Symbian C++ development, and the learning curve is relatively expensive. The idioms alone take time to get to grips with, so although you got a very powerful API, C++ on Windows desktop, or legacy ATL knowledge is not easily transferrable to a Symbian C++ development effort. Possible, but no as easy as say, being able to use a standard framework and language, with the same idioms, on both (all) platforms. That would be the ultimate prize (for me).

And it doesn’t have to be the same language. Case in point, i’m currently using Monorail (.NET web development) and RoR (other web development) concurrently on different projects and i’m enjoying the benefit of being able to work in a predictable (hence productive) manner switching between the two, relatively seamlessly. Whereas, switching between asp.net webform development and RoR, as an example would not be feasible. The traditional 30% context switch overhead would double.

So if you’re faced with “what to learn next”, take a closer look at the learning curve and where you can (need to) apply that knowledge in the future, in order to remain competitive- whether globally, or within your own department. Maybe it’s stating the obvious, but it’s surprising just how un-obvious the obvious can become when there are a lot of flashing lights going off all the time. So it’s not always about the language or the technology, but also a lot about the “way” in which things are done; which, by nature, is usually a little more sublime to spot since it’s hiding in plain sight 😉

Categories
Technology

Attitude Driven Development

A.D.D. From the textbooks of an introduction into the business world (Department of Decision Sciences, UNISA):

Control does not, however, keep workers from making mistakes. The motivation of workers and a positive attitude towards their tasks, limit the number of mistakes they make.

It explains why TDD on it’s own will fail, and also why some folk don’t even need a fully bulked up test suite, if one at all. Although personally, i think no matter how good you are, there has to be something challenging in every project which you need a safety net for to keep the productivity going.

And it explains a lot of things about business, but more importantly for me, the business of software production. Also, it helped me realise why the solid programmers i have had the honour of working with are good AND cool to work with.

Attitude towards your craft (and fellow crafters even) and the passion for what you do will be directly proportional to the number of bugs waiting for you in 3 months time on a tight deadline. And, i suppose, the converse would also be true: the number of bugs you’re dealing with today (of your own making) are a direct result of your attitude applied when first implemented, and if not of your own making, those bugs reflect the attitude of the guilty coder.

Of course, i maintain the assumption of all things being equal, most notably: skill and ability.

And therein lies a great life lesson too (it’s part of why i really groove on programming as a lifestyle). The relationship between the bugs in your life and your attitude towards your life is more apparent and plain to spot than you might imagine.

Categories
Technology

Annoying Software

One of the funniest things i read this morning… or maybe it was the tea?

“And yes, when I ask to exit the software, that’s because I really want to, not because I’m having a crisis of doubt.” (The bold is my emphasis)

LOL How many times have you joked about this? Are you really really really sure you want to exit? Really? For sure? Think about it carefully, because if you close me now, and you didn’t mean to, you’re going to have start me up all over again. So, are you sure you want to exit?

And the irony is, whenever i create an application where i don’t ask the user “Are you sure you want to <INSERT REQUESTED_ACTION HERE>?” after they explicitly clicked on the button to execute the aforementioned REQUESTED_ACTION, it feels like commiting a crime. In fact, i even had a user the other day log a “bug” saying: “Isn’t it supposed to ask me if i want to do that?” Priceless.

Btw, the quote is from an article on zdnet

Categories
Technology

Learn By Do. Part III

This is kinda like a bumper edition, since it wasn’t intended but after hacking this for a bit, it turned out to be a pretty useful exercise, no matter the language. Why? Primarily since you get to, depending on implementation, write your own data structures and use recursion. This combination of tasks usually allows you to explore and discover some interesting language-related issues. So then, without further ado.

The task: generate all the possible word combinations from a telephone number. The first stab, ignore dictionaries and words or phrases that actually make sense in English, and just be able to “translate” the number 23 => ad, ae, af, bd, be, bf, cd, ce and cf. If the number is 233, the options become add, ade, adf, aed, aee, aef and so on all the way through to cff. And then later maybe we can reverse the process and make up a word to come up with a number?

Right, the strategy: write tests first! The first thing i need is a class that can accept and validate a string as being a legit phone number.

class TestPhoneNumber < Test::Unit::TestCase
  def test_ctor
    p = PhoneNumber.new("0215556767")
  end
  def test_cant_have_alpha
    assert_raise(ArgumentError) {PhoneNumber.new("065a223")}
  end
  def test_cant_have_punctuation
    assert_raise(ArgumentError) {PhoneNumber.new("087!322")}
  end
  def test_cant_have_other
    assert_raise(ArgumentError) {PhoneNumber.new("0987%")}
  end
  def test_split_numbers
    p = PhoneNumber.new("0123")
    assert_equal(["0", "1", "2", "3"], p.split_numbers)
  end
end

I also wanted to store the individual digits since in my mind’s eye, i can see myself using a map to index and reference the letters using the digits so it just feels like something i need to do right now. We’ll see how it plays out. Turns out, the implementation is pretty straightforward:

def initialize(number_as_string)
   if number_as_string =~ /\D/
     raise ArgumentError.new("Can only contain numbers")
   end
   @split_numbers = split_the_numbers(number_as_string)
end

A simple regular expression takes care of most of what i need to cover. Splitting the numbers is a simple loop, no fuss there.

def split_the_numbers(numbers)
  i = 0
  result = [""]
  while i< numbers.length
    result[i] = numbers[i,1]; i += 1
  end
  return result
end

The trick now is to be able to write something like:

PhoneNumber.new("23").possible_words.each do {|word|
 print word
}

And get the output:

ad
ae
af
bd
be
bf
cd
ce
cf

Mmmm… Tree? Graph? Simple arrays and hashes? What will it be? (…to be continued)

Categories
Technology

Learn By Do. Part II

In the first installment, we discovered, from the eyes of a noob, a handful of basic concepts about the Ruby language. In this episode, we’ll complete the functions for mean, median, variance and hence standard deviation and discover something you might consider magic…

The mean. It’s the average and so it’s calculation is simple. Add up all the elements and divide by the number of elements. The sum:

    @sum = 0.0
    @elements.each{ |i| @sum += i }

The mean:

  def mean
    if 0 == @elements.length
      return 0
    end
    return @sum / @elements.length
  end

Straightforward and fairly clean. The median is also pretty straightforward; you want the middle element, in the case of an odd-numbered quantity and the average of the middle elements in the case of an even-numbered quantity.

  def median
    if 0 == @elements.length
      return 0
    end
    if 0 == (@elements.length % 2)
      return even_median
    else
      return odd_median
    end
  end

I used the modulus operator to determine if the quantity of elements is odd or even, and it’s pretty much the same as almost every other language i’ve used. There is another way, using the remainder method:
any_even_number.remainder(2) is equal to 0
any_odd_number.remainder(2) is equal to 1
The even/odd_median methods just return the appropriate middle element. First the odd_median:

  def odd_median
    return @elements[(@elements.length/2).floor]
  end

It might seem a little odd, at first, to not use the calculation (n+1)/2:

return @elements[(@elements.length + 1 )/2]

The reason we use the floor is because we know the number of elements divided by 2 will always yield a n.5 and we take the index down form that because we’re using a ZERO-based index in the array. (n+1)/2 works perfectly for a ONE-based index array. We could still use that approach however, but keeping in mind to subtract 1 from the result to get the correct index: ((n+1)/2) -1.

  def even_median
    top = @elements.length/2;
    bottom = top -1
    agg = @elements[bottom] + @elements[top]
    return agg / 2.0
  end

Again, because we’re working with ZERO-based index arrays, the calculations are slightly different to what you’d expect or do in “normal mathematics” (if there can ever be such a term?). Easy, peasy, japaneasy, right?

Variance is a slightly more complicated, although, not complex by any stretch of the imagination. There are two different algorithms for calculating the variance and in the provided code, i have implemented both. Armed with the knowledge of the equations and a decent grip on how to perform some calculations, the implementation is left to you as an exercise in applying your learning.

The magic. At last, the magic. (from Ruby-coloured glasses)

class Float
  def prec(x)
    mult = 10 ** x
    return (self * mult).truncate.to_f / mult
  end
end

The almost crazy thing happening here is that you have the ability to extend built-in types without much fuss. With this definition, you now have the prec method available to all your Floats. Try it in your console too.

irb(main):006:0> class Fixnum
irb(main):007:1> def plus10
irb(main):008:2> return self + 10
irb(main):009:2> end
irb(main):010:1> end
=> nil
irb(main):011:0> 43.plus10
=> 53

Now that’s cool. Strings, Times, Fixnums, Floats… If your domain requires a specific handling on a particular type; the ability to extend and make that appear “normal” for the remainder of the coding experience is easy. It just slides right in.

And that about wraps up Part II, save one small little detail you’ll find in the code but not elaborated just yet: the accessor. The Ruby User’s Guide has a great explanation, and now you also know about that website too!

The full source code for Learn By Do is available for download: sample_data.rb

Categories
Rants Technology

World’s Most Annoying Dialog

No matter how many times you say “later” it just keeps on asking the same question.. over and over and over…

most_annoying_dialog.png

Categories
Technology

Learn By Do. Part I

If you want to learn to code, the best way is to code… lots. No getting around it, and for me, my fingers seem to remember more than my brain. So keeping that in mind, here begins a short series of code snippets and samples which i’ve used to help myself learn the Ruby language. Hopefully, this helps you out a little as well as you start exploring the language for yourself. Of course, a lot of the information is also gleaned from around the web. I’ll endeavour to give credit where it’s due, if i forget or leave anyone out, it’s not intentional. Please feel free to prompt me a kind “ahem”. And also, i ain’t no matter expert, so if you spot an inefficiency somewhere, i’d appreciate a little pointer too. Thank you.

So, the key things that i want to learn are:
* language syntax
* keeping with lessons learned in oop
* how to write/test logic

And then of course, i also want to write something relatively “useful”. Not some imaginary and contrived Product-Catalogue relationship or Animal, Dog, Cat hierarchy, thank you very much.

That’s it, really. So essentially i want to capitalize on the two main languages i’ve spent a lot time in and what they taught me: C++ => OO principles, and then C++/C# => TDD. Armed with the basics, i, and by extension that is, you too, can pretty much tackle just about any problem within my (your) comprehension.

So the first challenge is writing a class that can handle finding the mean, median, variance and standard deviation for an array of numbers (integers or floats). Fits all my criteria and will certainly help me determine and check answers while i study through my courses at uni. That is to say, it’s very useful for me. So, with further ado…

TDD

require ‘test/unit’ at the top of your file and inherit from Test::Unit::TestCase.
If you’re familiar with TDD in general and been exposed to xUnit frameworks, that’s about all you need to know, the rest is straightforward.
So i want to test my new class SampleData which is initialized with an array of numbers and sports three basic methods: mean, median and variance (for now). The first thing i did was create TestSampleData

class TestSampleData < Test::Unit::TestCaseend

First task; make sure you can’t declare SampleData.new without passing in an array of numbers; that is, i want to force usage to always supply an array of numbers when you construct it. Hey, it’s my design so i get to choose the why.

class SampleData
private
  def initialize()
  end
public
  def initialize(elements)
  end
end

Almost like C++, the public and private sections of the class definition are straightforward. Nothing tricky there. Now i’m forced to, at minimum declare instances with a parameter: SampleData.new([]). It’s what i wanted.

Next concern was making sure the parameter passed in is what i expect it to be (defensive programming). Make sure it’s an array of either Fixnum or Float. If it’s not, i want the constructor to raise an exception.
The exception is the easy bit:

raise ArgumentError.new("message")

. Checking the type of the parameter is also easy with the class method.

  def initialize(elements)
    if Array != elements.class
      raise ArgumentError.new("Can only initialize sample data with an array of floating points or integers")
    end
  end

And then checking the type of each element in the array also turns out to be pretty straightforward

    elements.each do |e|
      if (!(Fixnum == e.class) || (Float == e.class))
        raise ArgumentError.new("Array can only contain floating points or integers: item " + e.to_s + " is a " + e.class.to_s)
      end
    end

Of course, all this is verified with a bunch of tests declared by the test case:

  def test_must_init_with_array
    assert_raise(ArgumentError) { SampleData.new("string") }
  end
  def test_must_init_with_array_of_numbers
    assert_raise(ArgumentError) { SampleData.new(['ll', 'llkj']) }
    assert_raise(ArgumentError) { SampleData.new([0, 8, 'll', 9, 7, 'llkj']) }
  end

The code reads for itself. All i need to do to verify is, from the commandline, run ruby filename.rb.

bryan@noah:~/src/sandbox/ruby/medians$ ruby sample_data.rb
Loaded suite sample_data
Started
......
Finished in 0.002402 seconds.

6 tests, 16 assertions, 0 failures, 0 errors

That’ll do it for Part I. Key things learned:
* public, private sections of a class definition and the syntax thereof
* writing a test case
* raising exceptions, and testing for expected exceptions
* checking types and forcing class usage
* a little tight looping and boolean logic

So far so good, and really nothing too different or difficult to grasp coming from either C++/C#. Part II to follow shortly…

Categories
Technology

SharpDevelop + Monorail

Monorail rocks, but getting going in #Develop can be cumbersome in that you need to create a lot of placeholders. Fortunately, you can create a template which you can drop into your data/templates/project/CSharp sub-path of your #develop installation
for example: C:\Program Files\SharpDevelop\2.2\data\templates\project\CSharp
Using this template, you can now

Create a “MonoRails” web project

create.png

Have it create all the skeletal placeholders

created.png

Build (change relevant config settings) and view when hosting it locally

running.png

This template in it’s current form references the Castle binaries from the install directory. You might want to change that bit of detail if your installation is not “standard” (ie. next > agree > all > next > finish).

Download Template

Categories
Technology

Subversion and Bzr

Subversion has been a friend of mine for some time now. Given the order of environments I have been required to work in, it’s more than suited our needs… anyhooo. Then there’s Bzr which has really grown on me, especially for offline version control. But what is really cool, is using both of them. I probably could set up a bzr server, but the subversion repository is already in place… incremental adoption always works smoother.

How easy is it? Just run bzr branch <svn:uri> and you’re set. Easy. Then you can run multiple ‘bzr commit’ commands to keep a local versioned control record of code changes, and when you’re within connectivity with the subversion repository, just ‘bzr push’ and Robert is your father’s brother. ‘Bzr update’ will check out changes from the repository.

For straightforward environments, this should suit you just fine with minimal fuss for a lot of satisfaction.

Categories
Technology

Will it Scale?

When Ruby/Rails is mentioned as a web development platform, the most common response is related to scalability and performance; usually with a liberal dash of skepticism. Fear, uncertainty and doubt, along with a couple of honest posts and reviews, all point to the perception that Rails has some sort of performance problem.

300 million page views per month anyone?

Good to hear about the success stories, no matter the tech, but particularly heartening to see the RoR tech maturing into something more than just a “toy”.