{"id":574,"date":"2008-05-22T17:07:57","date_gmt":"2008-05-22T17:07:57","guid":{"rendered":"http:\/\/neosmart.net\/blog\/2008\/programmers-should-trust-their-instincts\/"},"modified":"2013-08-26T18:18:22","modified_gmt":"2013-08-26T23:18:22","slug":"programmers-should-trust-their-instincts","status":"publish","type":"post","link":"https:\/\/neosmart.net\/blog\/programmers-should-trust-their-instincts\/","title":{"rendered":"Programmers Should Trust Their Instincts"},"content":{"rendered":"<p>People are either cut out to be programmers or they&#8217;re not. How to know, what to do if you&#8217;re not, and where to go from there is a huge issue and not the subject of discussion. But one of the signs of a good programmer is good programming instincts. The right instincts can save hours of work and provide creative solutions to even the most difficult problems; and &#8220;gut feelings&#8221; in programming are not something you should ignore lightly.<\/p>\n<p>One of the first thing Computer Science teachers drill into the heads of their students is that it&#8217;s important to map everything out beforehand. Design the algorithm. Draw the UML diagrams. Decide the entire flow of data and the relationships between everything before you even touch the IDE. While this is integral advice for anything above a small-complexity project, there is an exception: if you have a gut feeling, follow it.<\/p>\n<p>For instance, the other day I sat down to write a simulator for a MIPS datacache, with different replacement policies. &#8220;Ideally,&#8221; the planning procedure would have involved designing the sequence diagram, a flowchart detailing the method used by the cache to determine expired entries, and generally-speaking a lot of time down the hole just <em>visualizing<\/em> what happens beforehand.<\/p>\n<p><!--more--> <\/p>\n<p>While mulling things over for a minute or two in my head to gather my thoughts, I found myself scribbling three phrases on <a href=\"https:\/\/neosmart.net\/blog\/postit-notes\/\" rel=\"follow\">the PostIt note in front of me<\/a>:<\/p>\n<ul>\n<li>Access times -&gt; FIFO<\/li>\n<li>Access times defined by unique tag<\/li>\n<li>Reading memory == dequeue item<\/li>\n<\/ul>\n<p>These were spur-of-the-moment analyses of the caching procedure. Just thinking about the caching methodology brought these ideas to mind, with no particular &#8220;thinking through&#8221; of type. Looking back at them, I couldn&#8217;t (instantaneously) recall <em>why<\/em> I felt that access times should be removed FIFO from the data structure on read, but I figured it must have made sense on some subconscious level and plowed ahead right into the code.<\/p>\n<p>In the end, the code worked, the project was done far quicker than originally imagined, and I had time to <strike>kill<\/strike> post this article.<\/p>\n<p>Any good programmer you talk to will have a similar experience to share. The only reason I trusted my instinct in the first place on this matter (keeping in mind that the implementation of &#8220;random&#8221; algorithms can be a huge timesink if they don&#8217;t actually work) was because trusting my coding instincts has generally proved to be the right thing in the past &#8211; this is simply the most recent example.<\/p>\n<p>Of course, every once in a while an impromptu idea may not be perfect; indeed, it&#8217;s possible that they&#8217;re fatally flawed. Whether it&#8217;s because the problem itself wasn&#8217;t initially understood or simply a matter of arriving to the wrong (hasty) conclusion, mistakes can (and have) occur. But it&#8217;s important to bear in mind the <em>ratio<\/em> of brilliant ideas to failures &#8211; most good programmers I&#8217;ve spoken to reaffirm that it&#8217;s a very workable hit-miss ratio.<\/p>\n<p>Certainly programming by instinct has its drawbacks. For instance, these &#8220;strokes of brilliance&#8221; make up the majority of what we refer to &#8211; in retrospect &#8211; as quick and dirty solutions. There&#8217;s a time and a place for using them; and being unable to figure that part out can end up hurting you and your program. Typically speaking, using the first thought that occurs to you when structuring your program (what classes, how they interact with one another, etc.) isn&#8217;t such a good idea. Things like this need to be refined non-stop (until you get that warm, fuzzy feeling when you look at your code ;-) and quick solutions won&#8217;t help you there.<\/p>\n<p>It&#8217;s usually within individual functions when you need to get something done based on the state of one or more other objects that instincts prove handy. To put it another way: when the code you&#8217;re working needs some measure of creativity and out-of-the-box thinking, don&#8217;t ever pass up on a gut feeling. Programming gives experience and insight, much of it subconscious. Patterns and ideas may leap out at you in ways that aren&#8217;t immediately obvious, but even if we don&#8217;t fully comprehend how the ideas came into existence it doesn&#8217;t mean they don&#8217;t have a substantial amount of intricate logic and supporting foundation to back them.<\/p>\n<p>The next time an idea flashes into existence, like the proverbial lightbulb flickering on above your head, take a minute to appreciate its glow. Realize that you&#8217;re lucky to have such inexplicable moments, and trust them to take you and your code to the next level.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>People are either cut out to be programmers or they&#8217;re not. How to know, what to do if you&#8217;re not, and where to go from there is a huge issue and not the subject of discussion. But one of the &hellip; <a href=\"https:\/\/neosmart.net\/blog\/programmers-should-trust-their-instincts\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":505,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[360,46,212,649,11],"class_list":["post-574","post","type-post","status-publish","format-standard","hentry","category-software","tag-coding","tag-computer-science","tag-development","tag-instincts","tag-programming"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4xDa-9g","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/users\/505"}],"replies":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/comments?post=574"}],"version-history":[{"count":1,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/574\/revisions"}],"predecessor-version":[{"id":2530,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/574\/revisions\/2530"}],"wp:attachment":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/media?parent=574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/categories?post=574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/tags?post=574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}