{"id":682,"date":"2014-11-19T03:51:09","date_gmt":"2014-11-19T08:51:09","guid":{"rendered":"http:\/\/www.rfdm.com\/blog\/?p=682"},"modified":"2014-11-20T00:51:53","modified_gmt":"2014-11-20T05:51:53","slug":"dont-do-this-to-your-software-team-example-3","status":"publish","type":"post","link":"https:\/\/www.rfdm.com\/blog\/?p=682","title":{"rendered":"Don&#8217;t do this to your software team, example 3"},"content":{"rendered":"<p>This post could easily be titled, &#8220;Don&#8217;t Party Like It&#8217;s 1998&#8221;.  Even better, &#8220;Don&#8217;t Party Like It&#8217;s 2010&#8221;.<\/p>\n<p>I have been working on embedded software for a number of years now. First as a hobby while my &#8220;day job&#8221; was decidedly not embedded (UNIX system software, large distributed systems, etc.).  Then as my day job, specifically in embedded automotive software.<\/p>\n<p>One of the problematic symptoms in automotive software is its use of the C language.  This isn&#8217;t a C language issue: C is frequently the right tool for the job at hand in this space.  The issue is that a great deal of C code I&#8217;ve seen in automotive for embedded targets is pre-1999 C.  Completely absent of any of the useful features found in the 1999 C standard (ISO\/IEC 9899:1999), which is going on 16 years of age.  Nevermind the 2011 C standard (ISO\/IEC 9899:2011).  For what I&#8217;d call &#8220;No good reason.&#8221;<\/p>\n<p>Many of the automotive embedded developers I&#8217;ve worked with in the past 8 years would not fare well on a test of their knowledge of ISO\/IEC 9899:1999 (C99).  This is a sad state of affairs, given that many of the features of C99 are just as useful (if not more so) in embedded development as they are anywhere else.<\/p>\n<p>I say there&#8217;s no good reason because the toolchains were updated more than a decade ago.  The &#8220;My toolchain doesn&#8217;t support C99&#8221; excuse lost its validity more than 10 years ago.  Perhaps more cocerning to me is the fact that some of the developers who aren&#8217;t knowledgeable of C99 weren&#8217;t even in the profession in 1999.  In fact some of them were not far out of preschool.  This saddens me because these young engineers are our future and their industry appears to be content with stunted skill set development of their software engineers.  It also points to an education issue.  If a developer knew nothing about C until after 1999, why is it that they were taught a version of C that predates C99 by roughly 10 years (and in many cases, predates their birth)?<\/p>\n<p>If you write code in C, in any industry, please don&#8217;t write your code is if it&#8217;s 1998.  As I write this, it&#8217;s the end of 2014.  Use C99 to your advantage!<\/p>\n<p>And question industry initiatives that look backward as much as they look forward.  A case in point: why are so many that are involved with Autosar still oblivious to &lt;stdint.h&gt;\/&lt;inttypes.h&gt;?  &lt;stdbool.h&gt;?  Autosar was founded 4 years after C99 was ratified, and any toolchain worth using already had full C99 support.  I&#8217;m using this example because at more than one place of employment, I&#8217;ve found every compiler in our toolchain to be fully C99 compliant (including optional features like extended integer types) yet found most (if not all) current projects with their own hand-coded &#8220;Platform_Types.h&#8221;, &#8220;Std_Types.h&#8221;, etc. with no sign of &lt;stdint.h&gt;\/&lt;inttypes.h&gt;.  If the objective here is job security (someone has to review and potentially tweak the hand-coded header files to port code from one architecture to another), I wish them luck.  If they ever want to pursue a career outside of automotive, they&#8217;ll be lacking in the knowledge needed to be successful in the language they think they&#8217;ve mastered. \ud83d\ude41<\/p>\n<p>Before someone sends me a defensive email: I believe Autosar is a good thing.  I believe in standardized interfaces, and have leveraged them to my advantage for my entire career.  And there are some Autosar vendors that are using C99 wherever they can.  But when you find a wart, don&#8217;t just blindly embrace it.  Find a better way.  Don&#8217;t create work for yourself; seek to eliminate it.  It&#8217;s the nature of any good software developer to make the next project easier.  Reviewing and possibly tweaking header files every time you need to port code to a different microcontroller isn&#8217;t a good use of your time nor the company&#8217;s money.  Use &lt;inttypes.h&gt;\/&lt;stdint.h&gt; in your application code.  Why?  Because it&#8217;ll work unchanged on every C99 compiler for every target.  Including your PC for unit testing, simulation, etc.  You still need Platform_Types.h for your Autosar modules, but please don&#8217;t do this kind thing that will have to be reviewed and possibly tweaked for every porting effort:<\/p>\n<p><a href=\"https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/Platform_Types_wrong.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/Platform_Types_wrong.png\" alt=\"Platform_Types_wrong\" width=\"278\" height=\"120\" class=\"alignnone size-full wp-image-686\" \/><\/a><\/p>\n<p>When you can do this ONCE and be guaranteed it will work for every single target (and has for the last 15+ years), saving future work:<\/p>\n<p><a href=\"https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/Platform_Types_right.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/Platform_Types_right.png\" alt=\"Platform_Types_right\" width=\"227\" height=\"152\" class=\"alignnone size-full wp-image-687\" \/><\/a><\/p>\n<p>In our own code base, which includes a fair amount of &#8220;carry-over&#8221; code from previous projects, there are some projects with literally 4 different typedefs equivalent to uint32_t.  And the same for all other fixed-width integer types.  More work every time someone wants to &#8220;carry over&#8221; any of that code to a new platform and finds it doesn&#8217;t work.<\/p>\n<p>I continue to hear developers in my industry refer to <code>\/\/<\/code>style comments as &#8220;C++&#8221; comments, and to insist that they not be used.  To be blunt: get with the game.  Those aren&#8217;t &#8220;C++&#8221; comments.  Those are C comments and have been for more than 15 years.    And they exist for good reason; they harbor a smaller set of the dangers of <code>\/* ... *\/<\/code> comments and involve less typing for a large class of comments (single-liners).<\/p>\n<p>Then there&#8217;s &lt;stdbool.h&gt;.  Use it.  A while back I ran across some old code in our project that was carried over from another project, that disturbed me (NOTE: I&#8217;m easily disturbed by such things).  It looked something like this:<\/p>\n<p><a href=\"https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/BadUseOf_TRUE_FALSE.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/BadUseOf_TRUE_FALSE.png\" alt=\"BadUseOf_TRUE_FALSE\" width=\"246\" height=\"280\" class=\"alignnone size-full wp-image-688\" \/><\/a><\/p>\n<p>I have to wonder how many decent C programmers literally weep when they see this kind of thing in their project, knowing that it hints at problems in the callers.  Even for pre-1999 C, this breaks the spirit of boolean.  If you need a uint8_t, by all means use it.  But in this particular case, the right solution was simply:<\/p>\n<p><a href=\"https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/Fix-BadUseOf_TRUEFALSE.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/Fix-BadUseOf_TRUEFALSE.png\" alt=\"Fix BadUseOf_TRUEFALSE\" width=\"192\" height=\"224\" class=\"alignnone size-full wp-image-691\" \/><\/a><\/p>\n<p>If you&#8217;re a C programmer, don&#8217;t party like it&#8217;s 1998.  Party like it&#8217;s at least 2000.  Even better, like it&#8217;s at least 2011 (the year of <code>_Noreturn<\/code>, etc.).  Get more work done is less time, and consider improvement a life-long process.  If the code you write today isn&#8217;t significantly better (tighter, easier to read, more readily tested and proven, more reusable, etc.) than the code you wrote two years ago, something is seriously wrong.  Regardless of your processes, writing good software is a craft.  If you aren&#8217;t seeing continuous improvement throughout your career, you&#8217;re in a rut that you need to find a way to leave.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post could easily be titled, &#8220;Don&#8217;t Party Like It&#8217;s 1998&#8221;. Even better, &#8220;Don&#8217;t Party Like It&#8217;s 2010&#8221;. I have been working on embedded software for a number of years now. First as a hobby while my &#8220;day job&#8221; was decidedly not embedded (UNIX system software, large distributed systems, etc.). Then as my day job, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.rfdm.com\/blog\/?p=682\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Don&#8217;t do this to your software team, example 3&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-682","post","type-post","status-publish","format-standard","hentry","category-software-development"],"_links":{"self":[{"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=682"}],"version-history":[{"count":22,"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/682\/revisions"}],"predecessor-version":[{"id":710,"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/682\/revisions\/710"}],"wp:attachment":[{"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}