Tag Archives: method

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.


http://youtu.be/2OSAhYUacCc  đến lúc thả diều rồi

Hope every one have a good time this weekend.

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){
		    log.info(e.getMessage(), 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().

What to do when the computer go crazy

Last week I go to see a trouble laptop of a friend. There are two problems: the DVD drive doesn’t play, and she can’t use Microsoft Office to edit documents. Those things was just fine before re-installing Windows, so I don’t think it’s a hardware-related problem; if yes, a visit to professional repair service is needed.

I tackled the second one first: re-installing Microsoft Office. An error pops out: can’t un-installing MS Office Home & Student. Fine, a search in Google: “can’t uninstall MS Office student home” solve it.

The first one is more trickier. Checking drivers: no problem. Inserting disk: nothing happen. I detect no abnormal symptom, except the additional “DVD Region” on the device manager was pointing to US. Try changing it, the disk shout that an “appropriate region disk” is required. So I… Google again :)

I got some relevant results, just like the first case, but this time it can’t be sure what cause the problem. My only guess is that the “DVD region” might be responsible. Walking through lots of proposed solutions yield no good result.

I gave up at that time. After home, I re-think and find out that my methods depends too much in finding how people solve similar problems. It may not work for a brand new problem, as the solution doesn’t actually arise from the problem itself. I’ll put a short list of my thinking here – hope this list saves someone a little time. On the other hand, if anyone have a propose to improve the methods, I’m more than pleased to discuss it :)

1) What’s strange with the computer? Is there any new software just installed? Is Windows re-installed? Is there any abnormal symptom or configuration?

2) Googling: in my experience, searching in English yield more good results than in native language (Vietnamese). The more you specify the problem, the better the results you get.

3) Ask on supporting forum: there are plenty of them out there. I prefer asking in English global forum like superuser, but any native technical forums is also good.

4) Consider re-installing Windows/Linux/Mac (your operating system). This solution is better if you prepared a Ghost of your system or keeping the original install disk. Otherwise, finding drivers might become a painful task.

5) Ask the experts.

Fighting with the Black Box

Recently I had the opportunity to work with OpenSocial, an rather famous alternative for Facebook Platform. To make long story short, I have a difficult time: the API standard document is fairly good, but it depends on third-party implementations. The troubles arise from here: the OpenSocial implementation of the site is incomplete and have some non-standard parts. I was stuck.

This situation reminds me about many previous cases, in which I must work with a blackbox, with very few documents available. Zend Framework, SocialEngine, Grails… all pre-built system is a big scary Black Box. It’s like a big closed machine: you don’t know what mystery happens inside, but you must depend on it. And in case it’s bad documented, you must figure a way to wade through unexpected results & doubts… Well, I don’t like to say WTF, but it’s really that bad sometime.

On the other hand, it’s just good for not building a thing from scratch. I don’t know how many months it will take if I try to construct something like Grails/ SocialEngine by myself, in case I can live just for doing that. Every programmer once use an API/Framework: nothing new. And all must find a way to ease that pain.

So how to cope with the Blackbox?

First solution is asking senior programmers, who have lots of better experience. I have learn much from Younet seniors in SocialEngine (it have NO bit of document just yet) and just as much about Grails, Java from Evolus seniors. It was a big help when I’m with them – as it still be now.

The second place I look for help is from the community and black-box developing team. Most of this approach happens in cyber space, so I don’t have to worry about disturbing people, but it only works if someone out there know my problem. If the framework/API has a fair community, there’s a good chance that someone met a similar problem before. Hence I can try a Google search, ask on StackOverflow, or simply throw a question on the supporting mailing lists. But notice: when joining a community, there’s some responsibilities that come along with benefits. You need to figure out what you can do in returning the help you received.

Last but not least, in case you get nothing by previous ways, you can only use your creativity now. In my case, if I understand what causes the problem, I will try coming up with a work-around. If I don’t, I will try to throw several kinds of input into the Big Blackbox. The results will tell something, and changing the input little by little may tell where the problem is.

Above is all of my few heuristics for dealing with a closed system. It’s far from perfect and I am looking for some enhancement, but that’s another story.

Thoughts when viewing “Studying method for University”

This blog post is the English translation of this post. Because the content gets rather lengthly, I decided to split it to two posts.

Last Sunday I had the opportunity to attend the finals of “effective learning methods” by the Cultural Organizations of Student. Though observing time was short, I feel very interesting with the creation of participating teams. From the professional journals-like reports, to intelligent and witty answers on stage, all showed that participants have a very strong grasp of their learning methods.

The competition wraps up with the winning of team “Dai Nang No”(Great Advance) from the Open University. The remaining teams also gained valuable lessons and lots of fun. However, when the game was over, I feel a little anxious. Student Culture House held the contest to stir the improvement of student learning. But is it really effective?

For a long time, the press has prompted many to complain that their new students are not guided, some was shocked transferring into the university environment. But I’m not sure that hundreds of students sat in the auditorium of the competition, how many percent can apply the methods presented today.

Why do I say that?

Frankly, the “learning method” itself is not the matters of saying and remembering. Learning method is not knowledge.

Knowledge is something static, unchanging, can be recorded on paper. Methods, by contrast, are dynamic knowledge. You can’t learn it by heart, you can write it to papers in case of forgetting. It’s the matter of practice.

Just like learning martial arts, no one can learn by reading or watch others perform. Learners themselves need to practice, so feel each move, each piece of the new technique can be applied. To study a “method”, a learner must apply it, experiment it, flip back & forth his/her problems. Then he can adjust the method to suit the circumstances and character style.

Let’s talk about the most simple: writing letters. 90% of the letters were written by hand, but Nguyen Ngoc Ky, and many other disabled people do by foot. On learning, some people learn best alone, others prefer learning in libraries. Each method has advantages and disadvantages, depending on who all practiced.

So the question here is: How to apply effectively new studying techniques?
In my opinion,  students should note the following when adopting a new method:

  1. The learning methods are merely tools, not a universal key. There’s no silver bullet.
  2. Set a Goal. It can be simple like: I will learn 1 hours at 6 am everyday for a week. Goal itself has the ability to create motivation. This can be considered as the most important thing, help the learner orientation “on track” to overcome obstacles in the learning process.
  3. Notice habits & personal characteristics. Habits form actions, actions form destiny. Choose and form your desired habits, it’s a great asset.
  4. Discipline, autonomy of learners. At begin, it’s hard. As soon as it become a habit, it’s easy. Learn to make your habit.
  5. Review and self-regulation: nothing can be perfect at first try. Do it again and again, improve minor things in every circulation. At last, things change :)
  6. Group learning: not a big deal. It’s great to learn new things from different people.