35 ms·
No, text on a canvas is a somewhat obvious nightmare. No, we must go simpler. left-pad: you need to account for wide characters, such as CJK characters but al
by deathanatos 4y ago
No, text on a canvas is a somewhat obvious nightmare.
No, we must go simpler.
left-pad: you need to account for wide characters, such as CJK characters but also emoji, you need to account for things like combining characters, etc. left-pad is not some trivial function.
Of course, the infamous left-pad package was widely mocked "why do you need a whole package for such a simple task" — so simple, indeed, that it failed to handle many of those cases. But don't worry, it's been standardized now as padStart() … and still fails those cases:
> 'e\u0301'.padStart(2)
'é'
Okay, strings aren't simple! But numbers, numbers are fine right?
So then, Go issue #4594, "add a Round function [to Go]"[1]. Go maintainer Ross Cox suggests that "it's a one liner" and suggests … a buggy implementation. There are a total of no less than 6 different implementations in the issue, and every single one of them is buggy. The bug is closed, the function is "too simple" to add. Thankfully, the wound gets reopened nearly a half-decade later in #20100. Another buggy implementation is suggested in that thread, and thankfully, Go gets a round function. (A non-buggy one … I think.)
[1]: https://github.com/golang/go/issues/4594 https://github.com/golang/go/issues/4594
- mro_name 4y agothe basics are incredibly hard. Listen to a physicist explaining time, matter or energy.
- deleted 4y ago[deleted]
- gernb 4y agoThe entire idea of padding by characters only fits a few use cases. leftPad would never have covered those cases. If you want tabular data use a table or grid. No amount of string gymnastics will get you aligned strings across languages and fonts. So yea, leftPad was always a bad idea because the only useful implementation is too trivial too have been put in a 3rd party library. Unless you believe there should have been a library called 'add' that was just `export const add = (a, b) => a + b;`