Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

One can't proceed from the informal to the formal by formal means.


computers / comp.misc / Why Strict YAML Refuses To Do Implicit Typing

SubjectAuthor
* Why Strict YAML Refuses To Do Implicit TypingBen Collver
+* Re: Why Strict YAML Refuses To Do Implicit TypingStefan Ram
|`- Re: Why Strict YAML Refuses To Do Implicit TypingLawrence D'Oliveiro
+- Re: Why Strict YAML Refuses To Do Implicit TypingStefan Ram
`* Re: Why Strict YAML Refuses To Do Implicit TypingBlue-Maned_Hawk
 `- Re: Why Strict YAML Refuses To Do Implicit TypingLawrence D'Oliveiro

1
Why Strict YAML Refuses To Do Implicit Typing

<slrnv2gtfc.icd.bencollver@svadhyaya.localdomain>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=4210&group=comp.misc#4210

  copy link   Newsgroups: comp.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bencollver@tilde.pink (Ben Collver)
Newsgroups: comp.misc
Subject: Why Strict YAML Refuses To Do Implicit Typing
Date: Wed, 24 Apr 2024 03:08:15 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 151
Message-ID: <slrnv2gtfc.icd.bencollver@svadhyaya.localdomain>
Injection-Date: Wed, 24 Apr 2024 05:08:15 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0fae5f753d74169e78d90736c133b40c";
logging-data="2211715"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7EMz0EkZoiTjXDxT2N2LL+Vf/Fonk/IY="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:jtFusiIieKvQxLBaPfO5t6Ww4+8=
 by: Ben Collver - Wed, 24 Apr 2024 03:08 UTC

Why StrictYAML refuses to do implicit typing and so should you
==============================================================
The Norway Problem
------------------
A while back I met an old coworker and he started telling me about
this interesting bug he faced:

"So, we started internationalizing the website by creating a config
file. We added the UK, Ireland, France and Germany at first."

countries:
- GB
- IE
- FR
- DE

"This was all fine. However, one day after a quick configuration
change all hell broke loose. It turned out that while the UK, France
and Germany were all fine, Norway was not..."

"While the website went down and we were losing money we chased down
a number of loose ends until finally finding the root cause."

"If turned out that if feed this configuration file into pyyaml:"

countries:
- GB
- IE
- FR
- DE
- NO

"This is what you got in return:"

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

It snows a lot in False.

When this is fed to code that expects a string of the form 'NO', then
the code will usually break, often with a cryptic error, Typically it
would be a KeyError when trying to use 'False' as a key in a dict
when no such key exists.

It can be "quick fixed" by using quotes - a fix for sure, but kind of
a hack - and by that time the damage is done:

countries:
- GB
- IE
- FR
- DE
- 'NO'

The most tragic aspect of this bug, howevere, is that it is intended
behavior according to the YAML 2.0 specification. The real fix
requires explicitly disregaring the spec - which is why most YAML
parsers have it.

StrictYAML sidesteps this problem by ignoring key parts of the spec,
in an attempt to create a "zero surprises" parser.

Everything is a string by default:

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

String or float?
----------------
Norway is just the tip of the iceberg. The first time this problem
hit me I was maintaining a configuration file of application
versions. I had a file like this initially - which caused no
issues:

python: 3.5.3
postgres: 9.3.0

However, if I changed it very slightly:

python: 3.5.3
postgres: 9.3

I started getting type errors because it was parsed like this:

>>> from ruamel.yaml import load
>>> load(versions) == [{"python": "3.5.3", "postgres": 9.3}]
# oops those *both* should have been strings

Again, this led to type errors in my code. Again, I 'quick fixed' it
with quotes. However, the solution I really wanted was:

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

The world's most buggy name
---------------------------
Christopher Null has a name that is notorious for breaking software
code - airlines, banks, every bug caused by a programmer who didn't
know a type from their elbow has hit him.

YAML, sadly, is no exception:

first name: Christopher
surname: Null

Is it okay if we just call you Christopher None instead?
--------------------------------------------------------
>>> load(name) == {"first name": "Christopher", "surname": None}

With StrictYAML:

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

Type theoretical concerns
-------------------------
Type theory is a popular topic with regards to programming languages,
where a well designed type system is regarded (rightly) as a yoke
that can catch bugs at an early stage of development while poorly
designed type systems provide fertile breeding ground for edge case
bugs.

(it's equally true that extremely strict type systems require a lot
more upfront and the law of diminishing returns applies to type
strictness - a cogent answer to the question "why is so little
software written in haskell?").

A less popular, although equally true idea is the notion that markup
languages like YAML have the same issues with types - as demonstrated
above.

User Experience
---------------
In a way, type systems can be considered both a mathematical concern
and a UX device. In the above case

In the above, and in most cases, implicit typing represents a major
violation of the UX principle of least astonishment.

From: <https://hitchdev.com/strictyaml/why/implicit-typing-removed/>

p.s.

1. There is no YAML 2.0, only 1.0, 1.1, and 1.2.
2. If you just quoted every country, then it wouldn't be a problem.
3. The YAML 1.1 spec does NOT mandate "language independent types"
4. The YAML 1.2 spec solves this problem with "schemas."
<https://yaml.org/spec/1.2/spec.html#id2802346>

Re: Why Strict YAML Refuses To Do Implicit Typing

<HTML-20240424123915@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=4217&group=comp.misc#4217

  copy link   Newsgroups: comp.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.misc
Subject: Re: Why Strict YAML Refuses To Do Implicit Typing
Date: 24 Apr 2024 11:39:56 GMT
Organization: Stefan Ram
Lines: 7
Expires: 1 Feb 2025 11:59:58 GMT
Message-ID: <HTML-20240424123915@ram.dialup.fu-berlin.de>
References: <slrnv2gtfc.icd.bencollver@svadhyaya.localdomain>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de tdC1uFIIYpQ/SCmKz+GGxA5omLJcy5PQ5sgkHaCwYWBXqR
Cancel-Lock: sha1:9XaWA4tkIDM4ThyKF02VIcg9fMI= sha256:PtbhO5InIkZzmrypnHn3Gv3ltrq2avgdv4yXcWiuEq4=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
 by: Stefan Ram - Wed, 24 Apr 2024 11:39 UTC

Ben Collver <bencollver@tilde.pink> wrote or quoted:
>StrictYAML sidesteps this problem by ignoring key parts of the spec,
>in an attempt to create a "zero surprises" parser.

HTML went the opposite way. Back in the day, quotation marks around
attributes were mandatory, no ifs or buts. But nowadays, you can
sometimes skip 'em, depending on what's inside the attribute!

Re: Why Strict YAML Refuses To Do Implicit Typing

<notation-20240424131100@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=4218&group=comp.misc#4218

  copy link   Newsgroups: comp.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.misc
Subject: Re: Why Strict YAML Refuses To Do Implicit Typing
Date: 24 Apr 2024 12:14:22 GMT
Organization: Stefan Ram
Lines: 60
Expires: 1 Feb 2025 11:59:58 GMT
Message-ID: <notation-20240424131100@ram.dialup.fu-berlin.de>
References: <slrnv2gtfc.icd.bencollver@svadhyaya.localdomain>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de q7yZSTE6IsKu9MMcyZ9NtwMaUk78j8ZDxKeDq5z2d/aoBp
Cancel-Lock: sha1:dTHE/i4zpPa0tPPcGy3AxOptG18= sha256:uy9zQlF9gUrSttdoKs8oR2vxpliiSYq+7UUrGWitZDc=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
 by: Stefan Ram - Wed, 24 Apr 2024 12:14 UTC

Ben Collver <bencollver@tilde.pink> wrote or quoted:
>- GB
>- IE
>- FR
>- DE

These days JSON is ubiquitous on the web. In the programming world,
it's Python that rules. Check this out - the following notation is
valid JSON as well as valid Python, and it's so straightforward that
most people could understand it after a bit of training.

{ "countries":
[ "GB",
"IE",
"FR",
"DE" ]}

Here's a script that parses the same string (like it could
have been read from a config file) once as JSON and once
as Python - the result is the same.

Main.py

# This is a script for Python 3.9.

# Prepare that input like it's a string that got read from a file.
input = '''
{ "countries":
[ "GB",
"IE",
"FR",
"DE" ]}
'''[ 1: -1 ]
print( f"input is (without the outer apostrophes):\n'{input}'" )

print( "\nReading input as json:" )
import json
print( json.loads( input ))

print( "\nReading input as Python:" )
import ast
print( ast.literal_eval( input ))

Output

input is (without the outer apostrophes):
'{ "countries":
[ "GB",
"IE",
"FR",
"DE" ]}'

Reading input as json:
{'countries': ['GB', 'IE', 'FR', 'DE']}

Reading input as Python:
{'countries': ['GB', 'IE', 'FR', 'DE']}

So the input got converted into a Python dict, which contains
a Python list, which in turn holds Python strs (strings).

Re: Why Strict YAML Refuses To Do Implicit Typing

<v0c0r3$2ihq5$8@dont-email.me>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=4239&group=comp.misc#4239

  copy link   Newsgroups: comp.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.misc
Subject: Re: Why Strict YAML Refuses To Do Implicit Typing
Date: Wed, 24 Apr 2024 22:24:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <v0c0r3$2ihq5$8@dont-email.me>
References: <slrnv2gtfc.icd.bencollver@svadhyaya.localdomain>
<HTML-20240424123915@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 25 Apr 2024 00:24:36 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="962cdf4b668ef58e236ab9c5f423d5d6";
logging-data="2705221"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18yJGGCDQFIws3i70YW+ihP"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:iCf0p0YP7NETNIZPENGI34REER4=
 by: Lawrence D'Oliv - Wed, 24 Apr 2024 22:24 UTC

On 24 Apr 2024 11:39:56 GMT, Stefan Ram wrote:

> HTML went the opposite way. Back in the day, quotation marks around
> attributes were mandatory, no ifs or buts. But nowadays, you can
> sometimes skip 'em, depending on what's inside the attribute!

HTML was originally an “application” of SGML, and followed its
conventions. Which meant that quotation marks were optional if there was
no confusion.

Nowadays, we put them in as a matter of course.

Omitted closing tags are still with us.

Re: Why Strict YAML Refuses To Do Implicit Typing

<pan$d9566$d8fd69b3$57385fdb$f384b5ae@invalid.invalid>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=4240&group=comp.misc#4240

  copy link   Newsgroups: comp.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!bluemanedhawk.eternal-september.org!.POSTED!not-for-mail
From: bluemanedhawk@invalid.invalid (Blue-Maned_Hawk)
Newsgroups: comp.misc
Subject: Re: Why Strict YAML Refuses To Do Implicit Typing
Date: Thu, 25 Apr 2024 03:43:32 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <pan$d9566$d8fd69b3$57385fdb$f384b5ae@invalid.invalid>
References: <slrnv2gtfc.icd.bencollver@svadhyaya.localdomain>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 25 Apr 2024 05:43:32 +0200 (CEST)
Injection-Info: bluemanedhawk.eternal-september.org; posting-host="53130bda7eb8b4cb86366e3b7f75e7f3";
logging-data="2948172"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19g+a2AyPiZxHG9nlw5rTuZz9jzNTZ8F8Y="
User-Agent: Pan/0.154 (Izium; 517acf4)
Cancel-Lock: sha1:ZHFY0eL0mWICKnKuW0JEjkV0QDY=
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACh0lEQVRYw71Z21bD
MAzzevbfkr4cHjrSXJyL044+MDa6WLEl2SkvkrZ1AbAvXO+bUGSCPYnsuIVGMpm
ZLnjX718GhAKNsp8lON2F9VrhELwIgJlBepkZjA78rVK+FkmNhEJK76UsJlz8+E
rJsjrpYouhLo/SC6qPHgakFOR8wV9+8rCfO/I/oVnmUZUp42/LW2XkLj9TCFNM9
jp5g2EmHZgpYZjCOkYU7sXVogRylJqpdggoFLG1g09Flah/7kErCxzR9HgXPYsq
0glb9cxjIz2Vsk9AmAoCSxECpD713joMKjQqLAtmMqJmXjdVvlMnMQCVITotJd1
z+fh1f1NNo+vuc1KnhWUmY7t03vydTud9BbXCtN3L2PL3bK7JCNG0GHzuZxafyB
fxevCxpm1vrwZltqw6SILCcdoCE6PGQC8wZWDA9Or7Qp5s3lAZezys0nDazs9S9
R0TjwEiksRxLkNPC1NMMWPs1bj0Ei0Yuo+JVtFLuzP1NRJ16qXWN8DhhtmS4PDg
O6mqRxs4bEJrYt087mSIow/1VzW2oFlMQuiuIy/KsUagvhdw6hSjJGlIavbLF8x
j3X47bccLcUSi0dkWh1nUZNhANT1tHKUXrNxNLbd9KPb9wDDVrKwmPQMOPQ1oy6
k5I1DwzDeRJd3jVIhDAUxq3ngzJG4CCkNXZxZVMcjefoK2J0gUY2S3rxz/RuTFx
2zHd9U+obimJXMG4edsk/2j5pTU5G1MmzbRLxkfq5EiT1GGsidvMGzi+1goGb2l
GCrN+nGnV8xj3q3JLRDVPL96vUc7Z4aJ3TN1mVqWAMJMfG+Jxh6TQqP+92iZkCU
xtglds1AB6r0aiSHKcnFck+p/c/0CbacFLQcajGcAAAAASUVORK5CYII=
X-Face: Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronuku
pokaiwhenuakitanatahu
 by: Blue-Maned_Hawk - Thu, 25 Apr 2024 03:43 UTC

Datatypes are a social construct.

--
Blue-Maned_Hawk│shortens to Hawk│/blu.mɛin.dʰak/│he/him/his/himself/Mr.
blue-maned_hawk.srht.site
It's amazing to see how poorly it's possible to do this.

Re: Why Strict YAML Refuses To Do Implicit Typing

<v0cm74$2qh6b$1@dont-email.me>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=4241&group=comp.misc#4241

  copy link   Newsgroups: comp.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.misc
Subject: Re: Why Strict YAML Refuses To Do Implicit Typing
Date: Thu, 25 Apr 2024 04:29:24 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 5
Message-ID: <v0cm74$2qh6b$1@dont-email.me>
References: <slrnv2gtfc.icd.bencollver@svadhyaya.localdomain>
<pan$d9566$d8fd69b3$57385fdb$f384b5ae@invalid.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 25 Apr 2024 06:29:24 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="962cdf4b668ef58e236ab9c5f423d5d6";
logging-data="2966731"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180LkHrlNnkVX/feLyvG6jH"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:H7SrYmSe3BWAR9vp0R268JSC+p4=
 by: Lawrence D'Oliv - Thu, 25 Apr 2024 04:29 UTC

On Thu, 25 Apr 2024 03:43:32 -0000 (UTC), Blue-Maned_Hawk wrote:

> Datatypes are a social construct.

Is that interpretation inherited, or constructed?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor