• (disco)

    Brevity was obviously the second-last item on the requirements list. Why else use a generic JSON with name / value keys.

  • (disco)

    Is it just me, or is that really a JSON array in a string in JSON? :wtf:

  • (disco) in reply to RaceProUK

    it's not just you.... i see it too....

  • (disco) in reply to RaceProUK
    RaceProUK:
    Is it just me, or is that really a JSON array in a string in JSON? :wtf:

    The first snippet is a var_dumped PHP array; it looks like it contains the deserialized JSON data and the original JSON string in its data attribute (alongside with other stuff), for some reason.

    Speaking of redundancy, there’s some in the JSON itself:

    [
     {"name":"adAddress","value":"Address 123"},
     {"name":"adCity","value":"MyCity"},
     {"name":"adZip","value":"12345"},
     {"name":"adState","value":"RS"},
     {"name":"adTelephone","value":"0112323555"},
     {"name":"adJMBG","value":"1706987782831"},
     {"name":"check[]","value":"domain_adminperson"},
     {"name":"cp_osobaid","value":"156"}
    ]
    

    which could be simplified to

    {
     "adAddress":"Address 123",
     "adCity":"MyCity",
     "adZip":"12345",
     "adState":"RS",
     "adTelephone":"0112323555",
     "adJMBG":"1706987782831",
     "check":["domain_adminperson"],
     "cp_osobaid":"156",
    }
    
  • (disco) in reply to RaceProUK
    RaceProUK:
    Is it just me, or is that really a JSON array in a string in JSON?
    Maciejasjmj:
    Now for the ramblings part:

    http://i.imgur.com/ahheHQh.png

    "Instead of sending your draft as a sub-object, we'll send it as a nicely escaped JSON string, because fuck you, that's why".

    *cough*

  • (disco) in reply to Maciejasjmj
    Maciejasjmj:
    *cough*

    i knew that seemed familliar....

  • (disco) in reply to Maciejasjmj

    I must have missed that first time round; back in November, I was only just starting to up my activity levels, and I wasn't a regular in Programmers' Testing at the time either. It wasn't until I started contributing to @sockbot that I was active in that category.

  • (disco) in reply to RaceProUK
    RaceProUK:
    back in November

    Just now realized how long I've been telling myself "damn, I need to get back to that when I have some time". Ah well...

  • (disco)

    There izmeni things wrong with that code!

  • (disco)
    Maciejasjmj:
    Just now realized how long I've been telling myself "damn, I need to get back to that when I have some time". Ah well...

    Join the club :laughing:

  • (disco) in reply to Onyx
    Onyx:
    Join the club

    to be honest i'm still shocked that i'm still actively developing SockBot....

    i really thought that would die a quick death after i burned through the "see i can too write a bot nyeh nyeh neyh!" phase.... i didn't expect the "hey this is actually fun let's keep doing this" phase that was waiting right around the corner to ambush me.

    not that i'm complaining mind you.... :-D

  • (disco) in reply to accalia

    It's addictive, isn't it? You've even roped in a haplesshappy little hedgy to help you out ;)

  • (disco) in reply to dkf
    dkf:
    izmeni

    While I see what you did there, that means "change" btw.

    I also wonder how much fun they are having JS-side (if there is a JS side) with those phone numbers and "JMBG" fields which can also begin with a 0. Been there, done that, duck typing is a PITA in those cases if you're trying to make your interface generic....


    Filed under: Oh, it's an integer! Let me get that for you! Who needs those leading 0s anyway...

  • (disco) in reply to Onyx
    Onyx:
    I also wonder how much fun they are having JS-side (if there is a JS side) with those phone numbers and "JMBG" fields which can also begin with a 0. Been there, done that, duck typing is a PITA in those cases if you're trying to make your interface generic....

    Just like working with US postal codes through New England. :D

    (The problem with JS is not the duck typing, it's that it overloads + to do two — or maybe more — totally different things. If it always did addition, nobody would get nearly so excited…)

  • (disco) in reply to dkf
    dkf:
    it's that it overloads + to do two — or maybe more — totally different things.

    And then there's C++-style operator overloading, where "+" can do anything imaginable that may or may not have anything to do with addition.

  • (disco) in reply to dkf

    I'm pretty sure just calling JSON.parse() was enough to screw it up, because I know I wasn't doing any concatenation. Maybe the templating library I use does. In any case, I had to hack around it many a time using var = var + "".

  • (disco) in reply to EatenByAGrue
    EatenByAGrue:
    And then there's C++-style operator overloading, where "+" can do anything imaginable that may or may not have anything to do with addition.

    HOWEVER: in C++, you can predict exactly which operator+ is called simply by inspecting the types of the operands, which are available to you before the program runs.

    dkf:
    (The problem with JS is not the duck typing, it's that it overloads + to do two — or maybe more — totally different things. If it always did addition, nobody would get nearly so excited…)
    BINGO! For contrast:
    >>> 2 + "duck"
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: unsupported operand type(s) for +: 'int' and 'str'
    >>> {} + []
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: unsupported operand type(s) for +: 'dict' and 'list'
    >>> class Blurfle(object):
    ...     pass
    ...
    >>> Blurfle() + 3.14
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: unsupported operand type(s) for +: 'Blurfle' and 'float'
    >>> class Flubble(object):
    ...     pass
    ...
    >>> Blurfle() + Flubble()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: unsupported operand type(s) for +: 'Blurfle' and 'Flubble'
    >>>
    
  • (disco)

    I wonder whether the name/value thing was because someone didn't know how to iterate over an object in JavaScript. Might be one (dumb) reason for that (horrible) (anti)pattern.

  • (disco) in reply to EatenByAGrue
    EatenByAGrue:
    And then there's C++-style operator overloading, where "+" can do anything imaginable that may or may not have anything to do with addition.

    Is that the fault of C++ though? It's no different than writing a function add(a, b) that has nothing to do with addition. Would you blame that on the language, or on the programmer?

  • (disco) in reply to Dragnslcr

    Good point. All common words should be banned as function names to prevent this kind of abuse

  • (disco) in reply to Jaloopa

    Also, camelCase, because you can use it to trick the compiler otherwise. And case-sensitivity in general, really, because you just know some asshole will make both add() and Add() with the same signature but doing wildly different things.

  • (disco) in reply to tarunik
    tarunik:
    HOWEVER: in C++, you can predict exactly which operator+ is called simply by inspecting the types of the operands, which are available to you before the program runs.

    That's reasonable to do in C++03 code, but if you're working with C++11 code which makes heavy use of the auto keyword, manually deciphering all of the inferred types very quickly turns into a rat's nest.

  • (disco) in reply to Protoman
    Protoman:
    That's reasonable to do in C++03 code, but if you're working with C++11 code which makes heavy use of the auto keyword, manually deciphering all of the inferred types very quickly turns into a rat's nest.

    Just hover over the variable and have your IDE tell you!!!!! Nobody ever looks at code outside an IDE.

  • (disco) in reply to dkf
    Protoman:
    That's reasonable to do in C++03 code, but if you're working with C++11 code which makes heavy use of the `auto` keyword, manually deciphering all of the inferred types very quickly turns into a rat's nest.
    dkf:
    Just hover over the variable and have your IDE tell you!!!!! Nobody ever looks at code outside an IDE.
    Look at code outside of an IDE isn't hard to cater for. Just write `auto szName` and you'll never have to figure out the type!

    Filed under: Now going to solve world hunger next.

  • (disco) in reply to JBert
    JBert:
    Just write auto szName

    auto cflpszname? Am I doing it right?

  • (disco) in reply to JBert
    JBert:
    Look at code outside of an IDE isn't hard to cater for. Just write auto szName and you'll never have to figure out the type!

    What's the correct Hungarian notation for a variable of type std::unordered_map<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>, std::vector<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>, std::allocator<wchar_t>>>? And that's just the tip of the iceberg.

  • (disco) in reply to Protoman
    Protoman:
    What's the correct Hungarian notation for a variable of type `std::unordered_map<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>, std::vector<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>, std::allocator<wchar_t>>>`?
    `wtf`
  • (disco) in reply to RaceProUK

    Alternatively, witide

    Huh, interesting interaction between <abbr> and backticked words there...

  • (disco) in reply to Protoman
    Protoman:
    std::unordered_map<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>, std::vector<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>, std::allocator<wchar_t>>>?

    ..... that woulc be called.... RUN!

  • (disco) in reply to accalia
    accalia:
    ..... that woulc be called.... RUN!

    Oh please, you've clearly never soon any error messages from messing up a Boost template parameter. Those have been known to break some compilers' error message printers.

  • (disco) in reply to Protoman
    Protoman:
    Oh please, you've clearly never soon any error messages from messing up a Boost template parameter. Those have been known to break some compilers' error message printers.
    [image]
  • (disco) in reply to dkf
    dkf:
    (The problem with JS is not the duck typing, it's that it overloads `+` to do two — or maybe more — totally different things. If it always did addition, nobody would get nearly so excited…)

    Excuse my language, but this is one thing PHP gets right. + is addition. . is concatenation.

  • (disco) in reply to PleegWat
    PleegWat:
    `.` is concatenation.
    Isn't it also the object member operator? Or am I thinking of something else?

    Not that there's ambiguity of course; just curious.

  • (disco) in reply to RaceProUK

    That's actually -> in PHP. Though indeed there would be no ambiguity, as the right-hand operator would be a completely different token type.

  • (disco) in reply to PleegWat

    TIL :smile:

    It's been a long time since I did any PHP, and I've never used its OO features.

  • (disco) in reply to PleegWat
    PleegWat:
    Excuse my language, but this is one thing PHP gets right. + is addition. . is concatenation.

    I'm not sure I'd have picked . but at least it's not ambiguous. There. (It's PHP after all…)

  • (disco) in reply to dkf
    dkf:
    I'm not sure I'd have picked `.` but at least it's not ambiguous. There. (It's PHP after all…)
    IIRC, VB uses `&` for string concat; that would have been a better operator for PHP if it wasn't for `&` being bitwise-orand.
  • (disco) in reply to RaceProUK

    So VB and PHP do it right and everything else is TRWTF?

    When did I enter Bizarro world again?

  • (disco) in reply to Jaloopa
    Jaloopa:
    When did I enter Bizarro world again?
    The instant you signed up to this forum :stuck_out_tongue:
  • (disco) in reply to RaceProUK

    That would probably explain why I'm talking to a female hedgehog called Dave...

  • (disco) in reply to Jaloopa
    Jaloopa:
    So VB and PHP do it right and everything else is TRWTF?

    ML uses ^, Perl uses ., SQL and REXX use ||, Haskell uses ++. D uses ~. Tcl and Shell don't use an operator (or arguably it's the empty string).

  • (disco) in reply to dkf

    Obviously, when I say Everything Else I mean C#, the One True Language.

    Also, T-SQL uses +. I don't think I've ever used a SQL engine that uses ||

  • (disco) in reply to Jaloopa
    Jaloopa:
    Also, T-SQL uses `+`. I don't think I've ever used a SQL engine that uses `||`

    Oracle.

  • (disco) in reply to PleegWat
    PleegWat:
    Oracle.

    Also Postgres and SQLite. It's what the SQL92 standard actually specifies. (So it's naturally ignored by about half of all vendors…)

  • (disco) in reply to dkf

    That's SQL for you.

  • (disco) in reply to Jaloopa

    Lua uses ..

  • (disco) in reply to PleegWat
    PleegWat:
    That's actually -> in PHP.

    And this should give you a hint of why PHP is such a WTF language. You would think that a C-like language born to be embedded into HTML code would have used something different than the single most used character in HTML: ">"

    Also, it's a C-like language and it borrows basically everything else from C but not for member operators, because it's so much better to type . than - + Shift + >

    I just hate reading/writing PHP code because of this, specially if it's embedded in HTML where it's almost impossible without syntax highlight.

  • (disco) in reply to Eldelshell
    Eldelshell:
    it borrows basically everything else from C but not for member operators
    I was about ask 'when did C get a member operator', then remembered `struct`s.
    Eldelshell:
    You would think that a C-like language born to be embedded into HTML code would have used something different than the single most used character in HTML: ">"
    The end of a PHP block is marked with `?>`, which isn't valid PHP code. So I don't see the :wtf: here.
  • (disco) in reply to RaceProUK
    RaceProUK:
    I was about ask 'when did C get a member operator', then remembered structs.

    There, there. The loss of memory incidents only get more frequent as you get older…

  • (disco) in reply to dkf

    At least I avoided a fourth whoosh badger :relieved:

    I would also say I avoided Blakey calling me an idiot, but he would call me that anyway :smile:

Leave a comment on “Are You Down With PHP?”

Log In or post as a guest

Replying to comment #:

« Return to Article