juan_gandhi: (Default)
Сегодня на работе сюрприз. Пришлось мне в XmlObject  вставлять другие XmlObjects, как children. И вот вдруг обнаружил - коли ты его куда-то вставляешь, то у него имя изменяется! Вставь в два объекта - ну соответственно.

Нет, ну я думал, что эта эпоха идиотов давно прошла, лет 10 назад. Ан нет. Они все там же.
juan_gandhi: (VP)
  def questionHTML(i: Int, q: String) =
    <span>
      <h3>Question {i+1}</h3>{q}
      <br/><br/><br/><br/><br/><br/>
  </span>

  def variantHTML(v: List[String]) =
    <p style="page-break-after:always;">
      <h1><center>{title}</center></h1>
      {v.zipWithIndex map {case(q,j) => questionHTML(j,q)}}
    </p>

  def html(variants: List[List[String]]) = {
    <html><body>{
      variants map variantHTML
    }</body></html>
  }
juan_gandhi: (VP)
So, if this is the data format exclusively for machines, why not use ASN.1 instead? Pretty compact. Or protobuffers, and the like.

No, the advantage of JSON is that a) it's readable; b) it's executable (but everybody's afraid to execute it).

Parsing JSON the way data are written as literals in JavaScript is not harder than interpreting JavaScript. Which is fast. So we could add comments, quoteless names, hanging commas, multiline string literals. It's not a big deal.

The disadvantage is that a bunch of dumb software would not understand it. But the software is already dumb. I remember pinging Crockford when I found his implementation of JSON has some kind of error, forgot what.

It's not a big deal to start understanding more.

What JSON is definitely not good for is storing data and searching data by the key. Any hierarchical structure is not good. To store, data should be flattened.

Now properties.

People use JSON (good, readable), YAML (good, readable), XML (stupid, unreadable, traditional), HOCON (better than YAML, readable).

Of course configs, written by humans, should better be in HOCON.
But JSON is definitely read by humans; and pretty often written by humans, too. So why not give more freedom to the people? Gradually, of course.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

September 2025

S M T W T F S
 1 2345 6
78 9 10 111213
14151617181920
21222324252627
282930    

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 11th, 2025 04:37 pm
Powered by Dreamwidth Studios