- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
first or default comment
Admin
FristOrDefault() is tricky - it is not clear at first glance that it can return null since it's supposed to return the default(), right? But the default for object types is null.
Admin
FristOrDefault() { default="Secnod"; if ( List<Post>.length == null ) return Frist; return default; }
Admin
How bad must the original system have been that this code beat it?
Admin
Keep concurrency in mind, there's a class which does this in a thread safe fashion.
Admin
Has cornify.com been abandoned? Its SSL cert has been expired for a week. WHERE ARE MY UNICORNS AND RAINBOWS?!
Admin
Throw EOutOfNullsException();
Admin
Jeeeez... Anything to work around simple and efficient... :P
Admin
A C# dictionary cannot contain keys with the value of null. Additionally FirstAndDefault() exactly does what it says, it reurns the default value which can be a ValueType (something Java doesnt have, so I understand the confusion).
So is the WTF the explaination whats wrong with the code or the imaginary problems?
Admin
Aside from the issues highlighted in the article, this is a good example of a common mistake where people use FirstOrDefault in a scenario where there should only be zero or one result ... so they should have been using SingleOrDefault.
Admin
Re: Misuse of Map/Dictionary...
Programmers here created Map<Integer, Object> thingers so they could use 1-based indexed "arrays."
Admin
Occasionally, 1-based arrays can make implementations easier. Heck, Fortran has arbitrary starting indices for that reason, e.g. when representing a symmetric function numerically as a -42,-41,...,41,42 array.
But putting it into a Map object sounds pretty JavaScript :)