r/programminghorror 19h ago

C# Very readable and maintainable method

Post image

I wrote this several years ago. It does work.

58 Upvotes

12 comments sorted by

28

u/russellvt 17h ago

That color scheme is horrendous, and looks like it lost a number of pixels from all the times it's been reposted or resaved or something.

3

u/HeWhoShantNotBeNamed 16h ago

I screenshotted this straight from the code but Reddit compressed the shit out of it.

1

u/russellvt 16h ago

Use impurities? But I can understand them trying to compress it... annoying, to say the least.

12

u/mc_pm 18h ago

My eyes! The goggles do nothing!

4

u/plydauk 17h ago

The rainbow barf certainly doesn't help

7

u/Poiuytgfdsa 11h ago

If i saw a comment above a function that says “intelligently handles edge cases” with no specifics id get irritated

3

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 11h 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.

1

u/MeLittleThing 2h 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

2

u/tom83 16h ago

Hit reformat and it will be readable.  It's a pure function, so unit test can fully determine the behavior to the point that the impl is irrelevant. 

1

u/HeWhoShantNotBeNamed 16h ago

Reformat? Lol that is with it "formatted" correctly according to ReSharper/Rider

2

u/fakehalo 18h ago

This is what happens when people avoid learning regular expressions.

1

u/Superb_Chemistry_906 17h ago

At the least, that range 65-90 check can be put into a method.