The reverse string exercise asks people to implement reverse in bash. Many solutions simply call rev.
Thoughts on disabling rev for that exercise? We could do something drastic like deleting the executable in the test runner container.
The reverse string exercise asks people to implement reverse in bash. Many solutions simply call rev.
Thoughts on disabling rev for that exercise? We could do something drastic like deleting the executable in the test runner container.
bash is a glue language. Calling out to rev is exactly what bash is for. I don’t have any problems with such solutions.
We could encourage students to implement it in plain bash, but I would not want to enforce it.
Could the analyzer’s automated feedback gently suggest it but not enforce it?
Probably! We have a bash analyzer that runs shellcheck and has per-exercism logic. A simple grep -w rev test would flag variable names, but we can try to come up with clever regexes. /^[ \t]*rev\b/ and /| *rev\b/ might catch them.
also /=\$\(\s*rev\b/
Don’t forget about the back tick `
Also I think accounting for the pipe would be needed, since I noticed most solution is echo "$1" | rev
P/s: Also, also, I propose adding another solution to the “Deep dive” section for one that’s more POSIX friendly:
word="$1"
while [ -n "$word" ]; do
prefix="${word%?}"
echo -n "${word#"$prefix"}"
word="$prefix"
done
echo
# or maybe something like
reversed=''
word="$1"
until [ -z "$word" ]; do # literally only found out about `until' last month
prefix="${word%?}"
reversed="$reversed${word#"$prefix"}"
word="$prefix"
done
echo "$reversed"
(I’m not particularly happy I have to quote the $prefix on line 4, but whatever.)
I think this is a good addition for a deeper dive (valid solution on bash, no external utils, works on other shells too), not to mention it also introduce the user to the shell’s prefix/postfix trimming whatchamacallit, which I found to be really useful day-to-day.
I’m not opposed to more approaches.
I am opposed to advocating POSIX shell syntax. This is the bash track.
hmm… I think it followed bash syntax quite well, no? the only overtly POSIX-ism thing I used is the [ instead of [[. Like, if the piping echo into rev approach is allowed, I don’t see why this would be any less valid.
what if it is presented as an approach that make use of the shell’s string manipulation ability, with a footnote that it could easily be adapted to be POSIX compliant (“just remove one pair of [ ] lel”)?
idk, I got the feeling that quite some people approach the bash exercises as if it’s a (worse) generic programing language and just aren’t aware of features that don’t map cleanly into that paradime, and I would like to see that going away somehow.
Anyway I’m going a bit off topic, sorry.
That’s intruiging. Can you expand on that thought?