Why is the conditional byte order bad?

Linus claims [ 1 2 ] that conditional byte order is worse than stupid ones.

The first thing that comes to my mind is ZFS , but there must certainly be other examples.

He wrote:

The only reasonable model is to specify one fixed byte order. Jokes aside. It is equally portable, it generates the best code - even for architectures, which then must unconditionally perform byte replacement of bytes - and it is easier to add static type checks, etc. . This is literally less code and faster to execute the "bswap" instruction than to perform a conditional test on some variable (even if you can avoid bswap dynamically)

I think that conditional byte order can generate longer code, but it should be faster on machines that use the same byte order. Most of his views seem to be about code aesthetics. I am not an expert, so I would like a more detailed explanation of his points.

+4
source share
1 answer

You asked to explain Linus's claims. You are mistaken in the fact that they relate to aesthetics.

When Linus says: "[fixed byte order] generates better code," he basically talks about more efficient (i.e. faster) machine code.

When he says: "it's easier to add static type checks, etc." he probably talks about the C source code, but that's not a question of aesthetics. Simplified code is easier to understand, easier to maintain, and has less surface area for errors. Often (but not always) it also generates the best machine code.

, " " bswap ", ," , , , , . , , , , , .

Linus , , . , , , , . , , , , .

Linus .

+3

All Articles