Saturday, November 23, 2013

Humor: Stackoverflow is down



someecards.com - I'm calling in sick today because Stack Overflow is down.

Monday, September 30, 2013

Girl Develop It: Code & Coffee

Girl Develop It (GDI) must be really popular, because when I signed up there were at least 10 people on the wait list. I'm still not sure how I managed to pass those and snatched a spot to go to the meetup.

The event was hosted by Table XI, which was right around the corner from 8th Light. The event organizer, Jen Mozen, must have been a psychic because she knew I would get lost, thus she posted signs in front of the building and the elevator to direct us to the place. Although Meetup said 39 people will attend, I think ~15 showed up, which was really nice. It felt a little more intimate. We were able to introduce ourselves and talk about our background. I found a lot of people there are new, which is great. I wish my sisters were here so they can attend. It's a great learning environment.

Jen was nice enough to be extra prepare and things people could work on.
Although IFFF sounds really interesting, I opted for working on my own application. It's a code review app which allow users to submit their code and for others to review. Chris was nice enough to work with me on it. He showed me a really cool gem called table print which he develops. It prints out your SQL stuffs in a table format.

So instead of it looking like this:

The gem makes it looks like this:

The time Chris spent with me was really useful. I got the basic of take request down. It also reminded me how useful pairing it. It helped me focus on the problem at hand. And when I try to explain the application to Chris and what I wanted to do, I realize I was having a lot of problem because of the way I name things. So I went back home and rename my request to review request and review to review reply. It makes it easier for me to refer to things. Ideally I probably want to do one or two hours of pairing in the morning because that's when my mind easily distracted.

Overall, it was a really nice meetup. I would definitely go again :)

Wednesday, September 11, 2013

SOLID: Liskov's Substitution Principle

In 1988, Barbara Liskov wrote:
If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T.

Uncle Bob's interpretation:
Subtypes must be substitutable for their base types.

Head First Object-Oriented Analysis and Design's interpretation:
"When you inherit from a base class, you must be able to substitute your subclass for that base class without things going terribly wrong. Otherwise, you've used inheritance incorrectly!" 

If none of those interpretation makes sense, read on.

I will try to explain this using Java. But before I explain what the principle means, let's define what subtype is. A is a subtype of B if it implements or extends B. For example, ArrayList is a subtype of List because ArrayList implements List. List is a subtype Collection because it List extends Collection. Because this relationship is transitive, ArrayList is also a subtype of Collection.



Now we know what I mean when I say subtype, let's try to understand the principle.  Let's say we have the following code is Java:
What the principle is saying is that I can rewrite the code to this:
Or this:
Even though I changed Collection to List and Set, the behavior is unchanged because List and Set are subtypes of Collection, so you can substitute the subtype with its base class. What this translate to is that I can pass a List or a Set into removeAll because the method takes a Collection.

Be careful because this is a one way street. List can be substituted Collection but Collection may not be substitutable for List because List is a child of collection.

Photo by Derick Bailey

There are two ways you can violate the Liskov Substitution Principle:

  1. When the subtype Class removes functionality from the base class.
  2. When methods that reference the base class knows about its subtype.
Both of these violations translates to wrong abstraction. For example, look at this code:
Looks good right? In most cases, it is good. However, when I run this test, it will fail. I get an UnsupportedOperationException.
Why did it fail? Because Arrays.asList() returns an AbstractList, which is an unmodifiable list. It doesn't support List.add() or List.remove(). This is a violation of the Liskov Substitution Principle because AbstractList removes functionality from List. I can't substitute AbstractList (the subtype) for List (the base class). We can fix this by making the List interface have all the unmodifable methods. Then have another interface for ModifableList.


(Note: For the sake of simplicity, I ignored that the List interface implements Collection. But you get the idea.)

This way, our method can be changed to:
This makes a lot more sense because you can only remove items in list that are modifiable.

The second way to violate this principle is having your method knowing details about the subclass.
The calculateArea violates the Liskov Substitution Principle because it knows about the subtype of Shape. This makes it hard for the method to close for modification. What happens when you add a circle, now you have to add another if statement to check if it's a circle. To fix this, we can move the calculateArea() to the Shape class. Then each Shape can implements its calculateArea() so we don't have to check to see what type it is.

This is another way you can violate the principle: This method knows the subtype of the base class. It casts the list to LinkedList, but not all lists are LinkedList. Therefore we cannot substitute the subtype ArrayList in this method even though List is ArrayList base class.

And that's Liskov Substitution Principle. If you are removing functionality, then you want to ask, does this subtype belong to this base class? Or if you find yourself downcasting like I did with the LinkedList, then you want to replace the base type with the subtype. Or if you find yourself checking for case type, then you should ask, does this method belongs in the subtype class? Doing any of these things is an indication that you may be violating the Liskov Substitution Principle.


 Resource:
  1. Software Development Principles Patterns Practices
  2. Head First Object-Oriented Analysis and Design
  3. Object Mentor - Liskov's Substitution Principle
  4. OODesign - Liskov's Substitution Principle

Tuesday, September 10, 2013

Sweeping the floor

When I told people I was leaving my old job for an apprenticeship at 8th Light, my family and friends were worried (and they have good reasons to be). How long will it be? Will they pay you? What are you doing to do if they don't? Where are you going to live? What are you going to eat? You don't even know how to cook! So many questions and no concrete answer.

Thus when Eric sent me the offer letter which states I will get pay during my apprenticeship, I was thrilled! I couldn't believe 8th Light would take this chance on me. Six months of pure learning. That's a lot of money and time spent on me, and they don't know if they want to hire me for real!

On the first day of my apprenticeship, Eric and I talked about the high level "curriculum" of the apprenticeship. One of my duties as an apprentice is to help keep the office clean. Eric spoke about this duty quickly and told me to read more about it in the Apprenticeship Pattern book.

In the book, Dave Hoover and Adewale Oshieye called these unsexy tasks "Sweeping the Floor". (Yes, they used the word unsexy.) They recommends apprentices, like me, volunteer for unglamorous job in the beginning to contribute to the team, build trust, and learn humility. I look at it a little differently. I am thankful to have this opportunity, even if they didn't pay me, I would still do all the unsexy task. To me, it's like buying the craftsmen time. If I take out the garbage, the craftsmen don't have to. Since I free up some of their time, I don't feel as shy about asking them questions. Or when I keep the office clean, it makes the craftsmen happier, so they are more likely to answer questions when I ask. That is not to say the craftsmen here are unapproachable. It is the opposite. They are always friendly and nice. I've never had a craftsman who gives the don't-bother-me-attitude when I approach them.

By doing these unsexy tasks, it makes me feel a little useful. I feel like I am part of a team. I am providing values. It also create a bond knowing that most, if not all, of the craftsmen have "swept the floor," even our CEO.

Although the apprentices are probably the most expensive "custodian" around, the craftsmen still thank us for the little things like keeping the fridge stocks with cold soda. I think it's going to be hard to find a better company than 8th Light. Thank you Paul and Micah for creating such an awesome company. (I was not paid...well not paid specifically to write this blog.)

Wednesday, September 4, 2013

Coding by intention, not accident

There is still something that doesn't sit well with me when I write kata. You're supposed to write the simplest code to make the test pass, but I feel sometimes this lead to coding by accident instead of intention.

For example, for the coin changer kata, when the user enters anything less than 0, I want to return an empty array indicating I have no change for the user.

So my test looks like this:
it "returns nothing when amount is less than the smallest coin value" do
  CoinChanger.get_change(0).should == []
end

For a simplest case, the code looks like this:
get_change(amount)
  []
end
If you read the code, do you think it expresses my intention well?

What happen when the amount is 1 cent? The program changes to this:

def get_change(amount)
  if (amount == 0)
    []
  else
    get_change(amount - 1) << 1
  end
end

But that's not what I mean. I really mean, if amount is 0, -1, or anything smaller than 0, I want it to return the empty array. So the code should really look like this:
def get_change(amount)
  if (amount <= 0)
    []
  else
    get_change(amount - 1) << 1
  end
end

When I write the simplest test case, sometimes, I forget the other condition. In this case, maybe I need to add another test case to test what happen when amount is less than 0. In general, I should be more careful and understand why my test is passing.

Note: This is not the best way to write coin changer. I just want to demonstrate what I was thinking.

Tips for Cob Spec

Things that I found useful in trying to pass Cob Spec
  1. Understand what HTTP Request and Response looks like
    1. The only requirement you need for response is the first line (HTTP/1.1 200 OK)
    2. There is a line break between the header and the body
  2. You can debug your server with Cob Spec
    1. Run your server in Debugger (Right click in your IDE, select Debug)
    2. Put on your breakpoint
    3. Run your cobspec test. It should stop where your breakpoint is.
    4. You can use this method to print out the request Cobspec is sending
  3. Reading client request
    1. I use BufferReader to read my request
      1. To check the end of a header, I check to see if the line is null or empty string ("")

Wednesday, August 14, 2013

Gilded Rose Kata in Ruby


This one took quite a long time to do. First I have to refactor and find a solution that seems reasonable. Then practice. But no matter how many times I try, I couldn't get it the solution down pass 15 so I fast forward the video. Definitely a fun kata. If you're practicing refactoring, this one really helps reinstating how often you should run the test.

Wednesday, August 7, 2013

Getting started on Clojure

One of my task last week is to write Tic Tac Toe in Clojure. Seeing code like this, of course I freaked out: I have no idea what it is saying. If I don't understand it, I didn't like it! I want to crawl back to Ruby. Ruby is much more English-like and way easier to read. It doesn't have a million parenthesis like Clojure. However, after spending a whole week in Clojure, I hate to admit it, but I'm beginning to like it. I like how easy it is to do a lot of things. For example, if I want to say get a total of a few numbers, this is all I have to write:
(+ 1 2 3 4 5)
Ruby
 1 + 2 + 3 + 4 + 5
In this example, I have to say Clojure wins on account of simplicity. It is easy to read and write this statement. I don't know if you can get any easier than this.

Enough background, here is how I would have started to learn Clojure:

  1. Blackstag - It is a really simple guide to get you started. You will not learn everything you need, but it's a good place to start. (I skipped installation because it's already installed on my computer so I'm not sure if it's still relevant.)
  2. Clojure API - I read most of the methods in here. It will help you become familiar with what Clojure has to offer.
  3. Roman Numerals Kata - Write your own roman numeral kata. I looked at others to see how they do it. Look up keywords that you don't understand.
  4. Read other people code. I look at several Clojure implementations of TicTacToe because mainly I have to write it. But it really helps because I have an idea of how the game is suppose to work. That is not to say I read and understand everything I read. Anyway, here's a list of Github you want to checkout:
    1. Rylan Tic Tac Toe
    2. Micah
    3. Colin
    4. Wai Lee
    5. Clojure Cookbook - I didn't look at it, but it sounds promising.
  5. Clojure Docs - This is my best friend once I got an idea of what function I want to call. 
Note: I recommend using Emacs with rainbow parenthesis when you write Clojure code. If you are writing in Clojure, it is worth the time and effort to learn how to use Emacs. 

I got most of my Clojure Tic Tac Toe code done by reading Blackstag, Clojure API, and others code. I am much more comfortable with the language now.

Friday, July 26, 2013

Java: Sockets

Socket, defined by Oracle document, is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent.

What does this really mean?

Photo from The Bowery Boys

Imagine it is 1850. Rowland Hussey Macy, Macy's' store owner, is walking down the street of NYC when he notices strings hanging from several apartment complexes. 

"Excuse me, do you know what those strings are?" he asked a passerby. 

"They are can telephone lines. You attach cans to each end of the line and used it to talk to one another." 

"Intriguing. How far does it travel?"

"About half a mile." 

"Half a mile? I wonder....."

Photo by Jin Choi

As Mr. Macy walks back to the office, a plan begins to formulate. Two months later, he rented a small office across from Central park. The office has a window where people can come and request to talk to a representative. Because the window is small, only one person can come to the window at a time. To serve multiple clients at a time, Mr. Macy has the brilliant idea of using the can telephones. When a client needs to speak to a representative, she comes to the window. The representative at the window will give her a can telephone. She can use the telephone to speak with a representative inside of the office. This way, while Mary is talking on the side with one representative, Tom can comes to a window and request to speak to another. When Mary is done, she returns the can telephone so others can use it. 

Photo from Wiki

That is how I understand the socket. The building Mr. Macy rent is like the computer. It has many windows for many businesses. Macy can rent office 1 while Kohl rents office 2. The computer is the same way. It has many ports where an application can "rent/reserve" ports. From 0 - 1023, these ports are always in use, aka lifetime renter. You can't use these. But your application can rent any other ports from 1024+. Once you tell the computer you are using that port, no one else can use it. When a client need to speak to your application, it goes to the port that you "rent".



When you create a server, you need to create a ServerSocket. This socket is like the representative at the window, he is responsible for opening and closing the window(/port) and assigning request. He can also handle request, but if he is handling request, then no one will be able to speak to him, so it's best to hand the job to someone else.

The normal sockets are like the can telephones. When the client comes to your "window", you assigned a specific can telephone to him/her. That way, you can communicate freely. If I speak to socket one, I know I am talking to John because I assigned him that line. If I don't have sockets, I wouldn't know who I am talking to. When John is done talking to me, or I to him, we must close the socket so we can free up resources for other user. You can only talk to the client once.

This is what my server class looks like. Currently it accepts one client, returns "Hello, world!", then closes the sockets. After you run it, you can open your browser and go to http://localhost:4000 to see "Hello, world!"
import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

    public static void main(String[] args) throws IOException {
        Server server = new Server();
        server.start();
    }

public void start() {
        try {
           ServerSocket serverSocket = new ServerSocket(4000); //Representative at the window
            Socket clientSocket = getSocket().accept(); //Socket assign to client
            PrintWriter response = new PrintWriter(clientSocket.getOutputStream(), true); //get translator
            response.println("Hello, world!"); //Talk to client
            response.close(); 
            clientSocket.close(); //Return can telephone
            getSocket().close(); //close your window
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
One thing to note is the PrintWriter. When you call clientSocket.getOutputStream(), what you have to send to OutputStream are bytes. So PrintWriter is like a translator. You say, here's a string, translate it to bytes and give it to output stream.

Wednesday, July 10, 2013

SOLID: Single Responsibility Principle (SRP)


Even after five years of programming, I am still struggling with this principle. I don't know how to determine if a method is part of the class responsibility. In the Agile Software Development Principles, Patterns, and Practices book, Uncle Bob has this class structure:

At first glance, the design feels ok to me. The Rectangle class has an area and it knows how to draw itself. In my Tic Tac Toe, I have a similar logic for the players. I let the players give me a move by injecting a strategy in the player class. For a computer player, that means using minimax strategy. For a human player, a console "strategy" which really means display a message to the user to get the user input. This felt like a good design because the game doesn't have to worry about getting input. It doesn't even know what type of players it has.

However, after I watched the Clean Coder video, I understood what Uncle Bob means when he said it should change for one, and only one reason. Instead of thinking about responsibility, think about who uses the methods in the class. For example, look at this this class:
public class Employee {
  public Money calculatePay()
  public String reportHours()
  public void update()
  public void add()
}

Who will use these methods?

  • Someone who needs to know how much to pay the employee (aka payroll system)
  • Someone who needs to add/update the employee information

When you think about it that way, you can clearly see that these methods should be in two classes. And it makes sense because if you change the database schema, update() and add() need to know about it. But that doesn't have anything to do with reported hours or pay calculation.

Looking back at the graph, I can see why that is a violation of the single responsibility principle. The draw method uses the GUI and the computational class uses area. The application also uses the GUI. So when the GUI change, Rectangle has to change even though the area code didn't.

As for my Tic Tac Toe program, maybe it's ok because the class that gets the move is the strategy class, and the strategy only have one reason to change, which is how it gets the player's move.

Monday, June 24, 2013

Ruby: Mocking with Surrogate

Many people, most notably Martin Fowler, have written about mocking so I won't go into what it is and when to use it. (That is not to say I know the answer to both questions. It is something that I still need to research further. Maybe another post?) Eric Meyer has also written two posts on Surrogate at 8th Light blog (1, 2) but I don't think it hurts to add one more. This post assume you:
  • know Ruby
  • know Rspec
  • want another mocking mechanism for Ruby with Rspec
Let's say you have a game class that you are trying to test: 
class Game

  def initialize(rules)
    @rules = rules
  end

  def over?
    return true if @rules.winner
    return true if @rules.tied?
  end
end

This is what the Rules class looks like:
class Rules
  def initialize(board)
    @board = board
  end

  def tied?
    !winner && @board.filled?
  end

  def winner
    @board.unique_marked_values.detect {|p| win?(p)}
  end

  private
  def win?(player)
    square_sets.any? do |squares|
      squares.all? {|square| square == player}
    end
  end

  def square_sets
    @board.rows + @board.columns + @board.diagonals
  end
end
Note there are 4 methods in Rules, but only two are public, tied? and winner. Assuming you want to mock Rules because it is too complicated to set up a tied or winner situation.
  1. Create a mock folder in spec
  2. Create a mock file (you use the same name as your class file, in my case, rules.rb)
  3. In your mock file
    • Require surrogate
    • Endow the mock class
    • Define the class methods
      #game/spec/mock/rules.rb
      require 'surrogate/rspec'
      
      class MockRules
      
        Surrogate.endow(self)
      
        define(:tied?) do
          false
        end
      
        define(:winner)
      
      end
      
  4. Test if your mock is substitutable for the original class
    #game/spec/game/rules_spec.rb
    require 'game/game'
    require 'game/rules'
    require 'mock/rules'
    
    describe Game do
      it "checks if MockRules is substitutable for rules" do
        MockRules.should be_substitutable_for(Rules)
      end
    end
    
  5. Use the mock class
Let's go into a little more detail for step 3, 4, and 5.

3. Define your class method
There are three way to define your methods:
  1. One line with return type
  2.   define(:tied?) {false}
    
  3. Three lines with return type
  4.   define(:tied?) do
        false
      end
    
  5. One line with default return
  6.   define(:tied?)
    
    What this method really returns is "nil" and since nil evaluate to false as well, you can think of it as false.
If your method has a parameter, like this:
def winner(board)
   .....
end
then in your mock class, you can define the method as follow:
  define(:winner) do |value|
    value
  end
or
  define(:winner) {|value| value}

4. Test if the mock class is substitutable 
This step is important because it ensure your class has the same methods/interface as the class you are mocking. This means if I add the method def name to Rules, when I run rspec, it will fail. Or if I decide to remove def winner in Rules, running the test will fail. Again, this restrict your MockRules to have only methods defined by Rules.

5. Use the mock class
Let's say you want to test that the game is over when there is a tied. Again, this is the game over method
def over?
    return true if @rules.winner
    return true if @rules.tied?
    return false
end
For this test, you want to return true when rules.tied? is called and check to see if rules.winner is called. Here are the steps:
  1. Create a mock class with method you want to override
  2. Create the class under test
  3. Set the mock to game
  4. Call the method under test
  5. Verify expected behaviors
    • Verify over? is true
    • Verify winner was called
  it "is over when the game is tied" do
    rules = MockRules.factory(tied?: true)  #1. Create mock class with specified behavior
    game = Game.new(rules)                  #2. Create a game class 3. "Set" mock to game
    game.should be_over                     #4. Call method under test and 5. Verify expected behavior 
    rules.was asked_for :winner             #5. Verify expected behavior
  end
Note, some say that you should only test for one behavior in each test. I have not figure out where I stand on this argument, but this post is about using surrogate so it's easier for you to read if I put everything under one test. Surrogate can do a lot more. This is just a basic overview on how to use it.

Resource

Friday, June 7, 2013

The abstract factory pattern

Note: Code is in Java. 

According to OODesign, the intent of the abstract factory pattern is to "offer an interface for creating a family of related objects without specifying their classes."

So how does this relate to my story?

The factory

Let's imagine that when Gwen came to the village, they haven't figure out a system to plant vegetables yet. So everyone has to plant their own vegetables. In code, Todd class looks like this:
public class Todd {
 public Carrot getCarrot(){
  Carrot carrot = new Carrot();
  carrot.addWater(1);
  return carrot;
 }
 
 public Carrot getNoCrunchCarrot(){
  Carrot carrot = new Carrot();
  carrot.addWater(2);
  return carrot;
 }
}
Gwen class looks like this:
public class GwenSoupMaker {
 public Soup carrotSoup(){
  Carrot carrot = new Carrot();
  carrot.addWater(1);
  CarrotPieces carrot_pieces = cut(carrot);
  return cook(carrot_pieces);
 }
 
 private CarrotPieces cut(Carrot carrot) {
  return new CarrotPieces(carrot);
 }

 private Soup cook(CarrotPieces carrot) {
  return new Soup(carrot);
 }
}
See the duplication? It's just two line of code, so maybe it's ok. Now if one day, Alex says he found that if you add fertilizer, the carrot will grow faster. So everyone who grows carrot has to change their planting method by adding  fertilizer. Doesn't that sound like a lot of work? Couldn't I just tell Alex to grow the carrot and give it to me when I want it? That way only Alex needs to know about how to grow the carrot.public class Alex {
 
 public Carrot getCarrot(){
  return growCarrot(1);
 }
 
 public Carrot getNoCrunchCarrot(){
  return growCarrot(2);
 }
 
 private Carrot growCarrot(int gallonOfWater){
  Carrot carrot = new Carrot();
  carrot.addWater(gallonOfWater);
  carrot.addFertilizer();
  return carrot;  
 }
}
Now Todd class looks like this:
public class Todd {
 public Carrot getCarrot(){
  return Alex.getCarrot();
 }
 
 public Carrot getNoCrunchCarrot(){
  return Alex.getNoCrunchCarrot();
 }
}
Gwen looks like this:
public class GwenSoupMaker {
 
 public Soup carrotSoup(){
  Carrot carrot = Alex.getCarrot();
  CarrotPieces carrot_pieces = cut(carrot);
  return cook(carrot_pieces);
 }
 
 private CarrotPieces cut(Carrot carrot) {
  return new CarrotPieces(carrot);
 }

 private Soup cook(CarrotPieces carrot) {
  return new Soup(carrot);
 }
}
And if James wanted carrot, he doesn't need to know how to grow it either. He just asks Alex for it.
public class James {
 public Carrot getCarrot(){
  return Alex.getNoCrunchCarrot();
 }
}
In term of code, Alex is our factory. He is the only one with knowledge on how to grow carrot. If growing no crunch carrot needs 3 gallon of water, only Alex needs to know.

The abstract factory

Remember when Gwen started to do super well with her store? She had to go to Todd several times to buy zucchini. Every time she needs zucchini, she has to find Todd. But, Todd is busy man. To make it easier for customer to buy zucchini, he put up a stand in front of his house so his son or his wife can sell the zucchini when Todd is not available. That way, when Gwen needs zucchini, she goes to the stand instead of asking Todd.

In code term, that just mean Todd has an interface and Gwen just talk to the interface when she wants a zucchini. So Gwen class looks like this:
import java.util.List;

public class GwenSoupMaker {
 ZucchiniFarmer zucchiniFarmer;
 public GwenSoupMaker(ZucchiniFarmer farmer){
  zucchiniFarmer = farmer;
 }
 
 public Soup zucchiniSoup(){
  List zucchinis = zucchiniFarmer.buy(3);
  return cook(zucchinis);
 }
 
 private Soup cook(List zucchinis) {
  return new Soup(zucchinis);
 }

Todd:
import java.util.ArrayList;
import java.util.List;

public class Todd implements ZucchiniFarmer{
 public List buy(int amount) {
  List zucchinis = new ArrayList();
  for (int i = 0; i < amount; i++){
   zucchinis.add(new Zucchini(1));
  }
  return zucchinis;
 }
}
Zucchini farmers:
import java.util.List;


public interface ZucchiniFarmer {
 public List buy(int amount);
}

Thursday, June 6, 2013

Design pattern story - the beginning

I've been struggling to explain design pattern that I feel is easier to understand. So after reading "Storytelling for Software Professionals" by Arjen Uittenbogaard on May/June issue of IEEE Software, I decided to give it a try and explain design pattern in term of a story. This is a story I made up to serve as the base to explain design patterns.

----------------------------------------------------------------------------

Once upon a time, there was a farmer named Todd. Todd loves zucchini, so he spent all his time figuring out how to plant the perfect zucchini. After years of trial and error, he finally found a way to plant the perfect zucchini. He invited everyone in the village over to try his perfect zucchini. They were all amazed at how delicious they were! Everyone asked Todd to show them how he did it. "The secret," Todd said, "is to water the plant before sunrise." Everyone thanked Todd and went home to plant their own zucchini.

One day, Todd met Mary, a beautiful girl from a nearby village. The two fell in love and got married. Seeing the empty space on Todd's land, Mary asked if he can plant carrot because it's her favorite vegetable. As newlyweds, Todd was still in love. So he happily went to Alexander, the best carrot farmer and asked for instructions. "The secret," Alex said, "is to water it at 7AM and 6 PM to ensure the carrot has enough water to grow." Todd thanked Alex and happily went home. After months of hard work, Todd had a whole lot full of perfect carrots. It was sweet and crunchy, just as he expected. His wife was so happy. They hug, they kissed, and the next thing they know, they had a baby.

When the baby was born, Todd tried to feed the baby with his perfect carrot. But the baby couldn't eat it. It was too crunchy.

"You should ask Alex on how to plant baby carrot that has no crunch," his wife advised.

So Todd went back to Alex and explained his problem.

"If you want the carrot to be less crunchy, water it more and pull it up earlier," Alex, the carrot farmer said.

Todd did as instructed. And surely, he had carrot with no crunch. As the baby grow older, Mary wanted to add a little crunch to the carrot. But carrot takes months to grow. By the time Todd got the carrot to have a little crunch, the baby was ready for the regular carrot. Plus, keeping track of when to water the plant and how much water for which row becomes a little too much.

Feeling frustrated, Todd went to Alex, the carrot farmer and complained about the situation. Alex nodded understandingly, as if he had heard it before.

"Listen," Alex said. "James, my neighbor is also having a problem similar to yours. He grows the best potatoes. So I told him, if he grows me some potatoes, I'll grow the carrot for him. I can also do that for you if you grow me some of your zucchini. That way you don't have to worry about growing carrot."

"What a great idea!" Todd exclaimed. So next year, Alex grew only carrot and Todd only grew zucchini. Whenever Todd needed carrot, he goes to Alex and tell Alex the type of crunch he wants and Alex would pull it from his garden.

One day, Gwen, Mary's sister, came to visit the couple. She saw how beautiful and prosperous the village was and decided to make it her new home. Now Gwen was a very talented chef. She decided to open a soup shop to make a living. Instead of growing her own vegetables, Gwen went to Todd for zucchini, Alex for carrot, and James for potato. Because Gwen didn't have to worry about growing vegetables, she could focus on perfecting her soup. Her zucchini soup became so popular that it attracted many visitors from neighboring villages. This in turn increased her demand for Todd's zucchini. But Todd was often busy with the farm, so he didn't have time to sell the zucchini.

"Why don't we open a zucchini stand?" Mary wisely suggested. "That way, when you're busy on the farm, our son or I can sell it. The customer never have to go look for you when they want to buy zucchini."

"Great idea. Let's set up a zucchini stand in front of our house," said Todd.

So the couple set up a zucchini stand. Whenever Gwen needed zucchini, she went to Todd's stand. She didn't have to look for Todd nor did she care who is selling the zucchini. The zucchini stand did so well, Todd and Mary saved enough money to build a bigger house and send their son to school..................eh and they live happily ever after.

Wednesday, June 5, 2013

Deploying Rail with Heroku

One of my task this week is to learn Rails so I can build a web based Tic Tac Toe game. I followed the Ruby on Rails Tutorial but I was having trouble deploying my application on Heroku (i.e. section 1.4.2 in the book). Whenever I tried to do this:
git push heroku master
I get this:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

To solve this problem, I read how to manage your keys. I can't say I have the right answer, but this works for me.
  1. Make sure you have only one public key on Heroku (I'm not saying 2+ won't work. I'm saying it didn't work for me.) I'm doing this all in the command line.
    1. Type "heroku keys" to see what keys Heroku has for your profile
    2. Type "heroku keys:remove key_name" to remove the key you don't want
  2. Make sure the key you have is the same key on github
    1. To add the key "heroku add ~/.ssh/key_name.pub"

Note: You may need to login to heroku to do this. In order to log in, type "heroku login" then type your credentials.

If all that doesn't work, try to create a config file in your ssh folder. Your config file should look like this:
Host heroku.com
Hostname heroku.com
Port 22
IdentitiesOnly yes
IdentityFile ~/.ssh/your_key_name
TCPKeepAlive yes
User your_email
Resource:
  1. Managing your keys in Heroku
  2. Stackoverflow answer

Tuesday, June 4, 2013

Running slow test (with rake)

Situation: I have a test file that takes a really long time to run. What do I do?

Propose solution: Don't test the file? Of course not! The test file is there to ensure I didn't break anything.  If I don't test it, how do I know my code is working as intended? How do I know the new code didn't break existing code? 

Real solution: Separate out the tests. 

Example: I am working on a TicTacToe game. The game has a computer player that uses minimax to compute the next step. This algorithm takes a long time to calculate when the board has a lot of empty squares. So whenever I add new code and run rspec, it takes a really long time to run, even though the new code has nothing to do with the computer logic. So what I really want is simple command to:
  1. run all test
  2. run slow test
  3. run all test excluding the slow test
If I separated it out like that, I can run most of my test regularly and the slow one before I check in or when I actually change the file. How do I do this? Use Rake. 

Rake is a build tool created by Jim Weirich for Ruby. There are many articles on Rake, including Martin Fowler's detailed explanation. Most didn't really explained what I wanted, so I asked other apprentices for help. Thankful Taka is knowledgable on the subject and offered to help :)

Steps:

  1. Install rake "gem install rake"
  2. Create a file in your project directory call "Rakefile"
  3. Add the tasks to your rake file. This is what my rake file looks like: 
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:default)

RSpec::Core::RakeTask.new(:slow_test) do |t|
  t.rspec_opts = "--tag slow_test"
end

RSpec::Core::RakeTask.new(:test) do |t|
  t.rspec_opts = "--tag ~slow_test"
end
What the file say?
  • Line 3 says, run all tests as the default. 
    • Command: rake
  • Line 5 created a new task called "slow_test" which runs all the test with the tag "slow test" (more on this later). Note that you specify the task name with ":task_name".
    • Command: rake slow_test
  • Line 9 created a new task called "test" which runs all the test excluding the one with the tag "slow_test".
    • Command: rake test
In addition, I can also create a command to run my game. Normally, I would type in "ruby bin/tictactoe", but I can make a shorter command using rake. I called my task play, so I can just type "rake play" and it will start the game for me. Cool eh?
task :play do
  ruby "bin/tic_tac_toe"
end

Tagging test files

I will need to do more research on the topic, but for this rake file to work, I need to add this to my computer test file.
Normal
describe TicTacToe::Player::Computer do
end
Tagged.
Note Taka added a comma after the class under test, then the tag.
describe TicTacToe::Player::Computer, :slow_test => true do
end

Thursday, May 30, 2013

Updating my bash

Bash is a command language interpreter (i.e. shell) that executes commands from standard input or file. It was written by Brian Fox to replace the Bourne shell. The name is an acronym for the 'Bourne-Again SHell'  a pun on Stephen Bourne, the author of the current Unix shell sh. (Bash manual)

A few days after I started at 8th Light, Eric updated my bash to make it more readable. It has colors and smilie faces to indicate whether or not the last command was successful. Eric's bash profile is on github in case you want to update yours too. Since then, Eric gave two presentations on Bash which gave me a little confidence on changing mine. Here is what mine looks like currently:


There are several things to note here: 
1. When the shell is able to execute my command successfully, it gives me a green happy face ^_^
2. When it fails, it gives me a red "D'OH" face >_<
3. When I list the directory, the files are in grayish and the directories are cyan
4. It also tells me which branch I'm on and whether or not I made updates on the branch. The "+" show I added files to the directory. 

All the files for these changes are in ~/.bash. You can open it and explore. I made the face and color changes changes in the prompt file. 

While I had some confidence left, I decided to fix the thing that was most annoying to me, the case sensitive auto complete. For example, I have the folder Ruby. If I type "ru" then hit tab, it won't do anything. If I type "Ru" then it will show "Ruby". Nick Burwell had a blog post on this that seems super easy and clean. Note that this command add to the file, so you don't have to worry about overriding the file. Awesome eh? 

echo "set completion-ignore-case On" >> ~/.inputrc

Resource:

Monday, May 20, 2013

Ruby: Loops with value and index

How many way can you loop through an array in Ruby? A lot! I don't want to give a an exact count because I don't think I've learned them all. Here's just a list of the one I came across so far.

Situation:

I have two arrays, secret_code and guess.
secret_code = [2, 4, 6, 8]
guess = [8, 4, 6, 2]
I need to count how many values in the guess array that matches the values and the positions in the secret_code. So for the example above, my method should return 2 because 4 and 6 matches the values and position. 2 and 8 only match the values, but not the positions, so they don't count. This is what the test looks like.
describe MastermindRules do  
  it "counts the exact match when there exact match and value match" do
    secret_code = [2, 4, 6, 8]
    guess = [8, 4, 6, 2]
    MastermindRules.new.exact_match(secret_code, guess).should == 2
  end
end
This is the method api:
class MastermindRules
  
  def exact_match(secret_code, guess)
    
  end
  
end
So how many ways can I write the exact match method? Let's find out!

while loop

  def exact_match(secret_code, guess)
    exact_match = 0
    index = 0

    while index < secret_code.size
        exact_match += 1 if secret_code[index] == guess[index]
        index += 1
    end

    exact_match
  end

until loop

  def exact_match(secret_code, guess)
    exact_match = 0
    index = 0

    until index >= secret_code.size
        exact_match += 1 if secret_code[index] == guess[index]
        index += 1
    end
    
    exact_match
  end
Note that the condition statement is different than the while loop. In the while loop, it says, execute the loop while index is less than secret_code.size. But for the until statement, it says, execute the loop until the index is greater or equal the the code size. Which one do you choose? I prefer the one that is easier to understand. For example, if I have a method call game.over? I would use until game.over? because while sounds a little clunky, while !game.over?. On the other hand, if I have a method call game.in_progress? I would use while game.in_progress? but not until !game.in_progress?. In this case, if I have to choose between while and until, I would choose while.

loop loop

  def exact_match(secret_code, guess)
    exact_match = 0
    index = 0
    
    loop do
     break if index >= secret_code.size 
        exact_match += 1 if secret_code[index] == guess[index]
        index += 1
    end
    
    exact_match
  end
All of these feel a little clunky don't they? I have to initialize the index and manually increment it. The good thing I learned about Ruby is that if it feels clunky, there's probably a better way to write it.

for loop

  def exact_match(secret_code, guess)
    exact_match = 0

    for index in 0...secret_code.size
      exact_match += 1 if secret_code[index] == guess[index]
    end

    exact_match
  end
Note there are three periods for 0...secret_code.size. This gives me a range from 0 to secret_code.size, not including the code size which for me means 0-3. If there are two periods, then the range is 0-4. The two periods will make my test fail because secret_code[4] = nil and guess[4] = nil, which means my exact_match count will be 3. But I don't want that. So be careful with ranges. At the same time, I can also specify an array to loop through. However, this is not flexible for our case because we can't change the secret_code size on the fly.
  def exact_match(secret_code, guess)
    exact_match = 0

    for i in [0, 1, 2, 3]
      exact_match += 1 if secret_code[i] == guess[i]
    end

    exact_match
  end

each_with_index

  def exact_match(secret_code, guess)
    exact_match = 0

    secret_code.each_with_index do |value, index|
      exact_match += 1 if secret_code[index] == guess[index]
    end

    exact_match
  end

range with each

  def exact_match(secret_code, guess)
    exact_match = 0
    
    (0...secret_code.size).each do |index|
      exact_match += 1 if secret_code[index] == guess[index]
    end
    
    exact_match
  end

times

  def exact_match(secret_code, guess)
    exact_match = 0
    
    (secret_code.size).times do |index|
      exact_match += 1 if secret_code[index] == guess[index]
    end
    
    exact_match
  end

upto

  def exact_match(secret_code, guess)
    exact_match = 0
    
    0.upto(secret_code.size-1) do |index|
      exact_match += 1 if secret_code[index] == guess[index]
    end
    
    exact_match
  end

step

  def exact_match(secret_code, guess)
    exact_match = 0
    
    0.step(secret_code.size, 2) do |index|
      exact_match += 1 if secret_code[index] == guess[index]
    end
    
    exact_match
  end
As the name suggest, step is probably better when you want to skip elements in an array, but not when you need to loop through each element.
So with all these looping options, which one do you choose? It's really up to you. I prefer the one that best expresses my intent. For my problem, I chose each_with_index because when I read this, I know that the value and the index is important.
For more details, Alan has a great article on loops in ruby.

Monday, May 13, 2013

Elixir - Coin changer kata

At the end of week two, Eric told me to write the coin changer kata in Elixir to get myself familiar with the language.

Problem
Given an amount of money, write a program to return the least coin possible. For example:
Input: 47 (cents)
Output: 25, 10, 10, 1, 1 (which means 1 quarter, 2 dimes, and 2 pennies)

I did the coin changing kata with Kelly before in Ruby. It wasn't that hard. But Elixir has a different school of thoughts. I have to write the program without using if or regular looping. Instead, I have to use  guard statement and recursion for looping. Here's a video on what I did. 

I can't attached the files at this time. So here's the link:
http://www.youtube.com/watch?v=miN8XTE0XY0
Resource:

Thursday, May 9, 2013

Running PHP with Apache on Mac


  1. Open the terminal
  2. Type "cd /etc/apache2"
  3. Change permission on httpd.conf by typing "sudo chmod 755 httpd.conf"
  4. Open httpd.conf
    1. Search for "#LoadModule php5_module libexec/apache2/libphp5.so" (line 117)
    2. Uncomment the line by removing "#"
  5. To start the server type "sudo apachectl start"
  6. To stop your server type "sudo apachectl stop"
  7. Your files should be saved in "/Library/WebServer/Documents/ "
  8. On your browser, type "localhost"
    1. You should see "It works!"
Testing your server
  1. Create a file call "test.php"
  2. Copy/Type this in
  3. 
    
  4. Save it in "/Library/WebServer/Documents/ 
  5. Open your browser and type "localhost/test.php"
  6. You should see "Please work"
Ryan has a post explaining what each steps mean.

Source:
  • http://www.editrocket.com/articles/php_mac_os_x.html
  • http://www.cyberciti.biz/faq/restarting-apache-under-oxs-commandline/

Monday, April 29, 2013

Posting code in blogger

Alex Gorbatchev created a really awesome syntax highlighter for code. To add it to your blogger:
  1. Click "Template" on your main blogger menu
  2. Click "Edit HTML"
  3. Before "</head>" add the following code
  4. 
    
     
     
     
     
     
     
     
     
     
     
     
     
     
    
    
    Remove all the brush you don't need. Here's a list of all the available brush.
  5. Before "</body>", add the following code

Adding a test post

  1. Create a new post
  2. Click "HTML" on the left hand side to switch to the html view
  3. Enter the following
  4.     /**
         * SyntaxHighlighter
         */
        function foo()
        {
            if (counter <= 10)
                return;
            // it works!
        }
    
  5. Click "Preview" to view the test post
Resource: http://stackoverflow.com/questions/679189/formatting-code-snippets-for-blogging-on-blogger

Ruby: Accessor

Instance variables in Ruby are private by default.
class Book
  def initialize
    @title = "Ender's Game"
    @author = "Orson Scott Card"
    @location = "Chicago"
  end
end

book = Book.new
book.title = "Programming Ruby"
puts (book.title)
If you run the program, you get a no method error.
accessor.rb:10:in `
': undefined method `title=' for # (NoMethodError)

In order to access to the variables, you need to specify what type of access you want to grant. There are three types of access:
  • attr_reader - for read access only
  • attr_writer - for write access only
  • attr_accessor - for read and write access
Let's say you're writing a book. It's the first draft. You are sending it your friends for review. Let's imagine it's pre-email day, so you're sending it through snail mail. You only have one copy (because you're a poor author), so you want to keep track of where it is. So you have a location that others can read or write to. You haven't decided on a title yet, therefore you don't want anyone else to see it. They can change it, but they can't see it. As for the author, because it's your book, this is something that can't be change so others can only read this field. Let's review.

You have a book with the following attributes:
  • Title - write only access
  • Author - read only access
  • Location - read and write
So your class looks something like this:
class Book
  attr_reader :author
  attr_writer :title
  attr_accessor :location
  
  def initialize
    @title = "Ender's Game"
    @author = "Orson Scott Card"
    @location = "Chicago"
  end
end
So what can you do?
book = Book.new

book.title = "Ender's Shadow"

puts(book.author)

puts(book.location) 
book.location = "Philly"
You can do all that, but if you try to read the title or change the author, you will get an error.
put(book.title)

accessor.rb:22:in `
': undefined method `title' for # (NoMethodError) book.author = "Me" accessor.rb:23:in `
': undefined method `author=' for # (NoMethodError)

The really cool thing about all this is that one day, if you decide to collect all the friends ideas for the book title, you can do it, without changing the caller.
class Book
  attr_reader :author, :suggested_titles
  attr_accessor :location
  
  def initialize
    @title = "Ender's Game"
    @author = "Orson Scott Card"
    @location = "Chicago"
    @suggested_titles = []
    @suggested_titles << @title
  end
  
  def title=(title)
    @title = title
    @suggested_titles << @title
  end
end

book = Book.new
book.title = "Ender's Shadow"
puts(book.suggested_titles)
Even though I added def title, I still set the title by typing book.title = "book name". One thing to note is that you can specify more than variables to the attribute by separating them with commas as I did with :author and :suggested_titles.

Sunday, April 28, 2013

Egit: Checking out/in

Checking out


  1. Right click on "Package Explorer" view
  2. Select "Import"
  3. Type "Git" in the search text box
  4. Select "Projects from Git"
  5. Click "Next"
  6. Select "URI"
  7. Paste your git repository in the URI text box 
  8. Verify everything is correct click "Next"
  9. Select the branch you want to check out and click "Next"
  10. Verify the local destination is correct and click "Next"
  11. Wait a minute as it download the project
  12. Select "Import existing projects"
  13. Click "Next"
  14. Click "Finish" and voila, the project is in our workspace!

Checking in


  1. Right click on the project
  2. Select "Team"
  3. Select "Synchronize with workspace"
  4. Select "Yes" if asked to open the Synchronized view
  5. In this page, you can see what has been change. Verify the changes are correct.
  6. Right click on the project
  7. Select "Commit"
  8. Enter a commit message
  9. Click "Commit"
  10. Return to the "Package Explorer" view
  11. Select "Team"
  12. Select "Push to Upstream"
  13. Click "OK" when shown what has been committed
Note1: Will update with pictures once I figure out where the picture editor the a Mac is. 
Note2: I'm currently using the command line to do all the check in check out. But I thought this might be useful for someone who's familiar with Eclipse and is uncomfortable with the command line like I was a few weeks back.

Friday, April 26, 2013

Kata

Kata is an exercise which helps students hone their skills through practice and repetition (Wiki). As an apprentice, I have to perform one kata a week for my mentor, and once a month in front of a larger audience.

It's easy to dismiss this exercise because one is always looking to do bigger and newer things. As a karate student, you're often interest in learning how to do a spin kick or other cool things you see in Kung Fu movies. You probably don't know that if you execute a normal kick perfectly, you can injure your opponent in one shot instead of having to do several poorly spin kicks (which waste energy and time). It's been awhile since I took karate, but if I remember correctly, in order to do a perfect kick, you have to:
  • assess the situation which includes your surrounding and your opponent. (You don't want your foot to land on a banana peel after your kick.)
  • figure out your opponent weak spot.
  • execute the kick from your hip and focus your energy on the kick to create the most impact.
  • prepare for your opponent defense/counter attack.
All of these must be done in less than a second. It took me five minutes to remember the steps. In five minutes, my opponent could have beaten me to a pulp. So can anyone actually do this? Yes, all karate masters do this. The masters do all of these steps naturally, without even thinking because they've spent years and years performing the same kick over and over again. Through repetition, the masters have ingrained these steps into their memory so that it comes naturally. They don't even have to think before they execute.They execute perfectly each time, all the time, with very few exceptions. And whenever they don't perform one of these steps, they'll feel a nudge from their conscience telling them something is wrong. In addition, when they learn a new kick, they can focus on learning the movements because all the other steps are ingrained in their memories.

That is what I hope to achieve in code katas. I want all the good programming practices (e.g. write test first, write good variable names) to be ingrained in me so that it becomes second nature. I should feel a nudge whenever I start writing bad code.

The second part to practicing katas is that you often find new ways of doing things. The first time I did the prime factors kata, I was really slow. I struggled to write the test and write the simplest code to make the test pass. I had to watch Robert Martin do the kata, several times, to see how he came to the solution and try to emulate that.

After practicing the kata for a week, I'm beginning to feel its effect on me. I feel a nudge when I write code without a test. I begin to see what kind of test I should create to make the algorithm better. I still haven't perfected my kata yet, not that there is a perfect solution. Programming is an art, as they said. There is no perfect solution. However, I still haven't arrived at the solution I'm satisfied with. So the goal is to practice a kata a day. And only one kata a week, which means I will be doing the same kata at least five times. And every time I do the kata, I have to think of better way to write it.  

Monday, April 22, 2013

Installing/Uninstalling EGit for Eclipse in Mac

Installing

  1. Select "Help" from the main menu
  2. Select "Install new software" at the bottom of the menu
  3. Enter "http://download.eclipse.org/egit/updates" in the text box "Work with:" next to the add button
  4. Click on the checkbox to select "Eclipse Git Team Provider"
  5. Click "Next" to review the items to install
  6. Click "Next"
  7. Click "I accept the terms of the license agreement" after you read the terms
  8. Click "Finish"
Now you should have EGit install. If the Git Repositories doesn't open, follow these steps:
  1. Select "Window" from the main menu
  2. Select "Show View"
  3. Select "Other"
  4. Type "Git"
  5. Select "Git Repositories"
  6. Now the Git Repositories view should be open

Uninstalling

  1. Select "Eclipse" on the top menu
  2. Select "About Eclipse"
  3. Click the "Installation Details"
  4. Select the plugin you want to uninstall
  5. Restart eclipse

Thursday, April 18, 2013

Constants here, constants there, constants everywhere

As I'm writing Mastermind, I notice I reference the size constant a lot. It feels like it's in every class with logic. It makes it a little hard to test because I can't use my unit test to determine if the class will work if I change the size. What else can I do? Well, I can set the size in game and let the game tell all the other classes what the size is. But that means all the classes would have a reference to game, just to know the size. What's a better way to do this? These are the type of questions I hope I can answer by the end of my apprenticeship or at the least know someone who does.

If you ask why I think something is wrong with constant being reference everywhere? I feel if it's hard to test, I'm probably doing it wrong.

Wednesday, April 17, 2013

To debug or not to debug?

After going over the logistics, Eric Meyer, my mentor, told me to write Mastermind in any language that I choose. Considering I took about a week to write Tic Tac Toe, I thought this was going to be a breeze (I was wrong) so I gave myself the challenge of not using the debugger.

I'm not sure if I read this thought from somewhere or if it's my developer instinct. It is not something that I can concretely express or defend yet, but I feel if I write the code and the unit test well, I should immediately know what's wrong with the code. Thus I should never need a debugger to tell me what my code is doing. So on the first day of writing mastermind, I didn't use the debugger at all.  I like to think I did pretty well. I wrote the majority of the code without running anything through the debugger.

My problem came when I tried to figure out how to indicate the color is correct but the position was not. I spent most of my second and third day on this problem. It shouldn't have been that hard, but it was. Whenever I added new code, my tests were failing left and right. I couldn't figure out why. And the debugger devil kept whispering how easy it would be to solved the problem with the debugger. I resisted at first, but by 3PM my mind was too exhausted to fight so I gave up and used the debugger, "just to see why this test case is failing" I said. Well one thing led to another and the next thing I know, I couldn't stop running my app in debug mode.

I admit that was a total fail. I still have that mentality of getting things done. I forgot that I came here to learn, that I should do what I think is a better solution, especially when I don't have a deadline (yet). I should be patience and not rush through anything. What I should have done on day two was look at my tests again, then think, can I really trust my code? Can I really trust my tests? Did I test it well enough that I can confidently say every part of my app work and if there is a problem, I know where it is? The answer of course is no. My code and tests were messy.

I used to write unit tests to test my method. But when I went to a TDD class, the teacher said that I should focus on testing the application's behaviors. It made sense. As outsider, you just want to know if the code works. You shouldn't care about the implementation. So when I wrote my test, I test only public methods. Unfortunately, I don't think this is is working out well. Because I'm testing the class API, I can't guarantee that a certain protected method in the class work. So when I come across a problem like the one I encountered today, I didn't know how to solve it. This could be an indication that I didn't write my code well. That is probably what Eric will say when he sees the code. In fact, he probably won't say well. He'll probably say, this is bad. Do it again.