• Creator
    Topic
  • #6086

    OneMadGypsy
    Participant

    I keep seeing “Python is easy” all over the place. Let me tell you right now from somebody that is not at all new to programming … BULL FUCKING SHIT. It suffers from the same “not at all obvious” quirks that every other language suffers from and, as usual, those quirks are never documented. I will give you a perfect example

    from struct import *
    from collections import namedtuple
    
    record = b'raymond   \x32\x12\x08\x01\x08'
    
    Student = namedtuple('Student', 'name serialnum school gradelevel')
    Student._make(unpack('<10sHHb', record))
    print(Student.name)

    record is being cast as bytes for the purpose of making some quick bytes to work with. unpack is unpacking those bytes to the fields declared in the namedtuple instance. The ‘<10sHHb' part is just saying "use little endian(<), get a 10 character string(10s), then 2 unsigned shorts(HH) and finally a signed byte(b)". In other words it's defining a struct pattern. So, when you put all that together the results should be

    Student.name = raymond
    Student.serialnum = 4658
    Student.school = 264
    Student.grade = 8

    However, try and print any of that and you get "object at 0x00333874" (as an example). Nowhere in the fucking docs does it explain that you need to do this

    myStudent = Student._make(unpack(‘<10sHHb’, record))
    print(myStudent.name)

    If it wasn’t for the fact that I am not new to this shit it may have never struck me that Student is basically a class and make is basically a new instance. Meaning ‘Student” does not exist as anything beyond a possibility no matter how many times you call make. You have to actually capture the result of make. One thing that makes this very confusing is this line

    Student = namedtuple('Student', 'name serialnum school gradelevel')

    Why would I think I am inventing a “possibility” when that line clearly depicts an instantiation?

    Basically python has figured out a very confusing way to rewrite this

    Student = SomeClass;
    //Student = namedtuple('Student', 'name serialnum school gradelevel')
    
    new Student(...);
    //Student._make(unpack('<10sHHb', record))

    and if you don’t realize that, you probably won’t come to the conclusion you need to do this

    myStudent = new Student(...);
    //myStudent = Student._make(unpack('<10sHHb', record))

    I am not at a “fuck python” level though. Not even close. I just ordered a Raspberry Pi 3 B+ ultimate kit so, “fuck python” isn’t even an option. Even if it was an option I’m not mad as hell yet … and maybe I wont ever be as I work through these little intricacies and become proficient in the language. “Python is easy” though is some bullshit. Sure it has very simple syntax (that is completely different from basically every other OOP language) and it has some good modules* that make things very easy (once you figure out how the fuck to use it) but, “easy” in general? Nope.

    *good modules: that unpack feature is exciting to me. Being able to use a few letters to define a struct and then dumping in some bytes is going to come in VERY handy…

    …off to create a python BSP parser, like you didn’t see that coming, right?

    ——

    I also bought this 4gig Rock 64 Board. It’s .2 Ghz faster than the Pi with quadruple the ram and has a dedicated GPU for 4$ more than I paid for the board portion of my Pi kit. Both run Debian and both support Python. I’m tempted to turn it into a Quake server, plug it into the router at work and bury it in the wire garden behind the desk. I bet I could get away with it for a very long time. Maybe forever. Including after I inevitably quit.

    https://all3dp.com/1/single-board-computer-raspberry-pi-alternative/#rock64-media-board

    one day at a timetop | reply

    http://www.nextgenquake.com/forum/other/small-talk/

You must be logged in to reply to this topic.