March 2018
Intermediate to advanced
208 pages
4h 52m
English
| | class Inventory { |
| » | List<Supply> sl = new ArrayList<>(); |
| | |
| | boolean isInStock(String n) { |
| » | Supply s = new Supply(n); |
| | int l = 0; |
| | int h = sl.size() - 1; |
| | |
| | while (l <= h) { |
| » | int m = l + (h - l) / 2; |
| | int c = sl.get(m).compareTo(s); |
| | |
| | if (c < 0) { |
| | l = m + 1; |
| | } else if (c > 0) { |
| | h = m - 1; |
| | } else { |
| | return true; |
| | } |
| | } |
| | |
| | return false; |
| | } |
| | } |
In most code bases, you’ll often find a variable whose name is just a single letter. They’re common because they’re quicker to type and because some IDEs still generate names in this way. But they make the code much harder to read. After all, how much meaning can you convey in a single letter?
Let’s look at the code above. It shows ...