# ali

## Book Review: Program Development in Java

In Uncategorized on February 23, 2010 at 9:00 pm

Title: Program Development in Java

Author: Barbara Liskov, John Guttag

Year: 2001

I read this book because of Barbara Liskov. I first heard of Liskov via the Liskov substitution principle (also see 1 2). The book has a very academic flavor: there is discussion of a representation invariant, the meaning of subtypes, and the Alloy specification language is used, along with a novel notation for depicting dependencies between modules.

## Proof for the summation formula S(n)=n*(n+1)/2

In Uncategorized on February 5, 2010 at 5:20 pm

I was explaining to a co-worker how supposed worked out the formula and illustrating my simple proof. I tried to look it up online, but didn’t find it.

So, here it is:

 1 2 … N = $\sum_{1}^{N}N$ N N-1 … 1 = $\sum_{1}^{N}N$ N+1 N+1 … N+1 = $N*(N+1)$

Thus

$\sum_{1}^{N}N + \sum_{1}^{N}N = N*(N+1)$
$2\sum_{1}^{N}N = N*(N+1)$
$\sum_{1}^{N}N = N*(N+1)/2$

For a better explanation, see this PDF.

## Same binary, every build

In Uncategorized on February 4, 2010 at 11:47 pm

Wouldn’t it be nice if you did a make today and a make a week from now, and if nothing had changed, you got the same binaries? This is quite useful when trying to reproduce old firmware images.

I set out trying to carry out this task:

• Replace all references to the current date (__DATE__) with references to the last modification time of the file from your revision control system (CVS $Date$).
• Pass the --user=0 and --group=0 arguments to tar so that the same user is listed for every build.
• Use touch before running tar or gzip to likewise set the modification date of any binaries. I have a small C program that will go through a tar file and “fix” the modification dates.

I’m still working on a program to have the e2fs UUID be the MD5 or such of the contained binaries. I’m not sure I want to go ahead with this, it’s something I ran into quickly when trying to reproduce a file system image bit-for-bit.

## Why ECC is necessary

In Uncategorized on February 4, 2010 at 11:16 pm

After spending a few hours trying to debug why a certain program would crash. It turns out that the memory on this particular system is bad.

It’s bad in such a way that Linux boots up, init runs, most of our startup succeeds, yet the first program with a large memory footprint fails.

Here are some successive runs of md5sum:

2ed0de72c3bcbb7c882588781fbff676 flash-3002-1.sh.gz
292ea7da110c63d0014f2d1f804ed3c8 flash-3002-1.sh.gz

While dmesg shows that:

ERROR DDR0 ECC: 3 Single bit corrections, 1 Double bit errors
DDR0 ECC:       Failing dimm:   0
DDR0 ECC:       Failing rank:   1
DDR0 ECC:       Failing bank:   1
DDR0 ECC:       Failing row:    0x3123
DDR0 ECC:       Failing column: 0xee0

## Patch for the Meschach C library

In Uncategorized on February 4, 2010 at 11:06 pm

I had some old code sitting around for polynomial regressions. A colleague wanted some sample code for curve fitting. However, I must
have compiled it a long time ago, as it wasn’t linking any more.

I went back and fixed up version 12a of the Meschach library. My changes were all autoconf related.

You may find the patch at:

http://github.com/im/snippets/blob/master/patches/mesch12b.patch

## Comparison of build systems

In Uncategorized on February 4, 2010 at 11:05 pm

Some time ago I went looking for build systems. Currently we use
GNU Make and our make files have become unwieldy.

I remember reading an article comparing different build systems and going through the alternatives one-by-one.

Here’s what I looked at:

### Jam

Jam is a make alternative developed by Perforce Software.

Not chosen because:

• The last release was in 2003
• It seems very C/C++ specific
• No community (BTS, forums, public repository)

### CMake

CMake is a build-system generator. It will generate project files for Visual Studio etc. and also create make files. Note that CMake must be installed on every machine where the build takes place.

I may eventually switch to CMake, as the lesser of all evils.

Not chosen (at the moment) because:

• Complicated
• The scope didn’t seem to fit: I don’t want a build system generator, I want a build system

### Ant

We use Ant for Java. I’ve played enough with Ant to know that I don’t want to use it. To be fair, I could have invested more time learning Ant, but I really, really don’t want to write XML.

Not chosen because:

• Complicated
• XML
• Requires the JVM to run (huge)

### Scons

I played with SCons and Waf a little bit. I gave up on Waf after trying to do a few odd things and not finding any documentation.

SCons was OK. I tried a small project and it seemed to work.

Not chosen because:

• Requires Python to run
• Build files are Python:
• Users have to know Python
• Python can be misused in the build scripts
• I keep hearing that it’s really slow:

### OMake

I like OCaml so I tried OMake. After doing two or three projects, I ended up not using it because:

• Last release in 2007
• Cute output that is difficult to change
• No package for Fedora

I say the project seems dead because:

### Summary

At the moment I’m back to using GNU make after realizing that OMake is dead. I’ll investigate CMake and SCons again. If SCons hasn’t improved (speed wise), then alas, CMake is my only viable alternative.

## WordPress themes that support tables

In Uncategorized on February 1, 2010 at 11:04 pm

Alas I had to switch from MistyLook. Surprisingly, many of the top themes don’t support tables: Cutline, Freshy, Blix etc.

I had two requirements: a light theme, with a right sidebar.

Table viewed in MistyLook

I looked at the CSS, but I couldn’t find anything wrong. It was a choice between a theme, and displaying tables. I choose to switch themes.

## Cardinal, Ordinal, and Nominal numbers in software engineering

In Uncategorized on February 1, 2010 at 9:15 pm

I have two hands. I was the second person to arrive in the morning. My employee ID is 2.

Cardinal numbers are used for counting.

Ordinal numbers are used for ordering items.

Nominal numbers name things.

Even in regular prose we distinguish between cardinal and ordinal numbers.

Number Operations Supported
Ordinal Comparison
Nominal

The only language that I know of where I could easily restrict operations on numbers is Ada. I don’t like Ada. I think that’s because we misused Ada at work. All cardinal numbers were new types, and explicit coercions were strewn throughout the code base.

For instance, the work philosophy would have me create:

1. Type Fan_Count to count the number of fans in a system (range 1..10).
2. Type Fan_Index to index into an array of fans (range 1..10).
3. Type Fan_Controller_Count to count the number of fan controllers (range 1..10).
4. Type Fan_Controller_Index to index into an array of fan controllers (range 1..10).

We never created a Fan_Identifier type.

Now, the problems with the above were:

• What if I can’t communicate with any of the fans? I can’t represent 0 fans.
• I want to count the fans in two chassis. All of a sudden I overflowed the bounds of Fan_Count. Likewise with Fan_Controller_Count.
• I want to count the total number of fans and fan controllers in a chassis. I need to cast both to an integer.
• I want to look up some fault code depending on the number of fans, or fan controllers that have failed on a system. I needed two arrays containing exactly the same information, or I needed a cast.

Over time I came to believe that we should use natural numbers (Natural) for counting.

These days I program in the C programming language and I have the opposite problem. I wish for some type checking. Most C code conflates the index of something, with the count of something, or the index of something, with the identity of something.

1. Other operations such as multiplication and division may be supported.