$\newcommand{\defeq}{\mathrel{\mathop:}=}$

## 2007/08/19

### Hello World in CWEB

My comments after finishing the first CWEB program: it's truly fun. The feeling of writing, or rather, composing a program is quite different from my old approach(es). Still I think it takes time (which means lots of practice) to get accustomed to and make full use of CWEB. And before I can master Chinese typesetting in TeX and perhaps modify the source of CWEB, programming under CWEB is going to improve my technical English writing, for sure. Also I may be able to pick up vim and make this time, possibly along with other "old-fashioned" tools.

CWEB source:

@i c++lib.w

\def\CWEB{{\tt CWEB}}
\font\eighttt=cmtt8
\def\title{Hello World in {\eighttt CWEB}}
\def\topofcontents{\null\vfill
\centerline{\titlefont Hello World in {\ttitlefont CWEB}}
\vfill}

@* Hello World. This is my first \CWEB\ program in \CPLUSPLUS/, starting from
the classical hello, world''. The program is actually too trivial to be
written in \CWEB. In fact, writing it in \CWEB\ may have unnecessarily
increased its complexity. Anyway, the structure of the entire program is as
follows.

@c

int main() {
@<say hello, world''@>;
}

@ We need only one header for this simple program, namely {\tt <iostream>} for
writing the string hello, world'' to the terminal. We do not give a |using|
directive for namespace |std| as customarily done in very small programs since
this is going to save some typing (in the code).

#include <iostream>

@ The central part is the only one statement that outputs the string hello,
world''. The format of the string (all letters in lowercase, a comma as the
only punctuation, etc.) is kept loyal to Kernighan and Ritchie's {\sl The C
Programming Language}.

@<say...@>=
std::cout << "hello, world" << std::endl;

@* Comments. My comments after finishing the first \CWEB\ program: it's truly
fun. The feeling of writing, or rather, {\it composing} a program is quite
different from my old approach(es). Still I think it takes time (which means
lots of practice) to get accustomed to and make full use of \CWEB. And before
I can master Chinese typesetting in \TeX\ and perhaps modify the source of
\CWEB, programming under \CWEB\ is going to improve my technical English
writing, for sure. Also I may be able to pick up {\tt vim} and {\tt make} this
time, possibly along with other old-fashioned'' tools.


--