Trial-and-error programming

⌚Time: 2026-03-02 20:54:00

👨‍💻Author: Jack Ge

When I use Lua to generate static websites, I encounter many issues with the generated HTML files. The most complex problem is handling relative paths. This is because generating a static website involves many path relationships: page navigation paths, target folder paths, data folder paths, paths without extensions, paths with just filenames, JSON file paths, and encoding conversions. There are many such paths and also many variables involved.

And I am not someone who has good Lua scripting habits. I have never studied Lua either. I just use its convenient features and file operations to generate HTML static pages.

Because the code for generating HTML looks messy, similar to this:


html:write("<div class=\"card-header\">\n")
html:write("<div class=\"card-date\">\n")
html:write("<i class=\"far fa-calendar-alt\"></i>\n")
html:write("<span>"..obj.created_time.."</span>\n")
html:write("</div>\n")
html:write("<div class=\"card-length\">")

It is almost impossible to write correct code in one go. The generated HTML pages are either unusable or have functional errors, and my approach is trial and error.

I just randomly fill in content or variables that feel about right. Then I run the script directly. After that, I check the HTML page to see what it has become. Then I come back to make modifications.

This method works very well. I can only create this kind of Lua script through trial-and-error programming.

In short, trial-and-error programming is suitable for chaotic and complex systems. When a system is so chaotic that it cannot be fully reasoned out in the mind, the brain's working memory will be overloaded. Trial-and-error is equivalent to treating the test results as an extended brain, letting the computer execute, and the person only needs to observe the results.