Skip to content

Instantly share code, notes, and snippets.

@ichensky
Created March 3, 2017 13:59
Show Gist options
  • Save ichensky/d00d851f4c42eb2198708d86c8c9597f to your computer and use it in GitHub Desktop.
Save ichensky/d00d851f4c42eb2198708d86c8c9597f to your computer and use it in GitHub Desktop.
Why xml and json sucks to s-expressions

For ex. we have struct:

// Keeps info about users account in bank
typedef struct account {
   // account number in bank
   int account_number;
   char *first_name;
   char *last_name;
   // balance in bank 
   float balance;
   int cards[5];
} account;

with some data:

account a={100500,"Bob","Marley",999.999,{666,777,888,999,555}};

Let's serialize in ...

... XML

<?xml version="1.0"?>
<!-- Keeps info about users account in bank -->
<account>
<!-- account number in bank -->
<account_number>100500</account_number>
<first_name>"Bob"</first_name>
<last_name>"de Marley"</last_name>
<!-- balance in bank -->
<balance>999.999</balance>
<cards>
  <item>666</item>
  <item>777</item>
  <item>888</item>
  <item>999</item>
  <item>555</item>
<cards>
</account>

PROBLEMS:

* hard find and edit data by hands. 
* a lot of overhead data like close attributes for ex.: </account>
* a lot of overhead data with serialization arrays

or so ...

<?xml version="1.0"?>
<!-- Keeps info about users account in bank -->
<account first_name="Bob" last_name="de Marley">
<!-- account number in bank -->
<account_number>100500</account_number>
<!-- balance in bank -->
<balance>999.999</balance>
<cards>
  <item>666</item>
  <item>777</item>
  <item>888</item>
  <item>999</item>
  <item>555</item>
<cards>
</account>

PROBLEMS:

* hard find and edit data by hands. 
* for variables that appeares in attributes we can't add comments

... JSON

{ 
  "account" : { 
    "account_number":100500, 
    "first_name":"Bob", 
    "last_name":"de Marley", 
    "balance":999.999,
    "cards":[666,777,888,999,555]
    }
}

PROBLEMS:

* hard find and edit data by hands
* easy miss comma ',' at the end of last block
* several ways(standarts) to define keys with or without '"'
* no place to add comments
* different syntaxes for arrays and key-values

... S-EXPRESSION

(account ; Keeps info about users account in bank
 (account_number ; account number in bank
  100500)
 (first_name "Bob") 
 (last_name "de Marley") 
 (balance ; balance in bank
  999.999)
 (cards 666 777 888 999 555))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment