Meme transcription:

Panel 1: Bilbo Baggins ponders, “After all… why should I care about the difference between int and String?

Panel 2: Bilbo Baggins is revealed to be an API developer. He continues, “JSON is always String, anyways…”

You are viewing a single thread.
View all comments View context
17 points

Or even funnier: It gets parsed in octal, which does yield a valid zip code. Good luck finding that.

permalink
report
parent
reply
5 points

Well shit, my zip code starts with a 9.

permalink
report
parent
reply
5 points

I’m not sure if you’re getting it, so I’ll explain just in case.

In computer science a few conventions have emerged on how numbers should be interpreted, depending on how they start:

  • decimal (the usual system with digits from 0 to 9): no prefix
  • binary (digits 0 and 1): prefix 0b, so 0b1001110
  • octal (digits 0 through 7): prefix 0, so 0116
  • hexadecimal (digits 0 through 9 and then A through E): prefix 0x, so 0x8E

If your zip code starts with 9, it won’t be interpreted as octal. You’re fine.

permalink
report
parent
reply
7 points
*

Well, you’re right. I wasn’t getting it, but I’ve also never seen any piece of software that would treat a single leading zero as octal. That’s just a recipe for disaster, and it should use 0o116 to be unambiguous

(I am a software engineer, but was assuming you meant it was hardcoded to parse as octal, not some weird auto-detect)

permalink
report
parent
reply
3 points

Who tf decided that a 0 prefix means base 8 in the first place? If a time machine was invented somehow I’m going to cap that man, after the guy that created JavaScript.

permalink
report
parent
reply
7 points

Should be like 0o777 to mimic hex 0xFF

permalink
report
parent
reply
3 points

Oof.

I guess this is one of the reasons that some linters now scream if you don’t provide base when parsing numbers. But then again good luck finding it if it happens internally. Still, I feel like a ZIP should be treated as a string even if it looks like a number.

permalink
report
parent
reply
4 points

Yep. Much like we don’t treat phone numbers like a number. The rule of thumb is that if you don’t do any arithmetic with it, it is not a “number” but numeric.

permalink
report
parent
reply
1 point
*

Well, we don’t, but every electonic tables software out in the wild on the other hand…

/j

Yes, I know that you can force it to become text by prepending ' to the phone, choose an appropriate format for the cells, etc, etc

The point is that this often requires meddling after the phone gets displayed as something like 3e10

permalink
report
parent
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 2K

    Monthly active users

  • 861

    Posts

  • 14K

    Comments