• 0 Posts
  • 15 Comments
Joined 1 year ago
cake
Cake day: July 5th, 2023

help-circle

  • Whoops! When I looked at the second time that the shift value is calculated, I wondered if it would be inverted from the first time, but for some reason I decided that it wouldn’t be. But looking at it again it’s clear now that (1 - i) = (-i + 1) = ((~i + 1) + 1), making bit 0 the inverse. Then I wondered why there wasn’t more corruption and realized that the author’s compiler must perform postfix increments and decrements immediately after the variable is used, so the initial shift is also inverted. That’s why the character pairs are flipped, but they still decode correctly otherwise. I hope this version works better:

    long main () {
        char output;
        unsigned char shift;
        long temp;
        
        if (i < 152) {
            shift = (~i & 1) * 7;
            temp = b[i >> 1] >> shift;
            i++;
            output = (char)(64 & temp);
            output += (char)((n >> (temp & 63)) & main());
            printf("%c", output);
        }
    
        return 63;
    }
    

    EDIT: I just got a chance to compile it and it does work.


  • I first learned about Java in the late 90s and it sounded fantastic. “Write once, run anywhere!” Great!

    After I got past “Hello world!” and other simple text output tutorials, things took a turn for the worse. It seemed like if you wanted to do just about anything beyond producing text output with compile-time data (e.g. graphics, sound, file access), you needed to figure out what platform and which edition/version of Java your program was being run on, so you could import the right libraries and call the right functions with the right parameters. I guess that technically this was still “write once, run anywhere”.

    After that, I learned just enough Java to squeak past a university project that required it, then promptly forgot all of it.

    I feel like Sun was trying to hit multiple moving targets at the same time, and failing to land a solid hit on any of them. They were laser-focused on portable binaries, but without standardized storage or multimedia APIs at a time when even low-powered devices were starting to come with those capabilities. I presume that things are better now, but I’ve never been tempted to have another look. Even just trying to get my machines set up to run other people’s Java programs has been enough to keep me away.




  • You say active waiting, but I wonder if you mean a busy-wait? Busy-waiting is generally bad, but don’t forget that your main loop is just what executes when the OS decides to give your program some processor time. If you just check a stored timestamp vs the current clock at the start of each iteration, and then do nothing unless enough time has passed, control will go back to the OS for a bit, not the start of your next loop, so it’s not a true busy-wait.

    The original PC’s hardware timer was… not great, and I believe that the situation only got worse over time. I understand the desire not to waste resources, but modern OSs are designed with the fear of not fully exploiting resources, so there’s only so much you can do.







  • Did you read all the way to the end of the article? I did.

    At the very bottom of the piece, I found that the author had already expressed what I wanted to say quite well:

    In my humble opinion, here’s the key takeaway: just write your own fucking constructors! You see all that nonsense? Almost completely avoidable if you had just written your own fucking constructors. Don’t let the compiler figure it out for you. You’re the one in control here.

    The joke here isn’t C++. The joke is people who expect C++ to be as warm, fuzzy, and forgiving as JavaScript.





  • Yep, it’s probably easier to get an Android device and install readers on it than to try for a prepackaged FOSS reader.

    I use several apps on my Android phone, but mostly Kindle (for Kindle, duh), PDF Reader (for PDFs, duh again), and Lithium (mostly for EPUB but pretty much everything else, too). I get most of my e-books as DRM-free EPUBs and PDFs.