• 14 Posts
  • 1.97K Comments
Joined 4 years ago
cake
Cake day: May 31st, 2020

help-circle
  • Yep, some code examples from the official documentation. This:

    printPersons(
        roster,
        (Person p) -> p.getGender() == Person.Sex.MALE
            && p.getAge() >= 18
            && p.getAge() <= 25
    );
    

    …is syntactic sugar for this:

    interface CheckPerson {
        boolean test(Person p);
    }
    
    printPersons(
        roster,
        new CheckPerson() {
            public boolean test(Person p) {
                return p.getGender() == Person.Sex.MALE
                    && p.getAge() >= 18
                    && p.getAge() <= 25;
            }
        }
    );
    

    …which is syntactic sugar for this:

    interface CheckPerson {
        boolean test(Person p);
    }
    
    class CheckPersonEligibleForSelectiveService implements CheckPerson {
        public boolean test(Person p) {
            return p.gender == Person.Sex.MALE &&
                p.getAge() >= 18 &&
                p.getAge() <= 25;
        }
    }
    
    printPersons(roster, new CheckPersonEligibleForSelectiveService());
    

    The printPersons function looks like this:

    public static void printPersons(List<Person> roster, CheckPerson tester) {
        for (Person p : roster) {
            if (tester.test(p)) {
                p.printPerson();
            }
        }
    }
    

    Basically, if you accept a parameter that implements an interface with only one method (CheckPerson), then your caller can provide you an object like that by using the lambda syntax from the first example.

    They had to retrofit lambdas into the language, and they sure chose the one hammer that the language has.

    Source: https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html



  • I always hated the implementation for .toString() of Duration. It gives you a string like that: PT8H6M12.345S (not a hash)

    Apparently, it’s an ISO 8601 thing, but what the hell am I supposed to do with that?
    It’s not useful for outputting to end users (which is fair enough), but I don’t even want to write that into a log message.
    I got so used to this just being garbage that I would automatically call .toMillis() and write “ms” after it.

    Well, and not to gush about Rust too much, but I recently learned that its debug string representation is actually really good. As in, it’s better than my Java workaround, because it’ll even do things like printing 1000ms as 1s.
    And that’s just like, oh right, libraries can actually provide a better implementation than what I’ll slap down offhandedly.



  • Yeah, I came to Rust from Scala and Kotlin, where equality is default-implemented (for case class and data class respectively, which is basically all we ever used), so this meme surprised me a bit.

    I do actually like that you can decide a type cannot be compared, because sometimes it really just doesn’t make sense. How would you compare two HTTP clients, for example? But yeah, it certainly is a choice one can disagree with.


  • I find these videos give a very visual explanation and help to put you into the right mindset: http://intorust.com/
    (You can skip the first two videos.)

    Sort of when it clicked for me, was when I realized that your code needs to be a tree of function calls.
    I mean, that’s what all code is anyways, with a main-function at the top calling other functions which call other functions. But OOP adds a layer to that, i.e. objects, and encourages to do all function calls between objects. You don’t want to do that in Rust. You kind of have to write simpler code for it to fall into place.

    To make it a bit more concrete:
    You will have functions which hold ownership over some data, typically because they instantiated a struct. These sit at the root of a sub-tree, where you pass access to this data down into further functions by borrowing it to them.

    You don’t typically want to pass ownership all over the place, nor do you typically want to borrow (or pass references) to functions which are not part of this sub-tree.
    Of course, there’s situations where this isn’t easily possible, e.g. when having two independent threads talking to each other, and then you do need Rc or Arc, but yeah, the vast majority of programming problems can be solved with trees of function calls.






  • Hmm, I don’t know anything about Whoogle, but from other privacy-conscious search engines, I would expect it to work when you use that URL in your bookmark.

    Three things I can imagine:

    • Something in your hosting stack strips the URL parameters, like maybe your reverse proxy, if you use one. You might be able to see in the Whoogle or web server logs, which URLs actually reach it. Might need to set it to debug/trace logging.
    • Maybe there’s a flag in the Whoogle configuration you need to enable to accept these preference URLs.
    • It’s a bug in that Whoogle version.

  • I mean, the bulk of the work on this happens for the fun of it. The underlying game engine, Luanti, has a really lovely community. Some folks love creating mods/content, others love playing that content.

    If you really want a hard reason, it’s that Microsoft bought Minecraft and has forced changes, such as a Microsoft account being a requirement now.
    Microsoft has a long history of being extremely hostile to the open-source / libre software community, so after the news broke the community definitely bundled together even moreso to create our own Minecraft, with blackjack and hookers screwdrivers and mese.







  • Ephera@lemmy.mltoCurated Tumblr@sh.itjust.worksDenny's
    link
    fedilink
    English
    arrow-up
    3
    ·
    5 days ago

    A few years ago, I worked in a warehouse and one of my coworkers wanted to call for a Dennis across the warehouse. She’s not a native speaker, so she didn’t know which syllable to emphasize, so she shouted “DENNIIIIIS”, which ended up sounding like “Denise”.

    That is all. 🙃


  • Ephera@lemmy.mltoScience Memes@mander.xyzOopsies
    link
    fedilink
    English
    arrow-up
    18
    arrow-down
    1
    ·
    5 days ago

    Yeah, the formulation is a bit off here. With opt-out, you have no way to measure consent, because you can’t discern between people who actually consent and those who just haven’t opted out, for lack of knowledge or other reasons.

    These societies have simply weighed up the two options and decided that saving lives is more important than leaving personal freedom intact at all costs.


  • What I don’t like about the genre, is that I’m bad at it. 🙃

    More seriously, I do find it kind of frustrating at times. Restarting ten times in a roguelike, no problem, because it’s always a new challenge.
    But if I miss the same jump ten times, or have to retry the same platforming passage ten times, you’ll see me getting impatient, which means I’ll fail the next ten attempts, too…