r/programminghorror • u/HeWhoShantNotBeNamed • Sep 03 '26
C# Very readable and maintainable method
I wrote this several years ago. It does work.
132
Upvotes
r/programminghorror • u/HeWhoShantNotBeNamed • Sep 03 '26
I wrote this several years ago. It does work.
38
u/russellvt Sep 03 '26
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/tom83 Sep 03 '26
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.
21
u/mc_pm Sep 03 '26
My eyes! The goggles do nothing!
12
u/Poiuytgfdsa Sep 03 '26
If i saw a comment above a function that says “intelligently handles edge cases” with no specifics id get irritated
11
u/plydauk Sep 03 '26
The rainbow barf certainly doesn't help
6
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Sep 03 '26
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/creative_net_usr Sep 04 '26
That colour scheme gave me cancer.
1
u/Certain-Flow-0 Sep 05 '26
Great work, Aashish
2
u/fakehalo Sep 03 '26
This is what happens when people avoid learning regular expressions.
1
u/Brilliant-Parsley69 Sep 07 '26
This should actually the same with way less allocation.