~reykjalin/public-inbox

1

tday-sh bash vs POSIX sh

Details
Message ID
<20210320193235.q3cqg7jkrcxyi7jj@arch>
DKIM signature
pass
Download raw message
Hi!
I'm writing back to you after you applied my patch (thank you! I'm glad
you liked it!) because there's a small thing that I wanted to bring 
your attention to about tday. I think this is the sort of thing that
needs some discussion on a mailing list before even writing a line of
code.

I've noticed that tday-sh's shebang is #!/bin/sh, i.e. POSIX sh. But 
the code is full of non-portable bash features ("bashisms," as they
say): double bracket conditionals (e.g. [[ ]]), set -o pipefail, the
way you define IFS using $'\n\t' (which is a bash-exclusive thing) are
the ones I can think of the top of my head.

Depending on the user's shell implementation, this discrepancy might 
cause a few problems. Most users use bash as their shell; when bash
sees #!/bin/sh it enters a somewhat more strict POSIX mode, but not
really. On the other hand, dash (Debian's and derivatives' default) is
more picky... And some people might be using other implementations of
course.

IMHO, you'd be better off just changing the shebang into '#!/bin/bash'
and just support bash. It's perfectly fine, way more practical, and
wouldn't require you changing your code. That way your code would
correctly advertise itself as bash code and users would be required to
use a *bash*-compatible shell.

I'm a fan of strict POSIX compliant code, but sending you a patch 
converting your code into that would rather be rude, in my opinion...
It's like telling you "Hey, I don't like you're writing this in Python;
I've rewritten it entirely into OCaml." Of course, bash is related to
POSIX sh, but it should be taken as two different languages.

But, if you're interested in making your script POSIX compliant, I can
help with patches and resources! It'll take some more time to get used
to (and tutorials out there are... bad... you end up learning it from
the specs themselves).

Last but not least, I mantain a similar-ish program written in C. When
I saw tday earlier this day I was SO happy to see someone do a very
similar task in SO FEW lines! OK, mine has a different use-case (it
destroys the task list after 24 hrs on purpose)... but hey tday rocks
a lot! Nice work! \o/

Best,
Ari

-- 
Ariadna Vigo
(she/her)
Web: <https://ariadnavigo.xyz>
PGP: 0xA3B1324836A669BD
Details
Message ID
<CAC92379-E9A2-4739-9F0E-3FAB4A3FAE11@thorlaksson.com>
In-Reply-To
<20210320193235.q3cqg7jkrcxyi7jj@arch> (view parent)
DKIM signature
missing
Download raw message
Hi Ari!

Thank you for reaching out! I appreciate it :)

> I'm writing back to you after you applied my patch (thank you! I'm glad
> you liked it!)

I was happy to receive it! It's always nice to see someone else interested in your projects :)

> I've noticed that tday-sh's shebang is #!/bin/sh, i.e. POSIX sh. But
> the code is full of non-portable bash features ("bashisms," as they
> say)
> [...]
> if you're interested in making your script POSIX compliant, I can
> help with patches and resources! It'll take some more time to get used
> to (and tutorials out there are... bad... you end up learning it from
> the specs themselves).

Oh! I didn't know that! Thanks for bringing this to my attention.


I actually did intend for this to be written in plain sh for maximum portability but, like you mentioned, finding good material on that isn't easy. I had to refer to some bash specific guides, and this is the result.

I'd be happy to receive patches, or links to guides/examples on writing plain sh, and work on making the script fully POSIX compliant :)

If I wanted something more "complete" (for lack of a better word) without losing the brevity of the script I'd rewrite this in Python. Point being that the script is intended to be portable; other implementations can focus on readability and correctness.

> I'm a fan of strict POSIX compliant code, but sending you a patch
> converting your code into that would rather be rude, in my opinion...

Haha, without the context it'd probably raise an eyebrow or two :P

> I mantain a similar-ish program written in C. When
> I saw tday earlier this day I was SO happy to see someone do a very
> similar task in SO FEW lines! OK, mine has a different use-case (it
> destroys the task list after 24 hrs on purpose)... but hey tday rocks
> a lot! Nice work! \o/

I actually did see cras before writing tday, but it was too involved for what I wanted :) . I just wanted a simple way to set up today's tasks, and be able to refer back to what I haven't completed if necessary.

tday was intended to be a portable proof-of-concept for how something like it might work with the file format. If I have the time I plan to write something more elaborate without changing the simple format. It also seems like a decent exercise when learning a new programming language.


Thanks again for reaching out! I'd be happy to continue the discussions around this here.

Stay safe!

--
Kristófer R.


P.S. I'm sorry if the email is badly formatted. The e-mail client I'm using does a lot of magic, and I haven't quite figured out how to configure it properly yet. If it's well formatted; yay, success \o/
Reply to thread Export thread (mbox)