Samstag, 5. Februar 2011

long time no see...

Well, it's been a while... The reason is pretty simple, I am now a OSX user (MacBookPro). Nice. But getting used to this box and customizing it, so that I feel comfi and quick took loooooooog (longer, then I expected). Just to list some of my favorite tweaks/impediments:
  • cut & paste in Finder.app with appleScript
  • getting used to vim (again)
  • configuring Butler.app (a Pipe is CMD+< now, just as it has been on my windows box; CMD+ß is a backslash, .,,)
  • cintch, typinator, ...
  • and some more

Regarding my previous post: no, there is no bug. Hashes are ordered since ruby 1.9, which might appear weird. Well, accessing the keys of a hash by querying the value is weird too (nevertheless, it is build-in and "supported").

The german forum was kind of helpful. Mostly as it helped me to figure out which documentation comes from where. This encouraged me to contact the rubydoc mailing list. See http://thread.gmane.org/gmane.comp.lang.ruby.documentation/1171. When I am "grown up" I will submit a documentaton-only patch to ruby so that the confusing/incomplete documentation is enhanced...

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/