This is an engineering notebook post. It will be of interest primarily to devs.
The js branch contains the new code. I created this branch to fix bugs in the javascript importer, but the changes needed quickly resulted in the massive housekeeping I am about to describe. This housekeeping was greatly aided by the new "hasattr" pattern.
tl;dr: Many switches in methods of the AtFile class were confusing or unnecessary. The new code is now as simple as I can make it. Afaik, there are no more "huh?"s left.
The hasattr patternThe new pattern, described
here, allows
direct communication between code that wants to set a flag and code that uses the flag.
Intervening methods have no knowledge of the communication. In particular, there is no need to pass the flag around. This pattern has been a spectacular success in the two or three places it is used.
The new hasattr pattern seems like the reverse of exception handling. Exceptions pass data
up the calling tree. The new pattern passes data
down the calling tree.
What I did- Removed trialWrite from all methods
except at.writeOneAtAutoNode.
Only linescanner.Importer.trial_write sets this flag, so it's fairly clear from context what is going on.
- Removed perfectImportFlag.
- Replaced forceSentinels by hasattr(at, 'force_sentinels').
- Replaced partialFlag by force.
- Removed all thinFile code from the AtFile write logic.
thinFile still exists in Leo's
read logic, so that Leo can read ancient external files.
- Removed the scriptWrite arg.
The trialWrite, perfectImportFlag, scriptWrite and thinFile switches (in the write logic) were each major "huh?" producers.
CompatibilityEliminating keyword args in the AtFile class has the
potential to break scripts and plugins. Imo, the danger is small,
because scripts are unlikely ever to have used the weird keyword
args. Python will catch errors
provided that you use the following style for all calls to AtFile methods:
at.aMethod(
required_arg1,
required_arg2,
keyword_arg1 = aValue,
keyword_arg2 = aValue,
)
This style ensures that referencing a non-existent keyword arg will generate a Python error. Leo's core uses this style for all calls to AtFile methods.
SummaryFor the first time in a long, long time the AtFile class contains no "huh?"s.
The new clarity in the code is the foundation for @auto work. That work is nearly complete.
I'll merge the js branch into master in a day or three. Imo, the present code is safe to use.
Edward