{"id":230,"date":"2012-03-23T13:11:54","date_gmt":"2012-03-23T18:11:54","guid":{"rendered":"http:\/\/wordpress.morningside.edu\/meyersh\/?p=230"},"modified":"2013-03-13T12:00:55","modified_gmt":"2013-03-13T17:00:55","slug":"naive-programming","status":"publish","type":"post","link":"https:\/\/wordpress.morningside.edu\/meyersh\/2012\/03\/23\/naive-programming\/","title":{"rendered":"Naive Programming"},"content":{"rendered":"<p>I think that may always be the case, especially when the resulting program is a function of what I&#8217;m asked to do! I was instead considering how, give experience in mathematical reasoning and programming, one writes increasingly concise code.<\/p>\n<p>Because of the intense usefulness of Maths in programming, I cannot grok my fellow students&#8217; disapproval of the subject. One of the major ways my code has grown less naive is in the borrowing of mathematical concepts.<\/p>\n<p>Naive:<\/p>\n<pre>\/\/ print the sum of numbers x through y.\r\nint sum(int x, int y) {\r\n  int s = 0;\r\n  for (int i = x; i &lt;= y; i++)\r\n    s += i;\r\n\r\n  return s;\r\n}<\/pre>\n<p>Insightful:<\/p>\n<pre>\/\/ print the sum of numbers x through y.\r\nint sum(int x, int y) {\r\n  return y*(y+1)\/2 - x*(x+1)\/2; \r\n}<\/pre>\n<p>I cannot remember a time when a working insightful function has been worse then the naive equivalent. Even in my contrived example above the naive_sum() has inputs which would yield undefined output such as the case where y &lt;= x while the insightful_sum() would degrade more gracefully.<\/p>\n<p>In the naive style, we&#8217;d have to add conditionals to validate inputs that the maths would accept, meaning increased line count, reduced legibility, increased chance of errors, and increased nativity. The only advantage I can see to the naive style is the reduction in mathematically cluttered code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I think that may always be the case, especially when the resulting program is a function of what I&#8217;m asked to do! I was instead considering how, give experience in mathematical reasoning and programming, one writes increasingly concise code. Because of the intense usefulness of Maths in programming, I cannot grok my fellow students&#8217; disapproval &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/wordpress.morningside.edu\/meyersh\/2012\/03\/23\/naive-programming\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Naive Programming&#8221;<\/span><\/a><\/p>\n","protected":false},"author":11,"featured_media":334,"comment_status":"open","ping_status":"open","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":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[189,4057],"tags":[],"class_list":["post-230","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding","category-maths","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/wordpress.morningside.edu\/meyersh\/files\/2012\/03\/bottled-water-for-naive-people.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p16T7G-3I","_links":{"self":[{"href":"https:\/\/wordpress.morningside.edu\/meyersh\/wp-json\/wp\/v2\/posts\/230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.morningside.edu\/meyersh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.morningside.edu\/meyersh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.morningside.edu\/meyersh\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.morningside.edu\/meyersh\/wp-json\/wp\/v2\/comments?post=230"}],"version-history":[{"count":12,"href":"https:\/\/wordpress.morningside.edu\/meyersh\/wp-json\/wp\/v2\/posts\/230\/revisions"}],"predecessor-version":[{"id":335,"href":"https:\/\/wordpress.morningside.edu\/meyersh\/wp-json\/wp\/v2\/posts\/230\/revisions\/335"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.morningside.edu\/meyersh\/wp-json\/wp\/v2\/media\/334"}],"wp:attachment":[{"href":"https:\/\/wordpress.morningside.edu\/meyersh\/wp-json\/wp\/v2\/media?parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.morningside.edu\/meyersh\/wp-json\/wp\/v2\/categories?post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.morningside.edu\/meyersh\/wp-json\/wp\/v2\/tags?post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}