6

Using bitmasks in Javascript. Never done that before...

Comments
  • 4
    So why start now..?

    I've never eaten human flesh. Not starting to any time soon..
    So maybe you shouldn't start doing something more horrible then?
  • 5
    Well - js support bitwise operations.

    1 sec...
    I'm sure there is an npm package for this!
  • 1
    @magicMirror Or some jQuery crap.
  • 2
    @netikras It's not like bitmasks are bad. I needed a way of doing some truth table-like operations. Masks felt like a logical solution
  • 2
    @netikras what's so bad about them? They're quite straightforward and efficient.
  • 0
    @RememberMe readability. It's fine if these operations are encapsulated deep down. From what I have seen they usually are not. Once the dev discovers how nice bitwise operations are everything starts to look very much like a bitwise nail to him. Which can, ofc, only be handled with bitwise operations.

    This way rest of the code becomes riddled with shifts, logical mult/divs, etc.

    The result is NON-readable, NON-maintainable, NO-good.
  • 3
    @netikras You could say the same about ANY operations. Code that is riddled with additions and subtractions is unmaintainable? Yeah that sounds stupid.
  • 2
    @netikras Very much depends on use case.
  • 1
    @Fast-Nop bitwise operations is not something you need to use daily as a webdev. Additions and substractions - are. When I open a code file I DO know I will see some additions and substractions. I rarely ever expect to see shifts or masks.

    I don't mind them in low-level code in C or asm, perl, maybe even python. In those languages I always operate in bin/dec/hex. But jamming bitwise ops into high-lvl, like js, java et al feels unnatural and hardly readable. Hence the note about deep encapsulation behind easily readable method names.
  • 1
    @netikras It depends on whether these operations make sense, and you're right that this is rare in web dev. But when they are the right tool, they're only unmaintainable to people who lack the domain knowledge for that specific application, and these shouldn't be let loose on such code anyway.

    Just being afraid of shifts is not a valid argument.
  • 0
    @Fast-Nop I disagree. These people should be educated and grown. Noone is an expert in something new to them. Who's to say your bitwise code parts will not be passed over to junior devs as you will be off to a newer, better project? Are the juniors expected to be know-all now? Should they be let go of if they do not know the domain or are not bitwise experts? No they are not. They WILL master the domain and tech if they are educated, not gotten rid of.

    And I mostly agree with you that sometimes they feel like the best fit for the job. I'd just like to add that more readable alternatives should also be considered either way. IMO an approach easier to read and maintain by a new guy in the project or a junior dev should always have higher priority. Unless these approaches come with a cost that's just too high
  • 1
    @netikras If a junior can't even be expected to know shifting, I think he should instead go to McD and flip burgers.
  • 0
    @Fast-Nop allright, that is where our opinions separate paths
Add Comment