Re: [xsl] How to never make mistakes when coding?

Subject: Re: [xsl] How to never make mistakes when coding?
From: "Jean-Luc Chevillard jeanluc.chevillard@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 1 Mar 2025 17:01:51 -0000
Hello Roger,

have you read Chapter 34 of D.E.Knuth's /Digital Typography/ (1999)?

The title is "The Final Errors of TeX" (chapter written in August 1998)

It refers to an earlier article on "The errors of TeX", written in 1988, and reprinted as Chapter 10 of /Literate Programming/

It might interest you

All the best

-- Jean-Luc (Chevillard)

On 01.03.2025 15:49, Roger L Costello costello@xxxxxxxxx wrote:
Hi Folks,

A few days ago I found a mistake in my code. The input data to my code contained a sequence of records and my code should iterate over all the records after the first record. I wrote this:

<xsl:for-each select="/root/record[position() gt 2">

See the mistake?

I should have written position() ge 2 or position() gt 1

That mistake had been in my code for weeks. It was only a few days ago that I accidentally discovered it.

"How could I have made such a simple, basic mistake? Was it a lapse in attention? I asked myself.

How to avoid making mistakes? Is it even possible?

One part of me thinks, "You are human. Humans make mistakes. It's part of our psychological makeup. Accept that you will always make mistakes. The remedy for mistakes is to find good ways--testing, validation--to identify the mistakes and then fix them."

I don't like that. I'm an optimist--if there's a problem, then there's a solution.

Perhaps if I had extreme discipline, then I could have mistake-free code? Perhaps if I had no mental lapses when coding, then I could have mistake-free code? Perhaps if I adhered rigorously to some programming practice (e.g., literate programming), then I could have mistake-free code?

Perhaps if I had a tool that generates code, then I could have mistake-free code?

Perhaps code that is rooted in algorithms--do step 1, then step 2, then step3, etc.--will always lead to code with mistakes? Perhaps the declarative approach--state what is, not how to do it--is the path to mistake-free code?

Have you thought about these types of questions? What answers did you come up with?

/Roger

Current Thread