Archive for October, 2009

14
Oct
09

Average Arrival Time For A Flight, part 1

To be honest this was a bit of a disappointment when I first read it, but upon starting the challenge I realized there are way more subtleties than I first gave it credit for. My initial thought was to take a base time as milliseconds then convert all inputs to milliseconds, find the difference, average and put it back into regular hours. I started reading Date classes and found a pretty easy way to do this.
After working on this for a while I realized that I would have to use more than just DateTime. As usual, it was pretty much in the instructions to use Time. Once I brought that class in, this problem becomes pretty trivial. I’ll post my solution once it ends, but I think it’s pretty good. It’s only 18 lines, any tips on how to make it more Ruby-like would be much appreciated.

06
Oct
09

Shift Subtitle, Results

The first round is finally over! I received some great feedback from several people on the RPCFN comments section. AkitaOnRails says “Worked right off the bat, correct results, but it was just too brute force for my taste.” Michael Kohl says “A bit too complicated and repetitive for my personal taste, but definitely not bad for a Python coder coming over to Ruby-land.” And ashbb says “Ran the code with Ruby 1.9.1 and got the output file well. It was converted correctly. With Ruby 1.8.6, need to treat the message – undefined method ‘each_char’” These are all helpful comments and a good starting point. Now I know that each_char was called something else (or didn’t exist) pre Ruby 1.8.6. The other comments are a helpful starting place to learn what to look for in other code. Look for elegance and DRY principles. I don’t think I know enough Ruby to be elegant quite yet, but hopefully there will be improvement in round two.

Looking at AkitaOnRail’s last post congratulating everyone, he summarizes what the common problems were and styles of coding. Overall what I took away from that post to use in the next challenge is

  1. Naming conventions
  2. Gists on GitHub
  3. Project folder structure
  4. Attempt “Ruby-like” code

So I’m going to need to look up Ruby naming conventions when the next challenge starts/I have more time. All I’ve seen in Ruby code is an excess of underscores and verbose names, but I’m sure there are cases to learn when to use what. Honestly, I thought the goal was to make it all be in one file and not have a project structure, but now that I know that is what they are looking for, that is what I will do. Hmm I’ll have to look into gem specs as well. I think that will answer my question about executable programs.

Taking a look at other solutions I can clearly see a good project structure. Keep class files in the lib/, the binaries in the bin/ and the tests in spec/. I also picked up some ruby syntax, the delimited input! There are a ton of functions I need to look up, they seem like pretty basic ones. I’m liking the general feel of the Ruby code I’m looking at. I’ve only had a chance to read through a couple of solutions and would like to read through more before attempting to comment on any ones that I particularly like.

Definitely looking forward to the next challenge! This is a fun way to learn Ruby. Thanks to all people who are reading/test/judging the code. It seems like a lot of work and you guys are doing a great job!

01
Oct
09

to RSpec or not to RSpec

I took another look at RSpec today. I tried to re-write the script using a test driven development method but am finding it harder to use than expected. I think I just have to shift my brain into programming TDD style. I really didn’t come up with any good code, I must have started over at least 10 times. I started with things like it “should accept a parameter –operation that takes either ‘add’ or ‘sub’ as it’s value” Then I would read RSpec docs and try to test tha…needless to say it’s a good way to learn about RSpec albeit rather slow. Hopefully I can move my brain to this new style of thinking. It seemed so easy at first but once you try it, it’s actually kind of difficult to do.

Here is the list of requirements I’m going to be working off of.

  • it “should accept two parameters, an operation that is either add or sub and a time value formatted at least with one digit. It should also accept two arguments, an in_file and na out_file”
  • it “should add or subtract time based on the set operation”
  • it “should modify the time by the amount passed in as a parameter of –time”
  • it “should read times and all other lines from the first file”
  • it “should write modified times and unmodified other lines to the second file”

IF you can get these tests to pass, then you’ve got yourself a working program and RSpec test to go with it as well as some documentation!

Until next time…




Challenges

How often I post

October 2009
M T W T F S S
« Sep   Dec »
 1234
567891011
12131415161718
19202122232425
262728293031  

This is everything