4 ms·
toybox is pretty cool, but there is one big problem (though I am biased): the `bc` it has is old and outdated and not much better than the GNU `bc`. The last u
by ghoward 5y ago
toybox is pretty cool, but there is one big problem (though I am biased): the `bc` it has is old and outdated and not much better than the GNU `bc`.
The last update was several years ago because Rob wanted to maintain the version in toybox himself. It has not gotten much love since.
Source: I am the author of the `bc` in toybox. My current version [1] is much faster and has more math libraries and extensions. Even Android uses my current version rather than the version in toybox.
Edit: mistakenly said that toybox has my `dc`. It does not. Busybox does, and I mixed them up. I've corrected the above.
[1]: https://git.yzena.com/gavin/bc https://git.yzena.com/gavin/bc
- marcodiego 5y agoWhy isn't it merged?
- ghoward 5y agoRob has a big goal in conflict with my goals: he wants as few lines of code as possible. Obviously, the performance and extra features require more lines of code. So he does not want my updates.
- ducktective 5y agoActually as of now, toybox does not contain bc or dc. There is a bc in community dir. Even busybox in many builds does not come with bc which is a posix requirement.
- ghoward 5y agoBusybox's bc and dc are also based on mine, by the way. And no, many people don't include them in builds, but that doesn't mean it doesn't have them. The reason is probably because bc is a much bigger utility than most utilities in busybox and "bloats" the binary size. ("Bloat" is a relative term. The busybox version is probably less than 100 kb.) While toybox does not have my dc, I don't know what you mean by toybox not having a bc. It does, and it is based on mine. It's not in the community directory, it's in the pending directory (bc.c), which just means it's not enabled by default. You can enable it if you wish. Rob himself does because it's what allows toybox to have all of the utilities necessary for building Linux. (Yes, Linux requires bc to build.) Edit: I've corrected my parent comment because you are right that toybox does not have my dc. But it does still have my bc.
- ducktective 5y agoYeah, I meant that currently, there is no way to do non-trivial mathematical calculations with either of default builds of busybox* [1] or toybox [2] [1] https://busybox.net/downloads/BusyBox.html https://busybox.net/downloads/BusyBox.html [2] http://landley.net/toybox/status.html#done http://landley.net/toybox/status.html#done *In busybox, there is `dc` but that is really hard to code in due to RPN. Thanks for that note about bc being a build dependency of Linux kernel! For other people, more info here: https://unix.stackexchange.com/a/439483/306382 https://unix.stackexchange.com/a/439483/306382
- ghoward 5y ago> Yeah, I meant that currently, there is no way to do non-trivial mathematical calculations with either of default builds of busybox* [1] or toybox [2] Yeah, that is a fair assessment; thank you for clarifying. Rob has said that when he goes through my `bc` and ensures it is up to his standards, he'll take it out of `pending` and put it in `posix`. Honestly, I don't know why he won't just accept me as the maintainer of it; I know it's already up to his standards because my `bc` is more well-tested than the rest of toybox combined. And I've fuzzed it to the point where I am confident that it has no memory bugs.
- Ciantic 5y agoI think with "few lines of codes as possible" he wants auditability. Rob mentions it as something of a feature: https://youtu.be/MkJkyMuBm3g?t=744 https://youtu.be/MkJkyMuBm3g?t=744 about 12 minute mark, he mentions how people used BusyBox in US army because they wanted to audit all the code, and this was his realization. I think it's a worthy goal. But surely if bc is missing some useful features there is probably no harm having multiple implementations.
- ghoward 5y agoUpvoted your for good points. However... I think it's a false goal if it comes before correctness. Auditability is great, but it's kinda useless to say, "Yep, I know your code is wrong." Unfortunately, it seems to be Rob's number one goal over even correctness. (Busybox is even worse about binary size.) And with the way Rob asked for me to change things, it actually made things less readable, which is an important part of auditability. So he and I have a fundamental disagreement over it.
- ducktective 5y agoDo you know by any chance why POSIX bc has this weird limitation that function and variable identifiers should have a mere single letter (a-z)?
- ghoward 5y agoThat is a good question. I have a (very) educated guess, but it's still only a guess. I think there were two reasons. The first is historical practice. POSIX themselves say that they don't codify new standards. Instead, they codify existing practice as standards. In practical terms, this means that they look at what all implementations that they care about do, figure out what is common among them, and codify that as a standard. As far as I can tell, at the time that POSIX was first codified, there was at least one `bc` implementation that only accepted single letter names. So that's what they codified. Some evidence for this reason: in the Rationale section of the `bc` standard [1], they mention historical practice and implementations several times. (As an aside, the reason that that implementation only accepted single letter names is because it was a compiler for `dc`, and `dc` only accepts single letter names because of its reverse polish notation and "one letter per command" design.) The second reason, while related to the fact that historically, `bc` was a frontend to `dc`, is slightly different: it's easier to implement that way. If you look at the original source of the original Robert Morris and Lorinda Cherry `bc` (which I have because I'm a nerd), its parser only looked for the second letter of each keyword. They could do that because all other identifiers would be single letters. It worked, and they also probably wanted to spend little time on it since most of the users would be programmers like themselves who could deal with such limitations easily, though that is an assumption on my part. (Someday I would like to talk to Morris and Cherry about it, as well as Philip Nelson, the author of the GNU `bc`.) By the way, the original Morris and Cherry implementation was the implementation in use at the time of codifying POSIX that only allowed single letter names. Its direct descendant is still in use today as the `bc` for the Plan 9 operating system. So that's my guess. Take it with a grain of salt.
- ducktective 5y agoThank you very much for this thorough reply. That is probably it. Now, suppose I want to write a POSIX shell script that does trigonometric calculations. Should I actually use `bc`? Is there a "translator" that reads `GNU bc` or your `bc` for example, and converts it into POSIX-compliant bc? (meaning converting the symbols to one letter in a way that does not produce conflict, declaring all used variables in a function in the first line (auto), etc)