Ben Chuanlong Du's Blog

And let it direct your passion with reason.

Java Programming Style

Good Writing Style

  1. It is recommend to always use {} if even there is only one statement inside it. The reason is that you never know whether you are going to add more statements into it or not. And it will make the code more readable.

  2. Feel free to declare the …

Pointers in C++

Pointers

  1. No pointer, no polymorphism.

  2. C/C++ is notorious for raw pointers. While pointers can boost up the speed of programs, it invites a trillion chances for making mistakes. You should avoid using raw pointers, instead, consider using unique_ptr, shared_ptr and weak_ptr. They are almost as efficient as raw pointers …

Write Portable C++ Code

  1. Addresses on 64 and 32 OS are different, so you have to be careful when your program have to deal with address. For example, if you take the difference of two pointers/iterators, you should type std::ptrdiff_t (which is essentially a singed integer type). Using an arbitrary integer type …

Automated Verizon Phone Bill (Continued)

I have switched to the "Share Everything" plan of Verizon two weeks ago, and I got a little complex bill this month due to people leaving and joining my family plan. My ruby program for parsing phone bill still works well. It is actually surprising smarter than I thought on …

String in C++11

  1. auto s = "abcd" creats const char * not string, so use auto with caution.

  2. Since a string in C++ is an array of chars, you can operate it like an array. For example, you can use range-based for loop and so on.

  3. It is recommended that you use std::string in …

Define Operator in R

One thing I do not like R is that operations on String in R are not as convenient as in other programming langauges such as Java, Python and Ruby. In these 3 programming languages, you can simply use + to concatenate strings while in R you have to use the function …