logoalt Hacker News

AKSF_Ackermanntoday at 2:46 PM9 repliesview on HN

> When programming, it is still important to write code that runs correctly on systems with either byte order

What you should do instead is write all your code so it is little-endian only, as the only relevant big-endian architecture is s390x, and if someone wants to run your code on s390x, they can afford a support contract.


Replies

cbmusertoday at 6:24 PM

> What you should do instead is write all your code so it is little-endian only, as the only relevant big-endian architecture is s390x, and if someone wants to run your code on s390x, they can afford a support contract.

Or you can just be a nice person and make your code endian-agnostic. ;-)

jcalvinowenstoday at 4:31 PM

Don't ignore endianness. But making little endian the default is the right thing to do, it is so much more ubiquitous in the modern world.

The vast majority of modern network protocols use little endian byte ordering. Most Linux filesystems use little endian for their on-disk binary representations.

There is absolutely no good reason for networking protocols to be defined to use big endian. It's an antiquated arbitrary idea: just do what makes sense.

Use these functions to avoid ifdef noise: https://man7.org/linux/man-pages/man3/endian.3.html

GandalfHNtoday at 4:13 PM

Outsourcing endianness pain to your customers is an easy way to teach them about segfaults and silent data corruption. s390x is niche, endian bugs are not.

Network protocols and file formats still need a defined byte order, and the first time your code talks to hardware or reads old data, little-endian assumptions leak all over the place. Ignoring portability buys you a pile of vendor-specific hacks later, because your team will meet those 'irrelevant' platforms in appliances, embedded boxes, or somebody else's DB import path long before a sales rep waves a support contract at you.

show 4 replies
j16sdiztoday at 3:30 PM

If you comes to low level network protocol (e.g. writing a TCP stack), the "network byte order" is always big-endian.

show 4 replies
addaontoday at 3:53 PM

There's still at least one relevant big-endian-only ARM chip out there, the TI Hercules. While in the past five or ten years we've gone from having very few options for lockstep microcontrollers (with the Hercules being a very compelling option) to being spoiled for choice, the Hercules is still a good fit for some applications, and is a pretty solid chip.

sllabrestoday at 5:38 PM

Not only the System/390. Its also IBM i, AIX, and for many protocols the network byte order. AFAIK the binary data in JPG (1) and Java Class [2] files a re big endian. And if you write down a hexadecimal number as 0x12345678 you are writing big-endian.

(1) for JPG for embedded TIFF metadata which can have both.

[2] https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.ht...

show 1 reply
nyrikkitoday at 3:42 PM

The linked to blog post in the OP explains this better IMHO [0]:

   If the data stream encodes values with byte order B, then the algorithm to decode the value on computer with byte order C should be about B, not about the relationship between B and C.
One cannot just ignore the big/little data interchange problem MacOS[1], Java, TCP/IP, Jpeg etc...

The point (for me) is not that your code runs on a s390, it is that you abstract your personal local implementation details from the data interchange formats. And unfortunately almost all of the processors are little, and many of the popular and unavoidable externalization are big...

[0] https://commandcenter.blogspot.com/2012/04/byte-order-fallac... [1] https://github.com/apple/darwin-xnu/blob/main/EXTERNAL_HEADE...

show 2 replies
bear8642today at 3:23 PM

> the only relevant big-endian architecture is s390x

The adjacent POWER architecture is also still relevant - but as you say, they too can afford a support contract.

show 1 reply
EPWN3Dtoday at 3:27 PM

I mostly agree, but network byte ordering is still a thing.