[mousetrap/gnome3-wip: 110/240] Remove negation from function/method name.
- From: Heidi Ellis <heidiellis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mousetrap/gnome3-wip: 110/240] Remove negation from function/method name.
- Date: Mon, 8 Sep 2014 15:21:48 +0000 (UTC)
commit ceb1a379c9c6ce5140fb2d6b60e9e50e63b40768
Author: Stoney Jackson <dr stoney gmail com>
Date: Sat Jun 21 10:58:22 2014 -0400
Remove negation from function/method name.
(Kevin, this is not directed at you; this is just me rationalizing
why I don't like negations in function names. Surprisingly, I
found only one "article" on the subject:
http://programmers.stackexchange.com/questions/196830/boolean-method-naming-affirmative-vs-negative .
Maybe I need to put this on my blog.)
I'm not a fan of negations in function/method names that return
boolean values.
1. They set the stage for double negatives at the call site which
is difficult to read.
```
if not self._not_moving(): # is it moving or not? ouch!
```
2. They make the body of the method harder to interpret because
returning True is really returning False (or is it?).
3. Affirmatives are good for the soul! :)
Existing functions with negations in their name can be fixed in two ways:
1. Think of another name that describes what the function is testing.
```
_not_moving --> _stationary
```
2. Rewrite the function to test for the opposite and remove not from
the name.
```
_not_moving --> _moving
```
src/mousetrap/plugins/eyes.py | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/src/mousetrap/plugins/eyes.py b/src/mousetrap/plugins/eyes.py
index ad5ae61..a4ae1cc 100644
--- a/src/mousetrap/plugins/eyes.py
+++ b/src/mousetrap/plugins/eyes.py
@@ -20,7 +20,7 @@ class EyesPlugin(interface.Plugin):
except FeatureNotFoundException:
self._miss()
- if self._not_moving(app) and self._detect_closed():
+ if self._stationary(app) and self._detect_closed():
self._history = []
app.pointer.click()
@@ -30,7 +30,7 @@ class EyesPlugin(interface.Plugin):
def _miss(self):
self._history.append(None)
- def _not_moving(self, app):
+ def _stationary(self, app):
self._pointer_history.append(app.pointer.get_position())
last_point = app.pointer.get_position()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]