Monthly Archives: April 2011

Having fun with Groovy syntax

Sometimes programming can be quite fun enough. Take a look at the following code:

package fun.groovy

class Template {
  String template;

  def setTemplateGreen() {
    template = "Green"

  def setTemplateBlue() {
    template = "Blue"

  def showTemplate() {
    return template

Above is a class in Groovy language. It looks not different to a normal java class, doesn’t it? Ok, Groovy roots from Java, and it seems the only difference is that Groovy doesn’t have any semi-colon. Is it just that?

But the surprise lies silently in how one can use the method:

def color = "Blue"

def template = new Template()

template.('setTemplate' + color)()

Try running it with groovyConsole and have fun :)

Start at StackOverflow: Writing good question


** Vietnamese: Bài viết trình bày về những khó khăn khi bắt đầu tham gia cộng đồng StackOverflow, cùng một số mẹo có thể sẽ có ích cho người mới. **

Several months ago, I have written a native language post about Stack Overflow(SO), the current largest Q&A expertise sites for programmers. In short, the site’s goal is helping software developers find solutions and learn new things about all kinds of technology. It can also be known as a “knowledge pool” of programming. But from a user’s view, it’s more about sharing knowledge and earning trust.
The success of SO can be reasoned by its unique “reputation” model, which evaluate member contribution not by number of posts but by community responses. But this model also create obstacles that a newcomer must overcome if he/she wants to be a part of this community.

Problem of a new-comer

The fact is that, when starting, you only have the tiny cute “1″ reputation point. At this time, you only have two things to do: ask or answer. Fine, it’s the basic utilities of the site. If you want to go further and unlock more interesting functions, you must give back to the community by providing good posts. But the funny journey just begin: not any post you provide will get an up-vote(1) from other users. On the other hand, your poor question may likely get down-vote(2), which means throwing away your hard-work.

But there’s good news: as long as the new user know how to post good question, it’s not too hard to get enough reputation(15 points) for a start. The list of tips includes:

  1. Ask relevant questions: this is not only most basic rule, but also the most popular mistake. For a short explanation: SO is a QA site for questions that can be answered, which means no subjective questions or poll may survive here. A post like “which programming language you like most?” will get closed in few minutes, usually along with dozens of down-vote to the creator.
  2. Prove that you tried solving the problem: simple enough, no one will help you if you don’t help yourself first. Don’t ask question whose answer appears as the first result with a simple Google keyword. In short: search the answer first, only ask if you can’t find the appropriate result. A short summarization about your efforts is welcome: it saves others time for trying the way you already did and make the problem clearer.If you’d like to know, describe your problem in detail will benefits the users have the same problem with you. Doing good for others will be never a bad idea ;)
  3. Provide detailed information: like above, it’s necessary for others to understand your problem.
  4. Attach code: code is self-explanation. Specially if your English is not very good, posting code will help others understand your question better. But remember only posting the “relevant code”, which closely associated to the problem. No one will happily look through your 500 line HTML code to give you the answer ^^And the last thing: use the code tag to format your code. This snippet works very well for most of the programming language.
  5. Be open & polite: this is about communication. Treat people the same as you want people treat you.
That’s all :)

(1) & (2): up-vote & down-vote. When a SO user reach 15 reputation points, he/she can evaluate any other user’s post by up-vote or down-vote it. With each up-vote received, the owner of the post receive some reputation points as the prize. On the opposite, if the post is down-voted, the owner will lost some points as well.

Flock is gone. How about Rockmelt?

/** Vietnamese: sau hơn 5 năm, trình duyệt mạng xã hội Flock đã chấm dứt hoạt động. **/

Flock is gone.

Support for Flock browsers will be discontinued as of April 26th, 2011. We would like to thank our loyal users around the world for their support, and we encourage the Flock community to migrate in the coming weeks to one of the recommended web browsers listed below.

Though I haven’t use it recently, to me it’s a loss. Flock once be a product with great idea and good implementation.

It’s a simple fact. In our industry, when a start-up stop their stream of new ideas and innovation (specially after sold themselves up for a bigger company), it ceases.

Now with only Rockmelt in the social browser game, I actually put the question how it will become.

Personally, I love the competence. I meet Flock first with an ‘Oh’ then Rockmelt with a bigger “Ah”. Flock impress me for its simplicity and comforts, while Rockmelt proves itself for its creativity and unique design. Both are quite good.

Now without the opponent, how Rockmelt is going to do to re-invent itself?

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.

Dollar sign($) and the ReplaceAll Gotchas

/* Vietnamese summarization: String.replaceAll() là một hàm tiện dụng của Java, nhưng do cách đặt tên lại dễ bị hiểu nhầm tác dụng với String.replace(). Bài viết trình bày sự khác biệt giữa hai hàm này qua một trường hợp nhầm lẫn ngớ ngẩn của người viết. */

Today I got a “big” mistake, which take a fairly long time to solve. It’s a problem related to String.replaceAll() function of Java. The experience is so hot that I want to share it immediately.

Here’s the simplified problem: I need to construct a template for sending Email. The web application will take the template and insert user information into it. This task is performed by replacing some placeholder by user true information, for example:

Template: {USER_NAME}‘s hometown is {USER_COUNTRY}

Sending content: Long‘s hometown is Vietnam.

Usually, content = template.replaceAll(“{USER_NAME}”,username); is enough. It works well in most cases, but problem occurs when username contains some special characters, specifically, the dollar signs ($).

I know the “$” must have been interpreted different by Regex, so I try to escape the character. My first thought is that replacing “$” by “$”, but no matter how many “”, “QE” or “String.quote()” I put in, replaceAll still refuse to work.

I do a quick search on Google, and find this post. The writer once had the same problem but find no answer, so he decided to go for a quick fix. Temporarily, I accept the proposed solution.

But when asking the seniors about the solution, he tells me that there’s one thing I missed at the beginning: in Java6, ReplaceAll is for regex-replacement , in my case, I can use String.replace() instead!

In short, replaceAll() when you use Regex, if not, a String.replace() is enough.

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.

Dilbert & Programmer jokes

Some simple jokes for morning. Enjoy! :)

A Software Engineer, a Hardware Engineer and a Departmental Manager were on their way to a meeting. They were driving down a steep mountain road when suddenly the brakes on their car failed. The car careened almost out of control down the road, bouncing off the crash barriers, until it miraculously ground to a halt scraping along the mountainside. The car’s occupants, shaken but unhurt, now had a problem: they were stuck halfway down a mountain in a car with no brakes. What were they to do?

“I know,” said the Departmental Manager, “Let’s have a meeting, propose a Vision, formulate a Mission Statement, define some Goals, and by a process of Continuous Improvement find a solution to the Critical Problems, and we can be on our way.”

“No, no,” said the Hardware Engineer, “That will take far too long, and besides, that method has never worked before. I’ve got my Swiss Army knife with me, and in no time at all I can strip down the car’s braking system, isolate the fault, fix it, and we can be on our way.”

“Well,” said the Software Engineer, “Before we do anything, I think we should push the car back up the road and try to reproduce the case.”

A guy is standing on the corner of the street smoking one cigarette after another. A lady walking by notices him and says
“Hey, don’t you know that those things can kill you? I mean, didn’t you see the giant warning on the box?!”
“That’s OK” says the guy, puffing casually “I’m a computer programmer”
“So? What’s that got to do with anything?”
“We don’t care about warnings. We only care about errors.”

If you put a million monkeys at a million keyboards, one of them will eventually write a Java program.

The rest of them will write Perl programs.

And Dilbert:

Dealing with negativity – an incomplete post

Recently, some of my friends often complain about their stress, lonely feelings, worse mood… In short, they feel bad. It’s like spurring ink fluid into a water glass. So I decide to write something for my friends.

About a year ago, I share their same feelings. Graduating from university with not so-high grade, but I’m seriously lacking belief about my ability. I choose to work – not stay at school for learning higher – for the fact that I don’t like studying theories anymore. But I also don’t know if I can work well – I was born an earth-worm and my all family hope that I would become a professor, PhD… But I failed them.

I also failed someone I’m very caring about.

When thing happens, it happen. After all events, I suddenly realize that I fail myself. I fail to protect the one I love for my inability, for the fact that I haven’t trained myself facing difficulties, and lacking of preparation. I said to myself: things can’t be like this any longer. I must get back to shape as soon as possible. The spirit come back.

Well, if someone is in my case, maybe he will be a lot stronger and get back faster. Whatever.

I just need to know what do I live for.

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.

Về “Thách Thức” – cuộc thi học thuật dành cho sinh viên Công nghệ thông tin Tp. Hồ Chí Minh

** This post is written in Vietnamese only **

Thách Thức

Thách Thức là một cuộc thi học thuật thường niên được tổ chức bởi khoa Công nghệ thông tin, Đại học Khoa học Tự Nhiên, TP. Hồ Chí Minh. Được tổ chức lần đầu vào năm 2000, Thách Thức dần dần đã thu hút được số lượng đông đảo sinh viên từ các trường đại học trong địa bàn thành phố.

Mỗi trận đấu của Thách thức có 3 đội tham gia, chia thành nhiều phần thi nhỏ. Nhìn chung, các phần thi kiểm tra 3 mặt kĩ năng của sinh viên:

  1. Kiến thức tổng quan IT: các kiến thức nền tảng cơ bản về mạng máy tính, ngôn ngữ lập trình, thuật toán…
  2. Kĩ năng lập trình – thuật toán: đây là kĩ năng cơ bản được tập trung rèn luyện ở môi trường đại học. Trong cuộc thi, kĩ năng này chủ yếu được kiểm tra ở vòng thi lập trình. Luật chơi: Thành viên của mỗi đội sẽ hợp sức cùng giải một bài toán mà ban tổ chức đưa ra. Điều đặc biệt của phần thi này là ở chỗ: thời gian hội ý của mỗi đội bị giới hạn, và sau đó thành viên của các đội phải luân phiên thay nhau lập trình (mỗi thành viên chỉ có khoảng một phút để lập trình trên máy tính, sau đó phải nhường chỗ cho thành viên khác)
  3. Kĩ năng phối hợp đồng đội: ngoài phần thi lập trình tiếp sức, một phần thi khác cũng đòi hỏi sự phối hợp nhóm cao là “Nối mạng toàn cầu”.

    Luật chơi
    : mỗi đội sẽ phải chia làm 2 nhóm, nhóm truyền tin sẽ nhận một đoạn mật mã dưới dạng chuỗi bit. Sau đó nhóm truyền tin phải dùng các động tác để truyền tin cho nhóm giải mã. Nhóm giải mã dùng khóa được cung cấp giải mã tin rồi ghi ra kết quả, nộp về cho ban tổ chức. 

    Luật chơi nhìn có vẻ đơn giản, nhưng thật sự đây là một phần thi mang tính “thách thức” nhất. Do thời gian rất hạn chế, nên các đội phải phát huy tính sáng tạo của mình: làm sao cho truyền tin nhanh nhất, giải mã đúng nhất. Trong số 27 đội lọt vào chung kết, thường chỉ có 3, 4 đội có khả năng giải mã kịp thời gian; nhưng tính chính xác lại là một vấn đề khác :)

“Thách Thức” có thể tốt hơn?

Theo suy nghĩ cá nhân, tôi nghĩ “Thách thức” sẽ đầy đủ và phong phú hơn nếu thêm vào những phần chơi bổ trợ cho những kĩ năng sau:

Kĩ năng giải quyết bài toán mở:

Thách Thức có một phần thi gọi là Robot tìm đường. Mỗi đội sẽ điều khiển một Robot trên bàn cờ, cố gắng tìm cách làm sao để ăn được nhiều “quà” nhất. Phần thi sẽ kết thúc nếu có một đội về đến đích.

Tôi tự nghĩ, không biết sẽ thế nào nếu ta cho phép các đội lập trình cho robot đi, thay vì điều khiển bằng tay? Ý tưởng thi đấu các chương trình không mới, nhưng có lẽ sẽ làm cuộc thì thú vị hơn.

EDIT: Xin lỗi về việc chậm cập nhất thông tin: phần thi đấu Robot tìm đường đã thay đổi, từ Thách thức 2011 các đội sẽ viết code để điều khiển robot :)

Kĩ năng hiểu và vận dụng code “có sẵn”:

Khi đi làm, thường xảy ra trường hợp lập trình viên phải đọc hiểu code của người khác, sau đó sửa chữa, bảo trì và bổ sung tính năng mới. Tôi nghĩ sẽ rất tốt nếu Thách thức có một phần thi tương đương như vậy: cho một chương trình lớn đã chạy, tìm cách sửa chữa sao cho đáp ứng được yêu cầu thay đổi của “khách hàng” đề ra.

Tôi nghĩ phần thi này sẽ thiết thực và thú vị hơn phần thi “giải mã tiếp sức”, vốn thường là dạng “đánh đố” cú pháp ngôn ngữ C.

Chiều ngày hôm nay, 02/04/2011, Thách Thức 2011 sẽ chính thức khởi động ở Giảng đường I, Đại học Khoa học Tự Nhiên với trận đấu đầu tiên giữa ba đội: Vietchallenge, Zeros và BK 09. Nếu bạn là dân CNTT thì đừng nên bỏ qua cơ hội này: ngoài những vòng thi gay cấn, ban tổ chức còn thường dành ra những câu hỏi thú vị và những món quà cho khán giả.