Monday, May 4, 2009
Begin to Read The Art of Computer Programming
I baugh the book more than one year ago. Due to busy development work and other stuff to learn, I have not read it. Now it is time for me to read this great book. I will write notes when reading it.
Reading of Programming Language Pragmatics
After more than a year, I have finally finished reading PLP 2e. It is a wonderful book. Every programmer who want a complete and deep of programming language theory should read it. It teaches you compiler techniques. But unlike the dragon book which is for writing compilers, it teaches you the compiler concepts.
The book is written by Miachael Scott who is academic. I like his writing style, succint and precise. For one sentence of his writing, I often need a page to describe it. After his writing has a academic flavor, it is easy for non-academics to understand.
But there are two problems with this book. Only an instructor using this book can obtain the solutions to the exercises in the book. As a software professional outside of schools, I am not entitled to get these solutions. It is really frustrated if I can't solve one exercise and can't get the solution provided by the author. As a result, I did not do the exercises in the book.
The other problem is that the author often mention some technique in a short sentence. I often need some considerable time to understand the sentence because I am teaching myself.
During the reading of this book, I find some bugs of the book. I have emailed to the author. The author has listed these bugs in the errdata page.
The book is written by Miachael Scott who is academic. I like his writing style, succint and precise. For one sentence of his writing, I often need a page to describe it. After his writing has a academic flavor, it is easy for non-academics to understand.
But there are two problems with this book. Only an instructor using this book can obtain the solutions to the exercises in the book. As a software professional outside of schools, I am not entitled to get these solutions. It is really frustrated if I can't solve one exercise and can't get the solution provided by the author. As a result, I did not do the exercises in the book.
The other problem is that the author often mention some technique in a short sentence. I often need some considerable time to understand the sentence because I am teaching myself.
During the reading of this book, I find some bugs of the book. I have emailed to the author. The author has listed these bugs in the errdata page.
Sunday, May 3, 2009
Seeking in PrintStream
I played with maven today. I found the following output message when maven is downloading something. The xxx changes to indicate the download progress.
I am curious about how this is done. As far as I know, System.out is PrintStream. In PrintStream, there is no method to seek. I searched for the answer on the web. Unfortunately, I can't find the answer. I downloaded the maven source code. After some browsing, I found that printing \r will position the following printings at the beginning of a line. The following Java code shows how it is done.
I think that Javadoc should have documented this kind of usage, which can save developers a lot of time to scratch their heads.
xxx/yyyK
I am curious about how this is done. As far as I know, System.out is PrintStream. In PrintStream, there is no method to seek. I searched for the answer on the web. Unfortunately, I can't find the answer. I downloaded the maven source code. After some browsing, I found that printing \r will position the following printings at the beginning of a line. The following Java code shows how it is done.
import java.io.PrintStream;
public class Print {
public static void main(String[] args) {
PrintStream ps = System.out;
ps.print("100");
sleep2s();
ps.print("\r200");
sleep2s();
ps.print("\r300");
}
private static void sleep2s() {
try {
Thread.sleep(2 * 2000);
} catch (InterruptedException ie) {
throw new RuntimeException(ie);
}
}
}
I think that Javadoc should have documented this kind of usage, which can save developers a lot of time to scratch their heads.
Subscribe to:
Posts (Atom)