Thursday, May 28, 2015

Practical Object Oriented Design in Ruby Book Review

Rating : 3 out of 5 stars.

Things I liked:

1. The discussion of how messages form the basis for a good design and she classified what type of tests should be written in each case.

2. How TDD does not magically create design and how to apply good design principles as you code.

3. Writing contract tests to avoid problems due to mock abuse.

4. Guidelines for public interface.

Things I did not like:

1. Lot of fluff during the discussions. It is better to move them to her blog and make the book concise.

2. The cure is worse than the disease. Using template methods to avoid calling super.

3. Using toy examples in Bicyle domain is annoying.

4. She talks about coupling without covering the basics of coupling.

Content Review

Her Suggestion: 

Hide the variables, even from the class that defines them, by wrapping them in methods.

My Thoughts: 

#1 : If the class is small and has single purpose, this is not required. You can avoid the downside of exposing data and avoid the risk of name changes.

#2 : Her example of RevealingReferences class is an example for Data Coupling. The example of isolating knowledge of the data structure is an example of Localized Change.

Understanding Dependencies

#3. Coupling to a concrete class name. Coupling to a message name. Knowing the parameters and it's order is an example of Parameter Coupling.

#4. She probably forgot to mention in the section on Writing Loosely Coupled Code, 'If a class has too many arguments then it is likely that it violates Single Purpose Principle.

#5. Minimizing context is about providing a service.

#6. The diagram 4.7 is about raising the level of abstraction. There can be many ways to prepare for a trip. This flexibility allows reuse in different contexts.

#7. Things that change at different rates change for different reasons.

Some nuggets I liked in the book:

Nugget #1 : If you think of a class as having a single purpose, then the things it does are what it allows it to fulfill that purpose.

Nugget #2 : Public methods should read like a description of responsibilities. The public interface is a contract that articulates the responsibilities of your class.

Nugget #3 : Seeking Context Independence. The best possible situation is for an object to be completely independent of its context. An object that could collaborate with others without knowing who they are or what they do.

Find out what is running on a given port


1. Find out what is running on a given port

$sudo lsof -i :4567
Password:

COMMAND   PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ruby    86461 zepho    9u  IPv6 0xffffff803ac28f80      0t0  TCP localhost:tram (LISTEN)
ruby    86461 zepho   10u  IPv4 0xffffff8022e51c00      0t0  TCP localhost:tram (LISTEN)
ruby    86461 zepho   11u  IPv6 0xffffff802197bac0      0t0  TCP localhost:tram (LISTEN)

2. Check what process is running with that process id.

$ ps aux | grep 86461
zepho          86461   0.0  0.1  2492352  18280 s005  T     4:59PM   0:00.31 ruby hello.rb
zepho          91001   0.0  0.0  2434892    460 s005  R+    8:37PM   0:00.00 grep 86461

3. Kill that mother fucker like this:

$ kill -9 86461


Top 6 Ruby Links for the week May 21, 2015

1. Best Post of the Week : The Ruby Community: The Next Version
2. Most Useful Library of the Week : An intelligent pure Ruby WHOIS client and parser.
3. A good Alternative to Nokogiri 
4. How to Write Faster Ruby
5. Dynamic Site as fast as a Static Generated One with Raptor : Interesting article. I would do not do it. I don't need a dynamic site mixed with static static, if I need a static site, I use Python to deploy it to GAE. Essential TDD Tutorial site is deployed this way.
6. Rails 5 - Much Faster Collection Rendering

Wednesday, May 27, 2015

Setting Up Port Forwarding in VirtualBox

1) If the VM is running, stop it.

2) To forward from port 3001 on the host to port 3000 on the guest, run the following command on the host.
$ VBoxManage modifyvm "Ubuntu" --natpf1 "webrick,tcp,,3001,,3000"

3) To delete the port forwarding run:

VBoxManage modifyvm "Ubuntu" --natpf1 delete "webrick"

4) Now you can go to http://localhost:3001 on your host to hit webrick running on your VM.

The page loads very slow. Is there any way to speed it up?

Tuesday, May 19, 2015

** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000

Running mongodb in Mac OS 10.10.3 can give that warning. If this warning is ignored, it will lead to problems. In the same terminal,run :
$ulimit -n 1024

$ mongod --config /usr/local/etc/mongod.conf

Thursday, May 07, 2015

MOPED: Could not resolve IP for: xyz:27017 runtime: n/a

       Could not connect to a primary node for replica set #]>

     Moped::Errors::ConnectionFailure:

The following error can happen if the xyz is not localhost. If you are running the mongo on localhost on your machine, change the mongoid.yml file to point to localhost. This will fix the problem.