{"id":825,"date":"2016-10-31T20:51:22","date_gmt":"2016-10-31T20:51:22","guid":{"rendered":"http:\/\/blogs.kent.ac.uk\/mik\/?p=825"},"modified":"2024-09-29T11:09:37","modified_gmt":"2024-09-29T11:09:37","slug":"whats-in-a-symbol-assignment-revisited","status":"publish","type":"post","link":"https:\/\/blogs.kcl.ac.uk\/proged\/2016\/10\/31\/whats-in-a-symbol-assignment-revisited\/","title":{"rendered":"What&#8217;s in a symbol? Assignment revisited"},"content":{"rendered":"<p>I was at a Dagstuhl seminar recently, about programming education, and one of the things we discussed were common misconceptions of novice programmers. One of these, reported by several seasoned\u00a0programming teachers, was the difficulty in interpreting the assignment symbol in C-style languages:<\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier\">number = 42<\/span><\/p>\n<p>There are several things that can be misinterpreted here. Firstly, the equality operator is non-directional. Some students have problems remembering which way it operates. Consider this statement:<\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier\">a\u00a0= b<\/span><\/p>\n<p>Which way does it assign? To all of us who have programmed for some time this may seem a silly question \u2013 we get used to the right-to-left semantics so thoroughly that we can hardly imagine it to be different. But for beginners? Not so clear. (And, of course, the direction <em>is<\/em> arbitrary; language designers could just as well have decided the other way.)<\/p>\n<p>The second possible misconception is related to the previously learned meaning of the equals symbol: to express equality. This has been used in maths for centuries, and taught to most pupils before they ever encounter programming, and is quite different from assignment. Consider this code fragment:<\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier\">a\u00a0= 0;<br \/>\nb = a;<br \/>\na = 7;<\/span><\/p>\n<p>What, now, is the value of b? For learners holding the equality misconception, it will be 7. This is not entirely unreasonable; it is indeed an internally consistent mental model. The misconception is that variables, once expressed as equal, <em>remain<\/em> linked. So the equals symbol is interpreted as equality (&#8220;<em>b is the same as a<\/em>&#8220;), which might then remain true for the future.<\/p>\n<p>Many people have commented for a long time that the C-style equality-as-assignment is not ideal. Many languages do better. Algol and Pascal, for example, already used a different symbol in the 1960s, quite explicitly to express the directionality more clearly, and to distinguish from equality:<\/p>\n<p style=\"padding-left: 30px\"><span style=\"font-family: courier\">number := 42<\/span><\/p>\n<p>I have always like this much better than the single equals and have always been mildly annoyed by the C-style syntax.<\/p>\n<p>So when we designed our language <a href=\"https:\/\/blogs.kent.ac.uk\/mik\/2016\/10\/stride-an-introduction\/\">Stride<\/a> recently, the question surfaced again. What should we choose?<\/p>\n<p>We had two competing goals: On the one hand, we wanted the syntax to be clear and expressive, but on the other hand we want Stride to be a pathway into Java, so there is also a strong incentive to be consistent with Java syntax. (Java, of course, uses the C-style syntax, so these two goals are in conflict.)<\/p>\n<p>At first, we prioritised the Java-compatibility argument and chose the equality symbol. The first release of Stride had this as the assignment operator. But then the Dagstuhl discussion happened, and I started to think again.<\/p>\n<p>In Stride we have an advantage: Because the\u00a0representation of the program is not directly typed in, but produced by the system in reaction to command keys, we are not restricted to characters that can easily be typed on a standard keyboard. So initially I considered going back to a syntax that Smalltalk used (in early versions, before it\u00a0fell back onto the := variant), a left arrow:<\/p>\n<p style=\"padding-left: 30px\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-834\" src=\"http:\/\/blogs.kcl.ac.uk\/proged\/wp-content\/blogs.dir\/192\/files\/2016\/10\/arrow-assign-1.png\" alt=\"arrow-assign\" width=\"62\" height=\"20\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>I liked it for its clarity of expression, but it has one disadvantage in a teaching language that is intended to lead to Java and similar languages: it does not directly prepare learners for the equal symbol so widely used for assignment in other languages. After\u00a0we discussed this in one of our team meetings, Neil Brown, one of our team members, came up with what I think is a brilliant compromise:<\/p>\n<p style=\"padding-left: 30px\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-827\" src=\"http:\/\/blogs.kcl.ac.uk\/proged\/wp-content\/blogs.dir\/192\/files\/2016\/10\/assign-1.png\" width=\"175\" height=\"22\" srcset=\"https:\/\/blogs.kcl.ac.uk\/proged\/files\/2016\/10\/assign-1.png 349w, https:\/\/blogs.kcl.ac.uk\/proged\/files\/2016\/10\/assign-1-300x37.png 300w\" sizes=\"auto, (max-width: 175px) 100vw, 175px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>This is what assignment now looks like in Stride. The double arrow still has a visual link to an equals sign, but is clearly distinct from it; it is also clearly directional. We still use the equals key as a command key to enter an assignment, further reinforcing the link for the future.<\/p>\n<p>Here&#8217;s what our\u00a0assignment looks like in context:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-835\" src=\"http:\/\/blogs.kcl.ac.uk\/proged\/wp-content\/blogs.dir\/192\/files\/2016\/10\/stride-code.png\" alt=\"stride-code\" width=\"633\" height=\"208\" srcset=\"https:\/\/blogs.kcl.ac.uk\/proged\/files\/2016\/10\/stride-code.png 1266w, https:\/\/blogs.kcl.ac.uk\/proged\/files\/2016\/10\/stride-code-300x99.png 300w, https:\/\/blogs.kcl.ac.uk\/proged\/files\/2016\/10\/stride-code-1024x336.png 1024w, https:\/\/blogs.kcl.ac.uk\/proged\/files\/2016\/10\/stride-code-500x164.png 500w\" sizes=\"auto, (max-width: 633px) 100vw, 633px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>I am very happy with it. I think it reads well and is the closest we can get to reaching two competing goals.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was at a Dagstuhl seminar recently, about programming education, and one of the things we discussed were common misconceptions of novice programmers. One of these, reported by several seasoned\u00a0programming teachers, was the difficulty in interpreting the assignment symbol in &hellip; <a href=\"https:\/\/blogs.kcl.ac.uk\/proged\/2016\/10\/31\/whats-in-a-symbol-assignment-revisited\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":179,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[137,4,8,12,136,13],"tags":[101],"class_list":["post-825","post","type-post","status-publish","format-standard","hentry","category-frame-based-editing","category-hci","category-programming","category-stride","category-strype","category-teaching","tag-stride"],"_links":{"self":[{"href":"https:\/\/blogs.kcl.ac.uk\/proged\/wp-json\/wp\/v2\/posts\/825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.kcl.ac.uk\/proged\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.kcl.ac.uk\/proged\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.kcl.ac.uk\/proged\/wp-json\/wp\/v2\/users\/179"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.kcl.ac.uk\/proged\/wp-json\/wp\/v2\/comments?post=825"}],"version-history":[{"count":1,"href":"https:\/\/blogs.kcl.ac.uk\/proged\/wp-json\/wp\/v2\/posts\/825\/revisions"}],"predecessor-version":[{"id":989,"href":"https:\/\/blogs.kcl.ac.uk\/proged\/wp-json\/wp\/v2\/posts\/825\/revisions\/989"}],"wp:attachment":[{"href":"https:\/\/blogs.kcl.ac.uk\/proged\/wp-json\/wp\/v2\/media?parent=825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.kcl.ac.uk\/proged\/wp-json\/wp\/v2\/categories?post=825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.kcl.ac.uk\/proged\/wp-json\/wp\/v2\/tags?post=825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}