{"action":"created","issue":{"url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-goodies/issues/2696","repository_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-goodies","labels_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-goodies/issues/2696/labels{/name}","comments_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-goodies/issues/2696/comments","events_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-goodies/issues/2696/events","html_url":"https://github.com/duckduckgo/zeroclickinfo-goodies/issues/2696","id":138458456,"number":2696,"title":"Move work out of handlers","user":{"login":"GuiltyDolphin","id":8598426,"avatar_url":"https://avatars.githubusercontent.com/u/8598426?v=3","gravatar_id":"","url":"https://api.github.com/users/GuiltyDolphin","html_url":"https://github.com/GuiltyDolphin","followers_url":"https://api.github.com/users/GuiltyDolphin/followers","following_url":"https://api.github.com/users/GuiltyDolphin/following{/other_user}","gists_url":"https://api.github.com/users/GuiltyDolphin/gists{/gist_id}","starred_url":"https://api.github.com/users/GuiltyDolphin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GuiltyDolphin/subscriptions","organizations_url":"https://api.github.com/users/GuiltyDolphin/orgs","repos_url":"https://api.github.com/users/GuiltyDolphin/repos","events_url":"https://api.github.com/users/GuiltyDolphin/events{/privacy}","received_events_url":"https://api.github.com/users/GuiltyDolphin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-goodies/labels/Improvement","name":"Improvement","color":"d7e102"},{"url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-goodies/labels/Priority:%20Medium","name":"Priority: Medium","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-03-04T12:01:57Z","updated_at":"2016-03-04T14:31:37Z","closed_at":null,"body":"I've been looking through some of the Goodies (Perl) and noticed that in some there is a _lot_ of work being done in the handlers.\r\n\r\nThe handlers have to be called for *every query* (unless cached). This means that any code within them has to be re-built for *every query*, which as you can imagine, is quite slow.\r\n\r\nAdditionally, having a lot of work in the handlers means that it is more difficult to understand *what* the Goodie is doing - the handler should clearly show what information is being retrieved from the query and where it is used.\r\n\r\nI have compiled a list (incomplete) of Goodies that I think should be updated. For each of these Goodies we should move work *out* of the handler and into well-named subroutines that clearly indicate what their role is. The handlers should be concise and convey the overall approach the Goodie has to working with the query - we should minimize the amount of code *defined* in the handler.\r\n\r\n- [ ] [CalcRoots](https://duck.co/ia/view/calc_roots)\r\n- [ ] [ColorCodes](https://duck.co/ia/view/color_codes)\r\n- [ ] [ConvertLatLon](https://duck.co/ia/view/convert_lat_lon)\r\n- [ ] [Dice](https://duck.co/ia/view/dice)\r\n- [ ] [FrequencySpectrum](https://duck.co/ia/view/frequency_spectrum)\r\n- [ ] [ResistorColors](https://duck.co/ia/view/resistor_colors)\r\n- [ ] [SubnetCalc](https://duck.co/ia/view/subnet_calc)\r\n- [ ] [TimezoneConverter](https://duck.co/ia/view/timezone_converter)\r\n- [ ] [Unicode](https://duck.co/ia/view/unicode)\r\n- [ ] [UnixPermissions](https://duck.co/ia/view/unix_permissions)\r\n\r\nIf you think there are any Goodies that should be added to this list (or removed), please let me know!\r\n\r\nAlso, please let me know if you are actively working on any of these - it'd be good to know what is in progress and what has yet to be started."},"comment":{"url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-goodies/issues/comments/192303119","html_url":"https://github.com/duckduckgo/zeroclickinfo-goodies/issues/2696#issuecomment-192303119","issue_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-goodies/issues/2696","id":192303119,"user":{"login":"MrChrisW","id":5282264,"avatar_url":"https://avatars.githubusercontent.com/u/5282264?v=3","gravatar_id":"","url":"https://api.github.com/users/MrChrisW","html_url":"https://github.com/MrChrisW","followers_url":"https://api.github.com/users/MrChrisW/followers","following_url":"https://api.github.com/users/MrChrisW/following{/other_user}","gists_url":"https://api.github.com/users/MrChrisW/gists{/gist_id}","starred_url":"https://api.github.com/users/MrChrisW/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MrChrisW/subscriptions","organizations_url":"https://api.github.com/users/MrChrisW/orgs","repos_url":"https://api.github.com/users/MrChrisW/repos","events_url":"https://api.github.com/users/MrChrisW/events{/privacy}","received_events_url":"https://api.github.com/users/MrChrisW/received_events","type":"User","site_admin":false},"created_at":"2016-03-04T14:31:37Z","updated_at":"2016-03-04T14:31:37Z","body":"@GuiltyDolphin So you're talking about two things here: **Code Readability** & **Code Efficiency**\r\n\r\n>Additionally, having a lot of work in the handlers means that it is more difficult to understand what the Goodie is doing - the handler should clearly show what information is being retrieved from the query and where it is used.\r\n\r\nCode Readability\r\n\r\nYou'd like to move the majority of the logic out of the main `handle` subroutine and move it into new subroutines that are named better -  this will allow for better readability and maintainability. This will help new maintainers understand the program flow better. :+1: \r\n\r\n_________\r\n>The handlers have to be called for every query (unless cached). This means that any code within them has to be re-built for every query, which as you can imagine, is quite slow.\r\n\r\nCode Efficiency\r\n\r\nI'm not sure the efficiency would be improved much at all by moving the code out of the handle. There may be a slight improvement but not much to even notice. :frowning:  see http://www.perlmonks.org/?node_id=1115561 \r\n\r\n\r\n\r\n\r\n"}}