Bitwise operations



  • While doing a code review for a system written by another team, I encountered a class called: BitMask. Ok, that seems innocuous. Then I noticed a Spring configuration to provide it with a DB connection. WTF?!

    It turns out that the author is an SQL person, and didn't know that you could do bitwise operations in Java.

    So, instead of coding:

       long theMask;
    public void setBit(long bits) {
    theMask |= bits;
    }

    ...the guy created:

     

      - A DB table:
    threadName varchar2(64) not null, -- PK
    bitMaskNum number not null, -- index of bitmasks created in this thread (sub-PK)
    bitMask number not null -- the bitmask
    - Several SQL functions to take the argument and perform the required
    operation on the underlying bitmask using the builtin: bitand, and others
    - A stored procedure to query the value of the bitmask

    Of course, in mask-intensive activities, where you needed to check many bits in a row to see what to do if each one was set, it would pound the DB.

    When I pointed out the extreme inefficiency and complexity of his implementation of the requirements, he sheepishly admitted he isn't really a Java Guy.

    Ok, nobody knows everything; I certainly don't. But c'mon, what modern language does NOT support bitwise operations? At least ask someone or Google it.

     



  • Lol.



  • "If the only tool you have is a hammer..."



  • This isn't a WTF ... its a WTF when they start spinning up threads and adding DB connections to make it faster.



  • The beatings will continue until morale improves.



  • @zelmak said:

    This isn't a WTF ... its a WTF when they start spinning up threads and adding DB connections to make it faster.

    No... going to the DB for bitwise operations is indeed a WTF.



  • I've personally never used bitwise operators for any real-world business project.

    Therefore it's always useless and obscure. Always.



  • You clearly haven't been doing file format work then. I use bitwise operations all the time when working with binary files.



  • @snoofle said:

    Ok, nobody knows everything; I certainly don't. But c'mon, what modern language does NOT support bitwise operations? At least ask someone or Google it.
    This is also why learning the fundamentals of how computers actually work is important. Back in the day one of my EE Uni projects was to build a simple 4 bit CPU from 74xx series logic gates. And while I wouldn't expect programmers to be going to that level of education at least they should have been exposed to various assembler languages (another programming project I did was based on VAX assembler)



  • @snoofle said:

    At least ask someone or Google it.

    Couldn't agree more.

    I've been working my first real programming gig for about a year and a half now. At first, there was very little time to really guide me, so after a while I simply gave up asking about things every 5 minutes (also because a guy asking questions every 5 minutes turns out to be really annoying). Looking back, I'm amazed at what I learned simply by Googling for stuff and trying to figure things out for myself. It teaches you not only about your trade, but about Googling better, too. StackOverflow has become my friend in the process, and I've started to participate, just to be able to upvote questions and answers, because they were so helpful. I've grown so much more than I'd hoped I would when I started out.

    All because I took a little initiative and used a search engine!



  • snoofles, where the hell do you work at? They must be paying you a shit-ton of money to stick there... or you really love that endless WTF mine you've got in your hands

    Sigh... at least the guy used Spring and not a direct, never ending JDBC call to the database



  • @dhromed said:

    I've personally never used bitwise operators for any real-world business project.

    Therefore it's always useless and obscure. Always.

    COBOL doesn't have them at all, IIRC.



  • @snoofle said:

    It turns out that the author is an SQL person, and didn't know that you could do bitwise operations in Java.
     

    But he's even a lousy SQL person, since you can do such operations without a table, as in "SELECT a BITAND b FROM dual".


  • Considered Harmful

    @TGV said:

    Filed under: whoever thought from dual was a good idea

    Oracle, apparently. Microsoft SQL Server doesn't require such nonsense.



  • @dhromed said:

    I've personally never used bitwise operators for any real-world business project.

    Therefore it's always useless and obscure. Always.

    The main use I've seen for bitwise operations is enums where you can select multiple options (Such as (FooMode.Bar | FooMode.Qux).).



  • @ubersoldat said:

    where the hell do you work at?
    Unfortunately, someplace that has detailed personal information on most of you, myself included. And yes, they do pay me, as you put it, a shit-ton of money to be here.

    Bonus WTF: I looked myself up in the DB, and found a great deal of incorrect data. I put in a request to have it corrected, and got back the response: oh, it doesn't really matter.

    Really? This data is being used for data mining and is used to make recommendations to me that could cost me/the company a great deal of money, and it does NOT really matter? I politely escalated this conversation up a few levels until someone with a head on his shoulders (as opposed to up his ass) realized that perhaps data integrity might be a problem. A random check showed about 20% error rates (using employees, senior management and a few consultants as guinea pigs).

    Senior management acknowledged that there is a severe problem, but has circled the wagons, as now every memo about it comes from legal, and is marked Confidential.

     



  • @Cassidy said:

    "If the only tool you have is a hammer..."

    But snoofle has lots of "tools". Most of them are "programmers"

     



  • @snoofle said:

    Ok, nobody knows everything; I certainly don't. But c'mon, what modern language does NOT support bitwise operations? At least ask someone or Google it.

    Lua. (You can get Lua libraries to do them, though.)

     



  • @joe.edwards said:

    Oracle, apparently. Microsoft SQL Server doesn't require such nonsense.
     

    I thought it was that the SQL spec (at the time) stated that a query (SELECT) must be followed by a FROM clause, and this was a workaround to fulfil that requirement when dealing with psuedo-columns.



  • @Sutherlands said:

    @zelmak said:

    This isn't a WTF ... its a WTF when they start spinning up threads and adding DB connections to make it faster.

    No... going to the DB for bitwise operations is indeed a WTF.

    Yes, I realized that ... You were trolled ....



  • Doesn't matter what the spec says, no DBMS implements it.



  • @zelmak said:

    @Sutherlands said:

    @zelmak said:

    This isn't a WTF ... its a WTF when they start spinning up threads and adding DB connections to make it faster.

    No... going to the DB for bitwise operations is indeed a WTF.

    Yes, I realized that ... You were trolled ....

    Ah, yes, my response was very emotional.  You got me there.  Good job, chap!

  • BINNED

    Wow, IMO that's one of the biggest actual programming WTFs I've seen here in a while, even for snoofle posts. How did this guy ever get hired?? If he comes up with stuff like this, I bet even his SQL is so horrible that fixing his shit costs more than what he produces. Nevermind the Java code.

    Firing up a DB query for something that's a single CPU instruction? People like that need to get a different job.

    @ais523 said:

    @snoofle said:

    Ok, nobody knows everything; I certainly don't. But c'mon, what modern language does NOT support bitwise operations? At least ask someone or Google it.

    Lua. (You can get Lua libraries to do them, though.)

     

    Even rolling out your own implementation, maybe with some nice stupid string conversions thrown in for good measure, would be orders of magnitude less WTF.

     



  • @snoofle said:

    @ubersoldat said:

    where the hell do you work at?
    Unfortunately, someplace that has detailed personal information on most of you

    I get it, Snoofle works for [striketrough]youporn[/striketrough] [striketrough]Google[/striketrough] Facebook.


  • BINNED

    Your markup is bad and you should feel bad.



  • @snoofle said:

    But c'mon, what modern language does NOT support bitwise operations?
    SQL. That's why he needed all those functions and that stored procedure.

     


  • Discourse touched me in a no-no place

    @Severity One said:

    @snoofle said:
    But c'mon, what modern language does NOT support bitwise operations?
    SQL. That's why he needed all those functions and that stored procedure.
    The operative word is “modern”.



  • @Severity One said:

    @snoofle said:
    But c'mon, what modern language does NOT support bitwise operations?
    SQL.
     

    TSQL does.

  • ♿ (Parody)

    @dhromed said:

    @Severity One said:
    @snoofle said:
    But c'mon, what modern language does NOT support bitwise operations?</blockquote>
    SQL.

    TSQL does.

    So does PLSQL (as functions, not operators), which is presumably what's being used by the OP. But if you're going WTF, you might as well go full WTF.


Log in to reply