- 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
Frist! => Frist!
Admin
This code warrants a trip to HR. Reason: purposefully inappropriate, abusive, and/or fraudulent behaviour. inappropriate: this code insults co-workers abusive: this code creates a hostile work environment, elicits aggression, breaks down morale. fraudulent: during the job application they have knowingly deceived the interviewer. they have never even thought about programming. ever.
Admin
If I'm not mistaken, these guys have done it: they became paid, professional programmers without knowing how to use greater than and less than operators.
Admin
TRWTF is the article also being embedded in the comment
Admin
You mean the easy reader comment recreates information that could be expressed in a much more succinct manner? I wonder if that's related to the article in some way.
Admin
If all you have is a hammer, everything looks like a thumb.
Admin
But the for loop is using one!
Admin
Sadly, this is not the frist time I've seen a map that's really just an overwrought array. But it takes a special kind of brillance to do the same with the values.
Admin
That was copy-paste from a for-loop example they found on stackoverflow.
Admin
Even better and more fitting: it reuses something done once just because it's functionally sorta-kinda-similar, without caring whether it is in any way appropriate for the task.
Admin
Sometimes, an article is already that comprehensible that the Easy Reader Version is just the same. So what do you do? Now, each article covers a range…
Admin
Let's not forget the unnecessary
key = value = i;
when they could have just donemyMap.put(i, i);
Admin
Let's ignore the fact that storing each value is unnecessary. Even then, the use of a Map with the keys and values always the same is unnecessary. Why not just use a Set? That could also greatly improve the lookup:
Even with the Map, containsKey could improve this from O(n) to O(1). Guess they never heard of that (or even containsValue, which would do the same as this loop but without having to write the loop yourself).
Now everybody that says that this could be done with only greater than and less than is missing one feature of this setup - it allows multiple ranges and values. There's nothing preventing me from calling addRange(0, 10), addValue(15) and addRange(20, 30). 11-14 and 16-19 should obviously not be included. You can't do that with just one simple comparison.
However, even then there's a simple solution. With Java 8 or later: use a List<IntPredicate>, and add simple predicates like "i -> min <= i && i <= max" or "i -> i == value". With Java 7 or earlier: do the same with your custom interface and anonymous inner classes.
Admin
You mean like range() in Python 2?