The ability to count characters (or words or lines) is incredibly useful – especially if you are working in a text-based scripting environment (like Linux). Having a simple tool to do that would be especially helpful. What would a character-counting tool look like?
# charcount - count characters in standard input
character getc
character c
integer nc
nc = 0
while (getc(c) != EOF)
nc = nc + 1
call putdec(nc, 1)
call putc(NEWLINE)
stop
end
This is Ratfor again. Why don’t we use a real language? (Ahem! Ratfor is a REAL language!) Because by using a simple language like this, we can show how these functions work in a very simple and understandable way. From there, it’s easy enough to convert it to Java or Python or whatever language you want.
So here are some noteworthy points about the code above:
First, we introduce the character data type. What’s the difference between a character and an integer? For the purposes of the book, it’s just a documentation thing. A character has a specific use. It is used to read and write character text data. Integers are used to count things. So just like the NEWLINE is a special name for a specific, system-dependent value, a character is a specific name for a value with a specific purpose.
Next, we call the putdec() function. That is a special function (which we’ll define later) that takes a numeric value as the first parameter, formats it in a character string the size of the second parameter, and outputs it to the “standard output”. It does this by using the putc() function (as we’ll see later). So we’re already taking advantage of the software tools we’ve built already.
Finally we notice that there is a separate call to putc() to write out the NEWLINE character. That seems like a waste. Why would we do that? If we want to write multiple numbers on the same line, we can’t have putdec() inserting newlines. So we keep the function simple and that keeps it flexible. And it all hangs together in such a simple, clever way!
It’s like it was designed to be that way!



There are many skills necessary to be a successful software developer: language skills, mathematics, problem analysis, procedural thinking, patience, among many others. And for an area of specialization there are specific technologies to learn: Javascript, Hibernate, EE4J, etc.
A few weeks ago
Why is it you always find something you’ve lost in the last place you look? Because you don’t need to look for it any more! You already found it! Why would someone continue to seach for something they have already found?
A common concern for developers who want to implement better software development disciplines in their teams is how to convince management to go along with these great ideas. How do we convince management to let us take time to refactor the code? Or practice TDD? Or adopt agile disciplines?