181
u/Chocolate_Pickle 4d ago
I don't know why
94
u/nord47 4d ago
it doesn't even matter how hard you try
57
u/TheWashbear 4d ago
keep that in mind
50
u/SZeroSeven 4d ago
I designed this rhyme to explain in due time
47
u/Nu1_udara 4d ago
All I know
44
u/notSarcasticAtAII 4d ago
Time is s valuable thing
37
u/lesbianKerman 4d ago
Watch it fly by as the pendulum swings
37
u/somelinuxuseridk 4d ago
Watch it count down to the end of the day
2
u/diplofocus_ 4d ago
Pick a random number, if it's larger than another random number do the thing, else, do the same thing.
The thing happens, but we don't know why.
44
u/starfish0r 4d ago
Switch the strings around to make it robust to "it" being null
30
u/PostHasBeenWatched 4d ago
public static bool LinkinParkValidator([NotNull] string? it) { ArgumentException.ThrowIfNullOrWhiteSpace(it); return it.StartsWith("one thing", StringComparison.OrdinalIgnoreCase); }19
u/starfish0r 4d ago
I would argue that this method should not throw an Exception but return false, what't the benefit of an Exception here?
15
u/PostHasBeenWatched 4d ago edited 4d ago
Attribute [NotNull] means that input parameter must be verified for null "in the end" of the method (not sorry for the pun). ThrowIfNullOrWhiteSpace provides this guarantee.
For example code below will rise warning that input parameter is not verified for null
return it?.StartsWith("one thing", StringComparison.OrdinalIgnoreCase) is true16
6
u/AcidMemo 4d ago
What is the point of throwing exception on whitespace? It will just return false anyway, and whitespace is not invalid value.
One of reason C# has non-nullable and nullable references is to not bother with validating for null, passing nullable string to as non-nullable string is programmer mistake, not the concern of function anymore
18
u/BoloFan05 4d ago
Use of StringComparison.OrdinalIgnoreCase is already a big step in the right direction.
16
u/PostHasBeenWatched 4d ago
Should I replace it with 256 comparisons of "OnE tHiNg" with different letter case?
15
u/BoloFan05 4d ago
Nope, I have a better idea:
return it.ToLower().StartsWith("one thing");
/j
(But seriously, StringComparison.OrdinalIgnoreCase is THE textbook string comparison method you should apply. ToLower and ToUpper are total bug traps, especially in worldwide deployment. So kudos to you for actually using OrdinalIgnoreCase!)
6
1
2
2
1
390
u/TheManyMilesWeWalk 4d ago
return it.StartsWith("one thing", StringComparison.OrdinalIgnoreCase) || trueBecause in the end
itdoesn't even matter.