Sonntag, 21. November 2010

my first ruby bug?

as announced in my last post I fixed regexp_test.rb, hash_test.rb and open3_test.rb. If you are interested in the details have a look at github: https://github.com/SlevinMcGuigan/SMG--learn

But this seems to be my first ruby bug which I sumbled across while fising hash_test.rb. 1.8.7 behaves different compared to 1.9.2
testhash = {
      '1' => 'a',
      '2' => 'b',
      '3' => 'c'
    }
puts "#{testhash.index('a')}"         # => 1
testhash['3'] = 'a'  
puts "#{testhash.index('a')}"         # => 1
testhash.delete('1') 
puts "#{testhash.index('a')}"         # => 3
testhash['4'] = 'a'
puts "#{testhash.index('a')}"         # => 3
testhash['3'] = 'x'
puts "#{testhash.index('a')}"         # => 4
testhash['3'] = 'a'
puts "#{testhash.index('a')}"         # => 3
testhash['1'] = 'a'
puts "#{testhash.index('a')}"         # => 3 with ruby 1.9.1p243
                                      # => 1 with ruby 1.8.7

  it "returns the corresponding key for value" do
    new_hash(2 => 'a', 1 => 'b').send(@method, 'b').should == 1
  end


But shouln'd there be somthing like
  
  it "returns the first corresponding key for value if there is more then once occurance of value" do
    new_hash(1 => 'a', 2 => 'b', 3 => 'a').send(@method, 'a').should == 1
  end

As I didn't want to raise a newbe-nonsense-defect in the issue tracking system http://redmine.ruby-lang.org/ and as I didn't wan't to ask silly-newbie-questions in the mailing list http://www.ruby-lang.org/de/community/mailing-lists/#ruby-core I went for a german forum (which is directly linked from www.ruby-lang.org): 

This is my first post: bug in ruby 1.8.7 in hash.index?

Samstag, 6. November 2010

Cygwin ain't Linux

Today I looked at my failing tests in open3_test.rb. One of them failed here:
stdin, stdout, stderr = popen3('cd this_folder_does_not_exist')
After some investigation I found out that popen3 in Ubuntu expects a "real" executeable, shell build ins like 'cd' cause "Error:ENOENT". This is one more difference between cygwin and Ubuntu. Wanna try?

Ubuntu
egon@egon:/home/egon> ruby -e '%x[cd]'
-e:1:in ``': No such file or directory - cd (Errno::ENOENT)
        from -e:1:in `
'


cygwin
$ ruby -e '%x[cd]'
$

As my test was just a learning test I looked for better ways to interact with the underlying OS. These sites helped me a lot
http://stackoverflow.com/questions/2232/calling-bash-commands-from-ruby
http://tech.natemurray.com/2007/03/ruby-shell-commands.html
Result: I changed my tests and now I use the classes Dir and File interact with the underlying OS

As a side result I noticed somthing weird with Test::Unit. I don't know whether this is a bug or a feature. I will find out later on, hence I added a ToDo into my WiKi. See http://slevinmcguigan.wikispaces.com/ToDo's

Donnerstag, 4. November 2010

encode, decode, transcode, dog Kot (ha ha... not funny, even if you are german...)

Yesterday I stumbled across a failing test because of this
assert('Susi Sorglos lebt ein schönes Leben' =~ /lebt/,'Ja, Susi lebt :)')
This passed before I went from cygwin to Ubuntu. Why?


Once again the "bible" helped me. It's all about encoding! Ruby 1.9 introduced much more consequent encoding/transcoding/... and when going from cygwin to ruby I went from 1.8 to 1.9. Wanna re-read the encoding/transcoding/... stuff? Start with p92 and then goto chapter 17, p251

Bottom line for me. As long as I consider myself ruby noob I will only use ASCII.

I still have 130 pages to go until I reach chapter 17 (hmmmm... What about inventing ruby skill levels? Simiar to computer games? In this case I would still be a level 1 programmer. Assume you really understood all the contents of the "bible", would you then be a level 26 programmer...? And what follows next? What to do to become a real Yoda-like ruby master? :D )

Mittwoch, 3. November 2010

long time no see... Glad to see you Egon

To get a long story short...
- I noticed that there is not ruby 1.9 for cygwin (yet)
- I noticed this when the example given in the "bible", p21 didn't work
- I tried to use the ruby 1.9 windows installer verson in cygwin (I want to have a powerfull and usefull shell, not the windows cmd.exe crap), some of my tests suddently failed!
- I decided to setup a VM. And this took muuuuuuuch longer then I expected....
- but still, some of my tests still fail! GRRR!
- next time I will look at regexp_test.rb, hash_test.rb, open3_test.rb

Donnerstag, 21. Oktober 2010

Woooha. Real BDD using rspec in real life!


hi there...

long time no see. Well, I did continue with my learning tests but that's nothing that might be interesting for anyone except me...

But today I learned new stuff
a) there is no 1.9 ruby for cygwin (yet). I use v1.8.7 :-(
b) I cant use this
inst_section = {
  cello:    'string'
  clarinet: 'woodwind',
  ...
}
This is the new feature "New literal hash syntax" in ruby. See http://svn.ruby-lang.org/repos/ruby/tags/v1_9_1_0/NEWS
d) also have a look here: http://www.ruby-lang.org/de/news/2009/02/01/ruby-1-9-1-verffentlicht/ and here: http://www.ruby-lang.org/de/news/2010/08/24/ruby-1-9-2-verffentlicht/
  
But the coolest part I stubled across when I looked for v1.8 / v1.9 differences:  http://www.rubyspec.org/ These guys are using rubys rspec to write a (or maybe _the_) comprehensive ruby spec! As executable BDD code! COOL!.

Wanna see an example of the spec? Have a look here, even I a am still on page #21 in my ruby bible I am able to understand this spec! Great, imagin every business analyst would write such a spec!!! http://github.com/rubyspec/rubyspec/blob/master/core/array/flatten_spec.rb

Montag, 4. Oktober 2010

what would I have done without a book? Let's praise Mr. Gutenberg...

Yeah, I got my book. And learning this way is muuuuch more efficient compared to googling and reading the spec :) For now the most relevant and new aspects for me were
[Thomas, p15]
ruby is "genuine" object-oriented language. For instance
num = -1234          // Java code
abs = Math.abs(num)  // abs is 1234

num = -1234          # ruby code
abs = num.abs        # abs is 1234
                     # abs() is called on num! Not on Math

[Thomas, p16]
puts say_goodnight("John-Boy")
puts(say_goodnight("John-Boy"))
--> both lines are equivalent
--> precedence rules can make it difficult to know which argument goes with wich method invocation
--> so we recommend using parantheses in all but the simplest cases

But I also spent some time browsing the www. Focus this time: BDD. Have a look here: http://blog.dannorth.net/introducing-bdd/
and here: http://blog.davidchelimsky.net/2007/05/14/an-introduction-to-rspec-part-i/

Sonntag, 26. September 2010

using a config file

Yesterday I noticed that I will need a config file. For instance if I want to call a dos command like srvrmgr.exe (Siebel ServerManager) I need to be able to configure the path to srvrmgr.exe. Also there might be more then one srvrmgr.exe binaries around and I need to make sure the right one is executed...

After short time of googling "ruby read config file" and some other keywords the decision was obvious: I will use YAML [ToDo: learn YAML]

http://www.5dollarwhitebox.org/drupal/?q=node/21
--> does not seem to be sophisticated
--> what?!? No tests, only "# FIX ME AND WRITE TESTS" in "test_parse_config.rb". No way I will use this hack...

http://otype.de/index.php?id=151
--> straigthforward, should work
--> but most probably not powerfull enough for more tricky demands

http://blog.innovativethought.net/2007/07/25/making-configuration-files-with-yaml/
http://yaml.kwiki.org/?YamlInFiveMinutes
http://www.yaml.org/YAML_for_ruby.html
--> if YAML is so easy, I don't see any reason not to use it
--> and learning YAML is a must for rails anyhow (afaik)

Freitag, 24. September 2010

STDOUT, STDERR, STDIN


this time I started to work with STDOUT, STDERR, STDIN. Handy that there is a class which handles all this for me: open3: http://ruby-doc.org/stdlib/libdoc/open3/rdoc/index.html

While doing so I came along this piece of code:
stdin, stdout, stderr = popen3('pwd')
a = stdout.readlines()

And I started asking myself if there is a difference between
assert_equal("/cygdrive/d/BACKUP~1/SMG\n", a.to_s, 'using readlines to squeeze stdout into a string, with    braces')
assert_equal "/cygdrive/d/BACKUP~1/SMG\n", a.to_s, 'using readlines to squeeze stdout into a string, 
without braces'

I did not find an answer yet, hence a new todo was born: [ToDo: find out if there is a difference between function calls with or without braces]

What I did find out was that there are differences between strings and symbols: Have a look here: http://www.robertsosinski.com/2009/01/11/the-difference-between-ruby-symbols-and-strings/

What I also did find out was that there is a difference between "a String" and "an other String". Have a look here: http://en.wikibooks.org/wiki/Ruby_Programming/Strings#Interpolation

Donnerstag, 23. September 2010

tadaaaaa: my first unit tests

Now its time to get started. I wanna write some code. As mentioned before, I consider having tests as a MUST. Hence I will use Test::Unit from the first minute on. But how and where to start?

Of course the official reference helps: http://www.ruby-doc.org/core/classes/Test/Unit.html
Further on I had to have a short look what modules are about (I have to admit the "Test::Unit" notation reminded me far to much of PERL...) Look here: http://www.rubyfleebie.com/an-introduction-to-modules-part-1/ and here:
http://www.rubyfleebie.com/an-introduction-to-modules-part-2/

And the most important help for me was this tiny little post: But http://www.clarkware.com/cgi/blosxom/2005/03/18/RLT1 I really like the idea of just testing what the ruby language offers. Why reading books when you can play. Well, not poking around only, the combination of reading the specs and then trying/testing whether or not I got everything right is cool!

Result: I committed my first unit test to GitHub: http://github.com/SlevinMcGuigan/SMG--learn :-D   :-D   :-D

yeah, now I got a wiki :)

well, after short googling I decided to use wikispaces.com. I tried some features in the sandbox and this is much more convenient compared to Google Sites. Very, very much more!

Here we go, this is my wiki: http://slevinmcguigan.wikispaces.com/


Further on I started with git and signed on at github.com. After creating my public/private key pair I played around. Here comes the link to my github sources, a good-to-know gitref link and some git commands I consider most important
http://github.com/SlevinMcGuigan/SMG--ExecShellCommand
http://gitref.org/remotes/

git config --global user.name "Slevin McGuigan"
git config --global user.email "Slevin.McGuigan@googlemail.com"
git init
git add README
git commit -m 'first commit'
git remote add github git@github.com:SlevinMcGuigan/SMG--ExecShellCommand
git push github master
... some changes on README and README.txt ...
git add README.txt
git commit -m 'added hello world - attempt 3'
git push github master

Montag, 20. September 2010

me vs. google sites

Oh my god! I just wanted a tiny little To-Do list. Maintainable and editable like a wiki using wiki-markup (or something similar).

I tried...
I tried harder...
I fought...
...
I lost... :(

Although Google says "Erstellen Sie Websites und sichere Gruppen-Wikis" I neither managed to set up a simple (and more-or-less eye-friendly) website nor to set up a simple wiki. Grrrrrrrr!

getting started...


* getting started *
Um... some decisions to make like
- what programming language
- what to programm
- which OS
- which Tools
- ...

Without getting to much into detail, I decided to use
- windows and cygwin (as this is most easy-to-start option)
- ruby
- git

* first steps *
I just finished installing cygwin and the newest (cygwin) version of ruby and git. Now I need to learn ruby. I am pretty curious. I know C, C#, JAVA, PERL, shell-scripting. But I'm not an expert in any one of those. And I don't have a idea about ruby, except that it's young and sexy
Grrrrr. A bash. I dislike the bash shell. I prefer ksh. [ToDo: create wiki entry: how to customize ksh]

* first tutorial *
Wow, I am such a quick learner :) I just rushed through http://tryruby.org/ But is this sufficient? I guess not... [ToDo: get a good ruby book]
[EDIT 2010-09-26] Hey, this book is available online too: http://ruby-doc.org/docs/ProgrammingRuby/ Nevertheless, I prefer a hardcopy

Sonntag, 19. September 2010

about me

I am a 31 year old IT professional, working as consultant as project manager. There have been more then one project where I was pretty annoyed and disillusioned that the software development unit delivered very low quality and hundreds of bugs. I don't blame the single programmer (well, maybe a little too), I rather think they were helpless in their environment. No tools like automated CT, continous integration, static code analysis, coverage metrics, etc. etc .etc.

Well, I am not a programmer but I used to work in a project using SCRUM and some - but not all - TDD methods. This project was much more professional (from a development point of view). But just arguing "you need this, you need that" doesn't really help. That's why I decided to try it on my own. I want to get _real_ experience using _real_ technices and _real_ tools