Re: Literate style, making code more readable or going overboard?
Phil Goodwin <[email protected]> Thu, 11 Feb 2010 09:36:31 -0800
| Newsgroups | gmane.comp.programming.refactoring |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Feb 9, 2010 at 5:21 PM, aglet_sesamoid <[email protected]>wrote: > > > Consider this snippet of java code: > > ... > ArrayList adminUsers = getUsersWithAdminRights( allUsers ); > if ((adminUsers != null) && (adminUsers.size() > 0)) { > .... > } > ... > > I would prefer: if (allUsers.containsAdminUsers()) { allUsers.adminUsers()... } but, yes, in general it's better to err on the side of writing more literate code, just because there's a tendency to not do it enough. When in doubt, over do it and then start backing off until you aren't quite overdoing it anymore. This code has a separate issue with misplaced responsibilities, which is why I moved the methods, after that the issue of literacy becomes more important because there is a greater potential for reuse and it becomes easier to justify pulling out a separate "containsAdminUsers()". Often a little, pedantic seeming, refactoring will lead to other refactorings that make a big difference. > Does anyone think that this refactoring to a more literate style makes the > code easier to read and understand or is it overkill? > > ... > ArrayList adminUsers = getUsersWithAdminRights( all Users ); > if (thereAreAny(adminUsers) { > .... > } > ... > > private boolean thereAreAny(ArrayList list) { > if (list == null) > return false; > else > return (list.size() > 0) > } > > [Non-text portions of this message have been removed] ------------------------------------ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/refactoring/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/refactoring/join (Yahoo! ID required) <*> To change settings via email: [email protected] [email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/