lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] Code inspection requested


From: Greg Chicares
Subject: [lmi] Code inspection requested
Date: Fri, 14 May 2010 22:02:22 +0000
User-agent: Thunderbird 2.0.0.24 (Windows/20100228)

I changed quite a few files here:
  http://svn.savannah.gnu.org/viewvc?view=rev&root=lmi&revision=4951
Though I tried to be very careful, and ran every test I have, there's
a chance that I nevertheless made a mistake. I think the best way to
find any mistake in this changeset is inspection rather than testing.
The likeliest mistake is a parity reversal, such as
-  if(foo.end() == std::find(foo.begin(), foo.end(), bar))
+  if(contains(foo, bar) // wrong: should be !contains
It doesn't matter if I missed a refactoring opportunity somewhere;
all that matters is whether I introduced an error.

I generally avoid making such sweeping changes, but I always have to
stop and think what the verbose idiom above means in context, so I
see a lot of value in writing a clearer substitute. For instance,
without "map_lookup.hpp", I would write this the way it originally
appeared, but then I couldn't get it at a glance:

-    button_bitmaps const& bitmaps = all_button_bitmaps();
-    button_bitmaps::const_iterator it =
-        bitmaps.find(std::make_pair(button, state));
-    if(it == bitmaps.end())
-        {
-        fatal_error() << "Unknown or missing button bitmap" << LMI_FLUSH;
-        }
-    return it->second;
+    return map_lookup(all_button_bitmaps(), std::make_pair(button, state));



reply via email to

[Prev in Thread] Current Thread [Next in Thread]