Hacker News new | ask | show | jobs
by IshKebab 661 days ago
It isn't designed to be small; it's designed to be a fully featured string formatting library with size as an important secondary goal.

If you want something that has to be microscopic at the cost of not supporting basic features there are definitely better options.

> I can assure you that when writing code for microcontrollers with 2 kilobytes of code space, we don't include a 14 kilobyte string formatting library...

No shit. If you only have 2kB (unlikely these days) don't use this. Fortunately the vast majority of modern microcontrollers have way more than that. E.g. esp32 starts at 1MB. Perfectly reasonable to use a 14kB formatting library there.

2 comments

When you're designing something that sells for a dollar to retailers, eg. a birthday card that sings, your boss won't let you spend more than about 5 cents on the microcontroller, and probably wants you to spend 1-2 cents if you can.
Perhaps a singing birthday card doesn't need to format strings.
How else would you get nice looking logs for debugging it?
Using log4c
I kind of get where you're coming from but at what point do we admit that such use cases are the fringe and not the main?
> When you're designing something that sells for a dollar to retailers

Then you shouldn't prioritize compatibility with 1980s Unix code, which is what C++ is for.

Sure, but such extreme use cases are rare and don't need to be constantly brought up.
Even on larger microcontrollers you often have to write a bootloader...
Ok but most of these use cases don't link to the standard libs anyway, even if you're writing a C program.
Very occasionally I guess. They're almost always bare metal.
You still want a bootloader to support firmware updates, typically in the first 8 kB of flash or something like that.
Good point. I guess don't use `fmt` for that...
> esp32 starts at 1MB

Which models? The most I've ever seen on an ESP32 is 512KB of SRAM.

I think they are talking about the flash. The code is by default run from flash (a mechanism called XIP execute in place). But you can annotate functions (with a macro called IRAM_ATTR) that you want to have in ram if you need performance (you have to also be careful about the data types you use inside as they are not guaranteed to be put in RAM).