6
caiofior
168d

Today I learned.

In php if you cast a string to array you get an array with one value: the string.

Comments
  • 3
    Incredible
  • 6
    Fascinating. It’s like learning about how a long forgotten culture used some weird way of counting that we cannot comprehend today.
    Except that the php culture is still alive.
  • 1
    @Lensflare I imagine it’s similar to what those anthropologists that go to the Amazon to interact and observe the Yanomami must feel.
  • 1
    I can't say I've ever done this, and thinking about it, life would have been easier if I did.

    And people hate on php, it's just does things you never expect is all.
  • 1
    @ars1 keep in mind that I'm a fruit of this culture. And in latest versions php has a great syntax that could coexist with old strange oddities as the one that I described.
  • 1
    I gave up on PHP when it discovered that it can't send an array as JSON. It converts it to an object with the index as the key and sends that.

    It is annoying I have branching logic in the main application so that I can handle proper requests and PHP requests.
  • 1
    @Lensflare lol php culture
  • 3
    @cuddlyogre that’s exactly the reason why a well thought out and properly implemented type system is one of the most crucial parts of a programming language. Without that, we get those clown languages like php or js, which have random conversion rules between built in types, which were implemented for some irrelevant use case at the beginning and then stay forever in the language because of backwards compatibility.
  • 1
    I like how Haskell does it, a string is a list of characters and it's Begone Deimon!
  • 0
    @jestdotty https://dorey.github.io/JavaScript-...

    Implicit type conversions when using ==
  • 0
    @Lensflare noone sane uses == or needs to know about all these rules nowadays tho
  • 0
    Previous PHP versions had even worse implicit comparison of the same type: '0010e2' == '1e3'
  • 0
    @devRancid … which is a testament to its fucked up type system in itself.
    Not using it because it’s bad is admitting that it’s bad.
  • 0
    @devRancid Btw, js doesn’t have a built in way to check for equality for reference typed values. == and === will both not work.
    So two equal objects and two equal arrays would still be unequal according to == and ===.
    The type system is garbage.
  • 0
    @jestdotty show me the code to check two arrays or two arbitrary objects for equality in js.

    In Swift, you just conform the object to Equatable and then compare with ==. Arrays do conform to Equatable automatically if the element type is also Equatable. I bet my ass that Rust does the same.

    Now tell me which is more verbose.

    All that === does is skipping the retarded implicit conversions. It still is a joke of an equality operator which doesn‘t work with reference typed values like arrays and objects, as I said. The type system is still garbage.
  • 0
    @jestdotty what a strange question.

    You need to check objects for equality to check if some data has changed. That’s essential for reactive and functional programming.

    But I think I can see why js devs don’t recognize this problem because js doesn’t have custom value types, and changes in state are handled with reference types. That’s bad because you need to deal with mutable state but there is no other way of course.

    That’s the problem with js: It makes you blind for its problems because you never learn good coding practices because they are not possible with js.
  • 1
    @jestdotty tbh I think equality is too dangerous and limiting on non-lisp languages, so I avoid it as much as possible.

    I say dangerous cuz your average programmer will go on symbolic mode when doing it and most likely miss a fuckton of minutiae or come up with hard to maintain clusterfuck code.

    In that sense, pattern matching like Rust, Ocaml, or, better yet, Haskell, tends to be less error prone. Though it kicks readability out the window, it does remove all that equality nonsense @Lensflare's pic shows β˜πŸ»πŸ˜€

    Bet then, if all languages were like that, we'd have a hard time finding programmers πŸ˜ΆπŸ‘ŽπŸ»

    I am NOT sure if THAT would be a bad thing though
  • 0
    @kobenz readability is much better as well. See my example with Swift.
  • 0
    @jestdotty you quoted me wrongly and inserted a few words which change the meaning. I believe you misread or misunderstood me.

    My point wasn’t about performance. It was about verbosity and correctness.

    I don’t want to insult you. You insult yourself by confirming my prejudices about js devs.
    It may not be your first language but it is your main language that you also like. So it’s appropriate to refer to you as a typical js dev.
  • 1
    @jestdotty definitely, but throw in typescript instead and it's a world of pain. In that sense I rather do it python or JavaScript and rewrite in Rust afterwards
Add Comment