Hacker News new | ask | show | jobs
by HelloNurse 1419 days ago
Percentage calculations require multiplying or dividing by 100 in the right places, complicating both the progress bar itself and client code. In typical usage it would be more elegant and more general to have a fraction, x things done out of a total of y, with both x and y updateable.

For example, recursively enumerating the contents a file system interleaves increasing y (when subfolders are visited and unprocessed files and unvisited subfolders are found) with increasing x (when files and folders are processed/visited). At the end x catches up with y.

Lowbar could be easily adapted to a percentage-free style without backwards incompatibilities: the constructor could have a parameter, range with default 100, and new methods update_range() and update_range_smooth() could update y similarly to how update() and update_smooth() update x.