{"id":289,"date":"2018-11-01T12:08:26","date_gmt":"2018-11-01T12:08:26","guid":{"rendered":"https:\/\/books.compclassnotes.com\/elementarycomputing\/?page_id=289"},"modified":"2018-11-05T15:32:47","modified_gmt":"2018-11-05T15:32:47","slug":"design","status":"publish","type":"page","link":"https:\/\/books.compclassnotes.com\/elementarycomputing\/design\/","title":{"rendered":"Design"},"content":{"rendered":"<div class=\"page\" title=\"Page 1\">\n<div class=\"layoutArea\">\n<div class=\"column\">\n<p>At some point we will want to realise our beautiful designs and write code, so we need to decide what language to use. Languages such as Java and C++ are convenient, they are often too inconsistent because they contain a mix or\u00a0pre\/post\/infix (and or often know as \u201cmixfix\u201d).<\/p>\n<p>For example, this is a legal code snippet in Java.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\r\ni++; ++i; i+i;\r\n\r\nj=i+++++i;\r\n\r\n<\/pre>\n<p>Yes, that is five\u00a0<strong>+<\/strong> symbols in a row! In that code, if i started with the value 3, it would finish with 5, while j would have the value 8. Hard to see why? Well, that&#8217;s partly why we&#8217;re not going to use Java! Similarly, there is always a bunch of extra syntax, things like<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\r\npublic static void main(String&#x5B;] args)..\r\n\r\n<\/pre>\n<p>This appears in virtually every single Java program, but we still have to put it in. This is sometimes referred to as &#8220;syntactic sugar&#8221;: it doesn&#8217;t do anything to improve the semantics and is just there to make the program (allegedly) easier to read. However, too much sugar is neither useful nor good for you!<\/p>\n<p>Java isn&#8217;t the only language guilty of this, of course. Many languages suffer from it. For this book we will use\u00a0<em>functional programming<\/em>, which is a style of programming based on expressions and functions. Functional programs are often\u00a0<strong>tiny<\/strong> and can be very efficient. For example, here&#8217;s another Java program:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\r\nclass myfirstjavaprog\r\n\r\n{\r\n\r\npublic static void main(String args&#x5B;])\r\n\r\n{\r\n\r\nSystem.out.println(3 + 1);\r\n\r\n}\r\n\r\n}\r\n\r\n<\/pre>\n<\/div>\n<p>The source code is 133 bytes. That&#8217;s not entirely awful, but when we compile it we get a whopping 14,578 bytes. Here&#8217;s the equivalent program written in a functional programming language:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\r\n&gt; (+ 3 1)\r\n\r\n<\/pre>\n<p>Seven bytes!<\/p>\n<p>We&#8217;ll look at functional programming in <a href=\"https:\/\/books.compclassnotes.com\/elementarycomputing\/functional-programming\/\">the next section<\/a>.<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>At some point we will want to realise our beautiful designs and write code, so we need to decide what language to use. Languages such as Java and C++ are convenient, they are often too inconsistent because they contain a <span class=\"readmore\"><a href=\"https:\/\/books.compclassnotes.com\/elementarycomputing\/design\/\">Continue Reading<\/a><\/span><\/p>\n","protected":false},"author":4,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-289","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/books.compclassnotes.com\/elementarycomputing\/wp-json\/wp\/v2\/pages\/289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/books.compclassnotes.com\/elementarycomputing\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/books.compclassnotes.com\/elementarycomputing\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/books.compclassnotes.com\/elementarycomputing\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/books.compclassnotes.com\/elementarycomputing\/wp-json\/wp\/v2\/comments?post=289"}],"version-history":[{"count":6,"href":"https:\/\/books.compclassnotes.com\/elementarycomputing\/wp-json\/wp\/v2\/pages\/289\/revisions"}],"predecessor-version":[{"id":382,"href":"https:\/\/books.compclassnotes.com\/elementarycomputing\/wp-json\/wp\/v2\/pages\/289\/revisions\/382"}],"wp:attachment":[{"href":"https:\/\/books.compclassnotes.com\/elementarycomputing\/wp-json\/wp\/v2\/media?parent=289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}