WTF Bites
-
@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.
-
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.
Why bother fixing bugs when you can remove the feature instead?
-
@Zerosquare can't have bugs if you have no features
-
@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.
-
@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€.
"They just paid a lot of money to get this fixed, you can't just tell them 'it runs fine if you disable that.'"
"Hold my beer."
-
@Zerosquare
Don't forget to that they point to apps with competing features as solutions
-
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.
I think we all agree you're a pretty curious person indeed.
-
@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.
-
@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.
-
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....
-
Status: Mothersucker!
-
-
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
-
// 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.
-
@bobjanova 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 boxedInteger
. 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.
-
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.
-
-
@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.
-
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).
-
@Tsaukpaetra said in WTF Bites:
Status: Mothersucker!
How does it know if it should fade in or scale up?
-
@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.
-
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.
-
@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).
-
-
@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 usevalueOf()
to use the cache, or let the compiler insert it for you with auto-boxing.
-
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 theT
gets type-erased toBar
at runtime, and that's the API you can use inside the implementation ofFoo
's methods.
-
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).
-
@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.
-
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
).
-
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
-
@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.
-
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.
-
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…
-
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.
-
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.
-
@Tsaukpaetra said in WTF Bites:
Status: Mothersucker!
How does it know if it should fade in or scale up?
You're beginning to understand my rage.
-
@Tsaukpaetra But are you just a rat in a cage?
-
@Tsaukpaetra But are you just a rat in a cage?
You know, someone will say that what is lost can never be saved.
I've reverted, I've wiped clean, reinstalled, but nothing works.
Fuck Unity with serrated spikes on an orange dildo coated in ghost peppers!
-
-
@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. :)
-
@Tsaukpaetra said in WTF Bites:
Status: Mothersucker!
How does it know if it should fade in or scale up?
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 likesetEffect(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 writingsetEffect(TWEEN_SCALE_UP, TWEEN_MOVE_OUT, TWEEN_FADE_OUT)
.If instead there are three methods
setMove(int direction)
,setFade(int direction)
andsetScale(int direction)
, it's a nibble better, because it kind of looks like a stick in the eye if you writesetMove(TWEEN_SCALE_UP)
. I am not saying nibble better means good. It doesn't.
-
@Tsaukpaetra said in WTF Bites:
Status: Mothersucker!
How does it know if it should fade in or scale up?
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 likesetEffect(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 writingsetEffect(TWEEN_SCALE_UP, TWEEN_MOVE_OUT, TWEEN_FADE_OUT)
.If instead there are three methods
setMove(int direction)
,setFade(int direction)
andsetScale(int direction)
, it's a nibble better, because it kind of looks like a stick in the eye if you writesetMove(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...
-
@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:
Oh dear, are you a relative of Zonen-Gaby that you still can be fooled with cucumbers?