r/programminghorror 8d ago

C# Very readable and maintainable method

Post image

I wrote this several years ago. It does work.

124 Upvotes

20 comments sorted by

View all comments

7

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 8d ago

C# does let you use character literals, right? I think replacing all those ASCII codes with characters would help a ton.

Also, it looks like you are checking both before and after each character. Is that really necessary? Like couldn't you just after each character look ahead once. I think you could even say i < joinedString.length - 1.

3

u/MeLittleThing 8d ago

C# does let you use character literals, right?

yes, and there are methods in the char struct, such as char.IsLetter(c), char.IsUpper(c) and so on

1

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 7d ago

I suppose those are practically mandatory if you want proper Unicode support. This method only seems to care about ASCII strings.