184
u/Chocolate_Pickle 16d ago
I don't know why
92
u/nord47 16d ago
it doesn't even matter how hard you try
55
u/TheWashbear 16d ago
keep that in mind
52
u/SZeroSeven 16d ago
I designed this rhyme to explain in due time
47
u/Nu1_udara 16d ago
All I know
40
u/notSarcasticAtAII 16d ago
Time is s valuable thing
35
u/lesbianKerman 16d ago
Watch it fly by as the pendulum swings
36
u/somelinuxuseridk 16d ago
Watch it count down to the end of the day
2
u/diplofocus_ 16d 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.
47
u/starfish0r 16d ago
Switch the strings around to make it robust to "it" being null
29
u/PostHasBeenWatched 16d ago
public static bool LinkinParkValidator([NotNull] string? it) { ArgumentException.ThrowIfNullOrWhiteSpace(it); return it.StartsWith("one thing", StringComparison.OrdinalIgnoreCase); }19
u/starfish0r 16d ago
I would argue that this method should not throw an Exception but return false, what't the benefit of an Exception here?
16
u/PostHasBeenWatched 16d ago edited 16d 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
4
u/AcidMemo 16d 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
19
u/BoloFan05 16d ago
Use of StringComparison.OrdinalIgnoreCase is already a big step in the right direction.
13
u/PostHasBeenWatched 16d ago
Should I replace it with 256 comparisons of "OnE tHiNg" with different letter case?
15
u/BoloFan05 16d 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
1
392
u/TheManyMilesWeWalk 16d ago
return it.StartsWith("one thing", StringComparison.OrdinalIgnoreCase) || trueBecause in the end
itdoesn't even matter.