Re: Streamlined application/script development [Re: coding an Application in perl]

Chapman Flack <[email protected]> Tue, 12 Sep 2017 13:06:25 -0400
Newsgroups gmane.comp.archivers.amanda.devel
Message-ID <[email protected]>
On 09/12/2017 07:58 AM, Jean-Louis Martineau wrote:
> For read_local_state and write_local_state,
> 
> Why do not simply use Data::Dumper to write the data and eval to parse

That would work, and I have written things in Python that use repr
to write and ast.literal_eval to parse. I like that Python provides
an explicitly limited literal_eval - I am not as comfortable with
slurping up a file I think should be data and throwing full eval()
at it. As a practical matter, if the state files always live somewhere
only Amanda can write them, the exploit risk should be minimal or
at least no-worse-than-various-other-things, but I am happier to bar it
outright.

I also think it's worthwhile to have the application author give
some specification of what should be in the state, and do at least
a little bit of automated validation. It helps the application author
have more confidence in early testing that the stuff is as expected,
and gives others reading the code an easy place to look and see
what information is carried in the state.

If JSON or XML libraries were in core and supported JSON or XML schemas,
I would probably have gone that way. A Getopt::Long spec is less
flexible than JSON Schema or XML Schema, but it is enough to cover
simple numbers and strings, and has the advantage of being familiar
already to an application author (who has to know it for application
arguments already), where another schema language could be something
else to learn.

-Chap