Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: An Idiot's Guide to YAML

by perrin (Chancellor)
on Jun 08, 2007 at 20:39 UTC ( [id://620088]=note: print w/replies, xml ) Need Help??


in reply to An Idiot's Guide to YAML

Given that you were able to write a 100% working config in perl immediately and the one in YAML took longer than you care to admit, I wonder why you bothered to use YAML. Is there someone who has to edit this that will be put off by a perl config but not by a YAML one?

Replies are listed 'Best First'.
Re^2: An Idiot's Guide to YAML
by scorpio17 (Canon) on Jun 08, 2007 at 21:02 UTC
    Why bother? Good question! Most likely no one will use this but me. Like I said before, I had read about YAML and thought that it was cool. I wanted to learn something new. It should NOT have taken any longer to write than any other config reader. Maybe I'm the only one who ever had this problem? I did find a lot of hits when I googled for it... I think the root of the problem was a) I'm used to using other config file readers, and they all load based on filename, not file contents; b) after a quick scan of the docs, I thought I knew what I was doing; c) the error message I got led me off in the wrong direction.

    I'm fairly new to perlmonks and haven't made many contributions, and thought someone might appreciate the examples.

      Oh, don't get me wrong. Your post is very welcome, and we're glad to have you here. I was mostly interested in what your motivation was because I personally find YAML kind of pointless. It looks a lot harder to work with than most of the other config choices to me. Nevertheless, it seems to be very popular in certain camps.
        I don't understand the problems that people have with YAML. I have thousands of lines of YAML config files, all produced by hand, and the only problem I ever had was using an editor that added a tab rather than four spaces.

        The whitespace for me is a bonus, rather than a limitation - it makes it easy to read and thus easy to scan through.

        For XML, you really need an XML editor - it is good for portability because it is well supported, but for maintaining config data by hand, for me, nothing beats YAML

        clint

        Because it beats XML :)
      Appreciate!
Re^2: An Idiot's Guide to YAML
by doom (Deacon) on Jun 09, 2007 at 08:16 UTC
    How was he supposed to know it was going to take him a long time to do it in YAML? A lot of people (inlcluding me) talk up YAML config-file solutions as being relatively simple.

    Most programming tasks have a large indeterminancy about how long they'll take -- even the simple ones (like this) sometimes run into some odd hang-up (that leave you feeling like an idiot for spending a day on something that was supposed to take five minutes).

      Sure, he couldn't know he would hit this problem. I wondered what problem he was trying to solve by switching to YAML.
Re^2: An Idiot's Guide to YAML
by clinton (Priest) on Sep 04, 2007 at 09:16 UTC
    It seems that the problem he had was not with the YAML config, but with reading the documentation. However, in answer to your question about why I would bother to use YAML, let me give you an example.

    In my current project, I have a large amount of config, stored in a directory tree containing 59 separate YAML files, for ease of management.

    I loaded and merged (with Config::Loader) all of this data, and then printed it out to two separate files, one with YAML::Syck and one with Data::Dumper. Both were set to use two spaces as an indent.

    YAML Perl Perl > YAML ------------------------------------ Lines 3279 4150 27% Size 85 kB 139 kB 63% Size (no spaces) 49 kB 66 kB 35%
    While some would argue that the last measure is irrelevant, because YAML requires white space, I would say that it IS relevant because, to be legible and maintainable, Perl also needs white space. Instead those numbers are a measure of the extra punctuation that is needed to represent your data - the more punctuation, the less visible is the stuff that actually matters.

    In practice, I've added a lot of extra white space and comment lines etc, so that my actual config is 3350 lines and 105kB - still a good deal smaller than a compact Perl version. And the extra stuff is either unobtrusive (whitespace) or obviously not part of the actual data (comments). I would assume a similar growth in size if I were to do the same thing in Perl.

    People complain about how difficult it is to edit YAML by hand, a sentiment I do not understand at all. The format is simple and easy to read. This example covers 95% of my configuration needs:

    scalar: value array: - element 1 - element 2 - element 3 hash: key1: value1 key2: value2 key3: value3

    There is a lot more you can do with it, such as referencing other data structures within the YAML, recursion, loading Perl code, here docs and multiline scalars. However, most of this is unnecessary for day to day usage.

    The one thing that seem to trip people up is the whitespace. YAML doesn't accept tabs as whitespace and, in my opinion, this is a good thing. How wide is a tab? PBP recommends using spaces for indenting Perl code instead of tabs for this very reason. And quite frankly, if your Perl indentation is a mess, it's going to be difficult to maintain anyway. Clear indentation makes for legibility. Any editor that uses spaces for tabs and can do block indents will handle YAML with ease.

    Opinions about YAML are strongly polarised, and I'm not suggesting that it is the One True Way. But there are a lot of nay-sayers that give YAML a bad reputation, and I think it is undeserved. It is a very flexible, easy, useful and widely available format, and in my opinion, deserves its place at the table.

    Clint

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://620088]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-19 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found