[–] 2 points 7 months ago (2 children)

Eh, I get it. The equal operator creates a reference but the plus operator isn't destructive so it creates a new list and overwrites the variable b with a new list, when assigned.

Of course, this would all be avoided if creating copies was the norm; which is why I stick with functional languages.

  • source
  • parent
  • context
  • [–] 6 points 7 months ago (1 child)

    For immutable types it is the same though.

    The most twisted thing I learned is that all ints below a fixed limit share the same id() result, so

    >>> x = 1
    >>> id(x)
    135993914337648
    >>> y = 1
    >>> id(y)
    135993914337648
    

    But then suddenly:

    >>> x = 1000000
    >>> id(x)
    135993893250992
    >>> y = 1000000
    >>> id(y)
    135993893251056
    

    Using id() as a key in dict() may get you into trouble.

  • source
  • parent
  • context
  • [–] 2 points 7 months ago

    Oh absolutely, I understand that the language allows implementations to violate my proposed equivalence β€” I’m saying that’s a bad implementation (some might say a bad language, for allowing bad implementations, but I don’t necessarily agree)

  • source
  • parent
  • context
  • [–] 4 points 7 months ago* (last edited 7 months ago) (3 children)

    I expect A if "b" is a clone, or E if it's a reference. But I also wouldnt combine array operations like this.

    The answer being C feels like a bug.

  • source
  • [–] [S] 5 points 7 months ago* (3 children)

    It's definitely not the same. Similarly for a class you can define the __add__ dunder method for a + b and separately the __iadd__ dunder method for a += b. The first creates a new object, the latter changes/mutates the existing object a. For immutable types it is the same though.

  • source
  • parent
  • context
  • [–] 5 points 7 months ago (1 child)

    Tell me again how python is easy to learn for beginner programmers.

    Other languages that have similar behavior include Java and JavaScript, and yes you have to be careful with list / array operations in those languages as well, lest you operate on the wrong list inadvertently. Happened to me. It will happen to you.

  • source
  • [–] 1 point 7 months ago (1 child)

    LOL have never used the match statement. Has been one of those features just outta reach. So close can taste it. But alas ....

    Now py310 is here. Still not enthusiastic about it. But over time maybe will come around.

    __slots__ = (...) or frozen. Same thing. Make the data class read-only reducing memory usage by 30-40%. Like the memory usage difference between tuple and list.

    From experience, in stubs, __slots__ need to include "__weakref__". If frozen, then don't include "__weakref__".

    How about this. Lets meet each other half way.

    I'll stop thinking of the match statement as thorium reactor toxic waste.

    And maybe you can take a read through of the frozen option for dataclasses.

    Sound fair?

  • source
  • parent
  • context
  • [–] 1 point 7 months ago (2 children)

    Python advertises itself as being mature, which means changes if any are supposed to be incremental and backwards compatible. It's not so successful at that but I still don't particularly try to keep up with the bleeding edge. I don't know what slots in dataclasses even means. I do like the match statement.

  • source
  • parent
  • context
  • [–] 1 point 7 months ago (5 children)

    dataclasses required py310+ for critical features like slot support. Only now that py39 is history, is dataclasses even a thing. But then a must have feature will require an even more recent python version. So stuck waiting in a never ending loop.

    Fck that!

    python -m pip install attrs

    Problem solved.

  • source
  • parent
  • context
  • Have zero exposure to Astral. If they were bought out by OpenAI tomorrow, would not notice the difference.

    If i were a Rust coder, would have interest. Since i'm not, would be at the mercy of the maintainers.

    Saw uv and ruff as a liability. Now? What is uv and ruff. Never heard of it.

    Look forward to future discussions on requirement files again. Reintroduce everyone to the -r and -c options. How to put requirements into a hierarchy. How to deal with multiple venv. And how to manage requirement files across multiple packages.

  • source
  • [–] 3 points 7 months ago (3 children)

    Your truust in the Law is admirable. OpenAI does not care at all about laws. They do what they want and have an army of lawyers to fight anyone who says differently. Just look at copyright laws.

    This is why I am saying do it now. Better safe than sorry.

    But, since all l am getting is abuse.... I'm out! Y'all have the say you deserve.

  • source
  • parent
  • context
  • view more: β€Ή prev next β€Ί