{
  "version": "https://jsonfeed.org/version/1.1",
  "title": "chem-bla-ics",
  "description": "Chemblaics (pronounced chem-bla-ics) is the science that uses open science and computers to solve problems in chemistry, biochemistry and related fields.",
  "home_page_url": "https://chem-bla-ics.linkedchemistry.info/",
  "feed_url": "https://chem-bla-ics.linkedchemistry.info/2009/09/09/art-of-programming-do-not-leak.json",
  "icon": "https://chem-bla-ics.linkedchemistry.info/assets/images/chem-bla-ics_logo.png",
  "language": "en",
  "authors": [
    {
      "name": "Egon Willighagen",
      "url": "https://orcid.org/0000-0001-7542-0286",
      "_orcid": "0000-0001-7542-0286"
    }
  ],
  "items": [

    {
      "id": "https://doi.org/10.59350/vkj7r-zc905",
      "url": "https://chem-bla-ics.linkedchemistry.info/2009/09/09/art-of-programming-do-not-leak.html",
      "title": "The Art of Programming: do not leak implementation details",
      "content_html": "<p>At the <a href=\"http://sourceforge.net/apps/mediawiki/cdk/index.php?title=JChemPaintWorkshop2009#Work\">JChemPaint workshop</a> here in Uppsala, where we have\nMark from <a href=\"http://www.steinbeck-molecular.de/steinblog/\">Chris</a>’ group as our guest, we encountered an inconsistency in <a href=\"http://cdk.sf.net/\">CDK</a> 1.2,\nwhere the bond stereochemistry did not yet follow the pattern recently adopted of having Class fields, to allow using <em>null</em> to have the semantics\nof undefined. Previously, the defaults for native values were confounded with set values. For example, the formal charge <em>unset</em> and 0 would be have\na field value <em>int = 0</em>.</p>\n\n<p>So, I am now writing a patch which replaces the use of <em>int</em> in <code class=\"language-plaintext highlighter-rouge\">IBond.getStereo()</code>. But instead of going for <code class=\"language-plaintext highlighter-rouge\">Integer</code>, the patch is actually\ngoing to use a enumeration.</p>\n\n<p>Now, getting the the Art of Programming… while writing patches in the CDK, you run into those lovely bits of code, where intention is mixed with\nimplementation details. They should not, and often do not need to, but they typically do. This is actually one reason why we now have a more strict\npeer-review installed. Below are two nice examples where intention is mixed with implementation detail.</p>\n\n<h3 id=\"example-1\">Example 1</h3>\n\n<div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"kt\">int</span> <span class=\"n\">stereo</span> <span class=\"o\">=</span> <span class=\"n\">container</span><span class=\"o\">.</span><span class=\"na\">getBond</span><span class=\"o\">(</span><span class=\"n\">chiralNeighbours</span><span class=\"o\">.</span><span class=\"na\">get</span><span class=\"o\">(</span><span class=\"n\">i</span><span class=\"o\">),</span> <span class=\"n\">atom</span><span class=\"o\">).</span><span class=\"na\">getStereo</span><span class=\"o\">();</span>\n<span class=\"k\">if</span> <span class=\"o\">(</span><span class=\"n\">stereo</span> <span class=\"o\">==</span> <span class=\"mi\">0</span><span class=\"o\">)</span> <span class=\"o\">{</span>\n  <span class=\"c1\">// do something</span>\n<span class=\"o\">}</span>\n</code></pre></div></div>\n\n<p>This code is bad because we have no clue of what this code is supposed to do. When should the if-clause kick in? Be reminded that the <em>int = 0</em> has\nthe confounded meanings of <em>no stereochemistry</em> and perhaps <em>has stereochemistry, but no one ever bothered telling me</em>. So, which of the two situations\ndoes the if clause apply to. So, my patch can only assume that both were applicable (following the actual implementation), though I don’t think that\nmakes sense on an algorithmic level. Had the author used <code class=\"language-plaintext highlighter-rouge\">CDKConstants.STEREO_BOND_NONE</code> (which is the implementation for <em>int = 0</em> for <em>no stereochemistry</em>,\nthen I had known what the implementation was doing. Instead, the author chose to reuse implementation details: a hardcoded 0.</p>\n\n<h3 id=\"example-2\">Example 2</h3>\n\n<p>There is another instance of this problem. Look at this lovely piece of code:</p>\n\n<div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nc\">IBond</span> <span class=\"n\">bond</span> <span class=\"o\">=</span> <span class=\"n\">molecule</span><span class=\"o\">.</span><span class=\"na\">getBond</span><span class=\"o\">(</span><span class=\"n\">atomA</span><span class=\"o\">,</span> <span class=\"n\">unplacedAtom</span><span class=\"o\">);</span>\n<span class=\"k\">if</span> <span class=\"o\">(</span><span class=\"nc\">Math</span><span class=\"o\">.</span><span class=\"na\">abs</span><span class=\"o\">(</span><span class=\"n\">bond</span><span class=\"o\">.</span><span class=\"na\">getStereo</span><span class=\"o\">())</span> <span class=\"o\">&lt;</span> <span class=\"mi\">2</span>\n    <span class=\"o\">&amp;&amp;</span> <span class=\"nc\">Math</span><span class=\"o\">.</span><span class=\"na\">abs</span><span class=\"o\">(</span><span class=\"n\">bond</span><span class=\"o\">.</span><span class=\"na\">getStereo</span><span class=\"o\">())</span> <span class=\"o\">!=</span> <span class=\"mi\">0</span><span class=\"o\">)</span> <span class=\"o\">{</span>\n<span class=\"o\">}</span>\n</code></pre></div></div>\n\n<p>This example also uses hardcoded value, instead of the matching constants. Remember that <em>int = 0</em> had the meaning of no stereochemistry, so I assume\nthis code is determining is stereochemistry is defined for the bond, making nice use that those situations at some point were coded as non-zero values.\nMoreover, it is only interested in a few stereochemistry definitions, and from the implementation I learn (and that actually makes sense at this\nlocation) that it is only interested in those stereochemistry for which the first bond atom is the stereochemical center. This again is leaking\nimplementation details, instead of using semantically meaningful constants.</p>",
      "summary": "At the JChemPaint workshop here in Uppsala, where we have Mark from Chris’ group as our guest, we encountered an inconsistency in CDK 1.2, where the bond stereochemistry did not yet follow the pattern recently adopted of having Class fields, to allow using null to have the semantics of undefined. Previously, the defaults for native values were confounded with set values. For example, the formal charge unset and 0 would be have a field value int = 0.",
      
      "date_published": "2009-09-09T00:00:00+00:00",
      "date_modified": "2009-09-09T00:00:00+00:00",
      "tags": ["java","cdk","jchempaint"],
      
      
      
      
      
      
        "authors": [ { "name": "Egon Willighagen", "url": "https://orcid.org/0000-0001-7542-0286" } ]
      
    }

  ]
}
