21
Nov 12

Baselines

So the Coding Horror thread on boards.ie’s Development forum threw up an interesting post:

Originally Posted by COYW

[..] I was told not to comment my code, as it was a “waste of time”. Apparently, that is classic Agile!

A good code doesn’t need comments; a bad code doesn’t need comments either – it needs to be fixed! 

The responses were about as you’d expect, but in the course of answering, I made the following suggestion:

you still have your code from college exercises, right? No? You don’t keep a private archive of old code you wrote? So… how do you tell if you’re improving or getting worse without a baseline?

So I figured I’d take a peek again (last time I looked must have been before Calum was born) and compare it to what I’m writing today.

The really low-level stuff came off pretty well. Some code for programming a GAL chip for 3D2 (where you build a thin client from a 68008 chip and a handful of other chips and what feels like a mile of hand-wrapped wire):

[cc escaped=”true” lang=”asm” lines=”20″]
‘ GAL1 PLDASM
‘ Address Decoding

‘ 3D3 68008 Project

‘ Group 5 :
‘ Mark Dennehy 93369425
‘ Ellen Delaney

‘ This is the address decoding code for the board. It uses one
‘ GAL exclusively and the smallest selectable memory block is
‘ 1024 bytes. The CLK pin is attached to /AS via an inverter.

‘ INPUTS :
‘ A10..A19
‘ BOOT
‘ /AS
‘ OUTPUTS:
‘ EPROM1
‘ RAMROM1
‘ RAM1
‘ RAM2
‘ RAM3
‘ ACIA0
‘ ACIA1
‘ LCD
‘ SYSTEMBYTE
‘ TIMER

device 22v10

‘ Input pin definitions
as = 1
a19 = 2
a18 = 3
a17 = 4
a16 = 5
a15 = 6
a14 = 7
a13 = 8
a12 = 9
a11 = 10
a10 = 11
boot = 13

‘ Power & ground pin definitions
gnd = 12
vcc = 24

‘ Output pin definitions
/eprom1 = 14
/ramrom1 = 15
/ram1 = 16
/ram2 = 17
/acia0 = 18
/acia1 = 19
/lcd = 20
/sysbyte = 21
/timer = 22
/ram3 = 23

macro io a19*a18*a17*a16;
macro rom /a19*/a18*/a17*/a16;

start

‘ EPROM selection : $00000 -> $01FFF and boot
/eprom1 /= /as*/boot*&rom*/a15*/a14*/a13;

‘ RAM_ROM selection : $00000 -> $01FFF and not-boot
‘ $20000 -> $21FFF and boot
/ramrom1 /= /as*boot*&rom*/a15*/a14*/a13 + /as*/boot*/a19*/a18*a17*/a16*/a15*/a14*/a13;

‘ RAM 1 selection : $10000 -> $107FF
/ram1 /= /as*/a19*/a18*/a17*a16*/a15*/a14*/a13*/a12*/a11;

‘ RAM 2 selection : $10800 -> $10FFF
/ram2 /= /as*/a19*/a18*/a17*a16*/a15*/a14*/a13*/a12*a11;

‘ RAM 3 selection : $11000 -> $12FFF
/ram3 /= /as*/a19*/a18*/a17*a16*/a15*/a14*/a13*a12 + /a19*/a18*/a17*a16*/a15*/a14*a13*/a12;

‘ ACIA 0 selection : $F0000
/acia0 /= /as*&io*/a15*/a14*/a13*/a12*/a11*/a10;

‘ ACIA 1 selection : $F0400
/acia1 /= /as*&io*/a15*/a14*/a13*/a12*/a11*a10;

‘ LCD selection : $FE000
/lcd /= /as*&io*a15*a14*a13*/a12*/a11*/a10;

‘ SYSTEM_BYTE selection : $FF000
/sysbyte /= /as*&io*a15*a14*a13*a12*/a11*/a10;

‘ TIMER selection : $F1000
/timer /= /as*&io*/a15*/a14*/a13*a12*/a11*/a10;

end

[/cc]
And the assembler was about readable in most cases:

[cc escaped=”true” lang=”asm” lines=”20″]
;————————————————————
;
; Demonstration PICRAT program.
;
;————————————————————
; REVISION HISTORY :
;
; 13/10/97 First draft, preliminary modularisation
; of code.
;
;————————————————————

ERRORLEVEL 0
PROCESSOR PIC16C74A
LIST b=4
__CONFIG _BODEN_OFF & _CP_OFF & _PWRTE_OFF & _WDT_OFF & _XT_OSC
TITLE “Demonstration PICRAT program”
SUBTITLE “Version 1.00”

include

;————————————————————
; Context Saving registers

CONTEXT UDATA 0x20

int_w RES 1
int_status RES 1
int_pclath RES 1
int_fsr RES 1

CONTEXT2 UDATA 0xa0

int_w2 RES 1 ;Dummy Register

;————————————————————
; Variables used in Main Loop
Main UDATA

tmpChar RES 1

;————————————————————
;
; NAME : RESET_VECTOR
;
; FUNCTION : Executes reset interrupt service routine
;
;————————————————————

RESET_VECTOR CODE 0000
RESET_VECTOR
GLOBAL RESET_VECTOR

PAGESEL reset_isr
goto reset_isr

;——————–ROUTINE SPECIFICATION——————-
;
; NAME : INTERRUPT_VECTOR
;
; FUNCTION : Contect saving, correct ISR selection
;
; NOTES : Saves W, STATUS, PCLATH as per ex.14-1
; in datasheet
;
;————————————————————
; REVISION HISTORY :
;
;————————————————————

INTERRUPT_VECTOR CODE 0004
INTERRUPT_VECTOR
GLOBAL INTERRUPT_VECTOR

EXTERN USART_Tx_isr
EXTERN USART_Rx_isr

;INTERRUPT_VECTOR
;
; Save the W,STATUS,PCLATH and FSR registers,

movwf int_w
swapf STATUS,W
clrf STATUS
movwf int_status
movf PCLATH,W
movwf int_pclath
movf FSR,W
movwf int_fsr

; Check to see what caused the interrupt,
; Byte received ?

BANKSEL PIR1
PAGESEL USART_Rx_isr
btfsc PIR1,RCIF

; Jump to USART Rx ISR

call USART_Rx_isr

; Ready to transmit byte ?

BANKSEL PIR1
PAGESEL USART_Tx_isr
btfsc PIR1,TXIF

; Jump to USART Tx ISR

call USART_Tx_isr

; Unknown interrupt ?
; Jump to exception handler

; PAGESEL Exception
; call Exception

; Restore registers and return from interrupt.

clrf STATUS
movf int_fsr,W
movwf FSR
movf int_pclath,W
movwf PCLATH
swapf int_status,W
movwf STATUS
swapf int_w,F
swapf int_w,W

retfie

;——————–ROUTINE SPECIFICATION——————-
;
; NAME : Exception
;
; FUNCTION : Called when an unhandled interrupt
; condition occours.
;
; NOTES :
;
;————————————————————
; REVISION HISTORY :
;
;————————————————————

;EXCEPTION
; Endless loop

Exception CODE
Exception

goto Exception

;——————–ROUTINE SPECIFICATION——————-
;
; NAME : reset_isr
;
; FUNCTION : Reset Interrupt service routine
; Determines correct action to perform
; on startup.
;
; NOTES :
;
;————————————————————
; REVISION HISTORY :
;
;————————————————————

reset_isr CODE
reset_isr
GLOBAL reset_isr

EXTERN MemoryTest
EXTERN USART_init
EXTERN USART_puts
EXTERN USART_putc
EXTERN USART_hi_msg_tmp
EXTERN USART_lo_msg_tmp
EXTERN Startup_screen
; EXTERN LCD_Initialise
; EXTERN LCD_PutChar
EXTERN USART_getc

PAGESEL MemoryTest
call MemoryTest

PAGESEL USART_init
call USART_init

; PAGESEL LCD_Initialise
; call LCD_Initialise

PAGESEL USART_putc
movlw A’.’
call USART_putc
movlw A’.’
call USART_putc
movlw A’.’
call USART_putc
movlw A’\r’
call USART_putc
movlw A’\n’
call USART_putc

; PAGESEL LCD_PutChar
; movlw A’T’
; call LCD_PutChar
; movlw A’e’
; call LCD_PutChar
; movlw A’s’
; call LCD_PutChar
; movlw A’t’
; call LCD_PutChar

; Enable perihiperal interrupts

BANKSEL INTCON
bsf INTCON,PEIE

; Enable all interrupts
bsf INTCON,GIE

; Print out startup message
PAGESEL USART_puts
movlw high Startup_screen
movwf USART_hi_msg_tmp
movlw low Startup_screen
movwf USART_lo_msg_tmp
call USART_puts

bcf OPTION_REG,7
BANKSEL PORTB
clrf PORTB
BANKSEL TRISB
movlw 0x00
movwf TRISB

BANKSEL PORTD
clrf PORTD
BANKSEL TRISD
movlw 0x7F
movwf TRISD

BANKSEL PORTE
clrf PORTE
BANKSEL TRISE
movlw 0x07
movwf TRISE

PAGESEL MainLoop
call MainLoop

;——————–ROUTINE SPECIFICATION——————-
;
; NAME : MainLoop
;
; FUNCTION : Main Control Interpreter
;
; NOTES : A Finite State Machine
;
;————————————————————
; REVISION HISTORY :
; 9/1/98 First Draft
;————————————————————

MainLoop CODE
MainLoop
GLOBAL MainLoop
EXTERN USART_getc
EXTERN USART_putc
EXTERN AnalogRoot
ExTERN DigitalRoot
EXTERN CounterRoot
EXTERN PWMRoot
EXTERN MotorControlRoot
EXTERN TimerRoot

PAGESEL USART_getc
call USART_getc
BANKSEL tmpChar
movwf tmpChar
PAGESEL MainLoop
movf tmpChar,W
xorlw A’.’
btfss STATUS,Z
goto MainLoop

;————————————————————

ServiceSelect
PAGESEL USART_putc
movlw ‘-‘
call USART_putc
movlw ‘-‘
call USART_putc
movlw ‘\r’
call USART_putc
movlw ‘\n’
call USART_putc

PAGESEL USART_getc
call USART_getc
movwf tmpChar

PAGESEL AnalogRoot
movf tmpChar,W
xorlw A’a’
btfsc STATUS,Z
goto AnalogRoot

PAGESEL DigitalRoot
movf tmpChar,W
xorlw A’d’
btfsc STATUS,Z
goto DigitalRoot

PAGESEL DigitalRoot
movf tmpChar,W
xorlw A’c’
btfsc STATUS,Z
goto CounterRoot

PAGESEL PWMRoot
movf tmpChar,W
xorlw A’p’
btfsc STATUS,Z
goto PWMRoot

PAGESEL MotorControlRoot
movf tmpChar,W
xorlw A’m’
btfsc STATUS,Z
goto MotorControlRoot

PAGESEL TimerRoot
movf tmpChar,W
xorlw A’t’
btfsc STATUS,Z
goto TimerRoot

;————————————————————
; Error

PAGESEL USART_putc
movlw ‘*’
call USART_putc

goto MainLoop

END
[/cc]

Okay, so that’s not quite as good as it could be, but the libraries were better. What about the Java code?

[cc escaped=”true” lang=”java” lines=”20″]
/////////////////////////////////////////////////////////////////////
//
// TACAN – TeleAutonomous Control And Navigation
//
// Mark Dennehy, 93369425
// S.S. C.Eng.
// Final Year Project 1996/7
//
//////////////////////////////////////////////////////////////////////
//
// PolarHistogram.java
// implements the polar histogram
// —————–
// $Date: 1997/04/03 21:49:54 $
// $Revision: 2.0 $
// $State: Stable $
//
//////////////////////////////////////////////////////////////////////

package Tacan.RLC;

import Tacan.util.LogFile;
import Tacan.util.MathUtil;
import java.util.*;
import java.io.*;
import java.awt.event.*;

/**
* The Polar Histogram of the Certainty value grid. This is effectively a
* polar graph of obstacle density.
*
*@author
*@version
*@see Tacan.RLC.CVGrid
*@see java.util.Observer
*@see java.awt.event.ActionListener
**/
class PolarHistogram extends Observable implements Observer, ActionListener
{
private final static double A = 22;
private final static double B = 1;
private final static int maxFreeSectorSize = 18;

private int tmpPH[];
private RLC rlc_;
private int no_of_segments_;
private LogFile log_;
private LogFile data_;
private Vector segment_terms_[];

/**
* The current Polar Histogram values
**/
protected int PH_[];

/**
* The Local Autonomy Control graph values
**/
protected double LAC_[];

/**
* The current maximum value in the Polar Histogram (for normalisation)
**/
protected int PH_max = 0;

/**
* The current maximum value in the Local Autonomy Control graph (for normalisation)
*@see
**/
protected double LAC_max = 0.0;

/**
* The threshold value for deciding what path is free and what is not
**/
protected int PH_threshold = 100;

/**
* The maximum network lag permitted before full local autonomy is granted (in seconds)
**/
public final static double maxNetLag = 10;

/**
* Constructor
*
*@param rlc The Robot Local controller instance associated with this graph
**/
protected PolarHistogram(RLC rlc)
{
rlc_ = rlc;
PH_max = 0;
segment_terms_ = new Vector[rlc.robot_config.PH_RES];
no_of_segments_ = rlc.robot_config.PH_RES;
PH_ = new int[no_of_segments_];
tmpPH = new int[no_of_segments_];
LAC_ = new double[no_of_segments_];
log_ = new LogFile(“Polar.log”);
data_ = new LogFile(“Polar.dat”);

for (int i = 0; i PH_max) ? sum : PH_max;
}
}

public synchronized void LACupdate(int t,int desired_sector)
{
double b = (t LAC_max) ? LAC_[i] : LAC_max;
}
}

public int clearPath(int bearing)
{
int res = (int)360.0/no_of_segments_;
int desired_sector = (int)(bearing/res);
int b;
int l_centre =1;
int l_width = 1;
int r_centre =1;
int r_width = 1;

LACupdate(3,desired_sector);

if ((PH_[desired_sector] * LAC_[desired_sector]) PH_threshold)
{
//Set centre of sector
l_centre = a+(int)(l_width/2);
break;
}
break;
}

//Scan Right
for(int a = no_of_segments_-1; a > (no_of_segments_/2) ; a–)
//Start of first free sector
if ((PH_[(a+desired_sector)%no_of_segments_] * LAC_[(a+desired_sector)%no_of_segments_]) PH_threshold)
{
//Set centre of sector
r_centre = a-(int)(r_width/2);
break;
}
break;
}

//Choose left or right, weighing size of sector with deflection
b = ((l_width/l_centre) > (r_width/(no_of_segments_ – r_centre))) ? l_centre : r_centre ;
b += desired_sector;
b %= no_of_segments_;
b *= res;

return b;
}
}

public String toString()
{
String s = “[ “;
for (int i = 0;iOh dear. That’s very much a curate’s egg. Some parts are okay, but some… well, I wouldn’t give them an okay in a code review session today. Still, I suppose that’s a good thing – remind yourself that you were just not as hot as a teenage coder as you thought you were, and that you’ve gotten better in the interim.

What about the C++ though?

[cc escaped=”true” lang=”cpp” lines=”20″]
/****************************************************************
* *
* TCD Robocup Project 1996/7 *
* Intelligent Agents Group *
* (Artifical Intelligence Group) *
* *
****************************************************************
RCS Block :

$Author: mdennehy $
$Date: 1996/09/07 15:57:18 $
$RCSfile: main.cc,v $
$Revision: 1.6 $
****************************************************************
$Log: main.cc,v $
// Revision 1.6 1996/09/07 15:57:18 mdennehy
// Final version by mdennehy.
// Now knows how to locate itself on the field and
// can determine the error in this measurement.
//
// Revision 1.5 1996/09/04 14:03:22 mdennehy
// Visual and Audio parsing working.
// Minor bug : if more than 5/6 agents connected, Bus errors/segmentation faufollow
//
// Revision 1.4 1996/08/30 17:31:38 mdennehy
// First Working Version
//
// Revision 1.3 1996/08/26 15:10:49 mdennehy
// *** empty log message ***
//
// Revision 1.2 1996/08/24 16:25:08 mdennehy
// Added Threads
//
// Revision 1.1 1996/08/22 14:34:30 mdennehy
// Initial revision
//
****************************************************************/

/***** RCS Program Information *****/
char RCS_revision[]=”$Revision: 1.6 $”;
char RCS_state[]=”$State: Exp $”;

/***** Header Files *****/

#include #include
#include #include
#include
#include
#include
#include

#include
#include
#include
#include
#include
#include
#include
#include

#include “udpif.h”
#include “posdata.h”
#include “communications.h”
#include “dmalloc.h”

/***** Main Comms Socket *****/
UDPSocket comm;

#ifdef DEBUG
/***** Debugging Log file streams *****/
extern ofstream commlog;
extern ofstream datalog;
extern ofstream intsyslog;
#endif

/***** Function prototypes *****/
void usage();
void SignalHandler(int signal, siginfo_t *SignalInfo, void *ContextInfo);

/***** MAIN() *****/
int main(int argc, char **argv)
{
#ifdef DEBUG
print_statistics();
init_debugging_logfiles();
system_check();
intsyslog > s;

// parse returned initialisation message from server
err = sscanf(s,”(init %[lr] %i %[^)]”,side.cstring(),&unum,playmode.cstring());

#ifdef DEBUG
if (err == 3)
{
intsyslog si_code si_uid si_pid si_code == SI_NOINFO)
{
intsyslog si_code)
{
case BUS_ADRALN:
{
intsyslog si_errno si_addr;
intsyslog si_errno si_addr;
intsyslog si_errno si_addr;
intsyslog si_code == SI_NOINFO)
{
intsyslog si_code)
{
case SEGV_MAPERR:
{
intsyslog si_errno si_addr;
intsyslog si_errno si_addr;
intsyslog Erm. Yikes. I did get better though 😀

What about you? Do you check back over long periods to see how your standard of code is actually doing, rather than through the hazy pink-spectacled fog of old memories?


06
Sep 12

WTF phone calls

*ring*

ffs can’t I get any work done… “Hello?”

-“Hello?”
“Yes, hello?”
-“Hello?”

ah wtf is this… “Hello, who is this?”
-“Ah, hello, this is K from Three, how are you?”
“I’m fine, what’s up?”
-“I’m calling from Three and I just need to confirm your security details please, what is your date of birth?”

“Excuse me?”

-“What is your date of birth?”

You’re kidding me… “K, just repeat that to me, would you please?”

-sounding fustrated now “I’m calling from Three. I just need to verify your identity. Could you confirm your security details please, what is your date of birth?”

“K, you’ve called me on my personal phone, and you want me to give you *my* security details? Does that not sound like a really dumb idea to you?”

-“It’s just to verify your identity sir”

How did I wake up in a standup routine? “Thank you K, but I’m not going to be doing that today”

-“I can’t continue with this call then sir”

oh, the loss… “Grand, bye”

Seriously?
Who thinks this is a sane way to try to contact customers?


12
Mar 12

Data for Dads

With biscuit incoming, I’ve been reading quite a bit, as you’d do yourself. Thing is, there are a lot of books on parenting, and not many decent indexes or comparative reviews of the books out there, and so you wind up reading a lot of blurbs and reviews of books to try to figure out which ones you should then go buy and read in full (you can’t read everything, there’s not enough time).

Here’s the question – why is every book on fatherhood given a blurb that says it’s witty, pithy, touching, and “tells you all you need to know”? It’s annoying – I don’t need wit or pith in these books, I don’t want touchy-feely, and as to “tells all you need to know”, if I knew all the things I needed to know about, I wouldn’t need the book, and since I don’t, doesn’t that mean I can’t tell if it really does have all I need to know? Damn blurbs. Should just call them “marketing lies” and get it over with. Harumph.

Where are the books that explain in dry, boring, accurate, technical detail what’s going to happen, what needs to be done, and gives you multiple ways to try to do it? You know. Books for people who need to know the job, the best approach to the job, the tools needed for the job and then to be left get on with it? People who don’t read parenting books for entertainment, but for information? I understand that some people need the emotional support from a book written by a stranger for money, but I’m pretty sure — because I’m a part of it — that there’s a demographic of people with a three-digit IQ, who know their own minds, and who are looking forward to parenthood. These people don’t need handholding, and they’re fairly well able to figure things out. And I don’t mean they’re rocket scientists, though I’d bet good money that there are rocket scientists in the demographic too. I mean that if you can change brake pads safely on your car with the aid of a Haynes manual and then drive it, you can figure out a nappy change without needing wry humour, pithy observations on life, emotional therapy or insight into the universal truths of mankind and puppies. (And the Haynes baby manual is the worst offender, betraying the entire spirit of that line of books).

Trouble is, reading medical journals gives you that data from fairly well-constructed studies that get reviewed by professionals; but they mostly cover medical treatment rather than day-to-day parenting. So you learn that not clamping or cutting the umbilical cord until pulsations cease decreases the odds of anemia in the first few years of the child’s life by a third in return for a higher chance of jaundice (but phototherapy is easy so it’s better not to cut the cord early); and that C-sections may have SIDS implications for subsequent children; and that children delivered prior to week 39 have higher odds of health problems in the first 18 months even though they’re considered perfectly safe and viable today; and that aural canal and temporal artery thermometers are just not as good as rectal thermometers or oral thermometers in pacifiers for neonates with fevers; and other large chunks of useful data with proven sources. But these studies aren’t usually gathered together in a useful format for parents – they’re aimed at health professionals and researchers. And there are precious few studies on more basic aspects of parenting or broader areas; studies are done to expand knowledge which usually means they’re tightly focused on one thing, and usually are out looking at new things, rather than testing older things (though you do still find surprises, so always check pubmed first). And to top all of that, pubmed‘s abstracts are usually free (and are usually all you need to read), but the full text of articles in general aren’t even close to free unless you’re in a college.

What’s needed is a decent book on the mechanics of all of this, not the philosophy. Preferably one whose medical citations are from the JAMA, BMJ, Lancet or New England Journal of Medicine, and based on double-blind clinical trials and peer-reviewed research instead of “My mom always did it this way and I turned out fine. Who needs full use of their left arm anyway?”. Especially since it’s been shown recently that the books that have been printed over the past fifty-odd years don’t actually know what they’re talking about, always dictate to the reader, and go in cycles, with books printed today saying what was printed 10 years ago was precisely the wrong approach, and in 10 years time, you’ll see the same thing printed about today’s books while advocating approaches from 20 years previously. We need to know what the pros and cons of breastfeeding are and where to buy equipment (yes, there’s equipment) and what’s useful and what’s a gimmick and possible approaches if the usual approach doesn’t work so well; rather than to get an ideological earful from La Leche League or the antenatal courses about how breastfeeding is just the best possible thing and we shouldn’t even think about any contingencies; because frankly, they’re pushing an idea and we’re raising a kid and you have to pick one or the other as your top priority and it’s a decision made for you if you’re a parent. Would we like to breastfeed? Yes, we can see from the studies that its the superior method. Will we be able to? We don’t know yet, and if we can’t, we’d like to have a prepared contingency plan that isn’t “let the kid starve while we try to fix the problem”

The ideal book would be localised so that things like vaccination dates and so on can be discussed – and please don’t say “Oh, we couldn’t talk about that, it’d create legal liabilities!”. I mean, use some common sense. If I can get a book showing step-by-step how to change my brakes, and nobody worries about brake failure and plowing through a crowd of pedestrians in 1.5 tons of metal at 60mph killing dozens of people; but a book saying “Get your baby vaccinated at date X” is a liability because Jenny McCarthy can’t pull her head out of her voluminous backside for long enough to get a proper job, then our world is badly broken. Yes, the Public Health Nurses are great and will pass on data about this; but they tell you themselves that there will be conflicting data from them and from the doctors at 6-week checkups (which in themselves are something they only tell you about after baby is born), and reading through their leaflets… well… most of it is good, but look, the food pyramid was discredited quite a while back, and honestly, who wrote the bit that said that breast-fed babies’ poop doesn’t smell? Because I have a few binloads of evidence to the contrary! And when you spot clangers like that, it affects your confidence in the remainder unless you can go to a third party and verify it, and at that point, well, why not go to the third party to start with?

So what is out there?

Guess what, “old media” loses again, and “new media” is right there providing what you need, usually for free. Pubmed, BabyCenter.com, Parenting.com, Dad.ie, Rollercoaster.ie, Boards.ie’s pregnancy and parenting forums and sub-forums, Eumom.ie, Mumsnet.com – all of these have hard data, reviews of equipment by people who’re actually using it, and so on. To be honest, the only book I could recommend anyone buy when all those sources are out there for free, would be Safe Baby-Handling Tips, and that’s only because you need the laughs. Though I wouldn’t throw out Annabel Karmel’s Complete First Year Planner, even if I only kept it for the recipes.