- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- Teamwork
- Cuts Like a Knife
- Charge Me
- Que Sera, Sera
- Hot Dog
- Sentinel Headline
- Mais Que Nada
- Here Comes the Sun
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Edit Admin
Fortunately, they were experienced enough to declare it as an unsigned long to avoid . . . never mind.
Addendum 2025-05-20 06:40: ah, Java doesn't actually have that, mea culpa.
Admin
While
0xFFFFFFFF
is a valid literal in Java, it would also be the wrong literal. As dpm noted, Java does not have unsigned types like C(++) does, but it does guarantee thatlong
is exactly 64 bits andint
32.0xFFFFFFFF
would be a literal of typeint
and therefore have the value -1. Maybe the author found that out the hard way and that's how this code was born.What they really wanted, of course, is
private static final long BITMASK32 = 0xFFFFFFFFL;
Edit Admin
TRWTF is Java (ducks)
Edit Admin
FFFFFFFFF is the sound that one makes when seeing code like this
Edit Admin
No, the sound you're thinking of is "AAAAAAAAAAAAAAAAH! Run away! Run away!"
Edit Admin
There used to be a restaurant in Janesville, WI named HHFFRRRGH (pronounced huff-FARG). I submit that would be just as good (if not better) of variable name.
Edit Admin
I'm learning the difference between "TWENTY = 20" and "FFFFFFFF = 0xFFFFFFFF". While 20 is pretty easy to verify in one's code, it's easy to be off-by-one in a string of Fs. By using a symbol instead of a literal, one benefits from syntax checking in the IDE and the compiler.
Edit Admin
TRWTF is that the constant is not declared final.
Admin
While I enjoy twiddling bits as much as most devs, the proper way to do this in Java is the BitSet class.
I actually used that, and wrote it out to a MSSql table as.. a bigint, I think? at my old job. Then I did the unthinkable and made a view into said table that converted the compressed bit data and separated it out into individual enum values stored in another table. Lots of pow() functions, if memory serves.
I don't think anyone was dumb enough to use that human-query-only view for automated processes (rather than the service API, which is how it was supposed to be done), but who knows!
Admin
So why not name it ALL_BITS?
Edit Admin
If you actually have to deal with hex numbers, isn't Java a bad choice in general. It doesn't even have unsigned types.
Edit Admin
Absolutely, I do prefer more descriptive values. If Smithers is correct that "long" values are 64-bits, then maybe "SOME_BITS" or "LOW_WORD" would be appropriate.