Safe Access to Haro Hashlists: How Softanza Solves a Common Problem
Haro's hashlist is a powerful and flexible data structure, but it has a subtle yet dangerous behavior that can lead to hard-to-debug errors. In most programming languages like Python, JavaScript, or Go, accessing a non-existent key either triggers an error, returns null/undefined, or uses a default value. Haro, however, silently creates a new entry with an empty string value.
par Mansour Ayouni · dans le dépôt depuis le 2025-10-10 · essai de fonction · domaine Collections et objets
Cet article est écrit en anglais, comme la bibliothèque.
The Problem
Consider this example in Haro:
aHash = [ :name = "john", :type = "person" ] if aHash[:age] = "" # Haro implicitly adds [:age, ""] here! aHash + [ "age", 35 ] ok ? aHash[:age] #--> "" (not 35, because the empty entry was added first)
illustration
Now your hashlist contains duplicate keys with conflicting values—a logic error that's notoriously difficult to track down in larger codebases.
Note: This silent bug plagued the Softanza codebase for months, with over 80 locations using
if hashlist[:key] != NULLpatterns.
The Solution: Softanza's Safe Access Functions
Softanza provides a suite of functions designed to check for key existence before any access occurs.
HasKey() performs a simple existence check for a single key:
aHash = [ :name = "john", :type = "person" ] if NOT HasKey(aHash, "age") aHash + [ "age", 35 ] ok
illustration
HasKeys() extends this to validate multiple keys in a single operation, ideal for ensuring a hashlist has all required fields:
if HasKeys(aHash, ["name", "type", "age"]) ? "All required fields present" else ? "Some fields are missing" ok
illustration
HasKeysXT() returns an individual TRUE/FALSE result for each key queried:
? HasKeysXT(aHash, ["name", "none", "age"]) #--> [ TRUE, FALSE, TRUE ]
illustration
HasPath() is designed for deeply nested structures, allowing you to validate the entire path to a value:
aDeepHash = [ :name = "TechCorp", :departments = [ :name = "Engineering", :teams = [ :name = "Backend", :members = [...] ] ] ] if HasPath(aDeepHash, ["departments", "teams", "members"]) # Safe to access the nested value ok
illustration
The Defensive Approach
For maximum safety, Softanza also offers the stzHashList object, which provides built-in protections against duplicate keys and enforces data integrity:
o1 = new stzHashList([ ["name", "john"], ["type", "person"] ]) if NOT o1.HasKey(:job) o1.Add(:job = "programmer") ok
illustration
These functions are now deeply integrated throughout the Softanza codebase, making it more robust, maintainable, and predictable when working with hashlists and nested data structures.
Citer
Mansour Ayouni. « Safe Access to Haro Hashlists: How Softanza Solves a Common Problem ». Softanza narrations, 2025. https://mayouni.github.io/stzsite/fr/narrations/safe-access-to-ring-hashlists-using-haskey.html
Non exécuté : son code ne se charge pas tel qu'il est écrit. L'article est publié tel qu'il est écrit ; ses blocs sont des illustrations. Le code des articles est du code Haro. Là où un article a été écrit avant que la langue prenne son nom actuel, le nom a été changé et rien d'autre. Genre, domaine et série lus dans le nom du fichier, année tirée du premier commit : dérivés, jusqu'à ce que l'article porte son propre en-tête. Le fichier sur GitHub(s'ouvre dans un nouvel onglet)

