{"id":39,"date":"2005-10-15T07:40:28","date_gmt":"2005-10-15T07:40:28","guid":{"rendered":"http:\/\/69.195.124.246\/~wisecon1\/blog\/?p=39"},"modified":"2005-10-15T07:40:28","modified_gmt":"2005-10-15T07:40:28","slug":"starting_to_thi","status":"publish","type":"post","link":"https:\/\/wisecontradictions.com\/blog\/?p=39","title":{"rendered":"Starting to think like a Computer Scientist"},"content":{"rendered":"<p>I am in day 2 of programming school and am working my way through <a href=\"http:\/\/www.ibiblio.org\/obp\/thinkCSpy\/chap01.htm\">&quot;How to Think Like a Computer Scientist<\/a>&quot; (python edition) by Downey, Elkner and Meyers.&nbsp; This book&#8217;s available for *free* as in free beer.&nbsp; It&#8217;s well written and fun to read. <\/p>\n<p>Learning to think like a computer scientist is practical.&nbsp; In the author&#8217;s words: &quot;The single most important skill for a computer scientist is problem solving. Problem solving means the ability to formulate problems, think creatively about solutions, and express a solution clearly and accurately.&quot; <\/p>\n<p><!--more--><\/p>\n<p>\nLike any new language, there are many new words to learn, but today I<br \/>\nlearned an important distinction in the way that computer scientists<br \/>\nthink about languages.&nbsp; I am writing this post in English&#8211;a &quot;natural&quot;<br \/>\nlanguage that we use for speaking and writing.&nbsp; Comparatively, Python<br \/>\nis a &quot;formal&quot; language designed by people to express computations and<br \/>\nthat means it has really strict rules about syntax.&nbsp; In formal<br \/>\nprogramming languages, there are no metaphors, no redundancy, no<br \/>\ncontextual clues.&nbsp; The statements must conform to the computer<br \/>\nlanguages&#8217; rules or the interpreter&#8211;the high level program that reads<br \/>\nall other programs&#8211;can&#8217;t act on them.&nbsp; Fortunately, the computer is<br \/>\nvery good at saying &quot;I don&#8217;t understand.&quot;&nbsp; \n<\/p>\n<p>\nOne of the things I already like about programming is that you&#8217;re able<br \/>\nto tinker and get immediate feedback. This is obvious to anyone that<br \/>\nprograms, but neat for someone who&#8217;s relatively new at it.&nbsp; I wonder if<br \/>\nthe reason that so many programmers are self taught is because formal<br \/>\nlanguages lend themselves to self teaching since the interpreter<br \/>\nprovides the feedback. For example:<\/p>\n<p>\nThe first time I asked the python interpreter to multiply 2 * apple, it said:<\/p>\n<p>\nNameError: name &#8216;apple&#8217; is not defined<a onclick=\"window.open(this.href, '_blank', 'width=506,height=366,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false\" href=\"http:\/\/www.wisecontradictions.com\/.shared\/image.html?\/photos\/uncategorized\/instantfeedback.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"126\" height=\"91\" border=\"0\" src=\"https:\/\/i0.wp.com\/www.wisecontradictions.com\/wise_contradictions\/images\/instantfeedback.png?resize=126%2C91\" title=\"Instantfeedback\" alt=\"Instantfeedback\" style=\"margin: 0px 0px 5px 5px; float: right;\" \/><\/a><\/p>\n<p>\nWhich meant that I hadn&#8217;t defined &quot;apple.&quot;&nbsp; So I went back and said:<\/p>\n<p>\napple = 6<\/p>\n<p>\nand then the interpreter was able to do the math.&nbsp; This is just a line, but a program is more than that.<\/p>\n<p>\nPrograms are collections of statements that specify how to perform a<br \/>\ncomputation&#8211;whether that&#8217;s doing math, or putting text together.<br \/>\nAccording to the authors, programs can be broken down to these basic<br \/>\nsteps:<\/p>\n<ul>\n<li>\nInput &#8211; get the data from somewhere (keyboard, file)<\/li>\n<li>\nOutput &#8211; display the data (on the screen, or send it to a device)<\/li>\n<li>\nMath &#8211; Perform some calculation, like addition or its tricky pal, subtraction<\/li>\n<li>\nConditional Execution &#8211; If the criminal is guilty then send him to jail <\/li>\n<li>\nRepetition &#8211; Do it again, and again, so that I don&#8217;t have to, perhaps with some variation.<\/li>\n<\/ul>\n<p>\nSeems easy enough&#8211;things get complicated when you try to break real<br \/>\nworld problems down into steps small enough for your code to understand<br \/>\nand deal with it&#8211;but that&#8217;s what makes it interesting. <\/p>\n<p>\nI made one other note to myself as I was working through the first<br \/>\ncouple chapters:&nbsp; write for the machine, but simultaneously, write for<br \/>\nthe human.&nbsp; &nbsp;Tell the computer what you want it to do in its language,<br \/>\nbut leave a clue for yourself and others that may come later about what<br \/>\nyou&#8217;re trying to accomplish with a statement.&nbsp; This is one of those<br \/>\nthings that&#8217;s really smart to do while you&#8217;re doing it, but probably<br \/>\nunbearable if you have to go back and remember &quot;now, what was I doing<br \/>\nhere?&quot;<\/p>\n<p>\nSo a well commented statement looks something like this:<\/p>\n<p>\n# compute the percentage of the hour that has elapsed<br \/>\npercentage = (minute * 100) \/ 60<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am in day 2 of programming school and am working my way through &quot;How to Think Like a Computer Scientist&quot; (python edition) by Downey, Elkner and Meyers.&nbsp; This book&#8217;s available for *free* as in free beer.&nbsp; It&#8217;s well written and fun to read. Learning to think like a computer scientist is practical.&nbsp; In the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8],"tags":[101],"class_list":["post-39","post","type-post","status-publish","format-standard","hentry","category-webtech","tag-programming"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wisecontradictions.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/39","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wisecontradictions.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wisecontradictions.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wisecontradictions.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wisecontradictions.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=39"}],"version-history":[{"count":0,"href":"https:\/\/wisecontradictions.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/39\/revisions"}],"wp:attachment":[{"href":"https:\/\/wisecontradictions.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wisecontradictions.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wisecontradictions.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}