metal3d / bashsimplecurses

A simple curses library made in bash to draw terminal interfaces
BSD 3-Clause "New" or "Revised" License
921 stars 115 forks source link

Question About Strange and Inconsistent Logic #63

Closed ghost closed 1 year ago

ghost commented 1 year ago

Working on a PR (#65) for this cool project, but wanted to ask about something before charging in with this particular part.

There are quite a few instances of 'if true that something is not equal to nothing', which is unnecessarily taxing to mentally parse. This is why we have the -z and -n flags for when something is and is not empty, respectively. You've used this already, but — and this is largely why consistency is important — you've often not, which is confusing. Is there a bizarre nuanced use-case I'm missing?

Incidentally, is there a reason you've used a lot of [ instead of [[, yet also used [[? I can only imagine how much this will have confused people reading my old code, because I did the same thing, and I'm now confused reading someone else's for the same reason! Lol In a nut-shell, I found out (through quite a bit of testing) that [[ is far more efficient than [. I had to change all my code to correct this, which sucked.

metal3d commented 1 year ago

Because the code date from a time when I learned bash, there are certainly a lot of bad things to fix.

Of course, -n and -z are the recommendation. I didn't fixed this but it should be done.

Concerning [[ and [ there are different behaviors. [ - the "double square brackets are not so compatible (it's bash only, "sh" will not be able to work with).

If there are cleaning to do, do not hesitate 😄

ghost commented 1 year ago

Because the code date from a time when I learned bash, there are certainly a lot of bad things to fix.

Ah! That clears things up. It's almost like seeing a constant contrast of your improvement, which is pretty cool.

Of course, -n and -z are the recommendation. I didn't fixed this but it should be done.

Okidoke. I'll keep that in mind.

Concerning [[ and [ there are different behaviors. [...]

Indeed. I'm guessing you initially wanted it to support '/bin/sh'-type shells, but eventually settled on BASH. I'm glad you did, because that offers quite a few opportunities to optimize and tidy, where those old shells would really fall short.

What I eventually learned over the years, is that by trying to support everything in a shell script, it often ends up being inefficient and awkward, lacking utilization of the many great features of the shell you're using in the first place. Akin to distributions like Linux Mint coming with everything installed, which is suitable for many people but optimal for nobody. Rather, I would pick the best available tool for the job initially, such as '/bin/sh', if you wanted more portability. I don't doubt it depends on the task and target audience, though.

If there are cleaning to do, do not hesitate :smile:

I'll look into it! O7

Thank you for the warm welcome and for sharing what you have here. I'm genuinely impressed by what you've done. Please don't take any of my criticisms in any way other than 'this is cool, let us make it even better'. :smile: