Traversing the Internets

Web Development in NYC

Flatiron School Weekend One

I’m going to wrap Friday-Sunday into one big post.

Friday began my love affair with case statements. They are beautiful creatures that really can save you a lot of code over if/else statements and also read a bit more clearly.

EXAMPLES…

The case statement looks really clear…
1
2
3
4
5
6
7
8
9
10
11
12
13
def temperature_bot(temp)
  result = ""
  case temp
    when 0..16
      result = "cold"
    when 17..21
      result = "comfortable"
    when 22..100
      result = "hot"
    else
      result = "you're probably dead"
  end
end
The if statements are a lot more cluttered…
1
2
3
4
5
6
7
8
9
10
11
12
def temperature_bot(temp)
  result = ""
  if temp > 0 && temp < 17
    result = "cold"
  elsif temp > 16 && temp < 22
    result = "comfortable"
  elsif temp > 21 && temp < 100
    result = "hot"
  else
    result = "you're probably dead"
  end
end

The difference doesn’t seem to be a huge deal when you’re scanning over the different code, but the clarity and ease of the case statement makes debugging easier when you’re dealing with a larger set of code.

Over the weekend I managed to stay out of Manhattan. I don’t know in the long run if this is a good or a bad thing, but I spent the weekend in Brooklyn coding, climbing with some Flatiron folks and managed to have enough time to watch a little football on Sunday.

I was really happy with the assessment we were given over the weekend. I think everybody at Flatiron goes through points in a day when they feel like the ‘dumbest kid in class’ because they don’t get something yet or are having trouble. Somehow, despite this happening to virtually everyone we don’t seem to be able to shake that feeling just yet.

Having a solo assessment that goes over the material we’ve covered so far went a long way to helping me confirm that I knew what I was doing so far. Not everything came to me right away but I managed to make my way through everything with a little help from google and my new best friend Rubular.

My ‘take away’ from the weekend is the power of regular expressions. I think all of the code in my weekend homework that I am most proud of used regular expressions to accomplish a lot with very little code. They don’t read as easily as normal ruby syntax but you can do some really powerful stuff with regular expressions and it makes them a lot of fun to use.

My goal for this week is to use yield and code blocks better. I was reviewing the Treehouse ruby material to brush up for week two and they showed some very cool ways to organize a chunk of code where the main method organizes and runs the sub-methods and yields to them to do the ‘work’ to get the goals they want. This reminds me of the Jukebox assignment we worked on last week and makes me think that the program would have been a lot ‘cleaner’ if I was more comfortable yielding to other methods.

Comments