Wednesday, December 24, 2014

Using printf in C++ Instead of cout

If you study C++ from textbooks you will see the cout function used to print.  Later you might be surprised to see people using the older printf function from the C programming language within C++ programs.  When I first ran across this practice I asked why the older function was used and I was told that it was more efficient.

It is hard to find supporting evidence for this claim, so here is a link to "In defense of printf" by Kenny Kerr, which has this quote: "...cout has a serious performance problem."  The author presents a chart of performance measurement.

I remember the book Efficient C++: Performance Programming Techniques by Bulka & Mayhew recommending printf over cout, but I have lost my copy of this book and cannot verify my recollection.

So if you see someone using printf in a C++ program, be aware that it is an acceptable practice.  For a student's purposes, cout is fine.

Robert

Saturday, December 20, 2014

Dijkstra at the University of Texas Austin

I was surprised to learn that Edsger Dijkstra had been a Professor Emeritus in the Department of Computer Sciences at The University of Texas at Austin.  I thought of Dijkstra only as a Dutch computer scientist.  UT has a nice tribute to Dr. Dijkstra on the web.  The world famous Dijkstra taught students at U.T.!  Wow.  That tribute article provides a very nice, detailed description of his career and the importance of his ideas.  The university has scanned many of his papers and makes them available online.  His famous article, “Go To statement considered harmful," is available as paper EWD 215: A Case against the GO TO Statement.  It is a short paper, 4 pages plus the cover page.  I recommend it as a short, very readable paper.  His "Notes on Structured Programming" is much longer, but very influential.  The university maintains an archive of Dijkstra's papers.

If you are curious about computer science, I cannot think of a better way to explore the field than to explore Dijkstra's writings.

Robert