Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
inaba45895yDoes it work? If yes it's probably alright.
Extracting the bytes to constants would probably be a nice idea -
Or you could, you know, just make it explicit and iterate over an array or something, so the code speaks for itself.
-
@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.
-
@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.
-
@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.
-
Root797345y@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.
Related Rants
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.
rant
binary
cube
messy maths