329
parseInt(5) (lemmy.ml)
you are viewing a single comment's thread
view the rest of the comments
[-] heavy@sh.itjust.works 38 points 8 hours ago

I know this is for fun, but as general advice to the homies, if a language or system is doing something you didn't expect, make sure to look at the documentation

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

This will save a lot of time and headaches

[-] tauonite@lemmy.world 8 points 1 hour ago* (last edited 1 hour ago)

Holy fuck that is long. When the documentation for the integer parsing function is 10 pages long, there's something seriously wrong with the language

[-] Lemminary@lemmy.world 3 points 1 hour ago

Is it? I've seen longer articles for C# and not as many complaints about it.

[-] barsoap@lemm.ee 11 points 2 hours ago* (last edited 2 hours ago)

https://en.wikipedia.org/wiki/Principle_of_least_astonishment

...and of course JS made it into the examples, how could it not:

A programming language's standard library usually provides a function similar to the pseudocode ParseInteger(string, radix), which creates a machine-readable integer from a string of human-readable digits. The radix conventionally defaults to 10, meaning the string is interpreted as decimal (base 10). This function usually supports other bases, like binary (base 2) and octal (base 8), but only when they are specified explicitly. In a departure from this convention, JavaScript originally defaulted to base 8 for strings beginning with "0", causing developer confusion and software bugs. This was discouraged in ECMAScript 3 and dropped in ECMAScript 5.

[-] jsomae@lemmy.ml 1 points 3 hours ago* (last edited 3 hours ago)

Okay but this documentation is obviously wrong from the first sentence

The parseInt() function parses a string argument and returns an integer of the specified radix

Integers don't have radices. It should read:

The parseInt() function parses a string argument representing an integer of the specified radix and returns that integer.

~~Either way, I still don't understand the behaviour in the image.~~ nvm, thanks m_f@discuss.online

[-] Zacryon@feddit.org 7 points 7 hours ago

I'd advise to always look into the corresponding documentation before using something from any library.

[-] pinball_wizard@lemmy.zip 3 points 1 hour ago

But I'm too busy being confused by the behaviors of libraries I previously didn't read the documentation for, to read the documentation for every new library I adopt.

(This is sarcasm...mostly.)

[-] bisserkr@lemmy.world 14 points 5 hours ago

I'll go with 5 hours of debugging, thank you very much!

this post was submitted on 05 May 2025
329 points (98.5% liked)

Programmer Humor

23025 readers
1452 users here now

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

founded 2 years ago
MODERATORS