• Fmstrat@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      2 months ago

      I love JSON. But I really wish there was a standard that allowed commas with no following items and that there was a syntax for comments.

    • dohpaz42@lemmy.world
      link
      fedilink
      English
      arrow-up
      0
      ·
      2 months ago

      That’s not JSON. Note the use of equal signs for the property names. That’s something else.

      • ulterno@programming.dev
        link
        fedilink
        English
        arrow-up
        0
        ·
        2 months ago

        Equals schmequals.
        It could be a and it would be the same as JSON because it is still a single symbol used as a separator.

        a distinction without a difference

        Now, if it took multiple separators, each giving some specific different meaning, then it would be a something else.

      • unmagical@lemmy.ml
        link
        fedilink
        arrow-up
        0
        ·
        2 months ago

        Carcinisation is the phenomenon of non crabs to evolve crab like characteristics. It is not the process of non crabs becoming true crabs.

        In this case the language is trending toward JSON syntax, but it doesn’t have to actually be JSON for carcinisation to be an applicable analogy.

      • luciferofastora@feddit.org
        link
        fedilink
        arrow-up
        0
        ·
        2 months ago

        They were chucked out because, according to the guy who defined it, people started using them for parsing directives, which hurt interoperability because now you needed to be sure that the parser would both read the comments and interpret them correctly. Suddenly, those comments might make otherwise identical files parse differently. If the whole point is that it’s reliable and machine-readable, keeping it to the minimal set of features and not extending it any way whatsoever is a good way to ensure compatibility.

        What you can do is define some property for comments. It’s not standardised, but you could do stuff like

        {
          "//": "This is a common marker for comments",
          "#": "I've never seen that as a property name, so it might be safe?",
          "_comment": "Property names with underscore for technical fields seem common enough as well, and it's semantically explicit about its purpose"
        }
        
        • dejected_warp_core@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          1 month ago

          “_comment”

          I appreciate the workaround here, and I’ve tried this in production environments to one degree or another. This usually fails due to another problem: the number of systems that think unexpected JSON keys are an error, is is too damn high.

        • The_Decryptor@aussie.zone
          link
          fedilink
          English
          arrow-up
          0
          ·
          2 months ago

          And also, JSON was intended as a data serialisation format, and it’s not like computers actually get value from the comments, they’re just wasted space.

          People went on to use JSON for human readable configuration files, and instantly wanted to add comments, rather than reconsider their choice because the truth is that JSON isn’t a good configuration format.

          • BorgDrone@feddit.nl
            link
            fedilink
            arrow-up
            0
            ·
            2 months ago

            JSON was intended as a data serialisation format

            Why then use a inefficient text based format instead of a much more efficient and easy to parse binary format?

            Just use DER encoded ASN.1 like a normal person.

        • AlexanderTheDead@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          2 months ago

          I’m not a real programmer but I was wondering wtf you’re on about because I don’t think I’ve ever worked with a json file in a system that didn’t use // for comments lmfao

            • AlexanderTheDead@lemmy.world
              link
              fedilink
              arrow-up
              0
              ·
              2 months ago

              I did say “I’m not a real programmer” heh 😮‍💨 I just thought // was standard for comments across all json files

              • luciferofastora@feddit.org
                link
                fedilink
                arrow-up
                0
                ·
                2 months ago

                No biggie, I just named an example. Even “real” programmers, whatever definition you want to use for that, don’t know all languages.

                But yes, many languages do use // as comments and particularly the Javascript environment it originally stems from does. Python (#) and SQL (--) are the only examples I interact with frequently enough to know off the top of my head (but SQL still recognises /* ... */ for delimited comments). XML/HTML also has <!-- --> for comments, but that’s not so much a programming and more of a description language.

  • Michal@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    2 months ago

    I like this. I also like yaml, I’ve had very few issues with it and it’s nicer to work with than json.

    Json’s lack of support for trailing commas and comments makes it very annoying for everyday use.

    • backgroundcow@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      2 months ago

      Just the other day I had a list show up as [“a”, “b”, “c”, “d”, “e”, false, “g”, “h”, “i”].

      The issue was that, without me being overly aware of it, the data was going through a data -> yaml -> data step.

      Yes, the data -> yaml filter was broken for not putting general strings in quotes. But IMO the yaml design invites these odd “rare” bugs.

      I used to like yaml, but was happy to see Toml taking the niche of human-readable-JSON, but felt the format for nested key-value was a weird choice. However, I’ve always felt we could just have extended JSON a bit (allow line breaks, comments, if the outermost data type is an object, the curly brackets may be omitted).

      • Ethan@programming.dev
        link
        fedilink
        English
        arrow-up
        0
        ·
        2 months ago

        Using YAML as an intermediate format between steps of a process is a mistake. I love YAML for configuration but I’d never use it for machine-to-machine anything. If the tool you’re feeding data to requires YAML as input, just give it JSON. All JSON is valid YAML.

        Edit: I realize you weren’t the one who made that decision. I’m saying the problem isn’t YAML, the problem is someone using YAML inappropriately.

  • 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.

    • Ethan@programming.dev
      link
      fedilink
      English
      arrow-up
      0
      ·
      2 months ago

      Once you’re used to it, indentation makes code soooooooo much easier to read. When I was in school and a classmate asked me for help with their code, I outright refused to touch it until they properly indented it. It makes it easy to see the structure.

    • 404@lemmy.zip
      link
      fedilink
      English
      arrow-up
      0
      ·
      edit-2
      2 months 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()
      
    • Brokkr@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      2 months 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
      0
      ·
      2 months 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.

    • Hudell@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      0
      ·
      2 months 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.

    • ulterno@programming.dev
      link
      fedilink
      English
      arrow-up
      0
      ·
      edit-2
      2 months 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 {
      ...
      }
      
    • onlyhalfminotaur@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      2 months ago

      Almost all of those issues are solved by explicitly quoting your strings, the author even acknowledges that. Yeah it’s annoying that yaml lets you do otherwise, but the title is a bit dramatic.

  • Brosplosion@lemmy.zip
    link
    fedilink
    arrow-up
    0
    ·
    2 months ago

    I will die on the hill that XML is a superior config format and people are just afraid of it cause they see the advanced features (that you don’t need to use) and think it’s too complicated.

  • [object Object]@lemmy.ca
    link
    fedilink
    arrow-up
    0
    ·
    2 months 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.