public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Austin S. Hemmelgarn" <ahferroin7@gmail.com>
To: "Tomasz Kłoczko" <kloczko.tomasz@gmail.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: test if a subvolume is a snapshot?
Date: Mon, 11 Sep 2017 08:44:35 -0400	[thread overview]
Message-ID: <0aec5bfd-fe7b-c87f-4905-f5093bb39ce6@gmail.com> (raw)
In-Reply-To: <CABB28Cxf42y7DfHQ-WK381qyEZsQ4Coe3g_=WfFeN5MgGYmVaQ@mail.gmail.com>

On 2017-09-08 16:54, Tomasz Kłoczko wrote:
> On 8 September 2017 at 20:06, Austin S. Hemmelgarn <ahferroin7@gmail.com> wrote:
> [..]
>>> If you don't like awk you can use jq, sed, perl, python, ruby or
>>> whatever you have/like/want.
>>
>> And which command is more readable?  Something like the above, or:
>> btrfs device stats --format=json /
> 
> How many people you know who are communicating in json or using comma
> separated lines of text?
Directly between people?  Probably none other than CS students and 
developers.  JSON is one of the few reliably unambiguous ways of 
representing tables of data in a language agnostic manner while still 
having them be easily machine parseable (and in fact, many programming 
languages use a similar format for defining tables).

Indirectly between people?  Tens of millions at least.  At minimum, 
almost everyone who uses social media is using JSON.

When dealing with administering a computer?  No idea, but at least as 
many people as use LVM and a number of widely used web application 
frameworks (and web applications built from them).  There is quite a lot 
of software that uses JSON files for configuration because it's easy to 
parse and also pretty trivial for most people to understand (and allows 
for certain particularly useful things that the INI format doesn't).

> Maybe it is not obvious but such interface is not for the humans.
But the code communicating using those formats _is_ for humans.  One of 
the most basic rules of software development is to write code that is 
easily maintainable, which in turn means easily readable.  My comment on 
readability was not about the output, but about the means of generating 
that output, which humans (more specifically, programmers) _do_ care about.

Put slightly differently, here's a comparison of getting info about 
device error counters in Python with and without JSON support in 
btrfs-progs:

Without JSON support (and without any error handling:
```
import subprocess

raw = subprocess.check_output([
           '/sbin/btrfs',
           'device',
           'stats',
           '/'
       ])
raw = stats.splitlines()
stats = dict()
for i in range(0, len(raw)):
     line = raw[i].split()
     value = int(line[1])
     device = line[0].split('.')[0].lstrip('[').rstrip(']')
     counter = line[0].split('.')[1]
     if not device in stats.keys():
         stats[device] = dict()
     stats[device][counter] = value
```

With JSON support in btrfs-progs (and also without error handling):
```
import subprocess
import json

raw = subprocess.check_output([
           '/sbin/btrfs',
           'device',
           'stats',
           '--format=json',
           '/'
       ])
stats = json.loads(raw)
```

Notice that the second form is exponentially easier to follow (assuming 
you already know that json.loads() parses a string as JSON, but if 
you're working with Python you probably already know that), and will 
probably run faster too.

  reply	other threads:[~2017-09-11 12:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-08  8:54 test if a subvolume is a snapshot? Ulli Horlacher
2017-09-08 11:37 ` Peter Grandi
2017-09-08 13:10 ` David Sterba
2017-09-08 15:25   ` Tomasz Kłoczko
2017-09-08 15:38     ` Hugo Mills
2017-09-08 16:12       ` Tomasz Kłoczko
2017-09-08 16:24         ` Hugo Mills
2017-09-08 16:39       ` David Sterba
2017-09-08 18:09         ` Tomasz Kłoczko
2017-09-08 18:44           ` David Sterba
2017-09-08 19:06           ` Austin S. Hemmelgarn
2017-09-08 20:54             ` Tomasz Kłoczko
2017-09-11 12:44               ` Austin S. Hemmelgarn [this message]
2017-09-08 16:27     ` David Sterba
2017-09-08 18:41   ` Ulli Horlacher
2017-09-08 18:53     ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0aec5bfd-fe7b-c87f-4905-f5093bb39ce6@gmail.com \
    --to=ahferroin7@gmail.com \
    --cc=kloczko.tomasz@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox