[Info-vax] XML, JSON and YAML, was: Re: Security, support and VMS, was: Re: A new VMS?
Simon Clubley
clubley at remove_me.eisner.decus.org-Earth.UFP
Wed May 5 13:39:51 EDT 2021
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:
>>>
>>> You do not write much Python do you?
>>
>> I write quite a bit of Python. I also dislike how whitespace is used
>> in Python as well.
>
> >> 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.)
>>>
>>> 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!". :-)
Simon.
--
Simon Clubley, clubley at remove_me.eisner.decus.org-Earth.UFP
Walking destinations on a map are further away than they appear.
More information about the Info-vax
mailing list