Merge lp:~julien-spautz/cerbere/watchdog-refactor into lp:~elementary-pantheon/cerbere/cerbere
Proposed by
Julien Spautz
Status: | Merged |
---|---|
Approved by: | Cody Garver |
Approved revision: | 68 |
Merged at revision: | 47 |
Proposed branch: | lp:~julien-spautz/cerbere/watchdog-refactor |
Merge into: | lp:~elementary-pantheon/cerbere/cerbere |
Diff against target: |
126 lines (+57/-46) 1 file modified
src/Watchdog.vala (+57/-46) |
To merge this branch: | bzr merge lp:~julien-spautz/cerbere/watchdog-refactor |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Victor Martinez (community) | Approve | ||
David Gomes (community) | Approve | ||
Review via email: mp+186937@code.launchpad.net |
Commit message
Refactored the code in Watchdog.vala to eliminate the nested if clauses and make it more readable.
Description of the change
Refactored the code in Watchdog.vala to eliminate the nested if clauses and make it more readable.
None of the behavior should have changed, and the API is also untouched.
I commited each small refactoring step so you can see that they don't have any side-effects.
To post a comment you must log in.
Hey, nice work!
+1 for improving readability. This could use further improvements.
- "requires" is being used for things that can, and are expected to fail at runtime, instead of static contract definition. It is not a programming error to call "add_process" and pass the name of a process that is already monitored. This can happen if a user adds the same string twice to monitored-processed in GSettings. Instead, the method should just do nothing, and/or print a warning, but assertions are not applicable here.
- For consistency, since there is "is_new_command", the statements "processes.unset (command)" should be replaced by a new method "remove_command" (preferrably "unmonitor_ command" ) that does it, so that nobody accesses the hashmap directly.
- Diff line 91 should be: "if (is_new_command (command)) { ...".
- Diff line 32 should be: "return !processes.has_key (command);". Same style change is desired fo diff line 112.
- Diff line 102: use "%u" instead of "%s" to avoid calling "to_string" for "max_crashes".
- Instead of "is_new_command" and "remove_command" (not there yet), I would suggest using "is_command_ monitored" and "unmonitor_ command" , respectively.