WTF Bites


  • Discourse touched me in a no-no place

    @anonymous234 said in WTF Bites:

    It's a mess. The Microsoft store is just a mess.

    It's like a dumpster fire, except it's a toilet that's on fire and the fire is made out of smaller fires and enterprise tears.



  • https://support.strava.com/hc/en-us/articles/360032979131-Removing-Direct-Sensor-Pairing-from-the-Strava-Mobile-App

    Supporting Bluetooth devices was causing the app to crash during recording, whether or not a sensor was connected. Disabling this feature significantly improves recording stability for all athletes.

    54400cce-64fe-4873-91f7-f663078b0338-image.png
    Why bother fixing bugs when you can remove the feature instead?



  • @Zerosquare can't have bugs if you have no features


  • Java Dev

    @Zerosquare said in WTF Bites:

    Why bother fixing bugs when you can remove the feature instead?

    "Does anyone even use that" is a question that I've asked on occasion.


  • BINNED

    @PleegWat said in WTF Bites:

    @Zerosquare said in WTF Bites:

    Why bother fixing bugs when you can remove the feature instead?

    "Does anyone even use that" is a question that I've asked on occasion.

    I have asked "why are they even using that" for a support contract > 10,000€.

    :phb: "They just paid a lot of money to get this fixed, you can't just tell them 'it runs fine if you disable that.'"
    topspin "Hold my beer."


  • BINNED

    @Zerosquare
    Don't forget to that they point to apps with competing features as solutions


  • Notification Spam Recipient

    Status: Saw the following comment:

            // use ints for keys because enums cause (more) GC allocations
            private Dictionary<int, List<Advertisement>> _adsByLocation = new Dictionary<int, List<Advertisement>>();   
    

    I'm rather curious.



  • @Tsaukpaetra said in WTF Bites:

    I'm rather curious.

    About how big the clue bat should be?



  • @Tsaukpaetra said in WTF Bites:

    I'm rather curious.

    I think we all agree you're a pretty curious person indeed.


  • Notification Spam Recipient

    @Zerosquare said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    I'm rather curious.

    I think we all agree you're a pretty curious person indeed.

    Keeps the mind distracted from planning total domination. I think most of us would agree that would be a Bad Thing.


  • Java Dev

    @Tsaukpaetra said in WTF Bites:

    Status: Saw the following comment:

            // use ints for keys because enums cause (more) GC allocations
            private Dictionary<int, List<Advertisement>> _adsByLocation = new Dictionary<int, List<Advertisement>>();   
    

    I'm rather curious.

    If you're contemplating an enumeration, you know the keys you're going to get in advance, And unless the enumeration's values are all over the place for some reason, I'd then go for a plain old array rather than a dictionary.

    But then I don't C# so what do I know.


  • Notification Spam Recipient

    @PleegWat said in WTF Bites:

    If you're contemplating

    Not my code, I'm just pondering why it's like that in the first place.

    And whether it actually does cause GCs at all. Because, internally, enums are ints....


  • Notification Spam Recipient

    Status: Mothersucker!

    17e69d30-ee16-4ce1-b07a-e803a3b5ddf3-image.png



  • @Tsaukpaetra said in WTF Bites:

    17e69d30-ee16-4ce1-b07a-e803a3b5ddf3-image.png

    Pre-teen hokey pokey?



  • Please don't encourage him.

    @Tsaukpaetra said in WTF Bites:

    Keeps the mind distracted from planning total domination. I think most of us would agree that would be a Bad Thing.

    I'm not too worried. Any robot or AI you'd use would just keep crashing again and again 🎺



  • @PleegWat said in WTF Bites:

    // use ints for keys because enums cause (more) GC allocations

    He'd probably read something about Java - in Java Enums are wrappers around real class instances, so they will take up more space and if you're creating/dropping keys from your map they will exercise the GC.

    In C# enums are wrappers around a primitive (almost always int) so I don't believe that comment to be accurate.


  • Java Dev

    @bobjanova said in WTF Bites:

    @PleegWat said in WTF Bites:

    // use ints for keys because enums cause (more) GC allocations

    He'd probably read something about Java - in Java Enums are wrappers around real class instances, so they will take up more space and if you're creating/dropping keys from your map they will exercise the GC.

    In C# enums are wrappers around a primitive (almost always int) so I don't believe that comment to be accurate.

    I'm pretty sure java generic maps also only accept objects as keys. A generic map wouldn't accept a scalar int, only a boxed Integer. There might be a different collection which does accept scalar ints (and only scalar ints).

    I know C# can store non-scalar variables on the stack, so enums being scalar doesn't surprise me.



  • @PleegWat said in WTF Bites:

    I'm pretty sure java generic maps also only accept objects as keys. A generic map wouldn't accept a scalar int, only a boxed Integer.

    That is true but there is some sharing of instances for boxed numerics in Java so if your ints are numbers that are also used (and boxed) elsewhere - for example if they're sequential IDs this is quite likely - they won't need to be GCd.

    Edit: I should say though that this is almost guaranteed to be unnecessary micro-optimisation and there are much better places to look for wasted memory than this.


  • BINNED

    @Tsaukpaetra said in WTF Bites:

    total domination
    most of us would agree that would be a Bad Thing.

    error :um-actually:



  • @bobjanova said in WTF Bites:

    if your ints are numbers that are also used (and boxed) elsewhere

    AFAIR there are simply pre-created global instances for -128..127 that are always used for those values and any other values are always boxed fresh.



  • @PleegWat said in WTF Bites:

    I'm pretty sure java generic maps also only accept objects as keys.

    Yes, because Java generics are type-erased to use Object at runtime. But C# generics are not and CLR monomorphises the bytecode by patching appropriate size and copy instructions into it for value types (object types still end up being handled polymorphically IIRC).


  • BINNED

    @Tsaukpaetra said in WTF Bites:

    Status: Mothersucker!

    17e69d30-ee16-4ce1-b07a-e803a3b5ddf3-image.png

    How does it know if it should fade in or scale up? :sideways_owl:


  • Java Dev

    @bobjanova said in WTF Bites:

    Edit: I should say though that this is almost guaranteed to be unnecessary micro-optimisation and there are much better places to look for wasted memory than this.

    A couple of 4 or 8 byte integer objects in main memory are not that significant. In cache it'll be a different matter, since the boxed integer probably has to actually be loaded into cache and checked. I don't know what hash code Integers use; if they don't use the identity hash multiple boxed integers may need to be fetched in case of hash collisions.

    This could be optimised out by marking Integer->GetHashCode() to be injective (identical hash codes are always identical objects) and having the dictionary store the hash code in addition to the reference to the key object; if the flag is present then the key comparison can be skipped. I expect the hash code is stored, but I doubt the other required logic is present.


  • 🚽 Regular

    @Bulb said in WTF Bites:

    Yes, because Java generics are type-erased to use Object at runtime. But C# generics are not and CLR monomorphises the bytecode by patching appropriate size and copy instructions into it for value types (object types still end up being handled polymorphically IIRC).

    I feel like I've just read something about cricket except I know what you're talking about.


  • Discourse touched me in a no-no place

    @bobjanova said in WTF Bites:

    in Java Enums are wrappers around real class instances

    They're not wrappers. Enums are (special) classes and their values are instances.

    if you're creating/dropping keys from your map they will exercise the GC.

    Not so much. They're effectively shared constants that never get reclaimed (until the enum itself goes because you drop the classloader, if you're into such crazy things).



  • @dkf … so they are actually more efficient than integers, because integers above 127 (and below -128) will be reclaimed every time you remove them from the map (and just as efficient as integers between -128 and 127).



  • @dkf said in WTF Bites:

    They're effectively shared constants that never get reclaimed

    TIL


  • Discourse touched me in a no-no place

    @bobjanova said in WTF Bites:

    That is true but there is some sharing of instances for boxed numerics in Java so if your ints are numbers that are also used (and boxed) elsewhere - for example if they're sequential IDs this is quite likely - they won't need to be GCd.

    There is sharing of instances, but not if you use new Integer() directly. You have to use valueOf() to use the cache, or let the compiler insert it for you with auto-boxing.


  • Discourse touched me in a no-no place

    @Bulb said in WTF Bites:

    Yes, because Java generics are type-erased to use Object at runtime.

    It depends on what type constraints you've specified. If you've got a Foo<T extends Bar> declared then the T gets type-erased to Bar at runtime, and that's the API you can use inside the implementation of Foo's methods.


  • Discourse touched me in a no-no place

    @PleegWat said in WTF Bites:

    I don't know what hash code Integers use

    For Java, it's documented to be the integer value inside the box. That's a good choice: it's very cheap and has the correct hashcode properties (given that the value also drives equality).


  • Discourse touched me in a no-no place

    @Bulb said in WTF Bites:

    @dkf … so they are actually more efficient than integers, because integers above 127 (and below -128) will be reclaimed every time you remove them from the map (and just as efficient as integers between -128 and 127).

    Perhaps. It depends on what you're doing. Use integers if you're interested in the numeric values, and enums if you just care that they're distinct named tokens.

    The way Java does enums is nice in a number of ways, especially when you want to have the enumerated things have various properties that vary a bit but are distinct from the enumeration value itself. Instead if needing a switch on an enum all over the place, you instead just get the property from the enum value: it is its own expert on its nature. OTOH, they also have the weird feature that you can make the enum values be nameless subclasses, which lets you do quite odd things (while allowing for the fact that the instances are still effectively global static values). I can't remember if I've misused that in production code yet. 😆



  • @dkf said in WTF Bites:

    which lets you do quite odd things (while allowing for the fact that the instances are still effectively global static values). I can't remember if I've misused that in production code yet.

    You mean like

    public enum SessionFactoryProvider {
    
        INSTANCE("mybatis-config.xml");
    
        private SqlSessionFactory sqlSessionFactory;
    
        private void init(String config) {
            /* ~80-line function (+ some helpers) that loads a XML file (as text), loads
               a properties file, replaces some bits of text in the XML files with the
               properties using String.replace, creates a SqlSessionFactory with it and
               sets the sqlSessionFactory member… */
        }
    
        public getSessionFactory() {
            return sqlSessionFactory;
        }
    }
    

    I had to touch that just last week. I normally don't work on that project, or in Java at all, but they wanted help configuring something in the database and this is how they work the relevant bit of configuration. I didn't even have to anonymize it besides snipping the guts as it is a mostly generic bit of code setting up Apache MyBatis connection pool (SqlSessionFactory = org.apache.ibatis.session.SqlSessionFactory).


  • Discourse touched me in a no-no place

    @Bulb said in WTF Bites:

    You mean like

    Not quite. That's just a weird abuse. I meant more like this:

    public enum BinaryOperation {
        ADD("add") {
            public int apply(int x, int y) { return x + y; }
        }, MULT("multiply") {
            public int apply(int x, int y) { return x * y; }
        };
        private BinaryOperation(String name) { /* :kneeling_warthog: */ }
        public abstract int apply(int x, int y);
    }
    

    And yes, this works. Horrifying, isn't it?



  • @dkf yikes


  • Banned

    @dkf I use that all the time in Scala. I guess it's less awful there due to Scala not having actual enums so I have to fake them with sealed trait+object hierarchies.



  • @dkf said in WTF Bites:

    @Bulb said in WTF Bites:

    You mean like

    Not quite. That's just a weird abuse. I meant more like this:

    public enum BinaryOperation {
        ADD("add") {
            public int apply(int x, int y) { return x + y; }
        }, MULT("multiply") {
            public int apply(int x, int y) { return x * y; }
        };
        private BinaryOperation(String name) { /* :kneeling_warthog: */ }
        public abstract int apply(int x, int y);
    }
    

    And yes, this works. Horrifying, isn't it?

    One interesting abuse of the enum in java is to build simple state machines with it. The states themselves have all the logic for state transitions.


  • Discourse touched me in a no-no place

    @Carnage said in WTF Bites:

    One interesting abuse of the enum in java is to build simple state machines with it. The states themselves have all the logic for state transitions.

    Umm, yeah, about that…

    ea18c8e2-2de8-43fc-b25e-5e0e925eeb02-image.png


  • Banned

    @Carnage said in WTF Bites:

    @dkf said in WTF Bites:

    @Bulb said in WTF Bites:

    You mean like

    Not quite. That's just a weird abuse. I meant more like this:

    public enum BinaryOperation {
        ADD("add") {
            public int apply(int x, int y) { return x + y; }
        }, MULT("multiply") {
            public int apply(int x, int y) { return x * y; }
        };
        private BinaryOperation(String name) { /* :kneeling_warthog: */ }
        public abstract int apply(int x, int y);
    }
    

    And yes, this works. Horrifying, isn't it?

    One interesting abuse of the enum in java is to build simple state machines with it. The states themselves have all the logic for state transitions.

    That's only useful if you have to know the current state externally. Which is actually rarely needed, except maybe some debug strings, but you can get that with toString() overload.

    And even if you do want to know the current state externally, separating the denomination of the state from the logic of the state is still a good idea.



  • @Gąska said in WTF Bites:

    @Carnage said in WTF Bites:

    @dkf said in WTF Bites:

    @Bulb said in WTF Bites:

    You mean like

    Not quite. That's just a weird abuse. I meant more like this:

    public enum BinaryOperation {
        ADD("add") {
            public int apply(int x, int y) { return x + y; }
        }, MULT("multiply") {
            public int apply(int x, int y) { return x * y; }
        };
        private BinaryOperation(String name) { /* :kneeling_warthog: */ }
        public abstract int apply(int x, int y);
    }
    

    And yes, this works. Horrifying, isn't it?

    One interesting abuse of the enum in java is to build simple state machines with it. The states themselves have all the logic for state transitions.

    That's only useful if you have to know the current state externally. Which is actually rarely needed, except maybe some debug strings, but you can get that with toString() overload.

    And even if you do want to know the current state externally, separating the denomination of the state from the logic of the state is still a good idea.

    I agree. I prefer code that follows least suprise, and the enum state machine code makes you go WTF?! when you see it.


  • Notification Spam Recipient

    @topspin said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: Mothersucker!

    17e69d30-ee16-4ce1-b07a-e803a3b5ddf3-image.png

    How does it know if it should fade in or scale up? :sideways_owl:

    You're beginning to understand my rage.


  • Trolleybus Mechanic

    @Tsaukpaetra But are you just a rat in a cage?


  • Notification Spam Recipient

    @Mingan said in WTF Bites:

    @Tsaukpaetra But are you just a rat in a cage?

    You know, someone will say that what is lost can never be saved.

    80aeedda-c5df-4858-a625-8985bf814fac-image.png

    I've reverted, I've wiped clean, reinstalled, but nothing works.

    Fuck Unity with serrated spikes on an orange dildo coated in ghost peppers!


  • ♿ (Parody)

    @dkf said in WTF Bites:

    There is sharing of instances, but not if you use new Integer() directly.

    0_1485818111155_Flying_wharrgarbl.jpg



  • @boomzilla said in WTF Bites:

    @heterodox said in WTF Bites:

    @Mason_Wheeler said in WTF Bites:

    @HardwareGeek said in WTF Bites:

    Speaking of Greek, Spanish words of Greek origin ending in -ma retain the masculine gender of their Greek roots, even though all other words ending in -a are feminine.

    Yeah, "el sistema" throws everyone for a loop when they first encounter it.

    That's interesting to know. Also el problema and el tema and others I can't think of right now. I'd never noticed -ma being the common denominator.

    Generally words that have Greek, not Latin roots. Or so I was taught.

    That's what @HardwareGeek said in the original quote. :)



  • @topspin said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: Mothersucker!

    17e69d30-ee16-4ce1-b07a-e803a3b5ddf3-image.png

    How does it know if it should fade in or scale up? :sideways_owl:

    I suppose there is a function somewhere along the lines of setEffect(int move, int fade, int scale) and you are supposed to call it like setEffect(TWEEN_MOVE_IN, TWEEN_FADE_OUT, TWEEN_SCALE_DOWN) to make the code more readable. But there is nothing stopping you from making it less readable by instead writing setEffect(TWEEN_SCALE_UP, TWEEN_MOVE_OUT, TWEEN_FADE_OUT).

    If instead there are three methods setMove(int direction), setFade(int direction) and setScale(int direction), it's a nibble better, because it kind of looks like a stick in the eye if you write setMove(TWEEN_SCALE_UP). I am not saying nibble better means good. It doesn't.


  • Notification Spam Recipient

    @Bulb said in WTF Bites:

    @topspin said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: Mothersucker!

    17e69d30-ee16-4ce1-b07a-e803a3b5ddf3-image.png

    How does it know if it should fade in or scale up? :sideways_owl:

    I suppose there is a function somewhere along the lines of setEffect(int move, int fade, int scale) and you are supposed to call it like setEffect(TWEEN_MOVE_IN, TWEEN_FADE_OUT, TWEEN_SCALE_DOWN) to make the code more readable. But there is nothing stopping you from making it less readable by instead writing setEffect(TWEEN_SCALE_UP, TWEEN_MOVE_OUT, TWEEN_FADE_OUT).

    If instead there are three methods setMove(int direction), setFade(int direction) and setScale(int direction), it's a nibble better, because it kind of looks like a stick in the eye if you write setMove(TWEEN_SCALE_UP). I am not saying nibble better means good. It doesn't.

    There are actually six methods and six callbacks.

    I'm nearly choking on all this spaghetti...


  • Discourse touched me in a no-no place

    @Tsaukpaetra said in WTF Bites:

    I'm nearly choking on all this spaghetti...

    The code needs to go on a diet.

    How much of our code is just working around stupid abstractions in dependencies? So much effort, and all just to convey what's often just a single bit of information.



  • @boomzilla said in WTF Bites:

    setFoo( new Boolean( false ) )

    That's wrong. The author obviously intended

    setFoo( new Boolean( ! true ) )


  • @HardwareGeek said in WTF Bites:

    Spanish words of Greek origin ending in -ma retain the masculine gender of their Greek roots, even though all other words ending in -a are feminine.

    Sí. El guitarrista debe tocar las cordas con la mano derecha.



  • @Mason_Wheeler said in WTF Bites:

    805cf307-b791-4993-936d-2176ef4cbfdd-image.png

    Oh dear, are you a relative of Zonen-Gaby that you still can be fooled with cucumbers?


Log in to reply