{"id":256,"date":"2014-09-22T07:48:50","date_gmt":"2014-09-22T07:48:50","guid":{"rendered":"http:\/\/localhost:8000\/?p=256"},"modified":"2025-09-07T13:47:03","modified_gmt":"2025-09-07T13:47:03","slug":"bpgb-a-tale-of-two-lengths","status":"publish","type":"post","link":"https:\/\/blog.gwadej.org\/programmer-musings\/2014\/09\/bpgb-a-tale-of-two-lengths\/","title":{"rendered":"BPGB: A Tale of Two Lengths"},"content":{"rendered":"<p>As a first post in the <a href=\"\/programmer_musings\/series_of_posts\/best-practices-gone-bad\/\">Best Practices Gone Bad<\/a> series, I figured I would take an simple example from a previous job.<\/p>\n<h2 class=\"subhead\">An Example<\/h2>\n<p>In that position, there were two <em>best practices<\/em> that intersected to generate unreadable code. The first practice was expressive names. All names of variables, classes, and methods were required to be long enough to be <em>clear<\/em> and <em>readable<\/em>. In any moderately complex system, this will result in pretty long names.<\/p>\n<p>The second practice was to limit all lines to 80 characters. Research into both software and web page design has shown that longer lines are harder to read. Many programmers have settled on 80 characters as the perfect line length, despite the fact that we no longer program on punch cards.<\/p>\n<p>As this was a Java project, method chaining was a pretty common practice. This resulted in code that looks like:<\/p>\n<pre><code>\nSpecialResultClass resultOfInterestingAction\n                   = businessObjectCollection.getItemByIndex(\n                       theIndexOfTheObjectOfInterest\n                     ).performActionReturningInternalObject()\n                     .performInterestingAction();\n<\/code><\/pre>\n<p>Obviously, these are not the actual method and class names, but the length is consistent with actual code. The result is a relatively simple action has extended to five lines of code. This is not in any way clearer than code used shorter names and\/or a slightly longer line length.<\/p>\n<pre><code>\nResult result = businessObjs.get( i ).getFoo().act();\n<\/code><\/pre>\n<p>Obviously, this is only clear if you know what the objects are. But, that observation also applies to the longer case.<\/p>\n<h2 class=\"subhead\">The Intersection of Two Lengths<\/h2>\n<p>So, how did two best practices end up with code that was mostly unreadable? The problem is that the two best practices take opposite approaches to the readability problem. Since there is no <em>one, true solution<\/em> to any problem, a compromise was needed between these two approaches. Unfortunately, the people making the rules refused to compromise. The result was code that was painful to read.<\/p>\n<h2 class=\"subhead\">Conclusion<\/h2>\n<p>This is a really good example of how best practices go bad. The intent was to apply best practices to improve the software. Unfortunately, the people making the rules did not foresee how these practices would interact. The result was that even simple methods became long because almost every statement took up 3-10 lines.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a first post in the Best Practices Gone Bad series, I figured I would take an simple example from a previous job. An Example In that position, there were two best practices that intersected to generate unreadable code. The first practice was expressive names. All names of variables, classes, and methods were required to\u2026 <span class=\"read-more\"><a href=\"https:\/\/blog.gwadej.org\/programmer-musings\/2014\/09\/bpgb-a-tale-of-two-lengths\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[38,52,72,96,247,320,349],"_links":{"self":[{"href":"https:\/\/blog.gwadej.org\/programmer-musings\/wp-json\/wp\/v2\/posts\/256"}],"collection":[{"href":"https:\/\/blog.gwadej.org\/programmer-musings\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gwadej.org\/programmer-musings\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gwadej.org\/programmer-musings\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gwadej.org\/programmer-musings\/wp-json\/wp\/v2\/comments?post=256"}],"version-history":[{"count":1,"href":"https:\/\/blog.gwadej.org\/programmer-musings\/wp-json\/wp\/v2\/posts\/256\/revisions"}],"predecessor-version":[{"id":1362,"href":"https:\/\/blog.gwadej.org\/programmer-musings\/wp-json\/wp\/v2\/posts\/256\/revisions\/1362"}],"wp:attachment":[{"href":"https:\/\/blog.gwadej.org\/programmer-musings\/wp-json\/wp\/v2\/media?parent=256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gwadej.org\/programmer-musings\/wp-json\/wp\/v2\/categories?post=256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gwadej.org\/programmer-musings\/wp-json\/wp\/v2\/tags?post=256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}