|
|
|
|
|
by addictedcs
2451 days ago
|
|
First example I've checked is wrong [1]. Shuffle a list, with a static Random object initialization. Using a static random object is not thread-safe in .NET. "One common solution is to use a static field to store a single instance of Random and reuse it. That’s okay in Java (where Random is thread-safe) but it’s not so good in .NET – if you use the same instance repeatedly from .NET, you can corrupt the internal data structures." [2] Very often the very same resources which claim to be the source of truth provide bad code examples. [1] https://www.programming-idioms.org/cheatsheet/Csharp [2] https://codeblog.jonskeet.uk/2009/11/04/revisiting-randomnes... |
|
Case in point, Idiom #46 in C[0] uses strncpy and predictably fails to correctly terminate the buffer.
Idiom #55[1] converts a integer to a string with itoa, never bothering to mention that it isn't part of the C standard or POSIX, while for some reason using a 4096 byte big output buffer.
Idiom #39[2] first example uses clrscr(), which I assume is some sort of old DOS function? The entire example looks unrelated to the problem.
The idea is certainly good, but you need some serious vetting system to make this usable.
[0] https://www.programming-idioms.org/idiom/46/impl/477
[1] https://www.programming-idioms.org/idiom/55/impl/438
[2] https://www.programming-idioms.org/idiom/39/impl/2042