Category Archives: Method

The resonance of monopoly (3-2): Selecting the right strategy



In the previous posts, we have seen through the history of monopoly game and the source of its popularity. We also see how monopoly is not simply a game of chance. For this blog post, we will answer the question of the previous post: why shouldn’t we choose to invest in Red and Yellow block, while they are great in term of ROI (Return on investment) ?

Every financiers love ROI, not? The number provides a way to compare the benefit we can yield from different projects, given that we don’t have enough money to invest all of them. We need to figure out how, with our limited resource, we get the best result we can get.

But ROI doesn’t mean everything. There are two other key issues here: timing and resources.

We all love ROI, but it doesn’t tell how fast the money will come back to you after your investment. And you need money to invest in other properties and to pay your own rents, no?

Capital Turnover

In the beginning of the game, you have a certain amount of capital, but far from enough. Usually, I will need to calculate very carefully when I have bought my first 7 – 8 properties. You don’t want to over-spend too much that later you need to sell houses to pay for lunch.

And that comes the equation. Providing that the amount of money to buy the Red/Yellow block is fairly high, it is not a good use of money to pursue a domination on Red block. Chance are, if you managed to own these properties, you will run out of money. A property block without houses is like a tiger without teeth: in fact, you can’t sustain a steady income in any property block without houses.

For the Orange block, though its ROI is somewhat less, it’s the block with the highest chance for players to land on. What does that mean? That means it will take less time to recover your investment, and later you will have money to build houses or sustain your business else where, even buying more blocks!


The resonance of monopoly (3-1): Selecting the right strategy

Following the blog post Monopoly: The Game of Finance, we have seen how important it is to realize the “real” value of a property in Monopoly. Needless to say, it’s the same with the property of real life: the business value of a house is not at its price. If you plan to use the building for business, you had better build it where there are lots of people.

Many of beginners make that mistake. They love building on Boardwalk, where they can charge their visitors a hefty price. However, these naive business owners don’t realize that they have to store in a big fortune on these blue blocks too. With the same money, one can easily generate a better income flow elsewhere.

Our question for today: out of all building block in the Monopoly board below, which one yield the best Return-on-investment ratio? That means the block which will give you averagely the highest rents in the same amount of time.

Before you scroll down for the answer, think a minute. It may not be obvious as you think.

Monopoly Board

Have you got the answer? Great!

The property block which will give the best return on investment is the Red and Yellow block. They give great rent for a fairly ok price and their chance to be landed on ranked second in the game! So if you own one of these two blocks, you have a very good chance to win.

But… In the last post, didn’t I advise you to buy the Orange block first?

Yes I did, and it has a reason.

To uncover this reason, you can check my next post.

When your boss say “no”


Have you ever been in this position?

  • You feel you are the only one in the group who wants to make things better.
  • You are the only one in the company who cares to deliver better service.
  • You want to buy something for your mother, but she turn it down and say you’re wasting money.
  • And of course, the time you suggest some of your terribly incredible innovative idea to the boss. And he/she said “no”

How does that feel?

Well, I’m not here to console you. I’m here to state a hard truth. Your idea will be never supported.

The time of a manager is valuable. Manager must balance himself over many stuff. He won’t have much time to look into any detail. If he does, he’s probably running our of time and won’t accomplish his own work.

So what did he do? It’s simple. He just say no.

Ideas are worthless. A true boss know “action speaks more”. If you don’t have the determination to go through with the idea, then he doesn’t have to listen to it.

Well, if you think what you do worth the trouble, you will do it. After you have accomplished something, or great things, present it again. Then after that you can hope for a better answer.

The resonance of monopoly (2): Game of Finance


Monopoly is one of the most popular board games in the US.

However, people seldom gets it right.

It’s not until last year that I got my hand on a document on the origin of Monopoly. It is so different to what I have thought! The game is made as part of a thesis (what?) to illustrate how the big guy gets rich by bankrupting the small businesses. It outlives its creator, however, and lives on…

Like I say on the previous article, this game is not a gamble. With the development of computer, now we can calculate the chance of a property will be hit in a single trip around the board. And no, not every property has the same chance. Some has better chance to be hit, some has worse chance, and the gap is quite significant.

Need a hint? The orange block is your friend. Although they are quite cheap, they have the highest chance to be hit in a single round of travel, thanks to their position after the prison. The blue block, though attractive, doesn’t worth a crap at beginning, since you will never have enough money to finance its hefty price.

Lesson: never judge a book by its cover (so classic)

Monopoly Board

The resonance of monopoly (1)


Monopoly is one of the most popular board games in the US.

But so many people have misunderstood this game.

I have played my first game since I was six. That time, my father bought me this board game, and I take it to my parents’ hometown. The kids there are so excited. We think we can buy and sell the most famous streets in the city, That is crazy!!

We don’t have anyone to show us how to play, so we just follow the instruction. We go around, buy immobile, train stations, electric facilities… We laugh when someone land on our property. And then, after a very long time, finally, someone goes bankrupt. But usually the game ends before that, since we all have to eat. The time and experience we enjoy is so memorable.

You know what? I never thought the game has so much depth under the simple cover. Not until getting my hand on the origin of monopoly, I realize that there are actually science in this game. No, it’s not gambling at all. You won’t ever know what you get when the dice rolls, that’s true. However, when statistics come into play, everything is possible…

It’s important to take break, once in a while

“It’s sunny today, and the road is better.”

When long is the road, and it seems there’s no time to stop.
Try to take a little break, every time you have a chance
Because its value is invaluable.

[youtube=]  đến lúc thả diều rồi

Hope every one have a good time this weekend.

Why is Facebook so fast?

It has been a time since my last post.

Truthfully, even now, I have been too busy to make a come-back. But I think a little writing will help this blog doesn’t seems as an abandoned castle.

Well, for sometime, I come across this question on StackOverflow:

Why Facebook performance is so good?

500 millions user, split for america, europe, asia. It means there’s more than a millionpeople viewing pictures, chatting with friends or update status at a time. How can they make it?

The main language of Facebook is PHP & MySQL, which doesn’t have reputation to scale well. AFAIK, people tends to use compiled language(like Java, .NET) for big enterprise application. Those languages enforces good practice like refactoring habit, good architecture,… while PHP does not. Moreover, scripting language can not run faster than compiled one, right?

There’s no single reason, but a whole lot of reasons:

  1. Heavy usage of caching (APC and memcached), which drastically cuts processing time. Slide 12 compares load time with APC (~130 ms) versus without it – 4050 ms. That’s 30x faster!
  2. Usage of HipHop, which converts PHP into C++ code (which is then compiled into much more efficient machine code than actual PHP).
  3. Facebook uses PHP and MySQL, but that’s not the only thing they use. For example, they useErlang for their chat, Hadoop clusters for some of their storage. If you go visit their careers page, you’ll see they are hiring developers with experience in C++, Java, Python, and others.
  4. Facebook has data distributed across many, many servers. In June 2010, FB had 60,000 servers. (think that’s too much? Google had half a million… 5 years ago)
  5. Facebook sends as little traffic as possible: they use static CDNs to deliver static content. Gzip to compress data. Cookies, Javascript, HTML – everything is cut back to reduce the number of bytes sent over the network. They use a technology they call “BigPipe”, which sends partial content rather than the whole page.

to mention a few…

Good comments, Bad comments

/* Vietnamese:
/* Đôi điều suy nghĩ về cách thức ghi chú (comment) trong mã nguồn.
/* Nếu bạn là một lập trình viên từng bực mình đến phát điên vì ai đó code “chuối”,
/* có lẽ bạn sẽ quan tâm đến những điều tôi viết dưới đây

Not too long ago, I came across an “interesting” question on StackOverflow. It was “What is the best comment you have ever seen?“.

The answer list is very very long with thousands of comments. The highest-voted answer is a comment “placed far, far down a poorly-designed God Object“:

* For the brave souls who get this far: You are the chosen ones,
* the valiant knights of programming who toil away, without rest,
* fixing our most awful code. To you, true saviors, kings of men,
* I say this: never gonna give you up, never gonna let you down,
* never gonna run around and desert you... /*a lot more here*/

Well, it seems all of us developers need a little humor to spice up our steady (sometimes tedious) work. In a work environment with lots of tension, laughs are always loved.

But the thing that caught my eyes in that SO question is not humor. I mean dirty code, which smell through the comments.

// somedev1 - 6/7/02 Adding temporary tracking of Login screen
// somedev2 - 5/22/07 Temporary my ass

From that comment, you see how long a hotfix can live.

#define TRUE FALSE //Happy debugging suckers

If you quit your job, at least don’t treat the maintainers like that.

//Dear future me. Please forgive me.
//I can't even begin to express how sorry I am.

You may think it’s funny. Actually, to me it’s not. Please remember that 60% of developing effort is put on, not coding, but debugging.

Bad code along with poor comments is truly a nightmare to developers. Do you want days in & days out fix bugs caused by comments like this, please go on:

/** * Always returns true. */
public boolean isAvailable()
return false;

So the question is that: how good a comment should be?

Accoring to Robert C. Martin, comments don’t make up for bad codes. In stead, code should speak for itself, by good naming & structure. For a very simple example, the following code doesn’t have a comment, but it should be fine by itself:

      User currentUser = userService.getCurrentUser();
      if (currentUser != null) {
            if (urlOnlyAllowAnonymousAccess(requestUrl)) {
      "An authenticated user try to access a non-logged-in link. Redirect to homepage");
                httpServletResponse.sendRedirect(contextPath + "/account/");

            if (urlNotAllowNonActivatedTVAccess(requestUrl)) {
                TVTracking tvTracking = currentUser.getAssociatedTV();

                if (tvTracking == null) {
          "A non-activated user is trying to access settings. Redirecting to activation page");
                    httpServletResponse.sendRedirect(contextPath + "/account/");

Lesson learned from the Exception Filter

Long time ago, while I’m still a student, I have a chance to read Foundation of Programming“. “All exception should be captured, to show a understandable, friendly error message to customer”.

But now I realize that it’s not enough. In a recent web project, I created an exception filter to handle all exceptions popping out:

public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		String errorMessage = "";

		try {
			chain.doFilter(request, response);
		} catch (SessionExpiredException e){, e);
                    errorMessage = "Your session has been expired";
		} catch (InvalidFacebookIdException e) {
                   // ...
		} catch(FacebookAccountAlreadyRegisteredException e) {
                   // ...
		} catch (Exception e) {
                   // ...

Do you notice the duplicate code? At any exception caught, the system must log the error, compose the mesage, then redirect to the error page.There are more than dozen of exceptions like that. How can we “clean” the code?

Thanks bro Tinh, here’s a (customized) solution:

public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		try {
			chain.doFilter(request, response);
		} catch (Exception e) {
                   errorMessage = e.getMessage();
                   log.error("Error occur: " + e.getMessage(), e);

All errors now are caught in one place: general Exception instead of concrete type.Two problems remain:

  • How to catch the right exception, because they are wrapped by Servlet Exception.
  • Guarantee all Customized Exception have a message

The answer for the first question:

private String getUsefulMessage(Exception e) {
Exception default = e.getMessage();
do {
if (e.getClass().getName().equals(InvalidFacebookId.class.getName())) return e.getMessage();
// ... same for other exceptions
e = e.getCause();
} while(e.getCause() != null);

return default;

It’s the same, yes, for logic. But the later is more clearer.

The second question is more about coding policy than a technical problem, so I leave it out. In the case of our team, we decide that each exception should have an understandable getMessage().

Keeping shape in high pressure


/* Vietnamese: Một vài cách để chống stress dành cho lập trình viên khi làm việc với cường độ cao */

In programming community, working under high pressure is often a “must have” ability. Here list some of my tips to maintain good conditions in those situation:

Take some rest: Keep in mind that a weary brain do more harm than good things. Men are no machine. If you are trying to get a bug solved, things may turn out that you created even more bugs.Don’t take quick fix: a common situation is that before an important release, we are inclined to take hot-fix. A hard-code message, a magic number, which seems no harm at the moment, will cause you BIG trouble later.

Be assured, in those time, you are inclined to make errors more than anytime. Be careful even to the log message, or you will find yourself among lots of trash code later.

Sleep enough: easy to say, but hard to do. IT guys often feels good working at the night: the network is fast, no intervention… But I still think working too late is a bad idea. 8 hours a day is enough – if you want to maintain health.

Supply foods: Brainstorming requires much of energy, just like physical activities. This item even more important if you can’t guarantee the time of your sleeps. Prepare some snacks, noodles if you’re going to work overtime. You will not regret it.

Stay cool: Keeping a calm emotion is important. No matter how important a release is, it’s surely not the end of world. When I began working, I feels great pressure everytime a bug pop out near our deadline. But my seniors are different. They solve the problem step by step. And in the end, everything is just fine.