Clear Code: How To Write Code That Is Easy To Read

<p>This article is a follow up to a tweet I made on how I deal with my poor ability to remember implementation (code). It may seem funny to you, but I do actually tend to forget what I write shortly after writing it.</p> <p><iframe frameborder="0" height="345" scrolling="no" src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=twitter&amp;url=https%3A//twitter.com/wiseass301/status/1591181678051229696&amp;image=https%3A//i.embed.ly/1/image%3Furl%3Dhttps%253A%252F%252Fabs.twimg.com%252Ferrors%252Flogo46x38.png%26key%3Da19fcc184b9711e1b4764040d3dc5c07" title="Ryan Kay on Twitter: &quot;If you have a bad memory for code like I do, then I suggest you make your code read like a book. That way you don't need to remember what you wrote yesterday, or a month ago; the code will tell you as you read it. / Twitter&quot;" width="680"></iframe></p> <p>First, we will discuss why you may want to write more legible code as opposed to concise (short) code. Afterwards, we will look at the following strategies on how to do that with:</p> <ul> <li>Variable, class, and function naming</li> <li>Helper functions</li> <li>Code comments</li> <li>Enums/Dictionaries/Sealed Classes/Etc.</li> <li>Package organization and naming</li> </ul> <p><img alt="" src="https://miro.medium.com/v2/resize:fit:630/1*78uIqbPUrgsoIADGr0v1kg.jpeg" style="height:468px; width:700px" /></p> <p>Stock image of someone reading.</p> <h1>Does Efficiency Come From Fewer&nbsp;<strong>Keystrokes</strong>?</h1> <p>I recall as a junior developer, thinking that short or abbreviated names for identifiers (basically any code construct us developers are allowed to name) were more efficient.</p> <p>My logic was simple: If it takes me less time to write it, then I can get the job done faster.</p> <p><a href="https://medium.com/didact-publication/clear-code-how-to-write-code-that-is-easy-to-read-fc8f12820592">Website</a></p>
Tags: Code Read