• panda_abyss@lemmy.ca
    link
    fedilink
    arrow-up
    43
    ·
    4 hours ago

    If yaml didn’t have anchors and 8 different white space formats, it’d be a great replacement for this kind of thing.

    But yaml is a mess, and you’d think you could parse it easily, but you can’t.

  • AnyOldName3@lemmy.world
    link
    fedilink
    arrow-up
    22
    arrow-down
    1
    ·
    4 hours ago

    TOML’s design is based on the idea that INI was a good format. This was always going to cause problems, as INI was never good, and never a format. In reality, it was hundreds of different formats people decided to use the same file extension for, all with their own incompatible quirks and rarely any ability to identify which variant you were using and therefore which quirks would need to be worked around.

    The changes in the third panel were inevitable, as people have data with nested structure that they’re going to want to represent, and without significant whitespace, TOML was always going to need some kind of character to delimit nesting.

    • Ephera@lemmy.ml
      link
      fedilink
      English
      arrow-up
      6
      ·
      2 hours ago

      Well, Wikipedia does say:

      The [TOML] project standardizes the implementation of the ubiquitous INI file format (which it has largely supplanted[citation needed]), removing ambiguity from its interpretation.

      https://en.wikipedia.org/wiki/TOML

  • arcine@jlai.lu
    link
    fedilink
    arrow-up
    13
    ·
    3 hours ago

    Nix is the next step in that evolution. It’s basically just JSON that can generate itself !

    • KindaABigDyl@programming.dev
      link
      fedilink
      arrow-up
      6
      ·
      edit-2
      1 hour ago

      It’s basically just JSON that can generate itself !

      You have inspired me.

      I will make JSON with meta-programming

      I will call it DyJSON, i.e. “Dynamic JSON” but pronounced “Die, Jason!”

      It is JSON with meta-programming and the ability to call C functions from libraries

      Example:

      # This is a line comment
      
      # Put your function definitions up here
      (concat str_a str_b: "concat" "my-lib.so") # Import a function through a C ABI
      (make-person first_name last_name email -> { # Define our own generative func
          "name": (concat (concat $first_name " ") $last_name),
          "email": $email
      })
      
      # And then the JSON part which uses them
      [
          (make-person "Jenny" "Craig" "[email protected]"),
          (make-person "Parson" "Brown" null)
      ]
      

      As you can see, it is also a LISP to some degree

      Is there a need for this? A purpose? No. But some things simply should exist

      Thank you for helping bring this language into existence

      • KindaABigDyl@programming.dev
        link
        fedilink
        arrow-up
        2
        ·
        edit-2
        46 minutes ago

        Here is the grammar:

        <json> ::=              <value> | <fn-def> <json>
        <value> ::=             <object> | <array> | <string> | <number> | <bool>
                                | <fn-def> | <fn-app>
                                | "null"
        <object> ::=            "{" [ <member> { "," <member> } ] "}"
        <member> ::=            <string> ":" <value>
        <string> ::=            "\"" { <char> } "\""
        <char> ::=              (ASCII other than "\"", "\\", 0-31, 127-159)
                                | (Unicode other than ASCII)
                                | ( "\\" (
                                    "\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t"
                                    | "u" <hex> <hex> <hex> <hex>
                                )
        <hex> ::=               /A-Fa-f0-9/
        <array> ::=             "[" [ <value> { "," <value> } ] "]"
        <number> ::=            <integer> [ <fraction> ] [ <exponent> ]
        <integer> ::=           "0" | /[1-9]+/ | "-" <integer>
        <fractional> ::=        "." /[0-9]+/
        <exponent> ::=          ("E" | "e") [ "-" | "+" ] /[0-9]+/
        <bool> ::=              "true" | "false"
        <fn-def> ::=            "(" <ident> { <ident> }
                                    ("->" <value> | ":" <string> <string>) ")"
        <ident> ::=             <startc> { <identc> }
        <startc> ::=            /A-Za-z_/ or non-ASCII Unicode
        <identc> ::=            <startc> | /[0-9-]/
        <fn-app> ::=            "(" <ident> { <value> } ")"
        <var> ::=               "$" <ident>
        
  • 🇰 🌀 🇱 🇦 🇳 🇦 🇰 🇮 @pawb.social
    link
    fedilink
    English
    arrow-up
    5
    arrow-down
    1
    ·
    4 hours ago

    Is there any real reason why most progranming languages look more like the 3rd panel and not like the 1st panel? There’s gotta be a reason for all the nesting and indents that has nothing to do with readability since that shit makes it harder to read.

    • Hudell@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      5
      ·
      2 hours ago

      since that shit makes it harder to read

      It makes it harder to read the individual lines, but makes it easier to read them as a group, so you won’t have to read as many lines on your day to day.

    • Brokkr@lemmy.world
      link
      fedilink
      arrow-up
      15
      ·
      4 hours ago

      Because the 3rd panel looks better when you have dozens of physical properties to track. It also makes retrieval easier because you can get all the physical properties at once, instead of having to read every line.

      For an example that small it doesn’t matter, but for something larger it could become a performance benefit.

    • ProfessorScience@lemmy.world
      link
      fedilink
      English
      arrow-up
      12
      ·
      4 hours ago

      I would guess that it has to do with making it easier to parse. The indents won’t matter very much, but the parser sees "physical = " and knows that a property named physical is being defined. What is the value of that property? Well, there’s a “{”, so the value is an object. And the value of that object is everything up until the matching “}”. If you have a structure more like panel 1, then it’s harder for the parser to know when the value of orange.physical is complete. There might be a [orange.physical.texture] section somewhere, for example.

    • 404@lemmy.zip
      link
      fedilink
      English
      arrow-up
      3
      ·
      edit-2
      3 hours ago

      For programming languages that make use of {}, the reason is (almost always) scope.

      Take for instance this:

      for i in 0..10
      do_thing();
      do_other_thing();
      

      compared to this:

      for i in 0..10 {
          do_thing();
      }
      do_other_thing();
      

      The intent of the first one is unclear. In the second one it’s clear you should loop do_thing() and then run do_other_thing() afterwards. The indentation is only for readability in the above though. Logically there would be no difference in writing

      for i in 0..10 { do_thing(); } do_other_thing();
      

      Languages that use indentation and line breaks for scope look more similar to this:

      for i in 0..10:
          do_thing()
      do_other_thing()
      
    • ulterno@programming.dev
      link
      fedilink
      English
      arrow-up
      3
      ·
      edit-2
      3 hours ago

      A good way to feel that for yourself is by programming a little program in Assembly and C.

      Make sure the program needs to loop a bit and perhaps also require some if/ else logic.
      A simple one would be to read a 1000 integers and return the sum.

      In C, you would do something like:

      int MAX = 1000;
      int accumulator = 0;
      int counter = 0;
      while (counter < MAX)
      {
          accumulator = accumulator + value_at_next_memory_location_by_counter;
          counter = counter + 1;
      }
      

      In assembly, you would go (writing pseudo, because I have forgotten most assembly stuff):

      set reg1 = 1000 // For max value
      set accumulator = 0 // just choose a register and consider it an accumulator. older CPUs have a fixed accumulator and you can only operate on that. I am not considering that here
      set reg2 = 0 // For counter
      tag LOOP:
      set flag if true reg2 < reg1
      jump if false -> END
      move from memory location @counter(reg2) to reg3
      add accumulator reg3
      add reg2 1
      goto -> LOOP
      tag END:
      

      I also realised that you could just try using C with goto instead of any loops and would realise similar things, but I’m not in the mood to rewrite my comment.


      In conclusion, it is easier to understand something like BASIC, if you haven’t been introduced to other languages, but these {} structures end up making it easier to catch control flows at a glance.
      That’s also the argument I use when telling people to have opening and closing brackets of the same level at the same indent, while people prefer stuff like:

      if {
      ...
      } else {
      ...
      }
      
  • somegeek@programming.dev
    link
    fedilink
    arrow-up
    3
    ·
    4 hours ago

    I think edn is almost the only more advanced and ergonomic option to json. Edn is like the evolved json, but its interesting that its roots are way older than JSON.

    The fact that you can very efficiently define whole applications and software just with edn (and the lisp syntax in general) is what makes really amazing.

    I think this blog post sheds more light on how we only need lisp for defining data and applications.

    https://stopa.io/post/265