{"id":395,"date":"2014-08-05T07:15:41","date_gmt":"2014-08-05T12:15:41","guid":{"rendered":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/?p=395"},"modified":"2014-08-05T08:55:54","modified_gmt":"2014-08-05T13:55:54","slug":"type-safety","status":"publish","type":"post","link":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/","title":{"rendered":"What is type safety?"},"content":{"rendered":"<p>In response to my <a title=\"What is memory safety?\" href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/07\/21\/memory-safety\/\">previous post defining memory safety<\/a>\u00a0(for C), one commenter suggested it would be nice to have a post explaining type safety. Type safety is pretty well understood, but it&#8217;s still not something you can easily pin down. In particular, when someone says, &#8220;Java is a type-safe language,&#8221; what do they mean, exactly? Are all type-safe languages &#8220;the same&#8221; in some way? What is type safety getting you, for particular languages, and in general?<\/p>\n<p>In fact, what type safety means depends on\u00a0language type system&#8217;s definition. In the simplest\u00a0case, type safety ensures that\u00a0program behaviors are well defined. More generally,\u00a0as I discuss in this post, a language&#8217;s\u00a0type system\u00a0can be a powerful tool for reasoning about the correctness and security of its programs, and as such the development of novel type systems is a rich area of research.<\/p>\n<p><!--more--><\/p>\n<h2>Basic Type Safety<\/h2>\n<p>An intuitive\u00a0notion of type safety is pithily summarized by the phrase, &#8220;<i><strong>Well typed\u00a0<\/strong>programs\u00a0<strong>cannot go wrong<\/strong><\/i>.&#8221; This phrase was coined by\u00a0<a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.cl.cam.ac.uk\/archive\/rm135\/\">Robin Milner<\/a>\u00a0in his 1978 paper,\u00a0<a href=\"https:\/\/fd.xuwubk.eu.org:443\/https\/courses.engr.illinois.edu\/cs421\/sp2013\/project\/milner-polymorphism.pdf\">A Theory of Type Polymorphism in Programming<\/a>.\u00a0Let&#8217;s deconstruct this phrase and\u00a0define its parts, considering the second part first.<\/p>\n<h3>Going wrong<\/h3>\n<p>Programming languages are defined by their <em>syntax<\/em> &#8212; what programs you&#8217;re allowed to write down\u00a0&#8212;\u00a0and <em>semantics<\/em> &#8212; what those programs\u00a0mean. A problem all languages face is that there are many programs that are syntactically valid but are semantically problematic. A classic English example is Chomsky&#8217;s &#8220;Colorless green ideals sleep furiously&#8221;&#8212;perfectly syntactically correct, but meaningless. A\u00a0example in the OCaml programming language\u00a0is <strong>1 + &#8220;foo&#8221;<\/strong>; according to the language&#8217;s semantics, such a program has no meaning. Another example is <strong>{ char buf[4]; buf[4] = &#8216;x&#8217; }<\/strong> in C: the write to index 4 is outside the declared bounds of the buffer, and the language specification deems this action to be\u00a0undefined, i.e., meaningless. If we were to run such meaningless programs, we could say that they would\u00a0<em>go wrong.<\/em><\/p>\n<h3>Well typed \u27f9 Cannot go wrong<\/h3>\n<p>In a type-safe language, the language&#8217;s <em>type system<\/em> is a particular way of ensuring that\u00a0only the\u00a0&#8220;right&#8221; (non-wrong) programs go through. In particular, we say a program (or program phase) is <em>well typed<\/em> if the type system deems it acceptable, and type safety ensures that well typed programs never go wrong: they will have a (well defined) meaning. The following picture\u00a0visualizes what&#8217;s going on.<\/p>\n<p><a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-content\/uploads\/2014\/08\/typing-venn.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-399 aligncenter\" src=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-content\/uploads\/2014\/08\/typing-venn.jpg\" alt=\"typing-venn\" width=\"224\" height=\"224\" srcset=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-content\/uploads\/2014\/08\/typing-venn.jpg 224w, https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-content\/uploads\/2014\/08\/typing-venn-150x150.jpg 150w\" sizes=\"auto, (max-width: 224px) 100vw, 224px\" \/><\/a><\/p>\n<p>In a type safe language, well typed programs are a subset of the well defined programs, which are themselves a subset of all possible (syntactically valid) programs.<\/p>\n<h2>Which languages are type safe?<\/h2>\n<p>Let&#8217;s now\u00a0consider whether some <a title=\"IEEE posts its top list of languages\" href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/07\/10\/ieee-posts-its-top-list-of-languages\/\">popular languages<\/a>\u00a0are type safe.\u00a0We will see that for different languages, type safety might mean different things.<\/p>\n<p><strong>C and C++: <em>not<\/em> type safe<\/strong>. C&#8217;s standard\u00a0type system does not rule out programs that the standard (and common practice) considers meaningless, e.g., programs that write off the end of a buffer.[ref] C is also not <a title=\"What is memory safety?\" href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/07\/21\/memory-safety\/\">memory safe<\/a>; in effect, the undefined behaviors that memory safety rules out are\u00a0a subset of the undefined behaviors ruled out by type safety.[\/ref] So, for C, well typed programs can go wrong. C++ is (morally) a superset of C, and so it inherits C&#8217;s lack of type safety.<\/p>\n<p><strong>Java, C#:\u00a0type safe<\/strong> (probably). While it is quite difficult to ascertain whether a full-blown language implementation is type safe (e.g., an <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.seas.upenn.edu\/~sweirich\/types\/archive\/1999-2003\/msg00849.html\">early version of Java generics was buggy<\/a>), formalizations of smaller, hopefully-representative languages (like <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/dl.acm.org\/citation.cfm?id=503505\">Featherweight Java<\/a>) are type safe.[ref] While full-scale languages rarely receive the same attention as smaller<em> core calculi<\/em> that represent them, in 1997,\u00a0<a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/mitpress.mit.edu\/books\/definition-standard-ml\">Standard ML (SML) was formally specified<\/a> &#8212; both its semantics and type system &#8212; and proven to be type safe. Later work <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.cs.cmu.edu\/~dklee\/papers\/tslf-popl.pdf\">mechanized the metatheory of SML<\/a>, adding further assurance to this result. This was landmark work to prove that a full-scale language was indeed type safe.[\/ref] Interestingly, type safety hinges on the fact that behaviors that C&#8217;s semantics deem as undefined, these languages give meaning to. Most notably, a program in C that accesses an array out of bounds has no meaning, but in Java and C# it does: this program will throw an <em>ArrayBoundsException<\/em>.<\/p>\n<p><strong>Python, Ruby<\/strong>: <strong>type safe<\/strong> (arguably).\u00a0Python or Ruby are often referred to\u00a0as <em>dynamically typed languages<\/em>, which throw exceptions to signal type errors occurring during execution: Just like\u00a0Java throws an <em>ArrayBoundsException<\/em> on an array overflow at run-time, Ruby will throw an exception if you try to add an integer and a string. In both cases, this behavior is prescribed by the language semantics, and therefore the programs are well defined. In fact, the language semantics gives meaning to all programs, so the <em>well defined<\/em> and <em>all<\/em> circles of our diagram coincide. As such, we can think of these languages as type safe according to the <em>null<\/em> type system,[ref]Sometimes \u00a0languages like Python and Ruby are characterized as\u00a0<em>uni-typed<\/em>, meaning that for the purposes of type checking, all objects in the language have one type that accepts all operations, but these\u00a0operations\u00a0may fail at run-time. <a href=\"https:\/\/fd.xuwubk.eu.org:443\/https\/medium.com\/@samth\/on-typed-untyped-and-uni-typed-languages-8a3b4bedf68c\">Programmers may not think of the languages this way, though<\/a>.[\/ref] which accepts\u00a0all programs, none of which go\u00a0wrong (making all three circles coincide). Hence: type safety.<\/p>\n<p>This conclusion\u00a0might seem strange.\u00a0In Java, if program <strong>o.m()<\/strong> is deemed well typed, then type safety ensures that <strong>o<\/strong> is an object that has a no-argument method <strong>m<\/strong>, and so the call will always succeed. In Ruby, the same program <strong>o.m()<\/strong> is <em>always<\/em> deemed well typed by Ruby&#8217;s\u00a0(null) type system, but when we run it, we have no guarantee that <strong>o<\/strong>\u00a0defines the method <strong>m<\/strong>, and as such either the call will succeed, or it will\u00a0result in an exception.<\/p>\n<p>In short, type safety does not mean one thing. What it ensures depends on the language semantics, which implicitly defines wrong behavior. In Java, calling a nonexistent\u00a0method is wrong. In Ruby, it is not: doing so will simply produce an exception.[ref]You could imagine building an alternative type system to rule out some of Ruby&#8217;s\u00a0run-time errors; indeed that&#8217;s what the <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.cs.umd.edu\/projects\/PL\/druby\/\">Diamondback Ruby<\/a> project tries to do.[\/ref]<\/p>\n<h2>Beyond the Basics<\/h2>\n<p>Generic type safety is useful: without it, we have no guarantee that the programs we run are properly defined,\u00a0in which case they could do essentially\u00a0anything. C\/C++&#8217;s\u00a0allowance of undefined behavior is the source of a myriad security exploits, from\u00a0<a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/paulmakowski.wordpress.com\/2011\/01\/25\/smashing-the-stack-in-2011\/\">stack smashing<\/a> to\u00a0<a href=\"https:\/\/fd.xuwubk.eu.org:443\/https\/www.owasp.org\/index.php\/Format_string_attack\">format string attacks<\/a>. Such\u00a0exploits\u00a0are not possible in\u00a0type safe languages.<\/p>\n<p>On the other hand, as our discussion above about Ruby and Java illustrates, not all type systems are created equal: some can ensure properties that\u00a0others cannot. As such, we should\u00a0not just ask whether a language is type safe; we should ask what type safety actually buys you. We&#8217;ll finish out this post with a few examples of what type systems can do, drawing from a rich landscape of ongoing research.<\/p>\n<h3>Narrowing the gap<\/h3>\n<p class=\"p1\">The <em>well typed<\/em> and <em>well defined<\/em> circles in our diagram do not match up; in the gap between them are programs that are well defined but the type system nevertheless rejects. As an example, most type systems will reject the\u00a0following program:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nif (p) x = 5;\r\n  else x = &quot;hello&quot;;\r\nif (p) return x+5;\r\n  else return strlen(x);\r\n<\/pre>\n<p class=\"p1\">This program will always\u00a0return an integer, but the type system may reject it because the variable <strong>x<\/strong> is used as both an <strong>int<\/strong> and a <strong>string<\/strong>. Drawing an analogy\u00a0with\u00a0static analysis, as <a title=\"How did Heartbleed remain undiscovered, and what should we do about it?\" href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/07\/01\/how-did-heartbleed-remain-undiscovered-and-what-should-we-do-about-it\/\">discussed previously in the context of the Heartbleed bug<\/a>, type systems are <em>sound<\/em> but <em>incomplete<\/em>. This incompleteness is a source of frustration for\u00a0programmers, (and <a title=\"Why are some languages adopted and others aren\u2019t?\" href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/07\/09\/why-are-some-languages-adopted-and-others-arent\/\">may be one reason driving them to use dynamic languages like Python and Ruby<\/a>).\u00a0One remedy is to design type systems that narrow the gap, accepting more programs.<\/p>\n<p class=\"p1\">As an\u00a0example if this process in action, Java&#8217;s type system was extended in version 1.5 with the notion of\u00a0<a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/docs.oracle.com\/javase\/tutorial\/java\/generics\/\"><em>generics<\/em><\/a>. Whereas in Java\u00a01.4 you might need\u00a0to use\u00a0a cast to convince the type system to accept a program, in Java 1.5 this cast might\u00a0not be needed. As another example, consider the <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/en.wikipedia.org\/wiki\/Lambda_calculus\">lambda calculus<\/a>, the basis of functional programming languages. The <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/en.wikipedia.org\/wiki\/Simply_typed_lambda_calculus\">simple type system<\/a> for the\u00a0lambda calculus accepts strictly fewer programs than <a href=\"https:\/\/fd.xuwubk.eu.org:443\/https\/courses.engr.illinois.edu\/cs421\/sp2013\/project\/milner-polymorphism.pdf\">Milner&#8217;s polymorphic type system<\/a>, which accepts fewer programs than a type system that\u00a0supports <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.haskell.org\/haskellwiki\/Rank-N_types\">Rank-2 (or higher) polymorphism<\/a>. Designing type systems that are expressive (more complete) <em>and<\/em> usable is a rich area of research.<\/p>\n<h3>Enforcing invariants<\/h3>\n<p>Typical languages have types like <strong>int<\/strong> and <strong>string<\/strong>. Type safety will ensure that a program expression that claims to\u00a0be an <strong>int<\/strong> actually is: it will evaluate to -1, 2, 47, etc. at run-time.\u00a0But we don&#8217;t need to stop with <strong>int<\/strong>: A type system can support far richer types and thereby express more interesting properties about program expressions.<\/p>\n<p>For example, there has been much recent interest in the research community in\u00a0<em>refinement types<\/em>, which\u00a0refine\u00a0the set of a type&#8217;s possible values using\u00a0logical\u00a0formulae. The type\u00a0<strong>{v: int | 0\u00a0&lt;= v}<\/strong>\u00a0refines the type <strong>int<\/strong> with formula <strong>0 &lt;= v<\/strong>, and in effect defines the type of\u00a0non-negative integers. Refinement types allow programmers to express data structure invariants\u00a0in the\u00a0types of those data structures, and due to type safety be assured that those invariants will always hold. Refinement type systems have been developed for Haskell and F# (called\u00a0<a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/goto.ucsd.edu\/~rjhala\/liquid\/haskell\/blog\/about\/\">Liquid Haskell<\/a> and <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/research.microsoft.com\/en-us\/projects\/f7\/\">F7,<\/a>\u00a0respectively), among other languages.<\/p>\n<p>As another example, we can use a\u00a0type system\u00a0to ensure <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/blog.regehr.org\/archives\/490\">data race<\/a> freedom by enforcing\u00a0the invariant that a shared variable is only ever accessed by a thread that holds the lock that guards that variable. The type of a shared variable describes the locks that protect it. <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/users.soe.ucsc.edu\/~cormac\/papers\/esop99.pdf\">Types for safe locking<\/a>\u00a0was first proposed by Abadi and Flanagan, and <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/dl.acm.org\/citation.cfm?id=1119480\">implementations have been developed for Java<\/a>\u00a0and C (<a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.cs.umd.edu\/projects\/PL\/locksmith\/\">Locksmith<\/a>).<\/p>\n<p>There are many other examples, with type systems designed to <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.cs.umd.edu\/~jfoster\/cqual\/\">restrict the use of tainted data<\/a>, to <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.cs.cornell.edu\/jif\/\">prevent the release of private information<\/a>, to ensure <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.cs.cmu.edu\/~.\/aldrich\/plaid\/\">object usage follows a strict protocol called <em>type state<\/em><\/a> (e.g., so that an object is not used after it is freed), and more.<\/p>\n<h3>Type abstraction and information hiding<\/h3>\n<p>Many programming languages aim to allow programmers to enforce <em>data abstraction <\/em>(sometimes called\u00a0<em>information hiding<\/em>).\u00a0These languages permit writing\u00a0abstractions, like classes or modules or functions, that keep their internals hidden from the client code that uses them. Doing so leads to more robust and maintainable programs, because the internals can be changed without affecting the client code.<\/p>\n<p>Type systems can play a crucial role in enforcing abstraction. For example, with the aid of a well designed type system, we can prove <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/dl.acm.org\/citation.cfm?id=512669\">representation independence<\/a>, which says that programs only depend on the behavior of an abstraction, not on the way it is implemented. Type-enforced\u00a0abstraction can also be an enabler of\u00a0<a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/homepages.inf.ed.ac.uk\/wadler\/papers\/free\/free.ps\">free theorems<\/a>, as Wadler elegantly showed. The late\u00a0<a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.cs.cmu.edu\/~jcr\/\">John Reynolds<\/a>\u00a0did groundbreaking work on types and abstraction, most notably described in his 1983 paper, <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.cse.chalmers.se\/edu\/year\/2010\/course\/DAT140_Types\/Reynolds_typesabpara.pdf\">Types, Abstraction, and Parametric Polymorphism<\/a>. In this paper he famously\u00a0states\u00a0&#8220;<em>type structure is a syntactic discipline for maintaining\u00a0levels of\u00a0abstraction,<\/em>&#8221; positing\u00a0that types have\u00a0a <em>fundamental<\/em> role in building maintainable systems.<\/p>\n<h2>Parting thought<\/h2>\n<p>Type safety is an important property. At the least, a type safe language guarantees its programs are well defined. This guarantee is\u00a0necessary for reasoning about what programs might do, which is particularly important when security is a concern. But type systems can do more, forming a foundation for reasoning about programs, ensuring that they enforce invariants, and maintain abstractions. As software is becoming ever more pervasive and more complicated, type systems are\u00a0an important tool for ensuring the systems we rely on are trustworthy and secure.<\/p>\n<p>If you are interested in learning more about type systems, I&#8217;d recommend starting with <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.cis.upenn.edu\/~bcpierce\/\">Benjamin Pierce<\/a>&#8216;s books, <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.cis.upenn.edu\/~bcpierce\/tapl\/\">Types and Programming Languages<\/a>, and <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.cis.upenn.edu\/~bcpierce\/attapl\/\">Advanced Topics in Types and Programming Languages<\/a>.<\/p>\n<p>Thanks to <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.cs.umd.edu\/~hammer\/\">Matthew Hammer<\/a>, <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.cs.umd.edu\/~jfoster\/\">Jeff Foster<\/a>, and <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.cs.umd.edu\/~dvanhorn\/\">David Van Horn<\/a> for comments and suggestions on drafts of this post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In response to my previous post defining memory safety\u00a0(for C), one commenter suggested it would be nice to have a post explaining type safety. Type safety is pretty well understood, but it&#8217;s still not something you can easily pin down. &hellip; <a href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/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_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[32,19,26,3,31],"tags":[],"class_list":["post-395","post","type-post","status-publish","format-standard","hentry","category-dynamic-languages","category-pl-in-practice","category-semantics","category-softsec","category-types"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/fd.xuwubk.eu.org:443\/https\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What is type safety? - The PL Enthusiast<\/title>\n<meta name=\"description\" content=\"Type safety is the property of a programming language, ensuring its programs are well defined and creating a foundation for reasoning.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is type safety? - The PL Enthusiast\" \/>\n<meta property=\"og:description\" content=\"Type safety is the property of a programming language, ensuring its programs are well defined and creating a foundation for reasoning.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/\" \/>\n<meta property=\"og:site_name\" content=\"The Programming Languages Enthusiast\" \/>\n<meta property=\"article:published_time\" content=\"2014-08-05T12:15:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-08-05T13:55:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-content\/uploads\/2014\/08\/typing-venn.jpg\" \/>\n<meta name=\"author\" content=\"Michael Hicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Michael Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/2014\\\/08\\\/05\\\/type-safety\\\/#article\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/2014\\\/08\\\/05\\\/type-safety\\\/\"},\"author\":{\"name\":\"Michael Hicks\",\"@id\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/#\\\/schema\\\/person\\\/7d875a015cb2e83e9cd476df91028d5d\"},\"headline\":\"What is type safety?\",\"datePublished\":\"2014-08-05T12:15:41+00:00\",\"dateModified\":\"2014-08-05T13:55:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/2014\\\/08\\\/05\\\/type-safety\\\/\"},\"wordCount\":2026,\"commentCount\":40,\"image\":{\"@id\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/2014\\\/08\\\/05\\\/type-safety\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/wp-content\\\/uploads\\\/2014\\\/08\\\/typing-venn.jpg\",\"articleSection\":[\"Dynamic languages\",\"PL in practice\",\"Semantics\",\"Software Security\",\"Types\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\\\/\\\/www.pl-enthusiast.net\\\/2014\\\/08\\\/05\\\/type-safety\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/2014\\\/08\\\/05\\\/type-safety\\\/\",\"url\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/2014\\\/08\\\/05\\\/type-safety\\\/\",\"name\":\"What is type safety? - The PL Enthusiast\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/2014\\\/08\\\/05\\\/type-safety\\\/#primaryimage\"},\"image\":{\"@id\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/2014\\\/08\\\/05\\\/type-safety\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/wp-content\\\/uploads\\\/2014\\\/08\\\/typing-venn.jpg\",\"datePublished\":\"2014-08-05T12:15:41+00:00\",\"dateModified\":\"2014-08-05T13:55:54+00:00\",\"author\":{\"@id\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/#\\\/schema\\\/person\\\/7d875a015cb2e83e9cd476df91028d5d\"},\"description\":\"Type safety is the property of a programming language, ensuring its programs are well defined and creating a foundation for reasoning.\",\"breadcrumb\":{\"@id\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/2014\\\/08\\\/05\\\/type-safety\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\\\/\\\/www.pl-enthusiast.net\\\/2014\\\/08\\\/05\\\/type-safety\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/2014\\\/08\\\/05\\\/type-safety\\\/#primaryimage\",\"url\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/wp-content\\\/uploads\\\/2014\\\/08\\\/typing-venn.jpg\",\"contentUrl\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/wp-content\\\/uploads\\\/2014\\\/08\\\/typing-venn.jpg\",\"width\":224,\"height\":224},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/2014\\\/08\\\/05\\\/type-safety\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What is type safety?\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/#website\",\"url\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/\",\"name\":\"The Programming Languages Enthusiast\",\"description\":\"Developments in PL, and why they matter\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/#\\\/schema\\\/person\\\/7d875a015cb2e83e9cd476df91028d5d\",\"name\":\"Michael Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dd0371ad9a0cb821df683b5d6a6cccc911e6e2af1778f28b77e8c90b0c319d14?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dd0371ad9a0cb821df683b5d6a6cccc911e6e2af1778f28b77e8c90b0c319d14?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dd0371ad9a0cb821df683b5d6a6cccc911e6e2af1778f28b77e8c90b0c319d14?s=96&d=mm&r=g\",\"caption\":\"Michael Hicks\"},\"sameAs\":[\"http:\\\/\\\/www.cs.umd.edu\\\/~mwh\\\/\"],\"url\":\"http:\\\/\\\/www.pl-enthusiast.net\\\/author\\\/mwh\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is type safety? - The PL Enthusiast","description":"Type safety is the property of a programming language, ensuring its programs are well defined and creating a foundation for reasoning.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/","og_locale":"en_US","og_type":"article","og_title":"What is type safety? - The PL Enthusiast","og_description":"Type safety is the property of a programming language, ensuring its programs are well defined and creating a foundation for reasoning.","og_url":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/","og_site_name":"The Programming Languages Enthusiast","article_published_time":"2014-08-05T12:15:41+00:00","article_modified_time":"2014-08-05T13:55:54+00:00","og_image":[{"url":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-content\/uploads\/2014\/08\/typing-venn.jpg","type":"","width":"","height":""}],"author":"Michael Hicks","twitter_misc":{"Written by":"Michael Hicks","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/fd.xuwubk.eu.org:443\/https\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/#article","isPartOf":{"@id":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/"},"author":{"name":"Michael Hicks","@id":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/#\/schema\/person\/7d875a015cb2e83e9cd476df91028d5d"},"headline":"What is type safety?","datePublished":"2014-08-05T12:15:41+00:00","dateModified":"2014-08-05T13:55:54+00:00","mainEntityOfPage":{"@id":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/"},"wordCount":2026,"commentCount":40,"image":{"@id":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/#primaryimage"},"thumbnailUrl":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-content\/uploads\/2014\/08\/typing-venn.jpg","articleSection":["Dynamic languages","PL in practice","Semantics","Software Security","Types"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/","url":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/","name":"What is type safety? - The PL Enthusiast","isPartOf":{"@id":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/#primaryimage"},"image":{"@id":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/#primaryimage"},"thumbnailUrl":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-content\/uploads\/2014\/08\/typing-venn.jpg","datePublished":"2014-08-05T12:15:41+00:00","dateModified":"2014-08-05T13:55:54+00:00","author":{"@id":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/#\/schema\/person\/7d875a015cb2e83e9cd476df91028d5d"},"description":"Type safety is the property of a programming language, ensuring its programs are well defined and creating a foundation for reasoning.","breadcrumb":{"@id":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/#primaryimage","url":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-content\/uploads\/2014\/08\/typing-venn.jpg","contentUrl":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-content\/uploads\/2014\/08\/typing-venn.jpg","width":224,"height":224},{"@type":"BreadcrumbList","@id":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/2014\/08\/05\/type-safety\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/"},{"@type":"ListItem","position":2,"name":"What is type safety?"}]},{"@type":"WebSite","@id":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/#website","url":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/","name":"The Programming Languages Enthusiast","description":"Developments in PL, and why they matter","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/#\/schema\/person\/7d875a015cb2e83e9cd476df91028d5d","name":"Michael Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fd.xuwubk.eu.org:443\/https\/secure.gravatar.com\/avatar\/dd0371ad9a0cb821df683b5d6a6cccc911e6e2af1778f28b77e8c90b0c319d14?s=96&d=mm&r=g","url":"https:\/\/fd.xuwubk.eu.org:443\/https\/secure.gravatar.com\/avatar\/dd0371ad9a0cb821df683b5d6a6cccc911e6e2af1778f28b77e8c90b0c319d14?s=96&d=mm&r=g","contentUrl":"https:\/\/fd.xuwubk.eu.org:443\/https\/secure.gravatar.com\/avatar\/dd0371ad9a0cb821df683b5d6a6cccc911e6e2af1778f28b77e8c90b0c319d14?s=96&d=mm&r=g","caption":"Michael Hicks"},"sameAs":["https:\/\/fd.xuwubk.eu.org:443\/http\/www.cs.umd.edu\/~mwh\/"],"url":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/author\/mwh\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-json\/wp\/v2\/posts\/395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-json\/wp\/v2\/comments?post=395"}],"version-history":[{"count":10,"href":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-json\/wp\/v2\/posts\/395\/revisions"}],"predecessor-version":[{"id":430,"href":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-json\/wp\/v2\/posts\/395\/revisions\/430"}],"wp:attachment":[{"href":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-json\/wp\/v2\/media?parent=395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-json\/wp\/v2\/categories?post=395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fd.xuwubk.eu.org:443\/http\/www.pl-enthusiast.net\/wp-json\/wp\/v2\/tags?post=395"}],"curies":[{"name":"wp","href":"https:\/\/fd.xuwubk.eu.org:443\/https\/api.w.org\/{rel}","templated":true}]}}