{"id":218,"date":"2021-04-12T19:23:51","date_gmt":"2021-04-12T16:23:51","guid":{"rendered":"https:\/\/www.juustila.com\/antti\/?p=218"},"modified":"2021-04-12T19:23:51","modified_gmt":"2021-04-12T16:23:51","slug":"todays-thoughts","status":"publish","type":"post","link":"https:\/\/www.juustila.com\/antti\/2021\/04\/12\/todays-thoughts\/","title":{"rendered":"Today\u2019s thoughts"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Someone mentioned the book <a rel=\"noreferrer noopener\" href=\"https:\/\/www.routledge.com\/Exercises-in-Programming-Style\/Lopes\/p\/book\/9780367350208\" target=\"_blank\">Exercises in Programming Style<\/a> by Cristina Lopes in Twitter and I bought it. Interesting read, can recommend. I can bring some things from the book into my course next Fall. We should actually have a course focusing <em>mainly<\/em> on these topics but alas, do not have one. I just need to implement those things I could apply in Java, maybe as demonstrations, since the book is in Python. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Another thought I need to embed into course material is this nice example of how order of things may greatly influence the time performance of code. I was evaluating a student submission of a course project. A function added nodes (unique word counts of very large text files) into a binary search tree. First a node was allocated using <code>malloc<\/code> after which the tree was searched in a loop where to put the node. And if a node with the value already existed, the frequency count of the <em>existing<\/em> node was increased and the node just created could be <code>free<\/code>d and function would return. And if the value of the node was <em>not<\/em> found in the tree, then the node just allocated was inserted into the tree in the place that was found for it. By just moving the <code>malloc<\/code> <em>after<\/em> the loop (where the node was actually needed) got rid of <em>30%<\/em> of the execution time of the whole app.  Boom! What an improvement with such a small change. Which is obvious if you have some experience but not so for many students who are in the beginning. This will be a fun demonstration&#8230;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Final thought of the day popped to my mind because of that minor piece of code having a large effect, and that is this saying: <\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>The idiom &#8220;<strong>the straw that broke the camel&#8217;s back<\/strong>&#8220;, alluding to the proverb &#8220;it is the last straw that breaks the camel&#8217;s back&#8221;, describes the seemingly minor or routine action that causes an unpredictably large and sudden reaction, because of the cumulative effect of small actions.<\/p><cite>Wikipedia<\/cite><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Someone mentioned the book Exercises in Programming Style by Cristina Lopes in Twitter and I bought it. Interesting read, can recommend. I can bring some things from the book into my course next Fall. We should actually have a course focusing mainly on these topics but alas, do not have one. I just need to &hellip; <a href=\"https:\/\/www.juustila.com\/antti\/2021\/04\/12\/todays-thoughts\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Today\u2019s thoughts&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[2],"tags":[74,75,39],"class_list":["post-218","post","type-post","status-publish","format-standard","hentry","category-coding","tag-binary-search-tree","tag-book","tag-performance"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/posts\/218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/comments?post=218"}],"version-history":[{"count":1,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/posts\/218\/revisions"}],"predecessor-version":[{"id":220,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/posts\/218\/revisions\/220"}],"wp:attachment":[{"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/media?parent=218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/categories?post=218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/tags?post=218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}