{"id":349,"date":"2010-04-30T06:58:52","date_gmt":"2010-04-30T13:58:52","guid":{"rendered":"http:\/\/www.airs.com\/blog\/?p=349"},"modified":"2010-04-30T06:58:52","modified_gmt":"2010-04-30T13:58:52","slug":"container-models","status":"publish","type":"post","link":"https:\/\/www.airs.com\/blog\/archives\/349","title":{"rendered":"Container Models"},"content":{"rendered":"<p>A long time ago a friend of mine pointed out a sign of trouble in any program: defining a new container model.  If you are working in a language that provides containers in the standard library, then use them.  If you need a container with specific behaviour, then make it look like the standard containers.  If you come across a program which introduces a new model, beware.<\/p>\n<p>I&#8217;ve recently been adding Go support to SWIG.  SWIG can be used to build interfaces between various different languages and C++.  SWIG is a nice program in many ways: it provides a lot of power and flexibility in defining the interface.  Internally, though, big chunks are written in C++ but it uses a totally different container model.  I assume this is for historical reasons dating back to a beginning in C or possibly even Python.  In C++, though, it&#8217;s a mess.  There is no type checking: it&#8217;s all <code>void *<\/code> pointers.  Practically every type (strings, lists, hash tables) converts to everything else implicitly.  It brings all the weaknesses of a pure dynamically typed language into C++, without providing any of the benefits.<\/p>\n<p>Sometimes one encounters a programmer who carries a container model from program to program, rewriting it into different languages as needed.  The result is a program written for one person.  Don&#8217;t do that.  Use a language in the idioms of the language; don&#8217;t try to make it look like a different language.  Use the containers which the language provides.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A long time ago a friend of mine pointed out a sign of trouble in any program: defining a new container model. If you are working in a language that provides containers in the standard library, then use them. If you need a container with specific behaviour, then make it look like the standard containers. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-349","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.airs.com\/blog\/wp-json\/wp\/v2\/posts\/349","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.airs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.airs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.airs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.airs.com\/blog\/wp-json\/wp\/v2\/comments?post=349"}],"version-history":[{"count":1,"href":"https:\/\/www.airs.com\/blog\/wp-json\/wp\/v2\/posts\/349\/revisions"}],"predecessor-version":[{"id":350,"href":"https:\/\/www.airs.com\/blog\/wp-json\/wp\/v2\/posts\/349\/revisions\/350"}],"wp:attachment":[{"href":"https:\/\/www.airs.com\/blog\/wp-json\/wp\/v2\/media?parent=349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.airs.com\/blog\/wp-json\/wp\/v2\/categories?post=349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.airs.com\/blog\/wp-json\/wp\/v2\/tags?post=349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}