11
Lor-inc
11d

Is this a bad way to traverse corners of a cube?
The objective is obvious from the context and I assume that programmers know how binary works.

Comments
  • 1
    Does it work? If yes it's probably alright.

    Extracting the bytes to constants would probably be a nice idea
  • 12
    Perhaps add a small comment, since it might be confusing at first glance
  • 3
    @alexbrooklyn Comment is good idea. Better than named constants.
  • 1
    Or you could, you know, just make it explicit and iterate over an array or something, so the code speaks for itself.
  • 2
    @gronostaj That would be slow and long. The only way I can think of to not make it slower is with nested loops, but that's way too verbose for the complexity of the task.
  • 0
    @Lor-inc Depends what you're using this code for. If it's in a tight loop, then sure, this code is justified. If it runs less than 1000 times per second, make it clean rather than fast, you probably won't notice a difference in performance.
  • 0
    @gronostaj Actually, it's used to generate procedural 3d terrain data for a game where you can move quite fast. So, it probably runs at least 100 times per second.
  • 2
    @Lor-inc I think the code is clean and readable enough. Add a comment for those unfamiliar with what it's doing (and ofc why) and mention that it's using bitwise math for speed and conciseness. That should be plenty.

    If someone still can't follow, they shouldn't be touching it anyway.
Add Comment