Archive

Archive for the ‘Programming’ Category

Debugger Driven Development

December 4th, 2010 4 comments

An amazing feature of Smalltalk is that you can create methods right from the debugger.  This fits nicely with “write the code you wish you had.”

  • First, you write a test calling whatever methods you want (even if they don’t exist)
  • When you run the test, a debugger pops up with a create button

  • Like magic, with a push of that button, a method skeleton appears in which you fill the implementation

Field Report

Now this is where things get creepy…  It’s after midnight, and I just want to finish one last thing.  You see, I’ve been implementing a very basic Cucumber-like framework for acceptance tests in Squeak, and there’s just one thing left to do.  I’ve got helper methods that turn given/then/when descriptions into methods that define the steps, like this:

As you can see, #given: transforms the description string into a camel case method name.

All I had left to do was handle the case where the method didn’t exist yet.  In cucumber, templates are passed to the command line to be pasted into the step definition file.  Oh, I’ve got it, the transcript is like command line output, I’ll paste it there!  Let me just see what this debugger is about…

When I took a closer look, I started laughing and couldn’t stop…

Smalltalk handed me a magic Cucumber-step-definition-template-generator!  I checked one more item on my todo list and clicked the magic button.

Book Review: “The Engelbart Hypothesis: Dialogs with Douglas Engelbart”

October 7th, 2010 1 comment

Every human being should be familiar with Doug Engelbart’s work.

His mission is to raise human intelligence to match today’s problems, which are more complex and urgent than anything we’ve evolved to face, and are beyond the limits of our default abilities to solve.  This mission itself is urgent, because we have to do all this before we destabilize the global ecosystem, plunge into nuclear winter, or extinguish ourselves in any number of creative and possibly imminent ways.

Whether you are an Engelbart scholar, or are thinking, “Doug who?”, this book gives a great overall picture of the vision, as well as practical experiences of its application from prominent leaders.

Check it out at http://engelbartbook.com/

p.s. there is also a free online version, but if you like it (as I do), make a donation to support this gift to humanity

Categories: Performance, Programming, Smalltalk Tags:

Review: A Mentoring Course on Smalltalk

October 2nd, 2010 2 comments

Verdict

This is the best programming book I’ve ever read – and I’ve read them all – in C, C++, Ruby, and Smalltalk.

Summary

It’s definitely not a basic book – but it’s not complicated either (although it gets pretty deep).  In fact, while the code is all Smalltalk, it’s not about the language at all.  It could be called “Zen and the Art of Smalltalk”.  It gets at the heart of what it takes to go from an intention to create something, in a world we don’t really understand, to a successful outcome, that is simple, beautiful, efficient, and easily evolved.

Final Thoughts

I’m still gnawing on much of it (I just finished it a few days ago), but my viewpoint on programming has irreversibly shifted and, as Alan Kay says, “Point of view is worth 80 IQ points”. I think the programming world would be a better place if everyone read this book… I can’t believe I just gave a Reading Rainbow book report.  My life is complete.
Categories: Performance, Programming, Smalltalk Tags:

US Government Plays Rope-a-dope with Science

September 27th, 2010 No comments

The Boston Globe, in their article “How stop-and-go science funding puts the brakes on progress,” says “this chaotic funding environment” has “devastating implications.”

It reminded me of something Alan Kay said:

“90 percent of all good things that I can think of that have been done in computer science have been funded by [ARPA]. Chances that they would have been funded elsewhere are very low. The basic ARPA idea is that you find good people and you give them a lot of money and then you step back. If they don’t do good things in three years they get dropped – where ‘good’ is very much related to new or interesting.”

It’s unfortunate that government bureaucrats, who do not understand the consequences of their actions, are keeping us from all the benefits scientific progress brings.  Yet this quote, and the amazing things that came out of ARPA, point to how much can be done with a small amount of money (relative to total spending). Imagine the wave of innovation we could produce if we got a few of the purse-string holders on board :)

Categories: Programming, Smalltalk Tags:

BDD in Squeak Smalltalk: An exploration

April 27th, 2010 4 comments

Coming from Ruby, I’m obsessed with Behavior Driven Development.  The community (e.g. Rspec, Cucumber) is alive, and there is a body of practices to follow.

Since TDD was born in Smalltalk, I expected to find the same energy and guidance in Squeak.  Squeak represents the most profound, empowering environment I’ve ever seen (I will never go back to C, C++, or even Ruby – which misses the boat by not being a living system).  However, the testing situation seems frozen in the early days.

My intention is to create do a series of experiments, which will lead to BDD best-practices in Squeak.  My vision is code that is pulled into existence by what matters to its users, that is easy to understand, and easy to change.

I’ll keep you posted…

Premature optimization – wait, I learned that 10 years ago

February 12th, 2010 No comments

In reading Refactoring: Ruby Edition, I’m “learning” a lot of things that I already know, lol.

Optimization vs. Clarity

For instance… how many times have I heard “avoid premature optimization?” Yep, check, got that one; I would never do that.  Except I do!  I mean, I won’t go out of my way to optimize at first.  But I’m in this loop, and I want to record this other information that has nothing to do with what I’m doing right now… Let me just throw it in this temporary variable to use later.

Judges (Fowler, Beck, et al.).  Buuuuzzzzzzz, wrong answer.  Their advice (and you may not believe this, but I actually feel free now that it’s sunk in): don’t optimize with that temporary variable now, just code for clarity and repeat the loop as many times as it takes to get the info you need.  “Holy crap,” I thought.  “I’m not going to repeat that loop three times – that’s so inefficient!”  But luckily, the authors could sense me squirming in my seat, and added that I shouldn’t worry because, although this idea frequently causes “angst” in their presentation audiences

almost all the time extra method calls won’t matter; in the rare cases they do, they can be dealt with later

This is great, Kent Beck gave me permission to repeat loops over and over if the code is cleaner!

Categories: Programming Tags:

A Small but Effective Tweak to Vim’s snipMate plugin

February 6th, 2010 No comments

Already awesome

If you haven’t tried snipMate, you have to give it a test-drive.  If you want to define a new ruby class in Vim, type “cla<tab>” and you’re presented with your choice of class templates:

Enter a number, and the code is automagically generated for you.

The tweak

By default, hitting enter at the menu cancels the snippet.  However, a user can already easily cancel using escape, and this probably won’t happen all that often anyway (I don’t think ever for me).  So I altered the code to choose the first (most common) snippet if no number is entered.  This saves me a non-home-row keystroke in almost 100% of my usage.

The code

In plugin/snipMate.vim, comment out the last line of the s:ChooseSnippet function and add two lines in it’s place:

fun s:ChooseSnippet(scope, trigger)
  [snip...]
  " Original last line (which cancels on enter) commented out
  "return num == -1 ? '' : s:multi_snips[a:scope][a:trigger][num][1]

  " Two lines added to choose first snippet if none are selected
  let snip_to_return = num == -1 ? 0 : num
  return s:multi_snips[a:scope][a:trigger][snip_to_return][1]
endf

Pretty simple, huh? Oh, just remember to save a copy of the changed lines somewhere.  When you update the plugin, your changes will be erased and you’ll have to re-paste them.

Categories: Programming Tags:

Autospec with custom directory/file names

January 17th, 2010 No comments

Autotest is a great time-saver when doing BDD (or TDD for the less-enlightened, lol).  Autospec seemlessly integrates Rspec.  However, if you don’t use the expected “spec/*_spec.rb” structure, autotest will not find your specs – or examples, as I call them.

It is very easy to use whatever structure you want using the following steps:

Telling Autotest to use Rspec as the test runner

The first thing you want to happen is for Autotest to use Rspec as the test runner.  This usually happens automatically using autospec, which tests for the presence of the spec directory.  Since we do not want a spec directory, we must tell explicitly tell Autotest to do this.  So:

Step 1: in your project directory create a file autotest/discover.rb with the following line:

Autotest.add_discovery { "rspec" }

Teaching Autotest about our custom directory structure

In order to do this, we have two options.  If we want to use the same structure for all our projects, we can put a file in our home directory, otherwise we can add custom files to each project directory.

Step 2: create a file .autotest with the following code:


class Autotest::Rspec < Autotest remove_method :consolidate_failures def consolidate_failures(failed) filters = new_hash_of_arrays failed.each do |spec, trace| if trace =~ /\n(\.\/)?(.*example\.rb):[\d]+:/ filters[$2] << spec end end return filters end remove_method :add_options_if_present def add_options_if_present # :nodoc: File.exist?("examples/spec.opts") ? "-O examples/spec.opts " : "" end end Autotest.add_hook(:initialize) {|at| %w{.git .svn .hg .swp .DS_Store ._* tmp}.each do |exception| at.add_exception(exception) end at.clear_mappings # take out the default (test/test*rb) at.add_mapping(%r%^(examples|third_party)/.*_example.rb$%) { |filename, _| filename } at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m| ["examples/#{m[1]}_example.rb"] } at.add_mapping(%r%^examples/(example_helper|shared/.*)\.rb$%) { at.files_matching %r%^(examples|third_party)/.*_example\.rb$% } #nil }

Let’s take it piece by piece:


def consolidate_failures(failed)
  filters = new_hash_of_arrays
  failed.each do |spec, trace|
    if trace =~ /\n(\.\/)?(.*example\.rb):[\d]+:/
      filters[$2] << spec
    end
  end
  return filters
end

This method tells Autotest which test files have failed by pulling the file names out of the test output. Since autospec looks for *_spec.rb files, it will not find our custom files. I use *_example.rb filenames, so you should replace that part of the regex with whatever you use.


def add_options_if_present # :nodoc:
    File.exist?("examples/spec.opts") ? "-O examples/spec.opts " : ""
  end

This method tells Rspec where to find an option file. Again, replace the details with whatever you use.

In Autotest.add_hook(:initialize):

  %w{.git .svn .hg .swp .DS_Store ._* tmp}.each do |exception|
    at.add_exception(exception)
  end

This tells Autotest to ignore certain files that are irrelevent to testing

at.clear_mappings

This tells Autotest not to use any other mappings i.e. the default test/test*rb, or Rspec’s spec/*_spec.rb

at.add_mapping(%r%^(examples|third_party)/.*_example.rb$%) { |filename, _|
  filename
}
at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
  ["examples/#{m[1]}_example.rb"]
}
at.add_mapping(%r%^examples/(example_helper|shared/.*)\.rb$%) {
  at.files_matching %r%^(examples|third_party)/.*_example\.rb$%
}

This is the meat of the customization. It tells Autospec, based on which files have changed, which tests to run. Replace my regexes with your custom matches.

The end

Once you have added both these files, running autospec from your project directory will work as it should!

Cucumber.vim

December 12th, 2009 No comments

Awesome plug-in!  Uh, ok… but what the heck does it do?!?!  Here’s a list of the goodness:

  • syntax highlighting

  • Jump to steps
    • CTRL-] opens the step definition in the current window
    • CTRL-W ] opens it in a split window (optionally hold CTRL with the ‘]’)
    • CTRL-W opens in a split preview window
  • Autocomplete – it seems from the source that it should work, but I can’t get it going.  I posted a question on the cucumber mailing list.
    Categories: Programming Tags: ,

    Ruby, Vim, and Windows

    December 11th, 2009 2 comments

    It is unbelievably easy to create a wicked setup, although I spent half a day googling to narrow it down to the exsentials:

    Downloads

    1. Ruby with the One-click installer.
    2. Vim’s self-installing Windows executable (this comes with many customizations you read about online, and ruby support, included)
    3. snipMate, a plug-in that automatically expands common Ruby constructs (e.g. you type ‘cla<tab>,’ which becomes class…end with placeholders!)
    4. AutoComplPop (must have!!!), an autocomplete plugin very much like Xcode’s – start typing and a popup list of completion options appears.  superTab, another plug-in that allows you to use tab to auto-complete Ruby code
    5. wombat, a great color scheme

    Global configurations

    Add the following settings to /path/to/vim/_vimrc.

    note: the autocomplete menu colors, and vim’s default font are disgusting, hence the changes.

    Ruby-specific Configurations

    In the vimrc above, the following is added:

    • the first line sets up superTabs to look in the right place for Ruby completions (I use AutoComplPop now, see above)
    • adds line numbers to several source code file types
    • changes the ridiculous 8-space tabs to 2

    That’s it!  Happy coding :)

    Categories: Programming, Ruby Tags: , ,

    windows 7 product key

    windows 7 product key

    windows 7 key generator

    windows 7 key generator

    free winrar download

    free winrar download

    winzip activation code

    winzip activation code

    free winrar

    free winrar

    winzip free download

    winzip free download

    winrar free download

    winrar free download

    winrar download free

    winrar download free

    winzip free download full version

    winzip free download full version

    windows 7 activation crack

    windows7 activation crack

    windows 7 crack

    windows 7 crack

    free winzip

    free winzip
    \n