News for hackers. Stuff that matters.
Re:Help us collect modern Python NumPy code solutions by xnorswap on Monday March 28, 2022 @08:41AM (#30829892)
Indeed, their example is terrible, because it's also the kind of 'toy' problem that just doesn't have good real world uses too.

How often do you want to reverse a string.

I think your solution is fine and isn't "bad code" at all. Certainly a real explanation warrants talking about the IEnumerable interface.

I'd also consider the simpler (and ever so slightly better performing):

    var buffer = "1234simple".ToArray();
    Array.Reverse(buffer);
    new string(buffer);
edit: The following is dramatically (x10) even better performing:

    var buffer = "1234simple".ToCharArray();
    Array.Reverse(buffer);
    new string(buffer);
But again with the caveat of that not respecting unicode sequences.

But to re-iterate and to add to your criticism, I can't understand the use-case of needing to do this outside of toy problems.

Re:Help us collect modern Python NumPy code solutions by kingaillas on Monday March 28, 2022 @09:01AM (#30830086)
> I can't understand the use-case of needing to do this outside of toy problems.

Not sure, not my domain, but perhaps bioinformatics has the equivalent of the convolution operation on sequences?

EDIT: there is the "reversal" operation. Peeking ahead from the Rosalind problems, I'm not quite up to Reversal Distance (https://rosalind.info/problems/rear/).

Re:Help us collect modern Python NumPy code solutions by danbruc on Monday March 28, 2022 @09:17AM (#30830216)
But would they represent their data as character strings or would they pack four nucleotides with two bits each into one byte? Or would they be working on the amino acid level or something else all together? And would they really physically reverse potentially very long strings or just use a decreasing index into the original string? I am sure reversing strings has some use cases, maybe even in bioinformatics, but I would agree with the other comment, it seems a pretty niche operation, otherwise there would probably be a String.Reverse() method.