Wednesday, May 7, 2008

My 2 cents on code style I would like to avoid

While working on the assignment, I came across some code that took me a while to decipher. For example:
        for result in results:
if results[result][1].is_unsaved():
for i in range(self.scan_notebook.get_n_pages()):
if results[result][0] == "Unsaved " + \
self.scan_notebook.get_nth_page(i).get_tab_label():
self.scan_notebook.set_current_page(i)
else:
page = self._load(parsed_result=results[result][1],
title=results[result][1].scan_name)
page.status.set_search_loaded()
or
        selection = self.result_view.get_selection()
rows = selection.get_selected_rows()
list_store = rows[0]

results = {}
for row in rows[1]:
r = row[0]
results[list_store[r][2]] = self.parsed_results[list_store[r][2]]

return results

This stuff makes perfect sense, but only after a couple of minutes of deciphering (with possible documentation lookups). Also, it has no comments whatsoever. If we are to make Zenmap a better Nmap frontend, we need to start by improving code readability - it makes maintenance easier and allows new developers (like myself) to dig right into the code.

No comments: