It’s some common facile ‘evolution’ of the command line, pointlessly spitting Unicode all over the screen 100 times per second, simply to inform a supposedly technical user of what he should already know and has infinitelymoreappropriatetoolstodemonstrate: the program is running. Yes, I’m talking about text progress bars that have been proliferating recently.
I was intending to leave some comment on that post to the effect recorded below, but it seemed worthy of a somewhat longer response, so below find all the reasons why I will rip out your frivolous progress bar code and judge you eternally for ever including it.
You shouldn’t be typing those commands in a terminal. Period.
By now it should go without saying, but you work in an industry where almost every conceivable task can be wrapped up in some higher abstraction, some automation that will take care of ensuring that you, the tired grumpy user who has been awake all night dealing with a crying newborn doesn’t accidentally type “rm -rf *” as opposed to “./run-payroll-nightly.py”.
Of course the world is imperfect and continually evolving, and it is not every day we can spend the time to automate away every possible task, however the ideal should never waver: at some point the thing you are working on in a terminal should be considered imperfect precisely because it required a human’s involvement at all, which leads me to..
Better logging is infinitely preferable to ASCII art
Once you graduate from the state of total apprehension that your script will crash, or worse yet, partially fail to pay the workforce of angry armed henchmen your employer is paying you to ensure get paid, soon that ever present laziness will kick in, and you or your even lazier colleagues (i.e. all of us) will desire to escape tapping “./run-payroll-nightly.py” every evening at 4:59pm.
And the first thing you discover: damn! I can’t run this stupid thing under cron/supervisor/WebScaleMetaJobSchedulerWrittenInJavaOmgWhyGodWhy because it’s spitting TERMINAL ESCAPES into stdio! OK well I can, but the log file looks like ASS, where are these escapes even coming from? I never want to look in this file in my life again. And oh is that an exception? One of our analysis tools blows up when fed non-ASCII-unicode-full-width-solid-block-0x7193f! Argh it’s 11pm and wife is on the phone asking where is the baby food?!!?
The simple truth is the moment your script grows up and joins the rest of the herd, it’ll no doubt be living under ever caring shepherding of a process monitor be it systemd, Mesos, supervisor, or one of the 100 other variants of the same basic concept: eventually a human won’t be watching it up close and personal, and that non-human entity most certainly won’t care much for Unicode lego bricks.
Do yourself a favor and implement some decent logging instead. Perhaps your script will eventually be subsumed by a library, embedded in a Qt application, buried on some embedded device, who knows, but one thing is almost guaranteed: one of the first things to go will be it’s main() function, followed in close second place by the addition of a log file, or if you’re really web 3000 a log collection service.
This code looks like hell, and all for what, a fricking progress bar?
It’s so cute. Your progress bar tells me exactly how many of the payroll entries have run, and computed some nice percentage. You even went so far as to catch ZeroDivisionError for the case where there were no payroll entries, so thoughtful! But wait, what’s that? In order to calculate the percentage in the first place you needed to count the payroll entries! And they’re sitting, one per file, on an NFS server.. back in the evil space warfare cartel’s underground lair in Mozambique! Holy latency-inducing cowbells, the bank transfer API calls only takes 3 minutes to run, but counting the paycheques of those angry henchmen takes an hour!
But worse than that, you’ve buried that all-important “if I don’t get this right I’ll be shot before leaving the building” loop in excess logic calling out to some crappy library someone wrote half-drunk over a bored weekend.
You committed one of the worst sins
And the sin was? I hope you guessed it already: you included code that didn’t need to exist. It would not be the first, third, or 50th time I’ve been fixing a crash only to catch some blissful momentary glimpse of nirvana: this loop shouldn’t exist at all. Wait a minute, what is this class even doing? So it takes an int, <300 lines of code>, then calls a function with that int! *shakes fist* class IAbstractProgressMixin(meta=ProgressMetaBase), you will burrrn!
Generally if you can avoid writing a line of code then do it. In your sleep-starved state of imperfect incomprehension it might seem like a convenience, or dare I even say it, if you’re really lacking the vitamins, a good idea, but one of the most important things you can ever learn to avoid in IT land is minimizing the amount of ephemeral bitrot left behind for future generations, which oftentimes generally means for yourself.
You broke strace, you interminable wazzock
Them there lego bricks don’t draw themselves, you know. Every single one of those 100-per-second screen updates came at a cost: his highness the kernel was invoked! Ignoring the thousands of redundant write() calls now showing up in strace, the omg-i-havent-slept-in-a-week diagnostic tool of last resort, let’s hope in the panic of having a disruptor pointed at your head while needing a pee you remember to redirect that damn progress bar to /dev/null!@#!@
The simple truth is the command line is esoteric and weird, try to forget about it
This also applies to wasting your lunch hour perfecting your zshrc and requisite plugin collection. If your eyes are so finely focused on the inane minutiae of a 56 year old abstraction that only continues to exist thanks to a series of emulators (in such common use that people forget what they’re emulating: typewriters!@”#!@”#), there is simply no hope for you ever recognizing or embracing whatever future evolution of this crap finally comes along.
And trust me, it won’t involve ANSI escapes or a frickin’ array of characters. Oculus VR UI for infrastructure, where are you already?
[Seen the writing on the wall and ready to start logging? Try not to screw that up either]