The Norway Problem

Some time wait on I met an frail coworker and he started telling me about this
appealing worm he confronted:

“So, we started internationalizing the fetch online page by creating a config
file. We added the UK, Ireland, France and Germany first and predominant.”

- GB
- IE
- FR
- DE

“This used to be all magnificent. Alternatively, one day after a rapid configuration swap
all hell broke loose. It grew to modified into out that while the UK, France and
Germany hang been all magnificent, Norway used to be not…”

“Whereas the fetch online page went down and we hang been shedding money we chased down
a alternative of loose ends except within the raze finding the root space off.”

“If grew to modified into out that if feed this configuration file into

- GB
- IE
- FR
- DE
- NO

“Right here’s what you bought in return:”

>>> from pyyaml import load
>>> load(the_configuration)
{'nations':  ['GB', 'IE', 'FR', 'DE', False]}

It snows a lot in Unfaithful.

When right here is fed to code that expects a string of the form ‘NO’,
then the code will in overall damage, normally with a cryptic error,
In most cases it can well even be a KeyError when attempting to make expend of ‘Unfaithful’
as a key in a dict when no such key exists.

It’ll even be “quick mounted” by the expend of quotes – a repair for clear, but
roughly a hack – and by that time the harm is performed:

- GB
- IE
- FR
- DE
- 'NO'

Primarily the most tragic element of this worm, howevere, is that it is
meant behavior in accordance with the YAML 2.0 specification.
The valid repair requires explicitly disregaring the spec – which
is why most YAML parsers hang it.

StrictYAML sidesteps this exertion by ignoring key components of the
spec, in an strive to rating a “zero surprises” parser.

All the pieces is a string by default:

>>> from strictyaml import load
>>> load(the_configuration).information
{'nations':  ['GB', 'IE', 'FR', 'DE', 'NO']}

String or waft?

Norway is correct the tip of the iceberg. The fundamental time this exertion hit me
I was conserving a configuration file of utility versions. I had
a file like this within the origin – which ended in no components:

python:  3.5.3
postgres:  9.3.0

Alternatively, if I modified it very reasonably:

python:  3.5.3
postgres:  9.3

I started getting form errors because it used to be parsed like this:

>>> from ruamel.yaml import load
>>> load(versions) == [{"python": "3.5.3", "postgres": 9.3}]    # oops these *bothcan also simply aloof hang been strings

But again, this ended in form errors in my code. But again, I ‘quick mounted’ it with quotes.
Alternatively, the resolution I in actuality mandatory used to be:

>>> from strictyaml import load
>>> load(versions) == [{"python": "3.5.3", "postgres": "9.3"}]    # that's better

The realm’s most buggy establish

Christopher Null has a establish that is
infamous for breaking contrivance code – airways, banks, every worm ended in
by a programmer who didn’t know a form from their elbow has hit him.

YAML, sadly, isn’t any exception:

first establish:  Christopher
surname:  Null
# Is it good enough if we correct name you Christopher None as a replace?
>>> load(establish) == {"first establish":  "Christopher", "surname":  None}

With StrictYAML:

>>> from strictyaml import load
>>> load(establish) == {"first establish":  "Christopher", "surname":  "Null"}

Form theoretical considerations

Form theory is a preferred topic in the case of programming languages,
the place a properly designed form system is regarded (rightly) as a yoke that
can make a choice bugs at an early stage of pattern while poorly
designed form programs provide fertile breeding floor for edge case

(it’s equally correct that extraordinarily strict form programs require lots
extra upfront and the laws of diminishing returns applies to form
strictness – a cogent answer to the query “why is so microscopic
contrivance written in haskell?“).

A less standard, though equally correct thought is the concept that markup
languages like YAML hang the identical components with kinds – as demonstrated

Client Trip

In a technique, form programs will even be thought about both a mathematical relate
and a UX contrivance. Within the above case

Within the above, and typically, implicit typing represents a fundamental violation
of the UX thought of least astonishment.

Read More

Recent Content