News for hackers. Stuff that matters.
Re:The string type is broken (2013) by thrower123 on Tuesday June 22, 2021 @10:16PM (#27600036)
Reversing strings is such an odd thing to focus on. I have written dozens of implementations of string reversers for school and interviews and following books, but I would be hard pressed to come up with any real case where I needed to reverse a string. And then, it was because I was abusing a string to store some data that was not really text, at which point I really didn't care that it textually supported reversing Unicode code points.
Re:The string type is broken (2013) by mortoray on Wednesday June 23, 2021 @01:45AM (#27601154)
It's not about reversing, but about checking whether reverse iteration works. This is required to perform proper truncation (for limited length fields) as well as visual editing for a cursor to go through the text.

It can additionally be an indication as to whether regular expression matching works, though that is usually handled by a library, and not the core string types.

My contention was always that if a "string" does not reverse text, then it's no better than an "array<char>". The existence of a "string" type implies it should do more.

Re:The string type is broken (2013) by marcosdumay on Tuesday June 22, 2021 @10:33PM (#27600141)
What is even the meaning of reversing an string?

It's more meaningless the more a naive algorithm is broken... But shouldn't it at least use those reverse letters Unicode has somewhere? Or is it just a matter of putting the right to left symbol at its start?

Re:The string type is broken (2013) by paulmd on Tuesday June 22, 2021 @10:21PM (#27600070)
rev | cut | rev

is a pretty common idiom in the shell when you want to keep "all but the last N chunks" from some lines of input.

At least for me. I'm sure there's probably a better way, and performance of this is definitely notably poor.

And of course it's not like I'm actually writing the utility. ;)

Re:The string type is broken (2013) by marcosdumay on Tuesday June 22, 2021 @10:36PM (#27600154)
I would be very surprised if rev | cut | rev gave you the correct answer to anything that isn't "drop the last X lines or words" on a non western alphabet.

And for "drop the last X lines or words", you would do better with some specialized command.

Re:The string type is broken (2013) by paulmd on Wednesday June 23, 2021 @11:44AM (#27605831)
you don't ever work with directories? fortunately there is a pretty defined separator in my directory hierarchies, so that is pretty much always correct ;)

(although if you are taking arbitrary user data I suppose there is nothing stopping you doing something stupid like putting an escaped '/' in a filename, which would break this.)