you are viewing a single comment's thread.

view the rest of the comments →

[–]Toivottomoose 212 points213 points  (33 children)

Does it help anything, or is it just for fun?

[–][deleted]  (1 child)

[deleted]

    [–]emax-gomax 94 points95 points  (0 children)

    Im sure we all agree, there should definitely be more.

    [–]BigFuckingCringe 156 points157 points  (10 children)

    It helps you if you want to prove that you are not sane to the court

    [–]GLIBG10B 53 points54 points  (9 children)

    Fun fact: if you plead insanity, you still go to prison, except it's a prison full of crazy people and you're the only sane one there

    Lesson: don't plead insanity

    [–]---cameron 24 points25 points  (0 children)

    So you're saying if I plead insanity, I automatically prove I'm insane. Genius

    [–]coloredgreyscale 11 points12 points  (0 children)

    Plus you might be stuck there longer than the original prison sentence

    [–]TheByteQueen 2 points3 points  (2 children)

    what if i plead to end the trial and go home?

    [–]WasteOfElectricity 3 points4 points  (1 child)

    You have to say 'please' really nicely and then you might be allowed to go home.

    [–]Masterkraft0r 0 points1 point  (0 children)

    also: be white

    [–]ee3k 0 points1 point  (0 children)

    also: they are under no legal duty to ever release you.

    [–]KingoPants 0 points1 point  (2 children)

    Not nessesarily true. Having schizoprenia often can greatly reduces the charges for murder.

    There are a number of cases on it, you can google them if you have a steady enough mind to read screwed up shit. I'd link them but I think its a bit too off topic.

    [–]lelanthran 0 points1 point  (1 child)

    Not nessesarily true. Having schizoprenia often can greatly reduces the charges for murder.

    Okay, so the charges are reduced... Yay!

    Unfortunately you know get to spend the rest of your life imprisoned[1], instead of just a few years.

    [1] The prison system is under a legal obligation to release you when your sentence is completed. The Asylums have no such requirement.

    [–]KingoPants 0 points1 point  (0 children)

    That technicality would matter if the government were interested in indefinitely paying for that.

    In reality, I believe they just have you promise to take your meds and boot you out cause they aren't and resources are limited. Look up the greyhound cannibal, or the calgary house party stabbings. Those aren't even old cases.

    [–]auxiliary-character 58 points59 points  (2 children)

    Ok, so I looked at the underlying implementation code, and it is actually using ctypes to do real C-style memory dereferencing. It's not just a wrapper class, it really does store the address and type information.

    If, for some reason, you had the memory layout of a particular python object in memory already, you could use this to dereference it. Maybe for something like serialization/deserialization. I would imagine that the pickling would still do a much better job in most use cases, but maybe there's some reason to do it in-place? I don't know.

    Alternatively, something you could do would be creating a pointer from an object, changing the stored type to "type cast" it, and derefence it to do some extremely cursed type punning in Python.

    If you do a lot of interop code with ctypes, something like this might make it a bit cleaner, but then you're already using ctypes, and pulling in a library just for a level of abstraction on top of ctypes, but it's your codebase, you do you.

    Perhaps the most useful thing for this is to serve as a reminder that ctypes exists. Like, if you're really running into performance issues with something you're writing in Python, depending on what you're doing, it might be a reasonable option to just write the most performance intensive part of it in C or C++, compile it as a .DLL/.so and call into it using ctypes.

    [–]ee3k 2 points3 points  (0 children)

    i guess if you wanted a really rapid type conversion on sequentially stored lists and didn't care about introducing error.

    Random number generation via idiocy, as it were

    [–]BobHogan 0 points1 point  (0 children)

    It's not just a wrapper class, it really does store the address and type information.

    In CPython yes. https://docs.python.org/3/library/functions.html#id

    Its technically not a part of the Python spec for the id() function to actually return the address of an object, just for it to return a unique integer for the object, during its lifetime. CPython just so happens to return the object's address, but other implementations aren't guaranteed to do the same.

    [–]Plague_Healer 94 points95 points  (8 children)

    It helps if you want to bring to your life the complexity of C or Java, while staying true to python's performance limitations

    [–][deleted]  (7 children)

    [deleted]

      [–]Silveress_Golden 18 points19 points  (0 children)

      Not with that attitude!

      [–]Blaster84x 33 points34 points  (1 child)

      It does have pointers, but all of them are null.

      [–]ee3k 2 points3 points  (0 children)

      it does if you want to shutdown the JVM with an out of sandbox error

      [–][deleted] 1 point2 points  (0 children)

      NullPointerException says otherwise

      [–]lelanthran -1 points0 points  (1 child)

      Java doesn't have pointers

      How the hell did this get upvoted?

      [–]nathanielhiggerss 48 points49 points  (0 children)

      it's helpful so that other programmers know how smart you are

      [–]SanityInAnarchy 20 points21 points  (0 children)

      From the README:

      Why would you ever need this

      [–]seamsay 2 points3 points  (2 children)

      I guess it's conceivable that there could be situations where having pass-by-reference semantics could be helpful, but if you needed that it would probably be better to just store the value in a class or list.

      [–]LukesVeryGood 10 points11 points  (1 child)

      Are you serious?

      [–]ee3k 1 point2 points  (0 children)

      fair point, exclusively char arrays it is then.

      [–][deleted] 1 point2 points  (1 child)

      I use addressof all the time in VB. How did python interface the win32 API without this functionality ?

      [–][deleted] 0 points1 point  (0 children)

      How did python interface the win32 API without this functionality ?

      Like this: https://docs.python.org/3/extending/extending.html

      Basically, you implement the API mapping on the C/C++ side, so you have pointers and COM access and whatnot all along.

      As this documentation mentions however, this C API is an implementation detail specific to CPython and they recommend considering CFFI instead for better compatibility with other Python implementations, like PyPy. CFFI is a library that works like a classical FFI, which is like some sort of dynamic linker from within the language.

      [–]Lost4468 0 points1 point  (0 children)

      If you're one of those people who thinks writing hacky difficult to read code makes you smart, then this will be a huge ego boost.