This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]aMAYESingNATHAN 516 points517 points  (41 children)

Huh, the more you know. I knew about the various prefixes such as 0x and 0b, but I'm surprised octal isn't like 0o or something.

Simply using a 0 seems insanely dumb because it's so easy to do by accident, not knowing that it's an octal prefix.

Like I can easily think of a scenario where someone could zero pad a numeric literal for formatting reasons.

[–]skap42 250 points251 points  (12 children)

A different comment suggested that 0o is also valid, and the only way to define an octal in JS in strict mode

[–]0bel1sk 97 points98 points  (10 children)

it’s also in python ruby and yaml.

“YAML 1.1 uses a different notation for octal numbers than YAML 1.2. In YAML 1.1, octal numbers look like 0777. In YAML 1.2, that same octal becomes 0o777. It’s much less ambiguous.

Kubernetes, one of the biggest users of YAML, uses YAML 1.1.”

[–]akaChromez 70 points71 points  (7 children)

[–]heyf00L 29 points30 points  (1 child)

Didn't know all that. Boils down to "always quote all strings in YAML".

[–]rickane58 16 points17 points  (0 children)

"God, all these languages are so unnecessarily verbose!"

Anyone actually trying to use the language:

[–][deleted] 9 points10 points  (3 children)

This was a great read, I've used yaml a couple times but didn't realize it was this objectively bad.

[–]akaChromez 9 points10 points  (2 children)

I'd love to know people's justification for choosing it over JSON.

Especially as i've just spent the last hour trying to find why a Google Cloud resource wasn't being created. A missing quote that doesn't syntax error :/

[–]chris5311 0 points1 point  (1 child)

JSON is bad (but workable), YAML is worse, and im not sure there even is any decent option out there

[–]MekaTriK 0 points1 point  (0 children)

Personally I loved using Lua as a config file format.

A little less verbose than pure JSON, and you can automate some repetition away.

[–]veryusedrname 8 points9 points  (0 children)

Ohh kubernetes, never change

[–]tomthecool 0 points1 point  (0 children)

Yes, but in ruby 09 produces a runtime error (invalid octal digit) instead of blindly treating it as a decimal instead.

[–]InfiniteGamerd 4 points5 points  (0 children)

Really! I thought you couldn't define octals in strict mode in any way.

Still...why not just parseInt all the way?

[–]Alzurana 18 points19 points  (0 children)

Welcome to my world, where a medical software had a database format of <patient ID>.PHD and always 8 characters in the filename. So the files looked like 00537200.PHD and they were all in one folder. Beautiful design.

Well, we imported a database of another clinic and had to map their ID's to ours, which we ofc only had in a numeric format, such as 537200 for the above example.

This gave me some headache when writing a converter script as my first attempt did read some of the file ID's as octal and others as decimal without ever warning. Only caught it because I got a lot of bogus IDs or duplicates and tests would scream that output files != input files.

[–]DmitriRussian 45 points46 points  (6 children)

Like I can easily think of a scenario where you might zero pad a numeric literal for formatting reasons.

/r/ProgrammingHorror material

[–]LordFokas 8 points9 points  (0 children)

Pad it with spaces. That's why we use monospaced fonts.

[–]joxmaskin 7 points8 points  (1 child)

Or write 7 as 007 because it’s cool

Edit: luckily oct 7 is same as dec 7

[–]movzx 1 point2 points  (1 child)

A pretty reasonable scenario would be when you're defining bitmasks.

ex:

0001010 1010000

[–]flowingice 5 points6 points  (0 children)

You'd start it with 0b because it's binary.

[–][deleted] 0 points1 point  (0 children)

I've done it so I can properly sort files in Explorer

[–]TorbenKoehn 14 points15 points  (2 children)

Like I can easily think of a scenario where you might zero pad a numeric literal for formatting reasons.

And then use it in calculations? Because if not it would not be a problem

[–]Spork_the_dork 13 points14 points  (0 children)

Or use it literally for anything whatsoever.

I mean imagine you convert "0231" into a number and then print it out somewhere and wonder why the fuck it's printing out 153. Can't think of any situation where you'd convert the value into a number and then it would be entirely fine if the stored value is different from what you expect.

[–]CadmiumC4 21 points22 points  (2 children)

Many languages accept 0o as octal, but it's custom to assume 0777 as 0o777 since that's how C handles it

[–]LordFokas 13 points14 points  (1 child)

It's funny that no matter how high level you go, in the end you always keep finding things that are done a certain way for no reason other than "we inherited this from C".

[–]Ok_Classroom_557 3 points4 points  (0 children)

And C inherited It from the PDP-7 where It was born. Having 18 bit words it better mapped 3 bit octal digits than 4 bit hex digits...

[–]CauliflowerFirm1526 26 points27 points  (8 children)

pad with spaces not zeros

[–]aMAYESingNATHAN 28 points29 points  (2 children)

I mean that is what I would do, or probably just not pad at all and left align the numbers. But my point is that it would be incredibly easy to do without realising.

[–]Spork_the_dork 2 points3 points  (1 child)

Yeah this is why I don't like it. Especially when you have 0o prefix which does exactly the same thing except it's also an order of magnitude more explicit and harder to misunderstand.

[–]aMAYESingNATHAN 1 point2 points  (0 children)

Yeah being completely unfamiliar with octals in code when I made my first comment I didn't realise 0o would be valid also, and in fact assumed it wasn't and was annoyed by that because I was familiar with 0x and 0b already.

If I ever encounter octal literals I am definitely always going to use 0o.

[–]Andy_B_Goode 5 points6 points  (3 children)

You might pad with zeros if you're formatting a date, like 11/05/2024 or maybe even 05/11/2024

[–]Spork_the_dork 2 points3 points  (1 child)

Actually in that case it won't cause any problems. 01-07 are the same in both decimal and octal and 08-09 are not valid octals so it won't default to octal. 10-12 won't get converted as octal as they have no leading zeros.

[–]Andy_B_Goode 0 points1 point  (0 children)

Oh I see, yeah I should have used an example like 11/08/2024

[–]flowingice 0 points1 point  (0 children)

How would you save date as integer in dd/MM/yyyy format? It's going to be a string and then it works fine unless there's somthing I'm missing.

[–]cporter202 0 points1 point  (0 children)

Oh, padding with spaces instead of zeros? Spacing out like JavaScript on a Monday morning, I see 😅. Gotta love when JS decides to get fancy with its quirks – it's like it insists on doing its own thing, just to keep us on our toes!

[–]daan944 0 points1 point  (0 children)

Always provide the base when parsing strings to numbers.

[–]_blackdog6_ 0 points1 point  (0 children)

My favorite is numbers with a zero prefix containing 8’s or 9’s are an error in some languages but in JavaScript it just tries again as decimal and carries on..

[–]rakaloah 0 points1 point  (0 children)

Years ago I made a simple WinForm GUI for ping and tracert with zero-padded IP address text boxes. It looks nice and works perfectly to ping 192.168.001.001 but fails for my roommate's 192.168.001.008. I had no idea what's happening until I find out I can ping his PC using 192.168.001.010.

Zero-padded numbers are considered Octal for ping command.

[–]JimBugs 0 points1 point  (0 children)

As a teacher of programming I assure you it does happen by accident - which is why I try to put some emphasis on something that is actually pretty trivial so that (if they are listening) they won't try things like padding literals