|
Volguus posted:Hahaha. This reminds me of another JSP page that I had the pleasure of seeing a few years back: It was holding the currently logged in users in a static java.util.Hashtable. 2 people could not log in/browse at the exact same time or the application would crash.
|
![]() |
|
![]()
|
# ? Jun 7, 2024 00:33 |
|
Soricidus posted:Why did it crash? Hashtable is supposedly thread-safe so it can’t be that. Hashtable is not thread safe. Methods in it are synchronized, that's true, so you can call "put" from 2 different threads and it works fine. But you can't iterate over it while trying to call put, for example. In general, in java, if you need a thread safe map one should use ConcurrentHashMap.
|
![]() |
|
Volguus posted:Hahaha. This reminds me of another JSP page that I had the pleasure of seeing a few years back: It was holding the currently logged in users in a static java.util.Hashtable. 2 people could not log in/browse at the exact same time or the application would crash. That was in addition to its many other issues. We had something similarly horrific in our DBManager class through which all db connectivity in the platform flowed. As a manager it was a Singleton, but one of the class level static fields of the thing was WHO IS CONNECTING. Normally this wasn't a problem because we would at least set the thing at the last possible moment before connections opened, until we happened to have two requests come in at the exact same millisecond. Ugh that was a bad night. Thankfully my only involvement in it was in the aftermath because I was one of the few devs who knew how to read packet traces.
|
![]() |
|
Volguus posted:Hashtable is not thread safe. Methods in it are synchronized, that's true, so you can call "put" from 2 different threads and it works fine. But you can't iterate over it while trying to call put, for example. In general, in java, if you need a thread safe map one should use ConcurrentHashMap. Hashtable has the worst kind of thread-safety, in that you pay the performance cost of locking but don't actually get any beneficial semantics in exchange.
|
![]() |
|
I think you can read and write elements atomically; the problem is that that’s not really an adequate API for a concurrent dictionary. But iterating isn’t a good example of why, both because IIRC you can safely iterate it (by synchronizing on it yourself) and because iteration is not an operation you should generally be using on concurrent data structures.
|
![]() |
|
Java code:
|
![]() |
|
code:
code:
![]()
|
![]() |
|
Cuntpunch posted:
|
![]() |
|
Just found out that our software provider who have trouble providing fixes for relatively simple bugs, have decided to not use on open source map solution with the new GIS module, but will instead roll out their own implementation. Fun times ahead.
|
![]() |
|
Do they have access to ships, cartographers, or constellation-tracking equipment? Or are they gonna drive around in their car taking GPS readings
|
![]() |
|
Dumb Lowtax posted:Do they have access to ships, cartographers, or constellation-tracking equipment? Or are they gonna drive around in their car taking GPS readings
|
![]() |
|
code:
code:
|
![]() |
|
Do they also define IS_THE_SAME because if so I'm behind them.
|
![]() |
|
Nolgthorn posted:Do they also define IS_THE_SAME because if so I'm behind them. No, only code:
|
![]() |
|
At least it's not:code:
|
![]() |
|
Y'all are unnecessarily afraid of some literate programming.
|
![]() |
|
I'm being triggered by these worth assignments, who's to say one number is better than another??
|
![]() |
|
CPColin posted:At least it's not:
|
![]() |
|
Scaramouche posted:I'm being triggered by these worth assignments, who's to say one number is better than another?? You're having a panic attack because of bad code?
|
![]() |
|
Doom Mathematic posted:You're having a panic attack because of bad code? More of a Guru Meditation
|
![]() |
|
If you did code:
|
![]() |
|
Subtly grammatically incorrect literate programming, now there’s a trend I could jump on!
|
![]() |
|
![]()
|
![]() |
|
So I assume there's potential for very slightly negative floats to compare as not less than 0 and they solved this issue in the most ridiculous way possible?
|
![]() |
|
I've seen code like that in production, namely the lack of a free alongside stupid things like calling strdup doing one test and abandoning the memory.
|
![]() |
|
jit bull transpile posted:So I assume there's potential for very slightly negative floats to compare as not less than 0 and they solved this issue in the most ridiculous way possible? ![]() You tell me (yes that's python and not a C-like, sue me)
|
![]() |
|
MrMoo posted:I've seen code like that in production, namely the lack of a free alongside stupid things like calling strdup doing one test and abandoning the memory. Could be Java ![]()
|
![]() |
|
jit bull transpile posted:So I assume there's potential for very slightly negative floats to compare as not less than 0 and they solved this issue in the most ridiculous way possible? I don't think so, but it is different from return (x < 0.0) in exactly one situation -0.0 is a valid floating point value, and -0.0 < 0.0 evaluates to false
|
![]() |
|
Jeb Bush 2012 posted:I don't think so, but it is different from return (x < 0.0) in exactly one situation -0 is still 0. So therefore, it's false because it's less than, not less than or equal to ![]()
|
![]() |
|
iospace posted:-0 is still 0. So therefore, it's false because it's less than, not less than or equal to oh sure, I'm not saying it's the wrong answer (and if the output of your code depends on whether -0.0 < 0.0, something has almost certainly gone very wrong), just that it's the only situation I can think of where the weird stringcasting code would give a different answer from returning x < 0.0
|
![]() |
|
jit bull transpile posted:So I assume there's potential for very slightly negative floats to compare as not less than 0 and they solved this issue in the most ridiculous way possible? Floating point does a lot with the space it has. The biggest trick is a hidden '1', every binary floating point number would look like 1.010101 x 210101, so the leading "1." is dropped. To represent those very small numbers the exponent of '0' indicates that there's no leading "1.". I thought it might have something to do with not caring if the input was a 32bit float or 64bit? A 20-character string is properly sized for a 64bit float, which can expand to 17 significant decimal digits plus 3 for the the sign, decimal point, and terminating \0. But I think it's just a waste of 8 bytes, per call. The most obvious optimization is using 'snprintf' with the size set to 1 to (hopefully) bail once the stringifier has sussed out that sign bit.
|
![]() |
|
Kuule hain nussivan posted:Just found out that our software provider who have trouble providing fixes for relatively simple bugs, have decided to not use on open source map solution with the new GIS module, but will instead roll out their own implementation. Fun times ahead. Ahaha. AHAHAHAHA. AHAHAHAHAHAHAHAHAHA Sure. Yes. Professional software outfits at the very least use established open-source libraries like GDAL if they're cheap, but sure, I bet this one podunk outfit is going to outdo all of them. ![]()
|
![]() |
|
JawnV6 posted:No. There's a sign bit. That doesn't change for the subnormal numbers, they just needed to check it. Cool. I know just enough about float to understand precision issues but wasn't sure if that extended to comparisons between zero and a really small negative number.
|
![]() |
|
no you don't. nobody does. ![]() (For real though, to actually understand precision issues, you have to be domain expert in floating point computation and in whatever you computation is doing, because all of exact comparison, absolute margin comparison, relative margin comparison, ULP comparison, can be the right or wrong choice, dependent on what you are actually doing)
|
![]() |
|
Volguus posted:
How else are you going to make the code work both for basketball and golf?
|
![]() |
|
And how else am I going to make absolutely sure the compiler will inline it?
|
![]() |
MononcQc posted:How else are you going to make the code work both for basketball and golf? Easy. code:
Now the code correctly shows that BASKETBALL BETTER_THAN GOLF.
|
|
![]() |
|
VikingofRock posted:Easy. You can just go ahead and #define GOLF LONG_MIN
|
![]() |
|
Jeb Bush 2012 posted:I don't think so, but it is different from return (x < 0.0) in exactly one situation Your standard library may write a NaN value with its sign bit set as "-nan", but since it's a NaN that comparison is still false. So the function differs from a plain compare in at least two situations ![]()
|
![]() |
|
![]()
|
# ? Jun 7, 2024 00:33 |
|
Bonfire Lit posted:Your standard library may write a NaN value with its sign bit set as "-nan", but since it's a NaN that comparison is still false. So the function differs from a plain compare in at least two situations maybe. python prints NaN with a set sign bit as just "nan", but I haven't tried writing it in C (and it could be implementation-dependent anyway I guess)
|
![]() |