{"id":4794,"date":"2014-03-30T15:22:48","date_gmt":"2014-03-30T15:22:48","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/differences-between-self-and-smalltalk-collection-of-common-programming-errors\/"},"modified":"2014-03-30T15:22:48","modified_gmt":"2014-03-30T15:22:48","slug":"differences-between-self-and-smalltalk-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/differences-between-self-and-smalltalk-collection-of-common-programming-errors\/","title":{"rendered":"Differences between Self and Smalltalk-Collection of common programming errors"},"content":{"rendered":"<p>The most distinct difference between Self and Smalltalk is that Self does not have the notion of <em>Classes<\/em>. There is no &#8220;<em>is an instance of<\/em>&#8221; relation between an object and a class. Self rather has been one of the first <em>prototypical<\/em> object-oriented language, and in this respect a precursor to JavaScript. Hence, the typical way to create a new object in Smalltalk is <strong>instantiation<\/strong> whereas in Self it is <strong>cloning<\/strong>.<\/p>\n<h2>Execution and Messages<\/h2>\n<p>As you already have found out, the second fundamental difference is that in Self, the only notion of execution is the <em>message send<\/em>, whereas in Smalltalk, <em>assignment<\/em> and <em>object field access<\/em> also are present. Furthermore, there is no such thing as <em>global state<\/em> in Self. You can only access what you can retrieve by sending messages. Self however tracks some &#8220;well known objects&#8221;, which a newly created object can be given.<\/p>\n<h2>State and Slots<\/h2>\n<p>Pondering on the two previous points, &#8220;No classes&#8221; and &#8220;only messages&#8221;, makes it clear, that the Smalltalk distinction between and objects <em>state<\/em> and its <em>behavior<\/em> is not directly present in Self. Where Smalltalk stores <strong>state<\/strong> in an objects&#8217;s <strong>instances variables<\/strong> and <strong>behavior<\/strong> in <strong>method dictionaries<\/strong> in its class, Self uses the notion of <strong>slots<\/strong>, which can represent both state and behavior.<\/p>\n<h2>Sharing behavior<\/h2>\n<p>To help organizing behavior, Self not only provides <em>prototypes<\/em> but also <strong>traits<\/strong>. A trait is an object that only contains behavior, and which several objects share. (Moreover, there are also <em>mixins<\/em>, small portions of <em>behavior<\/em> and <em>state<\/em>, that can be composed into other objects).<\/p>\n<p>Objects in Self can have <strong>parents<\/strong> to which messages are sent that the object itself does not understand (<strong>delegation<\/strong>). This creates hierarchies that can be similar to class <strong>inheritance<\/strong> in Smalltalk, but does not need classes.<\/p>\n<h2>A few Examples<\/h2>\n<h3>Creating a new object<\/h3>\n<p>Smalltalk<\/p>\n<pre><code>Object new\n<\/code><\/pre>\n<p>Self:<\/p>\n<ul>\n<li>a plain object: <code>()<\/code> or <code>(||)<\/code> (to make the absence of slots explicit)<\/li>\n<li>a copied object: <code>someObject copy<\/code><\/li>\n<\/ul>\n<h3>Creating an object with some fields<\/h3>\n<p>Smalltalk<\/p>\n<pre><code>Object subclass: #MyObjects instanceVariableNames: 'foo bar'. \".\" \nMyObject new.\n<\/code><\/pre>\n<p>Self<\/p>\n<pre><code>( | foo. bar | )\n<\/code><\/pre>\n<h3>Making a collection<\/h3>\n<p>Smalltalk<\/p>\n<pre><code>OrderedCollection new.\n<\/code><\/pre>\n<p>Self<\/p>\n<pre><code>list copy.\n<\/code><\/pre>\n<h3>&#8220;Inheritance&#8221;<\/h3>\n<p>Smalltalk<\/p>\n<pre><code>Object subclass: #MyObject. \".\"\n<\/code><\/pre>\n<p>Self<\/p>\n<pre><code>( | parent*<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The most distinct difference between Self and Smalltalk is that Self does not have the notion of Classes. There is no &#8220;is an instance of&#8221; relation between an object and a class. Self rather has been one of the first prototypical object-oriented language, and in this respect a precursor to JavaScript. Hence, the typical way [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4794","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4794","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4794"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4794\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}