[Info-vax] XML, JSON and YAML, was: Re: Security, support and VMS, was: Re: A new VMS?
Arne Vajhøj
arne at vajhoej.dk
Wed May 5 14:10:10 EDT 2021
On 5/5/2021 1:39 PM, Simon Clubley wrote:
> On 2021-05-05, Arne Vajhøj <arne at vajhoej.dk> wrote:
>> On 5/5/2021 8:43 AM, Simon Clubley wrote:
>>> On 2021-05-04, Arne Vajhøj <arne at vajhoej.dk> wrote:
>>>> Using indentation for structure may seem weird for
>>>> those familiar with begin end and { }, but that does
>>>> not necessarily make it more error prone.
>>>
>>> I am familiar with Wirth style block structure, C style block structure
>>> and whitespace style block structure and the whitespace style block
>>> structure is horrible compared to the first two.
>>
>> Everyone is entitled to like or not like a certain style.
>>
>> But it is an observable fact that millions of people are able
>> to use indentation for structure.
>>
>
> El Reg readers have a different opinion:
>
> https://www.theregister.com/2021/05/04/yaml/
>
> (Skip the article and go straight to the comments if you wish.)
So on the internet there are 40 people that dislike something.
Impressive.
:-)
>>>> all good, but let us see what happens if the indentation of
>>>> the YAML gets messed up.
>>>>
>>>> $ type bad1.yaml
>>>> ab:
>>>> a: 1
>>>> b: 2
>>>> c: 3
>>>> $ java -cp ..:snakeyaml-1_12.jar "yaml.Demo1" bad1.yaml
>>>> java.lang.NullPointerException
>>>> at yaml.Demo1.main(Demo1.java:20)
>>>
>>> A NullPointerException error is _really_ bad here. Ideally, the
>>> syntax should allow some type of a syntax error exception or error
>>> along with the suspected line number causing the error.
>>>
>>> Failing that, even raising an exception saying that you could not find
>>> an expected element (and including the missing element name)
>>> would be vastly better than just throwing a NullPointerException.
>>
>> The point is that YAML is no different than JSON or a VMS logical
>> or most else.
>>
>> If something is not configured the info is missing.
>
> But it should fail in a more controlled manner than it does above.
>
>> If the code explicit test for whether it is present then it can
>> give a user friendly error message.
>
> The user's code should not have to test for this, it should be
> checked in the library itself. The assumption should be that
> the requested element is there when you use get() so it raises
> an exception if it is not.
>
> If it may not be there, then the library should implement something
> like get_optional() which returns null so it can be checked in
> the code. It's also a signal to future maintainers about exactly
> which elements are and are not optional.
>
> Not picking on this library specifically, but when I see something
> where you get java.lang.NullPointerException because a required
> element is missing in a data structure, then that immediately makes
> me go "Yuck, yuck, yuck!". :-)
Now I see what you mean.
But this is not a problem with neither YAML format or
the SnakeYaml library.
This is a problem with the Java Map. Get of non-existing key
returns null instead of throwing an exception.
.NET IDictionary throws a KeyNotFoundException in that case.
In many cases the Java Map way is nice, but not in this case. In this
case it contributes a bit to the infamous billion dollar.
Arne
More information about the Info-vax
mailing list