News for hackers. Stuff that matters.
Re:Left-Pad (2024) by yurishimo on Wednesday June 11, 2025 @07:06AM (#44246300)
You're missing the point. Nobody with a serious background in software development should ever need to pull in a package to pad a string or check if a number is even or odd. If someone is smart enough to use a package manager, they should be more than capable to write a function to pad a string (assuming the standard library doesn't include one already)!
Re:Left-Pad (2024) by gpiancastelli on Wednesday June 11, 2025 @07:54AM (#44246650)
However, JavaScript never had a proper standard library.

Combine this to mainstream education teaching that you should always reuse code when possible instead of "reinventing the wheel", and web shops agreeing to it because "using libraries saves time", and it's easy to understand the "popularity" of left-pad.

To a certain extent, and to the best of my knowledge, those things haven't really changed.

Re:Left-Pad (2024) by baobabKoodaa on Wednesday June 11, 2025 @07:18AM (#44246379)
While you are correct, the problem compounds when popular package developers choose to use tiny packages.

I don't need left-pad.

But maybe I need react-starter-kit.

Now, imagine that react-starter-kit has a dependency to markdown-js-blobber, which has a dependency to make-text-nice, which has a dependency to left-pad.

In this scenario I am now "pulling in a package to pad a string". If I am "smart enough to use a package manager", I should be "more than capable to write..." an alternative to react-starter-kit..?

Re:Left-Pad (2024) by jstanley on Wednesday June 11, 2025 @07:32AM (#44246475)
The onus there is on the "make-text-nice" developer, not an eventual user of "make-text-nice".
Re:Left-Pad (2024) by yurishimo on Wednesday June 11, 2025 @09:04AM (#44247172)
I don't place any blame here on the person using `react-starter-kit` and I think you're being a bit obtuse to suggest otherwise. It's the original person who pulled in a package for <10 lines of code who is to blame.
Re:Left-Pad (2024) by baobabKoodaa on Saturday June 14, 2025 @06:41AM (#44275534)
I provided the real reason for the high download counts of these packages.
Re:Left-Pad (2024) by eviks on Wednesday June 11, 2025 @08:40AM (#44247004)
How does serious background help the argument for wasting your time writing code that's already been written. By the way, why should serious people use padding from the standard library?
Re:Left-Pad (2024) by yurishimo on Wednesday June 11, 2025 @09:07AM (#44247198)
I would argue that a leftpad/is-odd package is the equivalent of writing a for loop. The time it cost you to search the internet, download the package, and rerun your build script cost more than the time to write the function from scratch and the behavior is indentical.

Duplicate code across the ecosystem is fine. Not every function must be unique for an entire programming language.

Re:Left-Pad (2024) by eviks on Wednesday June 11, 2025 @10:15AM (#44247871)
What about the time it cost you to search the internet, read the docs, and use the one from std? How many seconds does each variant take (with hot/cold memory cache?)

And the behavior could also be worse, there is no guarantee of perfection.

The last argument is too generic to offer any guidance. Why is it better for this function be duplicated?? Should it not be part of std to avoid uniqueness?

Re:Left-Pad (2024) by Izkata on Wednesday June 11, 2025 @06:25PM (#44252484)
> Should it not be part of std to avoid uniqueness?

> > > > (assuming the standard library doesn't include one already)

Re:Left-Pad (2024) by eviks on Wednesday June 11, 2025 @10:11PM (#44253699)
This doesn't address the should
Re:Left-Pad (2024) by beej71 on Wednesday June 11, 2025 @10:05AM (#44247772)
The standard library is a far less risky dependency than third-party libraries. It's far more reliable in presence and behavior.
Re:Left-Pad (2024) by eddd-ddde on Wednesday June 11, 2025 @09:14AM (#44247260)
Ironically I feel like this is something LLMs will improve. Now anyone can type "create left pad function" and it will essentially just vendor in the existing code.