{
  "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/2013/10/29/programming-in-life-sciences-8-coding.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/ckryb-b4v19",
      "url": "https://chem-bla-ics.linkedchemistry.info/2013/10/29/programming-in-life-sciences-8-coding.html",
      "title": "Programming in the Life Sciences #8: coding standards",
      "content_html": "<p>Never underestimate the power of lack of coding standards in code obfuscation. Just try randomly to\nread code you wrote a year ago or four years ago. You’ll be surprised with what you find. Coding\nstandards are like the grammar in writing: they ensure that our message gets understood. Of course,\nthe primary goal is that the CPU understands what you mean, but because programming languages are\nnot your native language, you may not always say what you think you are saying.</p>\n\n<h2 id=\"copyright-and-licensing\">Copyright and Licensing</h2>\n\n<p>First standard is attribution: if you use the solution of someone else, you write in your source\ncode whom wrote the solution. Secondly, you must allow others to do the same. Therefore, you always\nadd your name (and normally email address) to your source code, and under what conditions people\nmay use your code. This is commonly done by assigning a license. Open Source licenses promote\n(scientific) collaboration, and give others the rights to use your solution, redistribution\nmodifications, etc. They may explicitly require attributions, but often not. In a scholarly setting,\nyou always give attribution, even if not required by the license. Remember, that software falls\nunder copyright but algorithms typically not. Copyright/author and license information is typically\nadded to source code using a <a href=\"http://chem-bla-ics.blogspot.nl/2009/06/making-patches-attribution-copyright.html\">header</a>.</p>\n\n<h2 id=\"documentation\">Documentation</h2>\n\n<p>The second thing is to document what your code is supposed to do, what assumptions are made,\nhow people should use it, and preferably under what conditions it will fail. Comments in your\nsource are just as much documentation as a tutorial in Word format. They are complementary, and\ndocumentation must not only be targeted at users, but also at yourself so that you understand\nwhy you added that weird check. You will not (have to) remember in two years.</p>\n\n<h2 id=\"coding-standards\">Coding standards</h2>\n\n<p>Just like English has coding standards, programming language have too. Both also have styles,\nand a selection of a style is up to the author, but consistency is important. What coding\nstandards should you be thinking about, include consistent use of variable and method names,\nkeeping code blocks small, etc. For example, compare the following two code examples which do\nthe same thing:</p>\n\n<div class=\"language-javascript highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"kd\">var</span> <span class=\"nx\">method</span> <span class=\"o\">=</span> <span class=\"kd\">function</span><span class=\"p\">(</span><span class=\"nx\">string</span><span class=\"p\">)</span> <span class=\"p\">{</span>\n  <span class=\"nx\">number</span> <span class=\"o\">=</span> <span class=\"mi\">0</span>\n  <span class=\"k\">for </span><span class=\"p\">(</span><span class=\"kd\">var</span> <span class=\"nx\">i</span><span class=\"o\">=</span><span class=\"mi\">0</span><span class=\"p\">;</span> <span class=\"nx\">i</span><span class=\"o\">&lt;</span><span class=\"nx\">string</span><span class=\"p\">.</span><span class=\"nx\">length</span><span class=\"p\">;</span> <span class=\"nx\">i</span><span class=\"o\">++</span><span class=\"p\">)</span> <span class=\"p\">{</span>\n    <span class=\"k\">if </span><span class=\"p\">(</span><span class=\"nx\">string</span><span class=\"p\">[</span><span class=\"nx\">i</span><span class=\"p\">]</span> <span class=\"o\">==</span> <span class=\"dl\">\"</span><span class=\"s2\">A</span><span class=\"dl\">\"</span><span class=\"p\">)</span> <span class=\"nx\">number</span> <span class=\"o\">=</span> <span class=\"nx\">number</span> <span class=\"o\">+</span><span class=\"mi\">1</span> \n  <span class=\"p\">}</span>\n  <span class=\"k\">return</span> <span class=\"nx\">number</span>\n<span class=\"p\">}</span>\n</code></pre></div></div>\n\n<p>And this version:</p>\n\n<div class=\"language-javascript highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"kd\">var</span> <span class=\"nx\">countTheANucleotides</span> <span class=\"o\">=</span> <span class=\"kd\">function</span><span class=\"p\">(</span><span class=\"nx\">dnaSequence</span><span class=\"p\">)</span> <span class=\"p\">{</span>\n  <span class=\"nx\">count</span> <span class=\"o\">=</span> <span class=\"mi\">0</span>\n  <span class=\"c1\">// iterate over all nucleotides in the DNA string</span>\n  <span class=\"k\">for </span><span class=\"p\">(</span><span class=\"kd\">var</span> <span class=\"nx\">i</span><span class=\"o\">=</span><span class=\"mi\">0</span><span class=\"p\">;</span> <span class=\"nx\">i</span><span class=\"o\">&lt;</span><span class=\"nx\">dnaSequence</span><span class=\"p\">.</span><span class=\"nx\">length</span><span class=\"p\">;</span> <span class=\"nx\">i</span><span class=\"o\">++</span><span class=\"p\">)</span> <span class=\"p\">{</span>\n    <span class=\"k\">if </span><span class=\"p\">(</span><span class=\"nx\">dnaSequence</span><span class=\"p\">[</span><span class=\"nx\">i</span><span class=\"p\">]</span> <span class=\"o\">==</span> <span class=\"dl\">\"</span><span class=\"s2\">A</span><span class=\"dl\">\"</span><span class=\"p\">)</span> <span class=\"nx\">count</span> <span class=\"o\">=</span> <span class=\"nx\">count</span> <span class=\"o\">+</span><span class=\"mi\">1</span> \n  <span class=\"p\">}</span>\n  <span class=\"k\">return</span> <span class=\"nx\">count</span>\n<span class=\"p\">}</span>\n</code></pre></div></div>\n\n<p>Which one do you find easier to understand the function of?</p>\n\n<ol>\n  <li>use clear, descriptive variable and method names</li>\n  <li>use source code comments to describe the intention of source code</li>\n  <li>keep source code lines short enough that you can read the full line without (horizontal) scrolling</li>\n  <li>keep code blocks short enough that the fit a single screen (say, 25 lines max)</li>\n</ol>\n\n<h2 id=\"unit-testing\">Unit testing</h2>\n\n<p>It is important to realize that what you intend to have the computer to calculate is\nsomething different that what your source code actually tells the computer to do. Even\nmore important is to realize that it is not always your fault if the calculation goes\nwrong; in particular, the input you pass to some program can always be crafted such,\nthat it will fool your code in doing unintended things.</p>\n\n<p>But, a common cause of misbehaving code is the author itself. At first (and many, many\ntimes after that) it’s just getting the code to compile: missing semi-colons, typos in\nvariable names, etc, etc. After a bit, and hunting you down to your grave, are bugs\ncaused by unintuitive features of programming language, libraries you’re using, etc.\nCommon (and often expensive) mistakes include for-loops missing the first or the last\nelement, incorrect conversion of units (<a href=\"https://en.wikipedia.org/wiki/Mars_Climate_Orbiter\">125 M$ expensive!</a>),\netc.</p>\n\n<p>Fortunately, we can call in the help of computers for this too. We have code checking\ntools, and importantly, libraries to help us define (unit) tests. These tests call\nrunning code, and check if the calculated results are matching our expectation. For\nexample, for JavaScript we could use the <a href=\"https://github.com/jquery/qunit/blob/master/MIT-LICENSE.txt\">MIT-licensed</a>\nqunit. For example, we could write the following tests (in qunit):</p>\n\n<div class=\"language-javascript highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nf\">test</span><span class=\"p\">(</span> <span class=\"dl\">\"</span><span class=\"s2\">counting tests</span><span class=\"dl\">\"</span><span class=\"p\">,</span> <span class=\"kd\">function</span><span class=\"p\">()</span> <span class=\"p\">{</span>\n  <span class=\"nf\">equal</span><span class=\"p\">(</span><span class=\"mi\">1</span><span class=\"p\">,</span> <span class=\"nf\">countTheANucleotides</span><span class=\"p\">(</span><span class=\"dl\">\"</span><span class=\"s2\">AGCT</span><span class=\"dl\">\"</span><span class=\"p\">));</span>\n  <span class=\"nf\">equal</span><span class=\"p\">(</span><span class=\"mi\">4</span><span class=\"p\">,</span> <span class=\"nf\">countTheANucleotides</span><span class=\"p\">(</span><span class=\"dl\">\"</span><span class=\"s2\">AAAA</span><span class=\"dl\">\"</span><span class=\"p\">));</span>\n  <span class=\"nf\">equal</span><span class=\"p\">(</span><span class=\"mi\">0</span><span class=\"p\">,</span> <span class=\"nf\">countTheANucleotides</span><span class=\"p\">(</span><span class=\"dl\">\"</span><span class=\"s2\">GCGC</span><span class=\"dl\">\"</span><span class=\"p\">));</span>\n<span class=\"p\">});</span>\n</code></pre></div></div>\n\n<p>OK, you get the idea. That other scientists really start to care about these things,\nis shown by these two recent papers:</p>\n\n<ul>\n  <li><a href=\"http://dx.doi.org/10.1371/journal.pcbi.1002802\">Ten simple rules for the open development of scientific software</a></li>\n  <li><a href=\"http://dx.doi.org/10.1371/journal.pcbi.1003285\">Ten simple rules for reproducible computational research</a></li>\n</ul>\n\n<h4>References</h4>\n<div class=\"csl-bib-body\">\n    <div class=\"csl-entry\">Prlić, A., &#38; Procter, J. B. (2012). Ten Simple Rules for the Open Development of Scientific Software. <i>PLoS Computational Biology</i>, <i>8</i>(12), e1002802. https://doi.org/10.1371/journal.pcbi.1002802 <a href=\"https://doi.org/10.1371/journal.pcbi.1002802\">CrossRef</a> <a href=\"https://qlever.scholia.wiki/doi/10.1371/journal.pcbi.1002802\">Scholia</a></div>\n    <div class=\"csl-entry\">Sandve, G. K., Nekrutenko, A., Taylor, J., &#38; Hovig, E. (2013). Ten Simple Rules for Reproducible Computational Research. <i>PLoS Computational Biology</i>, <i>9</i>(10), e1003285. https://doi.org/10.1371/journal.pcbi.1003285 <a href=\"https://doi.org/10.1371/journal.pcbi.1003285\">CrossRef</a> <a href=\"https://qlever.scholia.wiki/doi/10.1371/journal.pcbi.1003285\">Scholia</a></div>\n  </div>",
      "summary": "Never underestimate the power of lack of coding standards in code obfuscation. Just try randomly to read code you wrote a year ago or four years ago. You’ll be surprised with what you find. Coding standards are like the grammar in writing: they ensure that our message gets understood. Of course, the primary goal is that the CPU understands what you mean, but because programming languages are not your native language, you may not always say what you think you are saying.",
      
      "date_published": "2013-10-29T00:00:00+00:00",
      "date_modified": "2025-02-16T00:00:00+00:00",
      "tags": ["pra3006"],
      "_references": [
        
          
          
            { "url": "https://doi.org/10.1371/journal.pcbi.1002802", "doi": "10.1371/journal.pcbi.1002802"
             }
            ,
          
        
          
          
            { "url": "https://doi.org/10.1371/journal.pcbi.1003285", "doi": "10.1371/journal.pcbi.1003285"
             }
            
          
        ],
      
      
      
      
      
      
        "authors": [ { "name": "Egon Willighagen", "url": "https://orcid.org/0000-0001-7542-0286" } ]
      
    }

  ]
}
