{"id":7,"date":"2003-05-02T12:34:40","date_gmt":"2003-05-02T11:34:40","guid":{"rendered":"http:\/\/www.nobugs.org\/blog\/archives\/2003\/05\/02\/once-upon-a-type\/"},"modified":"2003-05-02T12:34:40","modified_gmt":"2003-05-02T11:34:40","slug":"once-upon-a-type","status":"publish","type":"post","link":"https:\/\/www.nobugs.org\/blog\/archives\/2003\/05\/02\/once-upon-a-type\/","title":{"rendered":"Once upon a type"},"content":{"rendered":"<p>Static vs. dynamic type systems.  It used to be an easy choice.  Along with the rest of the human race, I make typos all the time.  If I made a typo whilst typing a function call in some rarely-used bit of code, a static type system would tell me.  Also, I&#8217;m a great believe in making computers do as much work as possible so that I can leave work on time and do something more fun.  I like the idea of a compiler whirring away, checking lots of common mistakes for me.  Letting go of that seemed <i>dangerous<\/i>&#8230;<br \/>\n<!--more--><br \/>\nBut then I played with <a href=\"http:\/\/www.squeak.org\/\">Squeak<\/a> for a while and now I&#8217;m not so sure.  Squeak is not just a nice development environment, it&#8217;s <i>really<\/i> nice.  It&#8217;s very easy to do stuff.  You want to find who calls this method?   Easy. You want to find which methods use this instance variable?  Easy.  You&#8217;d like to extract this chunk of code into it&#8217;s own method.  No problem.<\/p>\n<p>Furthermore, the Squeak world is consistent.  With C++, there are two worlds &#8211; compile time and run time.  The compile time world is a swirl of types, methods and files.  The run time world is a heady mix of memory addresses and instruction pointers.  It&#8217;s nearly impossible to ask questions about types once you&#8217;re in the run time world.  Never the twain shall meet.  Debuggers provide an uneasy bridge between the two worlds, but you never have the full power of either.  In Squeak, there&#8217;s just one world.  Your source code is an object.  The types you use are objects.  The virtual machine is an object.  You compile code by calling methods on a Compiler object.  There&#8217;s no split, so there&#8217;s no distinction between &#8220;writing code&#8221; mode and &#8220;running code&#8221; mode, like there is in C++.<\/p>\n<p>I have a feeling that Squeak&#8217;s flexibility is due to it&#8217;s runtime-typed nature.  I don&#8217;t know if that&#8217;s 100% true.  For example, a C++ compiler could very easily emit code so that each object contains a pointer to it&#8217;s type.  I don&#8217;t just mean a typename, I mean a full description of it&#8217;s type &#8211; member variable names, their types etc.  <\/p>\n<p>In a way, this partly defeats the point of having a statically typed language.  The reason you go to all that effort of figuring out types at compile-time is because you don&#8217;t want to do it at runtime.  Having said that, not everything in C++ is an object so it&#8217;s not that easy.<\/p>\n<p>I can&#8217;t finish an entry about type systems without mentioning that although C++ has a static type system, it really sucks compared to languages like <a href=\"http:\/\/caml.inria.fr\/\">ocaml<\/a> and <a href=\"http:\/\/www.haskell.org\/\">haskell<\/a>.  With these languages, you don&#8217;t have to specify any types in your program &#8211; the compiler will infer them all for you.  They deal elegantly with parametric polymorphism (templates in C++) and haskell has a very neat type class system (like templates in C++ where the template parameter has to satisfy some condition, like &#8220;has operator< defined\").\n\nA <a href=\"http:\/\/perl.plover.com\/yak\/typing\/\">perlmunger agrees<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Static vs. dynamic type systems. It used to be an easy choice. Along with the rest of the human race, I make typos all the time. If I made a typo whilst typing a function call in some rarely-used bit of code, a static type system would tell me. Also, I&#8217;m a great believe in [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-7","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/comments?post=7"}],"version-history":[{"count":0,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/7\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/media?parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/categories?post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/tags?post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}