JSONx is Sexy LIESx


  • Discourse touched me in a no-no place

    @flabdablet said:

    C allows but does not require this pattern

    I've got a feeling that C used to require that pattern, but that got changed, first to pure block-scoping (C89) and then to within-block-scoping (C99). Alas, apart from the change from C89 to C99, it's actually quite awkward to find out what the rules used to be: pre-C89 predates the web, so the amount of archived material out there is pretty small…



  • @tar said:

    Seriously though, this wtfjs blog is a gift which just keeps on giving...

    Last updated dec 15, 2013. That guy is probably node.js developer these days.



  • @flabdablet said:

    Moral: Javascript is not C, and is not Java, and variables are in scope for the whole function enclosing their declarations and not just from the point of declaration onward.

    Initiailization happens exactly where the var statement is, but the variable declared by that same statement is in scope all the way back to the start of the enclosing function.

    This is not WAT, this is RTFM.

    TRWTF is that they even try to inject DOM elements with id-s into the global scope. I didn't even know that was happening. I always just use document.getElementById() or jQuery.



  • @dkf said:

    pre-C89 predates the web

    I was using C before the Internet, let alone the Web, was a thing; I assure you that C has always had variables whose scope begins at point of declaration and ends with the enclosing block (or with the source file, if there is no enclosing block).



  • Might be fun to play with an HTML document containing a node with an ID of "getElementById" and see what breaks.


  • Java Dev

    @dkf said:

    I've got a feeling that C used to require that pattern, but that got changed, first to pure block-scoping (C89) and then to within-block-scoping (C99). Alas, apart from the change from C89 to C99, it's actually quite awkward to find out what the rules used to be: pre-C89 predates the web, so the amount of archived material out there is pretty small…

    Even with all variables at the top of a block, you can reference a shadowed global in an earlier initializer.

    int foo = 1;
    
    int main(void)
    {
        int global_foo = foo;
        int foo = 2;
    
        printf( "%d %d\n", global_foo, foo );
    }
    

    Prints 1 2. I'm also convinced I should be getting a shadowed global warning during compilcation, but I don't, even with -Wall -Wextra.


  • Discourse touched me in a no-no place

    @flabdablet said:

    I assure you that C has always had variables whose scope begins at point of declaration

    If it was pre-C89, then you might well have been taking advantage of a vendor extension at that point. Prior to standardization, knowing what was and what wasn't C was somewhere between tricky and meaningless. However, from the reams of old code I've read over the years, I get the impression that only putting declarations at the top of a function was really guaranteed to work on all compilers back then. (Commercial C compilers have had a long history of being a bit weird as soon as take even one step off the standards-compliant path. Case for the prosecution: IRIX cc. 🍊🔥🍊🔥🍊)


  • 🚽 Regular

    @flabdablet said:

    Might be fun to play with an HTML document containing a node with an ID of "getElementById" and see what breaks.
    You mean document.

    Also, window, Array, ...


  • FoxDev

    @Zecc said:

    You mean document.

    Also, window, Array, ...


    undefined


  • 🚽 Regular

    parseInt, parseFloat, ...



  • @cartman82 said:

    Last updated dec 15, 2013. That guy is probably node.js developer these days.

    Even so, there are at least 11 pages of :wtf: material—that was as far back as I got before I became exhausted...



  • @Zecc said:

    What else would it be (If not a syntax error)?

    Windows PowerShell
    Copyright (C) 2013 Microsoft Corporation. All rights reserved.
    
    PS C:\Users> 1+-+-+-+-+-+-+1
    2
    

    Alright, filed under , but not actually :wtf:, then...



  • @Zecc said:

    .length

    Think again:

    define(function() {
      
      function Sparse() { 
        if ( !( this instanceof Sparse )) return new Sparse();
      }
    
      Sparse.prototype = { constructor : Sparse };
      
      Object.defineProperty( Sparse.prototype, "length", {
        get : function() {
          var me = this;
          var numeric = Object.keys( me ).map( function( name ) {
            var num = Number( name );
            return ( Number.isInteger( num ) && ( name === String( num ))) ? num : 0;
          });
          return Math.max.apply( Math, numeric );
        },
        set : function( value ) {
          var me = this;
          if ( !Number.isInteger( value ) || ( 0 > value )) {
            throw new Error( "Not a non-negative integer." );
          }
          
          Object.keys( me ).forEach( function( name ) {
            var num = Number( name );
            if ( Number.isInteger( num ) && ( name === String( num ))) {
              if ( num >= value ) {
                delete me[ name ];
              }
            }
          });
        }
      });
      
      return Sparse;
    }());
    
    require([ "sparse" ], function( Sparse ) {
      var test = new Sparse();
      console.log( test.length );           // 0
      
      test[2] = "a";
      console.log( test.length );           // 2
      
      test[5] = "b";
      console.log( test.length );           // 5
      console.log( JSON.stringify( test )); // {"2":"a","5":"b"}
      
      test["foo"] = "c";
      console.log( test.length );           // 5
      console.log( JSON.stringify( test )); // {"2":"a","5":"b","foo":"c"}
      
      test.length = 3;
      console.log( test.length );           // 2
      console.log( JSON.stringify( test )); // {"2":"a","foo":"c"}
    });
    


  • Once again, we have a solution where it is possible to change an application so that it is possible to preserve information in a round-trip of JSON formatting. However, your example did not JSON serialize a spare array. It serialized a custom class you wrote. That's different.

    I'm not saying you're wrong, you just answered the wrong question.



  • @Jaime said:

    I'm not saying you're wrong, you just answered the wrong question.

    I'd say that the question is wrong to begin with.



  • JSON doesn't natively support cons-style lists, I have to use an array or some shit instead! This is bullshit!


  • Discourse touched me in a no-no place

    @tar said:

    JSON doesn't natively support cons-style lists, I have to use an array or some shit instead! This is bullshit!

    It also doesn't support cyclic graphs. :sadface:



  • @Ragnax said:

    I'd say that the question is wrong to begin with.

    You can call the question wrong all you want. That still won't make your answer applicable to it.



  • @dkf said:

    It also doesn't support cyclic graphs.

    Crockford's JSON library has that covered.



  • @Jaime said:

    Crockford's JSON library has that covered.

    But then we return to
    @Jaime said:
    Once again, we have a solution where it is possible to change an application so that it is possible to preserve information in a round-trip of JSON formatting. However, your example did not JSON serialize a spare array. It serialized a custom class you wrote. That's different.
    just with "sparse array" replaced by "cyclic structure."



  • Fair enough.



  • On a vaguely related note, there's always this:



  • It doesn't have a date serialization format. That makes it a non-starter as far as I'm concerned.



  • We may as well throw TOML into the mix as well...



  • @tar said:

    Tom's Obvious, Minimal Language

    Which is neither obvious nor minimal. It is Tom's and it might qualify as a language though.


    Filed under: No, sorry, doubly-bracketing sections to make a list of them is not obvious.



  • @Bulb said:

    Which is neither obvious nor minimal. It is Tom's and it might qualify as a language though.

    Yeah, it seems completely unnecessary to me. I think it's supposed to be some kind of cross between JSON and an .ini file...


Log in to reply