<?xml version="1.0" encoding="utf-8" standalone="yes"?><feed xmlns="http://www.w3.org/2005/Atom">
  <title></title>
  <subtitle></subtitle>
  <id>https://www.endpointdev.com/blog/tags/books/</id>
  <link href="https://www.endpointdev.com/blog/tags/books/"/>
  <link href="https://www.endpointdev.com/blog/tags/books/" rel="self"/>
  <updated>2026-04-06T00:00:00+00:00</updated>
  <author>
    <name>End Point Dev</name>
  </author>
  
    <entry>
      <title>High Level System Analysis and Design with Domain-Driven Design</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2026/04/high-level-system-analysis-and-design-ddd-part-1/"/>
      <id>https://www.endpointdev.com/blog/2026/04/high-level-system-analysis-and-design-ddd-part-1/</id>
      <published>2026-04-06T00:00:00+00:00</published>
      <author>
        <name>Kevin Campusano</name>
      </author>
      <content type="html">
        &lt;p&gt;&lt;img src=&#34;/blog/2026/04/high-level-system-analysis-and-design-ddd-part-1/pines-waterfall.webp&#34; alt=&#34;A wide waterfall cascades through a rocky, forested canyon surrounded by pine-covered hills under a cloudy sky.&#34;&gt;&lt;br&gt;
Photo by Zed Jensen, 2022.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Domain-Driven Design&lt;/strong&gt; is an approach to software development that focuses on, &lt;a href=&#34;https://www.oreilly.com/library/view/domain-driven-design-tackling/0321125215/&#34;&gt;as Eric Evans puts it&lt;/a&gt;, &amp;ldquo;tackling the complexity in the heart of software&amp;rdquo;. And what is in the heart of software? The business domain in which it operates. Or more specifically: a &lt;strong&gt;model&lt;/strong&gt; of it, made of code. That is, the code that implements the business logic that comes into play when solving problems within the realm of a particular business activity.&lt;/p&gt;
&lt;p&gt;DDD is not just about writing code though. It&amp;rsquo;s a whole methodology that touches on business needs, requirements gathering, organizational dynamics, high level architectural design, and lower level patterns for implementing software intensive systems.&lt;/p&gt;
&lt;p&gt;As a result, DDD offers a treasure trove of concepts, patterns and tools that can be applied to any software project, regardless of the size and complexity.&lt;/p&gt;
&lt;p&gt;In this series of blog posts we&amp;rsquo;re going to explore many aspects of DDD. We will be following the structure laid out by &lt;a href=&#34;https://vladikk.com/&#34;&gt;Vlad Khononov&lt;/a&gt;&amp;rsquo;s excellent book on the topic &amp;ldquo;&lt;a href=&#34;https://www.oreilly.com/library/view/learning-domain-driven-design/9781098100124/&#34;&gt;Learning Domain-Driven Design: Aligning Software Architecture and Business Strategy&lt;/a&gt;&amp;rdquo;. So you can think of this series as a summary of that book. An abridged version that can serve as a review for anybody who has read it; but also as an entry point for people who are new to DDD.&lt;/p&gt;
&lt;h3 id=&#34;table-of-contents&#34;&gt;Table of contents&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#high-level-system-analysis-and-design-with-domain-driven-design&#34;&gt;High level system analysis and design with Domain-Driven Design&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#table-of-contents&#34;&gt;Table of contents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#section-1-analyzing-business-domains&#34;&gt;Section 1. Analyzing business domains&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#domains-and-subdomains&#34;&gt;Domains and subdomains&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#types-of-subdomains&#34;&gt;Types of subdomains&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#using-subdomains-to-make-strategic-decisions&#34;&gt;Using subdomains to make strategic decisions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#section-2-discovering-domain-knowledge&#34;&gt;Section 2. Discovering domain knowledge&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#the-ubiquitous-language&#34;&gt;The ubiquitous language&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#the-ubiquitous-language-as-a-model-of-the-domain&#34;&gt;The ubiquitous language as a model of the domain&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#tools-for-capturing-the-ubiquitous-language&#34;&gt;Tools for capturing the ubiquitous language&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#section-3-managing-domain-complexity&#34;&gt;Section 3. Managing domain complexity&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#reasons-for-creating-bounded-contexts&#34;&gt;Reasons for creating bounded contexts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#bounded-contexts-vs-subdomains&#34;&gt;Bounded contexts vs subdomains&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#section-4-integrating-bounded-contexts&#34;&gt;Section 4. Integrating bounded contexts&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#cooperation-patterns&#34;&gt;Cooperation patterns&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#customer-supplier-patterns&#34;&gt;Customer-supplier patterns&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#separate-ways&#34;&gt;Separate ways&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#the-context-map&#34;&gt;The context map&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#the-ddd-high-level-design-concept-map&#34;&gt;The DDD high level design concept map&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;section-1-analyzing-business-domains&#34;&gt;Section 1. Analyzing business domains&lt;/h3&gt;
&lt;p&gt;It is a well understood notion that before writing code, we need to understand the problem we&amp;rsquo;re trying to solve. DDD is consistent with this notion and argues that developers need to, first and foremost, gain an understanding of the business that the software is being built for. To this end, DDD relies on three concepts: domains, subdomains and domain experts.&lt;/p&gt;
&lt;h4 id=&#34;domains-and-subdomains&#34;&gt;Domains and subdomains&lt;/h4&gt;
&lt;p&gt;In simple terms, the &lt;strong&gt;domain&lt;/strong&gt; of a business is what it does, its area of activity. For example, Starbucks is in the business of making coffee, Ford is in the business of making automobiles, AMC is in the business of movie theaters.&lt;/p&gt;
&lt;p&gt;Of course, analyzing a business as a single integrated whole can be unmanageable. That&amp;rsquo;s where subdomains come in. &lt;strong&gt;Subdomains&lt;/strong&gt; are the different divisions within a domain. Starbuck&amp;rsquo;s domain for example, is making coffee. But there are many smaller parts that make up that business and allow it to be successful. There&amp;rsquo;s of course, the subdomain of coffee preparation. But there&amp;rsquo;s also real estate management to find and secure good locations, there&amp;rsquo;s inventory management and logistics, there&amp;rsquo;s marketing, there&amp;rsquo;s human resources, etc. All these are the subdomains that make up the overall business of Starbucks.&lt;/p&gt;
&lt;p&gt;Depending on the business and on the project, these will vary greatly in granularity. And you can also decompose subdomains further and discover new fine-grained subdomains nested within more coarse-grained ones. The sizes and nesting levels can be very different from business to business, so it can be difficult to clearly delineate where a subdomain ends and another one starts, which activities belong to one or the other. One good rule of thumb to keep in mind is that generally, subdomains encapsulate a set of coherent, closely related use cases. That is, use cases that involve the same set of closely related actors, business entities and/or data.&lt;/p&gt;
&lt;p&gt;And finally, we have &lt;strong&gt;domain experts&lt;/strong&gt;. As the name suggests, these are the people within the organization who have intimate knowledge of the business, or certain areas of it. They are the subject matter experts. Usually they are the ones who identify the problems and come up with requirements. Developers need to rely on domain experts to gain the necessary understanding to be able to produce useful software solutions.&lt;/p&gt;
&lt;p&gt;So, when approaching software projects, DDD suggests that developers work closely with domain experts in order to learn from them about the business domain and subdomains. After all, it is their mental models and understanding that will be modeled and implemented in code.&lt;/p&gt;
&lt;h4 id=&#34;types-of-subdomains&#34;&gt;Types of subdomains&lt;/h4&gt;
&lt;p&gt;With the help of domain experts, developers can identify subdomains, understand their business value and how they fit within the overall business strategy. This is very important because it helps making some initial architecturally significant decisions. Namely, the general approach to solving the problems in the subdomains, how much to invest, how to organize development teams, etc. The main objective in this analysis stage is to identify the subdomains and whether they fall into one of three types: core, generic, and supporting.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Core subdomains&lt;/strong&gt; are the activities of the business with highest value. The ones that confer differentiation in the market and a competitive advantage. They are the business&amp;rsquo; raison d&amp;rsquo;être. For example, for Google, their search engine is a core subdomain. For Ford, their automotive engineering area would be a core subdomain. Core subdomains are generally the most complex parts of the business. They are constantly evolving and improving, and the company is compelled to invest heavily in them.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Generic subdomains&lt;/strong&gt; are also very complex. However, they are not business differentiators. Instead, these are the areas of the business that all organizations handle in the same way. Think accounting, a ticketing system, an online storefront. There&amp;rsquo;s no pressure to innovate in these areas, so the solutions are very stable and evolution is slow.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Supporting subdomains&lt;/strong&gt; on the other hand, do not provide any competitive advantage, nor are they very complex. They are however, necessary because they support the core business activities, and are fairly unique. The solutions to problems in these areas usually take the form of &lt;a href=&#34;https://en.wikipedia.org/wiki/Create,_read,_update_and_delete&#34;&gt;CRUD&lt;/a&gt; or &lt;a href=&#34;https://en.wikipedia.org/wiki/Extract,_transform,_load&#34;&gt;ETL&lt;/a&gt; oriented activities. Imagine for example populating a data warehouse, translating transactional business data into a format appropriate for analytics and business intelligence in a manufacturing corporation. Or maybe the digitization and storage of a registry of court documents for a law firm. These are behind the scenes activities that support the organizations&amp;rsquo; main businesses, but their business logic complexity is not high, and they don&amp;rsquo;t really represent big selling points for the company.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s worth noting as well, that there may be subdomains where software solutions are not appropriate, even if they are highly complex core subdomains. They are still part of the business so it&amp;rsquo;s worth identifying and considering for high level architectural design decisions. If anything, to know what parts of the business the planned software system should and should not focus on. You could have a restaurant, for example, who prides itself in having the best desserts in the city. For their business, the recipe development activities constitute a core subdomain. This is dependent on the art and craftsmanship of the chefs. Not an area in which software solutions could help a whole lot.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s also worth noting that, just as organizations&amp;rsquo; business strategies are dynamic, so too can be their subdomain distribution. Today&amp;rsquo;s generic subdomain can be tomorrow&amp;rsquo;s core subdomain, and so on. For example, imagine a big retail store chain that, up until now, managed its inventory in an industry standard way. But it has grown so much that the standard way of doing things has become a bottleneck for them. So they design a new procedure for highly efficient inventory management, and that gives them an edge against competitors. Inventory management started as a generic subdomain for them, but due to an ever evolving business strategy, it became a core subdomain.&lt;/p&gt;
&lt;p&gt;The knowledge of subdomain types can also help the analysis when dividing the business and discovering subdomains. If you find yourself recursively finding more and more fine-grained subdomains from already identified ones, a good time to stop recursing is when you find that a generic or supporting subdomain, when broken down, reveals only new finer-grained generic or supporting subdomains. The reasoning for this is simple: this analysis activity is most valuable when trying to identify core subdomains. When there are no more core subdomains to be found within a particular area of the business, then it&amp;rsquo;s probably not worth it to keep digging deeper.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2026/04/high-level-system-analysis-and-design-ddd-part-1/decomposing-a-generic-subdomain.png&#34; alt=&#34;Decomposing a generic subdomain&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Here we have an example of a hypothetical help desk system subdomain, part of a customer service subdomain, being decomposed and revealing that it only contains generic subdomains.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;In summary, these are the main characteristics of the three types of subdomains:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Core subdomains&lt;/strong&gt; have high complexity, provide competitive advantage, and change and evolve frequently.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Generic subdomains&lt;/strong&gt; have high complexity, do not provide competitive advantage and change overtime, although at a slower pace than core subdomains.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Support subdomains&lt;/strong&gt; have low complexity, do not provide competitive advantage and are the slowest to change.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2026/04/high-level-system-analysis-and-design-ddd-part-1/subdomain-types-complexity-vs-differentiation.png&#34; alt=&#34;Subdomain types complexity vs differentiation&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;This is where each type of subdomain fall when considering their business logic complexity and business differentiation.&lt;/em&gt;&lt;/p&gt;
&lt;h4 id=&#34;using-subdomains-to-make-strategic-decisions&#34;&gt;Using subdomains to make strategic decisions&lt;/h4&gt;
&lt;p&gt;Like I&amp;rsquo;ve already alluded to, armed with this knowledge, DDD practitioners are ready to start making some higher level architectural decisions. Depending on the type of subdomain that a problem belongs to, DDD has specific prescriptions on how to handle the implementation of software solutions for them.&lt;/p&gt;
&lt;p&gt;When working on &lt;strong&gt;core subdomains&lt;/strong&gt;, that&amp;rsquo;s where we want to make the biggest investments. We deploy the most advanced engineering tools, patterns and practices. This is to make sure that the software is efficient and high quality, and also easy to maintain and evolve. This is necessary because core subdomains have to evolve rapidly by nature, if the business is to maintain competitive advantage. Software solutions that operate within the context of core subdomains have to be implemented by high skill and high trust teams. Either in-house, or via trusted development partners, working hand in hand with domain experts.&lt;/p&gt;
&lt;p&gt;Problems in &lt;strong&gt;generic subdomains&lt;/strong&gt;, by nature of their business logic being very complex but also very common, are likely to have already been solved. For these types of problems, DDD recommends against implementing custom software, and instead buying and/or adopting tried and true, industry standard, off-the-shelf solutions. Their implementation and integration can be outsourced or handled by less specialized or skilled teams. The change management of these solutions is simple, as they get delivered generally via patches and updates.&lt;/p&gt;
&lt;p&gt;For &lt;strong&gt;support subdomains&lt;/strong&gt;, whose business logic is generally simple but uncommon, it is less likely that off-the-shelf solutions would be available. So software addressing problems in these subdomains will most likely have to be implemented as custom solutions. Due to their low complexity though, they can be easily outsourced, or handled by more junior team members. They can also be handled with &lt;a href=&#34;https://en.wikipedia.org/wiki/Rapid_application_development&#34;&gt;RAD&lt;/a&gt;, low-to-no-code technologies, since often times they are little more than ETL and pure CRUD applications.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a table to summarizes the differences between the types of subdomains:&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;Type of subdomain&lt;/th&gt;
          &lt;th&gt;Core&lt;/th&gt;
          &lt;th&gt;Generic&lt;/th&gt;
          &lt;th&gt;Supporting&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;Competitive advantage&lt;/td&gt;
          &lt;td&gt;Yes&lt;/td&gt;
          &lt;td&gt;No&lt;/td&gt;
          &lt;td&gt;No&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Complexity&lt;/td&gt;
          &lt;td&gt;High&lt;/td&gt;
          &lt;td&gt;High&lt;/td&gt;
          &lt;td&gt;Low&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Rate of change&lt;/td&gt;
          &lt;td&gt;High&lt;/td&gt;
          &lt;td&gt;Medium&lt;/td&gt;
          &lt;td&gt;Low&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Implementation&lt;/td&gt;
          &lt;td&gt;Custom development&lt;/td&gt;
          &lt;td&gt;Buy/adopt off-the-shelf&lt;/td&gt;
          &lt;td&gt;Custom development&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Team composition&lt;/td&gt;
          &lt;td&gt;In-house/partners&lt;/td&gt;
          &lt;td&gt;Can outsource&lt;/td&gt;
          &lt;td&gt;Can outsource&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Skill level&lt;/td&gt;
          &lt;td&gt;High&lt;/td&gt;
          &lt;td&gt;High/regular&lt;/td&gt;
          &lt;td&gt;Low&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Investment&lt;/td&gt;
          &lt;td&gt;High&lt;/td&gt;
          &lt;td&gt;Medium&lt;/td&gt;
          &lt;td&gt;Low&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Problems&lt;/td&gt;
          &lt;td&gt;Interesting&lt;/td&gt;
          &lt;td&gt;Solved&lt;/td&gt;
          &lt;td&gt;Simple&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;section-2-discovering-domain-knowledge&#34;&gt;Section 2. Discovering domain knowledge&lt;/h3&gt;
&lt;p&gt;After identifying the business domain and categorizing the various subdomains that compose it, we have a bird&amp;rsquo;s-eye view of the business. This is good enough to get started and make high level architectural decisions of potential software solutions to problems within these domains. To actually build the software though, we need much more than that. In order to gain a thorough understanding of the business logic, and be able to eventually model and implement it in code, DDD proposes the &lt;strong&gt;ubiquitous language&lt;/strong&gt; as a tool.&lt;/p&gt;
&lt;h4 id=&#34;the-ubiquitous-language&#34;&gt;The ubiquitous language&lt;/h4&gt;
&lt;p&gt;The &lt;strong&gt;ubiquitous language&lt;/strong&gt; is DDD&amp;rsquo;s tool for knowledge sharing, effective communication and software modeling. In simple terms, the ubiquitous language is the language of the business. It&amp;rsquo;s the language that domain experts use on a day to day basis to talk and reason about the business.&lt;/p&gt;
&lt;p&gt;For a software project to be successful, it&amp;rsquo;s essential that engineers and stakeholders understand each other. They have to be aligned when it comes to the meanings of the core concepts of the business domain. That&amp;rsquo;s why it&amp;rsquo;s so important that everybody uses the ubiquitous language for all project related communications, requirements, documentation, face to face discussions, and even code itself. It all needs to share the same language.&lt;/p&gt;
&lt;p&gt;Engineers will need to interact with domain experts in order to learn about the business domain and its rules. They need to acquire the necessary knowledge that allows them to implement these rules in the software. During these interactions, they converse using the ubiquitous language. However, the knowledge transfer is not always strictly unidirectional. Yes, engineers have to learn from the domain experts. But also, through conversations and questioning, engineers can help domain experts deepen and flesh out their own understanding about their domains.&lt;/p&gt;
&lt;p&gt;A classic example of this is when domain experts focus too much on the &amp;ldquo;happy paths&amp;rdquo; of given business processes. Then, through discussions with developers, on account of the inherent precision that software demands, they are forced to consider more edge cases, better specify ambiguous terms and fill out gaps in their understanding.&lt;/p&gt;
&lt;p&gt;This deepening of knowledge feeds back into the ubiquitous language and improves it. Making it more insightful and more precise. This means that, throughout the life cycle of a project, the ubiquitous language should keep evolving, expanding and refining. This allows it to continuously improve as an effective model of the business domain, for the problem that it&amp;rsquo;s trying to solve. Indeed, just like code is a model of the business domain, so too is the ubiquitous language.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2026/04/high-level-system-analysis-and-design-ddd-part-1/traditional-knowledge-sharing-flow.png&#34; alt=&#34;Traditional knowledge sharing flow&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;A classic pitfall in software projects is a manner of communication and knowledge sharing where developers are various steps removed from the domain experts. Consistent use of the ubiquitous language addresses this.&lt;/em&gt;&lt;/p&gt;
&lt;h4 id=&#34;the-ubiquitous-language-as-a-model-of-the-domain&#34;&gt;The ubiquitous language as a model of the domain&lt;/h4&gt;
&lt;p&gt;Through consistent use of the ubiquitous language, developers are able to obtain a deeper understanding of the domain, the problems we&amp;rsquo;re trying to solve, the reasoning behind the requirements and the mental model of the domain experts. This allows the construction of effective software solutions, with deep business insight, that go beyond simply translating requirements into code. If the implementation models the business domain effectively, there is potential for it to evolve with the business and better adapt as requirements change; and we reduce the risk of missing edge cases that may not be obvious to domain experts.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2026/04/high-level-system-analysis-and-design-ddd-part-1/knowledge-sharing-in-ddd.png&#34; alt=&#34;Knowledge sharing under DDD&#34;&gt;
&lt;em&gt;Under DDD, developers and domain experts develop the ubiquitous language, which then informs the implementation.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Effectively, when we build a ubiquitous language, we&amp;rsquo;re building a model of the domain. A model that reflects the relevant business entities, their behavior, and relationships. A model that will be eventually implemented into code, but also a model that needs to be understood by all stakeholders, regardless of their technical level. So it needs to be precise and rigorous, but also understandable. As such, in order to be useful, the ubiquitous language needs to respect certain restrictions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It must not include technical jargon like programming languages, constructs or frameworks; nor mention specific system structures like database tables, servers or programs. It is the language of the business and it needs to be understandable by non technical folks.&lt;/li&gt;
&lt;li&gt;It must avoid using the same term for different concepts. In conversation with humans, a lot of the meaning is extracted from the context. In software, not so much. Just like you can&amp;rsquo;t have two classes with the same name within the same namespace, the ubiquitous language cannot allow such ambiguities.&lt;/li&gt;
&lt;li&gt;It should also avoid using different words for the same concept. The classic example for this is words like users, accounts, customers, visitors. They all refer to closely related concepts which might actually have differences. The problem with these overlapping terms is that those differences are obscured by the notion of them &amp;ldquo;being the same&amp;rdquo; and being used interchangeably. For usage within the ubiquitous language, it&amp;rsquo;s best to be precise and clearly delineate terms and definitions. Eliminate what&amp;rsquo;s redundant, be strict with definitions.&lt;/li&gt;
&lt;li&gt;It should avoid including extraneous details. Just like code needs to include only what&amp;rsquo;s needed to solve the problem at hand and nothing else (in order to avoid accidental complexity); the ubiquitous language must not be polluted with details from outside of the area of business activity that it represents. That can create confusion and unnecessary cognitive load.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2026/04/high-level-system-analysis-and-design-ddd-part-1/model-translations.png&#34; alt=&#34;Classic model translations&#34;&gt;
&lt;em&gt;The ubiquitous language represents a unified model of the domain. This is in contrast to a more traditional process where domain knowledge gets &amp;ldquo;translated&amp;rdquo; multiple times before turning into code.&lt;/em&gt;&lt;/p&gt;
&lt;h4 id=&#34;tools-for-capturing-the-ubiquitous-language&#34;&gt;Tools for capturing the ubiquitous language&lt;/h4&gt;
&lt;p&gt;The &lt;a href=&#34;https://agilemanifesto.org/&#34;&gt;Agile Manifesto&lt;/a&gt; declares: &amp;ldquo;Individuals and interactions over processes and tools&amp;rdquo;. And of course, when it comes to the ubiquitous language, direct interaction and conversations between engineers, domain experts and other stakeholders reigns supreme. That&amp;rsquo;s when it can be most useful. It can also be useful, however, to capture the ubiquitous language in documentation and even in runnable form.&lt;/p&gt;
&lt;p&gt;A glossary of terms is a great asset for keeping a ubiquitous language. A wiki is a good place to put this. Definitions for key concepts in the business like entities, processes and rules can be captured here. The only caveat is that documentation is static by nature, while the ubiquitous language is continually evolving. So, great care needs to be taken to keep the wiki updated at all times to reflect the latest and most complete understanding of the domain. This should not be relegated to or gate-keeped by only certain people; it should be a team effort where everyone contributes.&lt;/p&gt;
&lt;p&gt;An automated acceptance tests suite, written using &lt;a href=&#34;https://en.wikipedia.org/wiki/Behavior-driven_development&#34;&gt;Behavior Driven Development&lt;/a&gt; frameworks, like &lt;a href=&#34;https://cucumber.io/&#34;&gt;Cucumber&lt;/a&gt;, is also a great way of capturing the ubiquitous language. The advantage of these tests is that they are written in plain human-readable language, not code. And while it may be far fetched to think that non technical domain experts would be capable of writing and maintaining such tests, they certainly can read and understand them, which is a great boon. These tests speak the language they understand: the language of the business.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2026/04/high-level-system-analysis-and-design-ddd-part-1/cucumber.png&#34; alt=&#34;Cucumber tests&#34;&gt;
&lt;em&gt;This is what Cucumber tests look like.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;By nature of being executable and tied closely to the implementation code, there is less chance that they become out of date. This can happen more easily with static documentation written in a wiki. The disadvantage is that they require much more effort. But for the right kind of project, one where business logic is very complex or the scope is very wide, they can be very well worth the cost.&lt;/p&gt;
&lt;h3 id=&#34;section-3-managing-domain-complexity&#34;&gt;Section 3. Managing domain complexity&lt;/h3&gt;
&lt;p&gt;We can attempt to model an entire business domain with one big ubiquitous language, but sometimes that&amp;rsquo;s impossible. Especially so for businesses of a certain size, you will inevitably find inconsistencies and conflicts between the mental models of different domain experts. The simplest example of this scenario is when different experts from different areas of the organization have the same word to describe different concepts. Or when they look at the same business entity with different levels of detail.&lt;/p&gt;
&lt;p&gt;When the different mental models are valid, and these inconsistencies are legitimate and cannot be reconciled, the solution is to follow the divide and conquer principle and decompose the language into separate ones, each one working within its own bounded context.&lt;/p&gt;
&lt;p&gt;Simply put, a &lt;strong&gt;bounded context&lt;/strong&gt; is the context within which a ubiquitous language, and the model it represents, operate, have meaning and are useful. Sure enough, just like a domain can be divided into subdomains, a ubiquitous language can be decomposed into smaller languages, each with its own context, to model different parts of the business. While we can attempt to capture an entire business domain with a single model, this is not advisable in the case of complex systems. It&amp;rsquo;s better to split up the model into smaller, more precise ones, tailored to work on specific problem domains.&lt;/p&gt;
&lt;h4 id=&#34;reasons-for-creating-bounded-contexts&#34;&gt;Reasons for creating bounded contexts&lt;/h4&gt;
&lt;p&gt;Like mentioned before, different domain experts having conflicting mental models is a clear indication that a division in the model needs to happen. However, that only tells us half of the story. There are other indicators that point to when and where further division should happen:&lt;/p&gt;
&lt;p&gt;First of all, there is of course, size. Size by itself is not a deciding factor, but it is something to consider and balance. Fewer, bigger models can help keep the overall environment simpler, but if they become too big they can become unmanageable and prone to corruption. A higher number of smaller models keep cognitive load low, but you run the risk of exploding integration and management complexity. The better principles to keep in mind here are coupling and cohesion. Beware of separating closely tied use cases, that deal with similar actors, entities and data.&lt;/p&gt;
&lt;p&gt;System-level nonfunctional requirements also play a role in dividing a model into separate bounded contexts. For example, you might need to decouple the life cycle of several software components. Have them be developed, evolved, versioned and deployed independently. You might also need them to scale separately. You might even need to use completely different technology stacks, whatever is appropriate for the task at hand. This means that bounded contexts generally get implemented as individual services and/or applications. That is, as individual runtime components.&lt;/p&gt;
&lt;p&gt;The organization&amp;rsquo;s composition also plays a role when designing bounded contexts. The general rule is that a given ubiquitous language, the model it represents and the bounded context is lives in, must be owned by a single team. In software, high ownership, cohesion and consistency are desirable traits. Having a single team own and maintain a particular component foments these. Single ownership also helps reduce communication overhead, and prevents people from stepping on one another&amp;rsquo;s toes. Of course, a single team can own multiple bounded contexts, what cannot happen is one bounded context being owned by multiple teams.&lt;/p&gt;
&lt;p&gt;Indeed, in bounded contexts, we have the tools we need to make strategic decisions related to the decomposition of software systems into architecturally significant components or modules. With bounded contexts, we are able to specify the physical and ownership boundaries of these components.&lt;/p&gt;
&lt;h4 id=&#34;bounded-contexts-vs-subdomains&#34;&gt;Bounded contexts vs subdomains&lt;/h4&gt;
&lt;p&gt;Bounded contexts and subdomains are closely related concepts, but there&amp;rsquo;s one key distinction: &lt;strong&gt;subdomains&lt;/strong&gt; are discovered, while &lt;strong&gt;bounded contexts&lt;/strong&gt; are designed. Subdomains are useful because they help us understand the business strategy. Splitting the business domain into smaller problem domains is useful because it can break down a complex whole into smaller and more manageable parts.&lt;/p&gt;
&lt;p&gt;Depending on the situation, it is certainly possible to end up with a set of bounded contexts that align one-to-one with the business subdomains. However, this is not mandatory. We can develop a solution with a single bounded context that spans multiple subdomains; the same way that we can decompose the problem into many bounded contexts, some of which operate within the same particular subdomain.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2026/04/high-level-system-analysis-and-design-ddd-part-1/subdomains-and-bounded-contexts.png&#34; alt=&#34;Subdomains and bounded contexts&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Bounded contexts are closely related to subdomains, but aren&amp;rsquo;t tied to them. They are flexible and can be organized in many ways.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Each bounded context becomes a separate major architectural component. That is, a (micro) service, a project, an application. When we have a component that spans multiple subdomains, programming language organizational structures like namespaces or modules can be used to logically separate the subdomains within.&lt;/p&gt;
&lt;h3 id=&#34;section-4-integrating-bounded-contexts&#34;&gt;Section 4. Integrating bounded contexts&lt;/h3&gt;
&lt;p&gt;For a system to function, its components need to interact with each other. So, once we have decomposed the problem domain into separate bounded contexts, we need to decide their relationship and integration strategies. This need for interaction between them implies that there are touch points between bounded contexts. We call them &lt;strong&gt;contracts&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;These contracts are necessary because each bounded context contains its own version of the world. That is, its own model and ubiquitous language. In order to integrate, some level of translation needs to happen. They need to be adapted to one another. The contracts define these adaptations.&lt;/p&gt;
&lt;p&gt;Domain-Driven Design offers various patterns that are useful for defining contracts between bounded contexts. The decision to use one pattern vs the other depends greatly on the nature of the teams tackling the project. Depending on the teams&amp;rsquo; relationship, we can put the patterns in one of three categories: cooperation, customer-supplier, and separate ways.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2026/04/high-level-system-analysis-and-design-ddd-part-1/collaboration-spectrum.png&#34; alt=&#34;Collaboration spectrum&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Integration patterns are determined mainly by the level of cooperation between the teams that own the interacting bounded contexts.&lt;/em&gt;&lt;/p&gt;
&lt;h4 id=&#34;cooperation-patterns&#34;&gt;Cooperation patterns&lt;/h4&gt;
&lt;p&gt;When the components that need to interact are owned by teams which are in close communication, work well together, and whose goals are aligned, &lt;strong&gt;cooperation&lt;/strong&gt; patterns can be applied.&lt;/p&gt;
&lt;p&gt;If the teams meet these criteria, a &lt;strong&gt;partnership&lt;/strong&gt; model can be implemented. This is where the integration is managed in an ad-hoc manner. Both teams work together to define the API through which their components interact and that&amp;rsquo;s that. Whenever changes happen on either side, the other team learns about it quickly and adjusts their code right away. Continuous integration is a great tool here, as breakages are immediately apparent, closing down the feedback loop.&lt;/p&gt;
&lt;p&gt;Sometimes, when different bounded contexts need to implement the same functionality, it makes more sense to develop this functionality once and package it as a reusable library, or a sub-module within a shared repository. This is what DDD calls a &lt;strong&gt;shared kernel&lt;/strong&gt;. A shared kernel is effectively a bounded context of its own, one that is statically linked to other components and implements the logic that others depend on.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2026/04/high-level-system-analysis-and-design-ddd-part-1/shared-kernel.png&#34; alt=&#34;Shared kernel&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;A shared kernel is its own bounded context, but also &amp;ldquo;belongs&amp;rdquo; to multiple other bounded contexts.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The shared kernel integration pattern needs to be used carefully though, as it creates tight coupling between the components that use it. If the involved bounded contexts are owned by different teams, then this shared kernel that emerges violates the DDD principle of bounded contexts having single-team ownership. This is something to watch out for, as bad team synergy can produce problems during development and maintenance.&lt;/p&gt;
&lt;p&gt;When using a shared kernel, the quality of the communication and the coordination between the teams has to strike the right balance: when they aren&amp;rsquo;t strong enough to support a partnership model, but not so weak that the shared kernel would become more trouble than it&amp;rsquo;s worth.&lt;/p&gt;
&lt;p&gt;The alternative to a shared kernel is the duplication of the logic across multiple components. When deciding whether to apply this pattern, the costs of duplication vs coordination need to be considered. That is, the cost of implementing the same logic within multiple components and its subsequent changes, vs the cost of changes in the shared kernel propagating into dependent components and coordinating with the owners of each. When it is cheaper to just duplicate the logic, shared kernel should not be applied.&lt;/p&gt;
&lt;p&gt;This means that complicated models that change frequently, like those of core subdomains, are good candidates for shared kernel. Shared kernels allow complexity to be encapsulated and exposed through stable contracts. This means that frequent changes are easier to contain. Frequent changes in logic that&amp;rsquo;s highly complex and also repeated in multiple places, quickly becomes much more expensive to maintain.&lt;/p&gt;
&lt;p&gt;Another good scenario for applying a shared kernel is when refactoring a legacy monolithic system into more separated modules. The legacy system can become the shared kernel during the time that modules are being extracted from it but not yet fully decoupled.&lt;/p&gt;
&lt;h4 id=&#34;customer-supplier-patterns&#34;&gt;Customer-supplier patterns&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Customer-supplier&lt;/strong&gt; patterns establish a relationship between components where one (the provider, who is &amp;ldquo;upstream&amp;rdquo;), provides a service to another (the consumer, who is &amp;ldquo;downstream&amp;rdquo;). These types of patterns emerge when the teams who own the involved bounded contexts are not in close collaboration and have their own independent goals.&lt;/p&gt;
&lt;p&gt;One form of customer-supplier integration is the &lt;strong&gt;conformist&lt;/strong&gt; pattern. This happens when the supplier defines the integration contract/API, using its own language, concepts and model, and the consumer accepts it. This can happen when the upstream service has a well established or industry-standard model. Or maybe the model is &amp;ldquo;good enough&amp;rdquo; for the consumer to interact with directly. Organizational politics may also be a reason for this type of integration, where there is an imbalance of power favoring the supplier&amp;rsquo;s team, and they get to impose their model or can&amp;rsquo;t be bothered to adapt it.&lt;/p&gt;
&lt;p&gt;Sometimes, the consumer won&amp;rsquo;t accept the supplier&amp;rsquo;s model. In that case, an &lt;strong&gt;anticorruption layer&lt;/strong&gt; can be created. An anticorruption layer is implemented by the consumer and translates the supplier&amp;rsquo;s model into its own. This allows the consumer to use the supplier&amp;rsquo;s service without polluting its model with extraneous concepts.&lt;/p&gt;
&lt;p&gt;Anticorruption layers can be good solutions for the following scenarios:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;When the consumer represents a core subdomain. The consumer is solving hard and interesting problems, so it&amp;rsquo;s best to protect its model with the ACL.&lt;/li&gt;
&lt;li&gt;When the supplier&amp;rsquo;s model is messy and inconvenient. The ACL can protect the consumer&amp;rsquo;s model from having to contend with a mess of extraneous concepts.&lt;/li&gt;
&lt;li&gt;When the supplier&amp;rsquo;s contract changes frequently. The ACL can protect the consumer from those changes, encapsulating them, allowing it to be less volatile.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;A third pattern represents an anticorruption layer of sorts, only built on the supplier&amp;rsquo;s side. DDD calls this the &lt;strong&gt;open-host service&lt;/strong&gt; pattern. Here, the upstream service comes up with a new language, separate from its own, tailored to its consumers&amp;rsquo; convenience, and exposes that as its contract. This public protocol is called a &amp;ldquo;published language&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2026/04/high-level-system-analysis-and-design-ddd-part-1/open-host-service.png&#34; alt=&#34;Open-host service&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;An open-host service provides a protocol for consumers to interact with. It can also support multiple versions of this protocol simultaneously.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;An open-host service applies to similar scenarios as an anticorruption layer. Decoupling a service&amp;rsquo;s internal model from its integration model frees it up for continuous evolution without fear of breaking its consumers. Another advantage of this is that multiple versions of the published language can be exposed, affording clients options on what to support and gradually migrate if they so choose.&lt;/p&gt;
&lt;h4 id=&#34;separate-ways&#34;&gt;Separate ways&lt;/h4&gt;
&lt;p&gt;Sometimes, the right decision is to not integrate at all. I alluded to this outcome back when discussing the pitfalls of the shared kernel. Sometimes duplication, &lt;a href=&#34;https://refactoring.guru/smells/duplicate-code&#34;&gt;in spite of how bad it smells&lt;/a&gt;, may be the most cost effective solution to a given situation. So the teams go their &lt;strong&gt;separate ways&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This can happen when the involved teams cannot collaborate effectively for whatever reason. It could be due to geographical, timezone, or organizational issues.&lt;/p&gt;
&lt;p&gt;This can also be a good solution when the repeated logic belongs in a generic subdomain, and it&amp;rsquo;s easy to integrate. For example consider a logging framework. Exposing that kind of functionality in a service for others to consume, in most cases would be much more trouble than just including some third party library or package.&lt;/p&gt;
&lt;p&gt;It may also be that the models being integrated are just so different that they are fundamentally incompatible. It may be cost-prohibitive for collaboration or customer-supplier patterns to be applied; and duplication again, is cheaper.&lt;/p&gt;
&lt;p&gt;Going separate ways can be dangerous when we&amp;rsquo;re talking about core subdomains though. So we have to tread carefully in those scenarios. Remember that models that represent core subdomain should be implemented in the most effective and efficient ways, with few shortcuts and minimized technical debt.&lt;/p&gt;
&lt;h4 id=&#34;the-context-map&#34;&gt;The context map&lt;/h4&gt;
&lt;p&gt;The &lt;strong&gt;context map&lt;/strong&gt; can be a useful tool for high level design as it plots all the major bounded contexts (i.e. modules, components, subsystems) that we&amp;rsquo;ve designed and their interaction patterns.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2026/04/high-level-system-analysis-and-design-ddd-part-1/context-map.png&#34; alt=&#34;Context map&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Here&amp;rsquo;s a context map which captures the various bounded contexts that compose a big system and their interactions. The arrows point to the upstream component in the relationship. &amp;ldquo;ACL&amp;rdquo; denotes an anticorruption layer and &amp;ldquo;OHS&amp;rdquo; represents an open-host service.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Of course, they can also offer valuable insight into organizational dynamics, as team composition and relationships with others are intrinsic parts of the discussion when talking about bounded contexts. For example, it can show teams that prefer to collaborate closely or at a healthy distance. I can also show problematic components, which are surrounded by anticorruption layers or have had their ties completely cut via a separate ways approach.&lt;/p&gt;
&lt;p&gt;As with any document, they run the risk of becoming stale as the system evolves. So it should be a team-wide responsibility to keep it up to date. Each team taking care of their own components and their integration points.&lt;/p&gt;
&lt;h3 id=&#34;the-ddd-high-level-design-concept-map&#34;&gt;The DDD high level design concept map&lt;/h3&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2026/04/high-level-system-analysis-and-design-ddd-part-1/concept-map.png&#34; alt=&#34;The DDD high level design concept map&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;These are the main concepts that we&amp;rsquo;ve explored so far, and how they relate to each other.&lt;/em&gt;&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>Studying “The Mythical Man-Month” in Collaboration with a Client</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2024/12/studying-the-mythical-man-month/"/>
      <id>https://www.endpointdev.com/blog/2024/12/studying-the-mythical-man-month/</id>
      <published>2024-12-23T00:00:00+00:00</published>
      <author>
        <name>TJ Christofferson</name>
      </author>
      <content type="html">
        &lt;p&gt;&lt;img src=&#34;/blog/2024/12/studying-the-mythical-man-month/study-group-video-call.webp&#34; alt=&#34;Fourteen End Pointers and Cybergenetics team members in a videoconference meeting&#34;&gt;&lt;/p&gt;
&lt;!-- Image used with permission from Cybergenetics --&gt;
&lt;p&gt;Here at End Point we did an enlightening and fun eleven-week study group in collaboration with one of our clients. We worked through Frederick Brooks Jr.’s book The Mythical Man-Month: Essays on Software Engineering, which was originally published in 1975, with an expanded edition published in 1995. In certain ways this book is still applicable to our time, and it was a delight to discuss it in a structured study group with coworkers and peers. This particular study group even piqued the curiosity of the owners of both our companies who participated throughout the course!&lt;/p&gt;
&lt;p&gt;As part of our effort to continually improve our abilities and awareness, and thus build a strong technical company culture, End Point has done many study groups over the years, such as the &lt;a href=&#34;/blog/2016/08/ruby-fight-club/&#34;&gt;Ruby Fight Club&lt;/a&gt; and the &lt;a href=&#34;/blog/2019/07/tribute-to-kyle-simpsons-book-series/&#34;&gt;You Don&amp;rsquo;t Know JS study group&lt;/a&gt;. Participation in these groups is voluntary, and they have covered a range of other topics including PostgreSQL, terminal fluency skills, and regular expressions. The opportunity to step away from regular work duties for an hour during the week, and to have meaningful discourse between coworkers has been invaluable for building relationships across teams.&lt;/p&gt;
&lt;p&gt;For this group, we collaborated with our client &lt;a href=&#34;https://www.cybgen.com/&#34;&gt;Cybergenetics&lt;/a&gt;, who works in forensic DNA analysis. We have been working with Cybergenetics since 2003 on PostgreSQL, websites, system deployment automation, and security. A few Cybergenetics staff members joined our PostgreSQL study group some years ago.&lt;/p&gt;
&lt;p&gt;Dr. Mark Perlin, the Chief Scientific and Executive Officer of Cybergenetics, approached us a few months earlier with the desire for his team to better understand the history and controversies of software engineering, and to relate relevant topics to software user or developer experiences. He thought working together through this book would be a good way to achieve both those goals, and we agreed.&lt;/p&gt;
&lt;p&gt;Fred Brooks’s book on software engineering and project management has a central theme that adding more people to a software project that is behind schedule usually delays it even longer, a concept known as “Brooks’s Law.” Each chapter covers various reasons why this is the case, such as increased communication complexity and overhead, conceptual integrity, and design cohesion degradation. He posits that properly planning projects, including using realistic estimations and considering communication needs, is essential to avoid delays.&lt;/p&gt;
&lt;p&gt;Though not all of us found significant modern application for Brooks’s book, it was an interesting historical read, with some relevant points. One such point is his idea that looking forward to some “silver bullet” solution wastes effort and inhibits forward progress. Today, when some are counting on AI technology to magically fix their code, remove the need to properly document that code, or erase the discipline of software development altogether, it seems wise to apply Brooks’s advice and avoid treating AI and similar advances as a “silver bullet.”&lt;/p&gt;
&lt;p&gt;At End Point we love encouraging thought and discussion on relevant topics, and we appreciate having a historical awareness of what we&amp;rsquo;re doing in the context of decades. We also love an opportunity to collaborate with a client on something that is mutually beneficial.&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>Key Takeaways from Practical Object-Oriented Design by Sandi Metz</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2024/02/key-takeaways-from-poodr/"/>
      <id>https://www.endpointdev.com/blog/2024/02/key-takeaways-from-poodr/</id>
      <published>2024-02-27T00:00:00+00:00</published>
      <author>
        <name>Kevin Campusano</name>
      </author>
      <content type="html">
        &lt;p&gt;&lt;img src=&#34;/blog/2024/02/key-takeaways-from-poodr/well-trimmed-trees.webp&#34; alt=&#34;View upward at a bright sky, with lines drawn down at an angle toward the left center by a tree trimmed into a rectangular prism and one trimmed into a vague cone. The lens is imperfect, leaving the corner of the square tree in focus while the rest of the green foliage and blue and bright white sky is somewhat distorted by the lens.&#34;&gt;&lt;/p&gt;
&lt;!-- Photo by Seth Jensen, 2022 --&gt;
&lt;p&gt;&lt;a href=&#34;https://www.poodr.com/&#34;&gt;Practical Object-Oriented Design: An Agile Primer Using Ruby&lt;/a&gt; by &lt;a href=&#34;https://sandimetz.com/&#34;&gt;Sandi Metz&lt;/a&gt; is one of those books that everybody who writes or aspires to write object-oriented code should read. Indeed, reading through this book will be valuable for seasoned practitioners and inexperienced novices alike. Whether it be to discover new concepts, remember why they are important, or articulate the reasons behind that warm fuzzy feeling you get in your stomach when you read well designed code, POODR can help.&lt;/p&gt;
&lt;p&gt;I personally really like this book, and here at End Point it does have quite a following as well; it was the subject of a &lt;a href=&#34;/blog/2016/08/ruby-fight-club/&#34;&gt;study group that we ran back in 2016&lt;/a&gt;. I like to dust it off every now and then to give it a re-read. To help with that, I&amp;rsquo;ve come up with a list of key takeaways from the book, with some of my own interpretations sprinkled in. For me, it serves as a sort of summary to help commit the book&amp;rsquo;s contents to memory. I thought I&amp;rsquo;d share it with you today.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;While this book uses the Ruby language for its examples and discussions, the concepts it describes are equally applicable to any classical object-oriented language. Dynamically typed language users do get a little more mileage than users of statically typed ones. But still, something like 90% of the content is relevant to both. For this summary, I&amp;rsquo;ve taken care not to tie the discussion to Ruby too much and be as language agnostic as possible. I&amp;rsquo;ve chosen to write the code examples in C#.&lt;/p&gt;&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Images taken from the book. Code taken from the book&amp;rsquo;s examples in Ruby and translated to C#.&lt;/p&gt;&lt;/blockquote&gt;
&lt;h3 id=&#34;chapter-1-object-oriented-design&#34;&gt;Chapter 1: Object-Oriented Design&lt;/h3&gt;
&lt;h4 id=&#34;about-design&#34;&gt;About design&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;Following the principles and patterns of object-oriented design produces code that is both cost-effective and a joy to work with. &amp;ldquo;Cost effective&amp;rdquo; means that it doesn&amp;rsquo;t take more effort than necessary to evolve, to change.&lt;/li&gt;
&lt;li&gt;The reason design is important is because software changes. A good design is one that makes software easy to change.&lt;/li&gt;
&lt;li&gt;Object-oriented design sees the world as a collection of parts that interact with each other. The parts we call &amp;ldquo;objects&amp;rdquo;, and the interactions we call &amp;ldquo;messages&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;In order to send messages to each other, objects need to have some knowledge about one another. This knowledge produces &amp;ldquo;dependencies&amp;rdquo; between them.&lt;/li&gt;
&lt;li&gt;Managing these dependencies is a big part of object-oriented design. OOD aims to create dependencies in such a way that they don&amp;rsquo;t make the process of changing objects too difficult.&lt;/li&gt;
&lt;li&gt;Design is important no matter the size of the application. Because both small and large applications change. And change is what design allows. A badly designed small application will eventually become a badly designed large one.&lt;/li&gt;
&lt;li&gt;Design is the way in which code is arranged. Good design is an arrangement of code that makes change easy.&lt;/li&gt;
&lt;li&gt;Our job as developers is to take our application&amp;rsquo;s requirements and our knowledge of design principles and use them to produce code that is cost effective today and tomorrow: code that is easy to change.&lt;/li&gt;
&lt;li&gt;The idea is not to predict future changes. Instead, we have to accept that change will come and prepare for it. We prepare for it by writing code that leaves our options open for the future.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;The purpose of design is to allow you to design later, and its primary goal is to reduce the cost of change.&amp;rdquo;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;failures-of-design&#34;&gt;Failures of design&lt;/h4&gt;
&lt;ol start=&#34;11&#34;&gt;
&lt;li&gt;&lt;strong&gt;Design fails when you don&amp;rsquo;t do it.&lt;/strong&gt; Code bases that lack in design will eventually evolve into unmaintainable messes, where change becomes increasingly hard even for the most minor new requirements. &amp;ldquo;Throwing everything away and beginning from scratch&amp;rdquo; becomes a viable alternative.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Design fails when you overdesign.&lt;/strong&gt; Armed with basic design skills, it&amp;rsquo;s easy to fall into the trap of developing wrong abstractions, applying principles incorrectly, seeing the wrong pattern in the wrong context. Applications that suffer from overdesign become gigantic castles of code full of indirection that become hard to change.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Design fails when you separate it from programming.&lt;/strong&gt; Design is best executed as an iterative and incremental process with a quick feedback loop. The design needs to be adjusted frequently, as understanding of the domain changes. Design that is dictated to programmers from on high as part of a &amp;ldquo;&lt;a href=&#34;https://en.wikipedia.org/wiki/Big_design_up_front&#34;&gt;Big Up Front Design&lt;/a&gt;&amp;rdquo; is doomed to failure. Such arrangements are not agile enough to be resilient to requirement changes.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;agile-and-design&#34;&gt;Agile and design&lt;/h4&gt;
&lt;ol start=&#34;14&#34;&gt;
&lt;li&gt;Agile development says: &amp;ldquo;Avoid Big Up Front Design because you can&amp;rsquo;t know what the application will end up being because requirements always change and they do so often.&amp;rdquo;&lt;/li&gt;
&lt;li&gt;Agile also says: &amp;ldquo;Good design is essential. Because change comes often, your code needs to be ready to accommodate those changes in an efficient and cost effective way.&amp;rdquo;&lt;/li&gt;
&lt;li&gt;Design is not a &amp;ldquo;one time at the beginning of the project&amp;rdquo; type of task. It is an ongoing, iterative and incremental task that happens as requirements change, and as our domain knowledge and skills increase.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;metrics&#34;&gt;Metrics&lt;/h4&gt;
&lt;ol start=&#34;17&#34;&gt;
&lt;li&gt;Bad object-oriented design metrics are an indicator of a bad design. But good metrics are not an indicator of good design. A code base with bad metrics will most likely be hard to change.&lt;/li&gt;
&lt;li&gt;The ideal software metric would be &amp;ldquo;&lt;strong&gt;cost per feature per time interval&lt;/strong&gt;&amp;rdquo;. But this is nigh on impossible to calculate because &amp;ldquo;cost&amp;rdquo;, &amp;ldquo;feature&amp;rdquo;, and &amp;ldquo;time interval&amp;rdquo; are in most cases nebulous concepts.&lt;/li&gt;
&lt;li&gt;Still, &amp;ldquo;cost per feature per time interval&amp;rdquo; tells us that our goal should always be to write code with a low cost per feature. Making sure that it is also low cost to evolve in the future.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;technical-debt&#34;&gt;Technical debt&lt;/h4&gt;
&lt;ol start=&#34;20&#34;&gt;
&lt;li&gt;&lt;strong&gt;Technical debt&lt;/strong&gt; is borrowing time from the future. That is, putting out a bad design today in order to release a feature quickly. Tomorrow, when change comes, the bad design will prevent cost effective change. So time will have to be spent refactoring, turning the bad design into a good one. If refactoring doesn&amp;rsquo;t happen, the debt increases, making future changes more and more expensive.&lt;/li&gt;
&lt;li&gt;How much design you do depends on your skill and your time frame. You can&amp;rsquo;t do so much design that it prevents you from delivering on time. Design is an investment, and for an investment to be good, it needs to return some profit. Good design&amp;rsquo;s returns are quick and plentiful.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;The trick to getting the most bang for your design buck is to acquire an understanding of the theories of design and to apply them appropriately, at the right time, and in the right amounts.&amp;rdquo;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;chapter-2-designing-classes-with-a-single-responsibility&#34;&gt;Chapter 2: Designing Classes with a Single Responsibility&lt;/h3&gt;
&lt;h4 id=&#34;about-classes&#34;&gt;About classes&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Classes&lt;/strong&gt; are the most basic organizational structure of object-oriented systems written with class-based object-oriented languages. As such, that&amp;rsquo;s the first thing that we focus on when designing such systems.&lt;/li&gt;
&lt;li&gt;Your first instinct should be to keep things simple. Use classes to model only the features that your application needs today and make sure that they are easy to change tomorrow.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Design is more the art of preserving changeability than it is the act of achieving perfection.&amp;rdquo;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;write-code-that-is-true&#34;&gt;Write code that is TRUE&lt;/h4&gt;
&lt;ol start=&#34;4&#34;&gt;
&lt;li&gt;In order to be easy to change, code should be &lt;strong&gt;TRUE&lt;/strong&gt;:&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Code should be &amp;ldquo;Transparent&amp;rdquo;.&lt;/strong&gt; It should be easy to tell what will be the consequences of changing the code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Code should be &amp;ldquo;Reasonable&amp;rdquo;.&lt;/strong&gt; The cost of a change should be proportional to the size of the requirement that provoked the change.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Code should be &amp;ldquo;Usable&amp;rdquo;.&lt;/strong&gt; The code should be easy to reuse in situations other than the one it&amp;rsquo;s currently being used in.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Code should be &amp;ldquo;Exemplary&amp;rdquo;.&lt;/strong&gt; The code should exhibit qualities that guide and/or encourage those who change it to keep and replicate those qualities.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&#34;https://en.wikipedia.org/wiki/Single_responsibility_principle&#34;&gt;Single Responsibility Principle&lt;/a&gt; is a prerequisite to creating code that is TRUE.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;single-responsibility&#34;&gt;Single Responsibility&lt;/h4&gt;
&lt;ol start=&#34;10&#34;&gt;
&lt;li&gt;A class should have one single responsibility. That means that it needs to do one thing and do it well. It needs to be as small as possible and fulfill a single purpose. It needs to have only one reason to change.&lt;/li&gt;
&lt;li&gt;A good way to identify what classes your system needs is to read through your user stories or problem descriptions and identify &lt;strong&gt;nouns&lt;/strong&gt;. Those nouns are good candidates for classes.&lt;/li&gt;
&lt;li&gt;If there are &lt;strong&gt;verbs&lt;/strong&gt; and &lt;strong&gt;properties&lt;/strong&gt; associated with those nouns, then it is most likely a class. Because classes represent bundles of both data (attributes) and behavior (methods).&lt;/li&gt;
&lt;li&gt;Classes that have many responsibilities are hard to reuse. And because they are not &amp;ldquo;Usable&amp;rdquo;, they are not easy to change.&lt;/li&gt;
&lt;li&gt;A class that has many responsibilities usually has unrelated code tangled together within it. This makes the class hard to reason about, and hard to reuse.&lt;/li&gt;
&lt;li&gt;In order to reuse the behavior defined within a class with multiple tangled responsibilities, you either need to duplicate code or use the entire class, even the parts that you don&amp;rsquo;t need.&lt;/li&gt;
&lt;li&gt;If you use a class that has many reasons to change, when something unrelated to your use case changes, you will still have to change your code. This is unexpected and surprising. This is not &amp;ldquo;Transparent&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Depending on classes that have many responsibilities increases the chances of your application breaking.&lt;/li&gt;
&lt;li&gt;A good way to determine whether a class has a single responsibility is to try to enunciate what it does in a single sentence. That sentence should be simple, because classes should be simple. Look out for the words &amp;ldquo;and&amp;rdquo; and &amp;ldquo;or&amp;rdquo; in this sentence, as they point to it having more than one responsibility.&lt;/li&gt;
&lt;li&gt;Another good way to determine whether a class has a single responsibility is thinking about every one of its methods as a question that the class would be able to respond to if it were a sentient being. For example: &amp;ldquo;Array, what is your length?&amp;rdquo; If the question doesn&amp;rsquo;t make sense, then maybe the method does not belong in the class.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cohesion&lt;/strong&gt; is the measure of how related to their core purpose the elements of a component are. Classes that have a single responsibility are highly cohesive because all of their parts work towards a single goal.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;when-to-make-design-decisions&#34;&gt;When to make design decisions&lt;/h4&gt;
&lt;ol start=&#34;21&#34;&gt;
&lt;li&gt;Only design as much as you need to for right now. Don&amp;rsquo;t make design decisions prematurely. Sometimes waiting for more information before committing to a design is the way to go. More information in the future will often reveal a better design.&lt;/li&gt;
&lt;li&gt;Consider postponing design decisions when the information available to you today does not point clearly to a good design. Also, when the cost of not doing it now does not considerably make tomorrow&amp;rsquo;s change more expensive.&lt;/li&gt;
&lt;li&gt;On the other hand, consider that a class that&amp;rsquo;s left in a &amp;ldquo;bad state&amp;rdquo; may be reused by others, making their code depend on badly designed code. The application will suffer as a result.&lt;/li&gt;
&lt;li&gt;The structure of a class is supposed to reveal your design&amp;rsquo;s intention to other developers. When it doesn&amp;rsquo;t, when it is not &amp;ldquo;Exemplary&amp;rdquo;, then future maintenance costs increase.&lt;/li&gt;
&lt;li&gt;The tension between &amp;ldquo;improve it now&amp;rdquo; and &amp;ldquo;improve it later&amp;rdquo; is always present. Our job as designers is to strike a good balance &amp;ldquo;between the needs of the present and the possibilities of the future&amp;rdquo; so that the costs of change are kept low.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;techniques-for-writing-code-thats-easy-to-change&#34;&gt;Techniques for writing code that&amp;rsquo;s easy to change&lt;/h4&gt;
&lt;ol start=&#34;26&#34;&gt;
&lt;li&gt;&lt;strong&gt;Depend on behavior, not data: hide instance variables.&lt;/strong&gt; Instead of accessing instance variables directly, use accessor methods. Even from within the class that owns them. &amp;ldquo;Always send messages to access data.&amp;rdquo;&lt;/li&gt;
&lt;li&gt;That way you consolidate the knowledge of what the data represents in a single place. That&amp;rsquo;s the Single Responsibility Principle in action. Changing it becomes easy as a result because instead of changing references to a variable in potentially multiple places; you only need to change the definition of a method, in a single location.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Depend on behavior, not data: hide data structures.&lt;/strong&gt; When code depends on or receives as input a complex data structure like a big array or hash, encapsulate the data structure in a class with a clear interface, instead of accessing and manipulating the structure directly.&lt;/li&gt;
&lt;li&gt;Directly manipulating complex data structures is a style of coding that tends to propagate. If the incoming data structure changes, even slightly, then a lot of your code also needs to change because it depends on its very particular structure.&lt;/li&gt;
&lt;li&gt;Handling complex raw data structures through classes and messages with clear, intention-revealing names demystifies the structure and gives it meaning within the context of the application domain.&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;For example, instead of this&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;ObscuringReferences&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt;[][] data;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; ObscuringReferences(&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt;[][] data)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;this&lt;/span&gt;.data = data;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; IEnumerable&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt;&amp;gt; GetDiameters()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; data.Select(cell =&amp;gt; cell[&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;] + (cell[&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;] * &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;));
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&amp;hellip;do this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;RevealingReferences&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    IEnumerable&amp;lt;Wheel&amp;gt; Wheels { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; RevealingReferences(&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt;[][] data)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        Wheels = Wheelify(data);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// This method is now more readable.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; IEnumerable&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt;&amp;gt; GetDiameters()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; Wheels.Select(wheel =&amp;gt; wheel.Rim + (wheel.Tire * &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;));
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// Now everyone can send rim/tire to wheel.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;record&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Wheel&lt;/span&gt;(&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt; Rim, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt; Tire);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;private&lt;/span&gt; IEnumerable&amp;lt;Wheel&amp;gt; Wheelify(&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt;[][] data)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; data.Select(cell =&amp;gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;new&lt;/span&gt; Wheel(cell[&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;], cell[&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;]));
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;ol start=&#34;31&#34;&gt;
&lt;li&gt;&lt;strong&gt;Enforce single responsibility everywhere: extract extra responsibilities from methods.&lt;/strong&gt; Methods should also have a single responsibility. Just like classes, that makes them easy to reuse, change, and understand.&lt;/li&gt;
&lt;li&gt;To determine if a method has a single responsibility, the same techniques that work for classes apply. Try to enunciate their purpose in a single sentence, and ask them what they do.&lt;/li&gt;
&lt;li&gt;Methods that iterate on items and act upon them too are a common case of multiple responsibilities. Separating iteration and action into two methods is a common refactoring to correct it.&lt;/li&gt;
&lt;li&gt;Complex calculations embedded within methods are also good candidates to be separated into other methods. It gives them a name and makes them reusable.&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;For example, instead of this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;IEnumerable&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt;&amp;gt; GetDiameters()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; Wheels.Select(wheel =&amp;gt; wheel.Rim + (wheel.Tire * &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;));
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&amp;hellip;do this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// First - iterate over the collection.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;IEnumerable&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt;&amp;gt; _GetDiameters()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; Wheels.Select(wheel =&amp;gt; GetDiameter(wheel));
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// Second - calculate diameter of ONE wheel.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt; GetDiameter(Wheel wheel)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; wheel.Rim + (wheel.Tire * &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;ol start=&#34;35&#34;&gt;
&lt;li&gt;These refactorings are useful and necessary even when you don&amp;rsquo;t know what the final design will look like. In fact, these refactorings (and good practices like these) will often reveal the final design.&lt;/li&gt;
&lt;li&gt;Small methods with a single responsibility have many benefits. They make a class&amp;rsquo;s details, features, and components more obvious, they are self-documenting, encourage reuse, establish a style of programming that is self-perpetuating, become easy to move to another class when and if that time comes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Enforce single responsibility everywhere: isolate extra responsibilities in classes.&lt;/strong&gt; Move the responsibilities that are extraneous to a class into another class. If you can afford it, create a separate class to hold them. If not, at least encapsulate them in an embedded class so that they are contained and don&amp;rsquo;t leak.&lt;/li&gt;
&lt;li&gt;Embedded classes say: This class only has meaning and value when thought about within the context of this other class.&lt;/li&gt;
&lt;li&gt;Embedded classes can be easily promoted to independent classes later if the need arises.&lt;/li&gt;
&lt;li&gt;Once all methods inside a class have a single responsibility and are each doing the smallest useful thing, it becomes easier to identify the features that may belong to another class.&lt;/li&gt;
&lt;li&gt;The purpose of design is not to produce &amp;ldquo;perfect&amp;rdquo; code but instead to produce code that&amp;rsquo;s &amp;ldquo;good enough&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;The Single Responsibility Principle &amp;ldquo;allows change without consequence and reuse without duplication&amp;rdquo;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;chapter-3-managing-dependencies&#34;&gt;Chapter 3: Managing Dependencies&lt;/h3&gt;
&lt;h4 id=&#34;about-dependencies&#34;&gt;About dependencies&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;Objects should have a single responsibility and do the smallest useful thing. This means that, in order to fulfill complex application requirements, objects need to collaborate with one another.&lt;/li&gt;
&lt;li&gt;Objects collaborate by knowing things about and sending messages to each other. That creates &lt;strong&gt;dependencies&lt;/strong&gt;. A good design manages these dependencies, making sure they don&amp;rsquo;t couple objects so much that change becomes painful.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Coupling&lt;/strong&gt; measures how much interdependency exists between software components. High coupling makes things hard to change.&lt;/li&gt;
&lt;li&gt;An object has a dependency when it knows &lt;strong&gt;the name of another class&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;An object has a dependency when it knows &lt;strong&gt;the name of a method from another class&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;An object has a dependency when it knows &lt;strong&gt;the arguments of that method&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;An object has a dependency when it knows &lt;strong&gt;the order of those arguments&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Dependencies create a situation where if an object changes, then other objects that depend on it may be forced to change as well.&lt;/li&gt;
&lt;li&gt;Dependencies couple objects to each other. Highly coupled objects behave as if they were a unit. It becomes hard to reuse one without the other. If not managed properly, dependencies will disseminate and entangle the entire code base.&lt;/li&gt;
&lt;li&gt;Some dependencies are unavoidable. So the purpose of design is to reduce and contain dependencies. Ensure objects only have the minimum number of dependencies that they need to do their jobs. Keep the essential ones, remove the rest.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;techniques-for-writing-loosely-coupled-code&#34;&gt;Techniques for writing loosely coupled code&lt;/h4&gt;
&lt;ol start=&#34;11&#34;&gt;
&lt;li&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Dependency_injection&#34;&gt;&lt;strong&gt;Dependency injection&lt;/strong&gt;&lt;/a&gt;. It can help eliminate dependencies on concrete classes. Instead of instantiating new objects of another class inside your object, let the object receive it as a constructor or method parameter. The object&amp;rsquo;s users can do the instantiation.&lt;/li&gt;
&lt;li&gt;An object that knows less can often times do more. The knowledge of how to instantiate a particular object limits its potential. Object creation and utilization don&amp;rsquo;t need to be contained within the same unit of code.&lt;/li&gt;
&lt;li&gt;When an object hard-codes the reference to a class, it advertises that it can&amp;rsquo;t work with any other type. Replace the reference to the concrete class with an abstraction (e.g. an &lt;a href=&#34;https://en.wikipedia.org/wiki/Interface_(object-oriented_programming)&#34;&gt;interface&lt;/a&gt; or &lt;a href=&#34;https://en.wikipedia.org/wiki/Duck_typing&#34;&gt;duck type&lt;/a&gt;). That gives it the flexibility to be able to collaborate with other objects that respond to the same messages.&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;With dependency injection you can turn this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Gear&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;float&lt;/span&gt; Ratio { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt; Rim { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt; Tire { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; Gear(&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;float&lt;/span&gt; ratio, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt; rim, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt; tire)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        Ratio = ratio;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        Rim = rim;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        Tire = tire;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;float&lt;/span&gt; GetGearInches()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; Ratio * &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;new&lt;/span&gt; Wheel(Rim, Tire).GetDiameter();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Into this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Gear&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;float&lt;/span&gt; Ratio { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    Wheel Wheel { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// Instead of rim and tire, Gear&amp;#39;s constructor now receives a wheel.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; Gear(&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;float&lt;/span&gt; ratio, Wheel wheel)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        Ratio = ratio;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        Wheel = wheel;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;float&lt;/span&gt; GetGearInches()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#888&#34;&gt;// Instead of creating a new wheel, it uses the one that&amp;#39;s been injected.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; Ratio * Wheel.GetDiameter();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;ol start=&#34;14&#34;&gt;
&lt;li&gt;Sometimes it is not possible to remove a dependency from an object. In those cases, your best bet is to isolate it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Isolate dependencies: isolate instance creation&lt;/strong&gt;. Sometimes it is not possible to apply dependency injection. In those cases, the next best thing is to encapsulate instantiation of external classes into their own methods.&lt;/li&gt;
&lt;li&gt;An instantiation encapsulated in a method allows the code to clearly and explicitly communicate that there&amp;rsquo;s an extraneous dependency here. One that we&amp;rsquo;d like to remove but for now cannot. We also protect the class from that dependency propagating through it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Isolate dependencies: isolate vulnerable external messages&lt;/strong&gt;. The same technique can be applied to invocations of methods on external classes. Encapsulate such calls into their own methods in order to contain the dependency.&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;Here&amp;rsquo;s what isolating some dependencies could look like. From this&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;float&lt;/span&gt; GetGearInches()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; Ratio * &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;new&lt;/span&gt; Wheel(Rim, Tire).GetDiameter();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&amp;hellip;to this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;float&lt;/span&gt; GetGearInches()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; Ratio * GetWheelDiameter();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// The dependency on the Wheel class is isolated in this method.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;int&lt;/span&gt; GetWheelDiameter()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;new&lt;/span&gt; Wheel(Rim, Tire).GetDiameter();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;ol start=&#34;18&#34;&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reduce argument dependencies: use keyword arguments&lt;/strong&gt;. If your language supports them, keyword arguments are a great way of reducing the dependency incurred via method invocations. They allow the parameters to be sent in any order, which means that changes to the method&amp;rsquo;s definition and signature are less likely to cause the callers to have to also change. Also, they have a self-documenting property on both caller and callee. (See &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/named-and-optional-arguments&#34;&gt;named arguments in C#&lt;/a&gt; and &lt;a href=&#34;https://thoughtbot.com/blog/ruby-2-keyword-arguments&#34;&gt;keyword arguments in Ruby&lt;/a&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reduce argument dependencies: explicitly define defaults&lt;/strong&gt;. If your language has the feature, parameter defaults are a great way of reducing dependencies to method parameters, as establishing a default for a parameter makes it optional.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reduce argument dependencies: isolate multiparameter initialization&lt;/strong&gt;. If you don&amp;rsquo;t own the code for a complex object initialization or method invocation, you can always encapsulate it in an object or method of your own. It can be done with a thin wrapper that exposes an interface that follows the techniques we&amp;rsquo;ve discussed and that uses the language of your application.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Classes should depend on things that change less often than they do.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;There are three truths about code related to change and dependencies:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&amp;ldquo;Some classes are more likely to change than others&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Concrete classes are more likely to change than abstract classes&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Changing a class that has many dependents will have many consequences&amp;rdquo;.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It&amp;rsquo;s OK to depend on classes with a low likelihood of change. For example, classes in the built-in library of your language generally will change less than your own custom classes. Framework classes commonly change less often too, but that may not always be the case if you framework is new or rapidly evolving.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Abstractions are generally much more stable than concretions. Because of this, &lt;strong&gt;it is safer to depend on abstract classes&lt;/strong&gt; (e.g. interfaces and duck types) than on concrete ones.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Avoid classes that have lots of dependencies. Any changes done to them produce a ripple effect of changes throughout the code base. Also, because of that, people will go through great lengths to try to avoid changing them.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When thinking about dependents and likelihood of change, &lt;strong&gt;the following are harmless&lt;/strong&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Classes with few dependents and low likelihood of change (e.g. specialized infrastructure interaction classes).&lt;/li&gt;
&lt;li&gt;Classes with few dependents and high likelihood of change (e.g. concrete classes that implement your app&amp;rsquo;s domain logic).&lt;/li&gt;
&lt;li&gt;Classes with many dependents and low likelihood of change (e.g. interfaces and other abstractions).&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When thinking about dependents and likelihood of change, &lt;strong&gt;the following is harmful&lt;/strong&gt;: Classes with many dependents and high likelihood of change (e.g. concrete classes that are used throughout the code base).&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2024/02/key-takeaways-from-poodr/likelihood-of-change-versus-number-of-dependents.webp&#34; alt=&#34;A graph divided into four cells. The y axis is labeled &amp;ldquo;dependents&amp;rdquo;, from Few to Many. The x axis is labeled &amp;ldquo;Likelihood of requirements change&amp;rdquo;, from Less to More. The cell with less likelihood of requirements change and many dependents reads &amp;ldquo;Abstract Zone: Changes are unlikely but, if they occur, will have broad effects.&amp;rdquo; The cell with less likelihood of requirements change and fewer dependents reads &amp;ldquo;Neutral Zone: Changes are unlikely and have few side effects.&amp;rdquo; The cell with more likelihood of requirements change and few dependents reads &amp;ldquo;Neutral Zone: Changes are likely but they have few side effects.&amp;rdquo; The cell with more likelihood of requirements change and many dependents reads &amp;ldquo;Danger Zone: These classes WILL change and the changes will cascade into dependents.&amp;rdquo;&#34;&gt;&lt;/p&gt;
&lt;h3 id=&#34;chapter-4-creating-flexible-interfaces&#34;&gt;Chapter 4: Creating Flexible Interfaces&lt;/h3&gt;
&lt;h4 id=&#34;about-interfaces&#34;&gt;About interfaces&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;The messages that objects pass between each other are a big concern for design. In addition to what objects know (responsibilities), and who they know (dependencies), design cares about how they talk to one another. Messages pass between objects through their interfaces.&lt;/li&gt;
&lt;li&gt;In a well designed application, the messages that pass between objects follow a pattern that&amp;rsquo;s closer to the diagram on the right than that of the diagram on the left:&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2024/02/key-takeaways-from-poodr/communication-patterns.webp&#34; alt=&#34;On the left, many dots are connected by a complex network of single-direction arrows. Dots have several arrows pointing to and from them. On the right, the same dots are connected by a single arrow to each. Each dot either has one or more arrows pointing away from it, or a single arrow pointing to it.&#34;&gt;&lt;/p&gt;
&lt;ol start=&#34;3&#34;&gt;
&lt;li&gt;
&lt;p&gt;Objects that expose too much of themselves and know too much about others are hard to reuse and make systems hard to change.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Objects that minimize what they expose of themselves and know little about others are easily reusable and changeable.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;An object&amp;rsquo;s &lt;strong&gt;public interface&lt;/strong&gt; is the set of messages that it responds to. That is, the set of methods that other objects are welcome to invoke. Good design calls for objects with clear and concise public interfaces.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Classes should have one responsibility, but they will likely have many methods. Some methods are more general and expose the main features of a class; they are the services that the class offers its callers. These should make up the class&amp;rsquo;s public interface. Other methods are more specific, serve to support those features, and contain implementation details internal to the class and uninteresting to callers. These make up the class&amp;rsquo;s private interface.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The methods in a class&amp;rsquo;s public interface&lt;/strong&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&amp;ldquo;Reveal its primary responsibility&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Are expected to be invoked by others&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Are not likely to change&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Are safe for others to depend on&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Are directly covered by tests&amp;rdquo;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The methods in a class&amp;rsquo;s private interface&lt;/strong&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&amp;ldquo;Handle implementation details&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Are not expected to be invoked by other objects&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Are likely to change&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Are unsafe for others to depend on&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&amp;ldquo;May not even be referenced in the tests&amp;rdquo;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Public methods list the specific features of a class that allow it to fulfill its responsibility. They advertise to the world what the purpose of the class they belong to is.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Public methods are stable and are expected to not change often, so others are welcome to depend on them.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Private methods are not stable at all. They are hidden from others so nobody should depend on them.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;discovering-less-obvious-objects-and-messages&#34;&gt;Discovering less obvious objects and messages&lt;/h4&gt;
&lt;ol start=&#34;12&#34;&gt;
&lt;li&gt;When analyzing a problem domain, the nouns in the narrative usually become your first classes. These are called &amp;ldquo;&lt;strong&gt;domain objects&lt;/strong&gt;&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Don&amp;rsquo;t let domain objects be your only classes, though. Shift your focus toward messages and away from classes to discover new, less obvious objects that will implement key functionality. Not doing so will risk overloading your domain objects with more responsibility than what they can handle.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Sequence_diagram&#34;&gt;UML sequence diagrams&lt;/a&gt; are an excellent way to explore design alternatives. You can use them to draft objects and their interactions, i.e. the messages they send each other. They are quick, low cost, and allow easy communication of ideas between team members. Here&amp;rsquo;s an online tool that generates them based on plain text: &lt;a href=&#34;https://sequencediagram.org/&#34;&gt;sequencediagram.org&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The transition from class-based design to message-based design is one that yields more flexible applications. It means asking &amp;ldquo;I need to send this message, who should respond to it?&amp;rdquo; instead of &amp;ldquo;I know I need this class, what should it do?&amp;rdquo;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;focusing-on-what-instead-of-how&#34;&gt;Focusing on &amp;ldquo;what&amp;rdquo; instead of &amp;ldquo;how&amp;rdquo;&lt;/h4&gt;
&lt;ol start=&#34;16&#34;&gt;
&lt;li&gt;Public methods should focus on &amp;ldquo;what&amp;rdquo; instead of &amp;ldquo;how&amp;rdquo;. That is, they should express what the caller wants instead of how the callee must behave.&lt;/li&gt;
&lt;li&gt;If you&amp;rsquo;re in a situation where an object calls many methods on another in succession, try to refactor so that all the logic is executed as a result of a single message. This consolidation reduces the size of the second object&amp;rsquo;s public interface, which reduces what callers need to know about it, which reduces dependency, which makes change easier. The caller only knows &amp;ldquo;what&amp;rdquo; it needs, not &amp;ldquo;how&amp;rdquo; to make the callee deliver.&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;When focusing on &amp;ldquo;what&amp;rdquo; instead of &amp;ldquo;how&amp;rdquo;, code like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Trip&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    IEnumerable&amp;lt;Bicycle&amp;gt; Bicycles { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    Mechanic Mechanic { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; Prepare()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;foreach&lt;/span&gt; (&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;var&lt;/span&gt; bike &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;in&lt;/span&gt; Bicycles)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            Mechanic.CleanBicyble(bike);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            Mechanic.PumpTires(bike);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            Mechanic.LubeChain(bike);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            Mechanic.CheckBrakes(bike);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Mechanic&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; CheckBrakes(Bicycle bike) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; CleanBicyble(Bicycle bike) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; LubeChain(Bicycle bike) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; PumpTires(Bicycle bike) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Can be transformed into code like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Trip&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    IEnumerable&amp;lt;Bicycle&amp;gt; Bicycles { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    Mechanic Mechanic { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// This method was greatly simplified and its dependencies were reduced.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; Prepare()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;foreach&lt;/span&gt; (&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;var&lt;/span&gt; bike &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;in&lt;/span&gt; Bicycles)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            Mechanic.PrepareBicycle(bike);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Mechanic&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; PrepareBicycle(Bicycle bike)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        CleanBicyble(bike);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        PumpTires(bike);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        LubeChain(bike);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        CheckBrakes(bike);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// Notice how Mechanic&amp;#39;s public interface was reduced considerably.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// All of these methods are private now.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; CheckBrakes(Bicycle bike) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; CleanBicyble(Bicycle bike) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; LubeChain(Bicycle bike) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; PumpTires(Bicycle bike) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;h4 id=&#34;liberate-objects-from-their-context&#34;&gt;Liberate objects from their context&lt;/h4&gt;
&lt;ol start=&#34;18&#34;&gt;
&lt;li&gt;An object&amp;rsquo;s context is made up of the things that an object knows about others. What other objects it calls and how. What it needs in order to be able to work.&lt;/li&gt;
&lt;li&gt;A good design tries to allow objects to work with minimal context. &amp;ldquo;Objects that have a simple context are easy to use and easy to test; they expect few things from their surroundings. Objects that have a complicated context are hard to use and hard to test; they require complicated setup before they can do anything&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;In order to reduce context, we need to reduce the knowledge that callers have about the other components they call. A simple public interface helps with that. In practical terms that means fewer and less verbose methods, fewer parameters, fewer dependencies.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Objects need to trust their collaborators to do their part&lt;/strong&gt;. Focusing on what the caller wants instead of what the callee does is a way of keeping context in check. This allows objects to collaborate with others regardless of what type they are and what they do.&lt;/li&gt;
&lt;li&gt;Dependency injection is a mechanism through which objects can collaborate with others when they don&amp;rsquo;t know their type. A dependency injected via parameter (declared as an interface or duck type) hides its identity from its user.&lt;/li&gt;
&lt;li&gt;Naming the methods of this injected dependency from the perspective of the caller reveals a generic interface that offers the features that the caller wants in the vocabulary that it understands. The caller does not need to know what the injected dependency does, only what it needs it to do.&lt;/li&gt;
&lt;li&gt;Highly coupled objects with verbose public interfaces say to their collaborators: &amp;ldquo;I know what I want, and I know how you do it&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;More decoupled objects with concise public interfaces say to their collaborators: &amp;ldquo;I know what I want, and I know what you do&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Highly decoupled objects with concise public interface and minimal required context say to their collaborators: &amp;ldquo;I know what I want, and I trust you to do your part&amp;rdquo;.&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;When objects trust their collaborators, and focus on what they want instead of what others do, the previous Trip/​Mechanic example can become like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Trip&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; IEnumerable&amp;lt;Bicycle&amp;gt; Bicycles { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    Mechanic Mechanic { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; Prepare()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#888&#34;&gt;// Trip now fully trusts Mechanic, and doesn&amp;#39;t even know what it does.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        Mechanic.PrepareTrip(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;this&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Mechanic&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// The knowledge of &amp;#34;how a mechanic prepares a trip&amp;#34; now completely lives&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// within Mechanic.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; PrepareTrip(Trip trip)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;foreach&lt;/span&gt; (&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;var&lt;/span&gt; bike &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;in&lt;/span&gt; trip.Bicycles)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            PrepareBicycle(bike);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; PrepareBicycle(Bicycle bike)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        CleanBicyble(bike);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        PumpTires(bike);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        LubeChain(bike);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        CheckBrakes(bike);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; CheckBrakes(Bicycle bike) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; CleanBicyble(Bicycle bike) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; LubeChain(Bicycle bike) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; PumpTires(Bicycle bike) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;h4 id=&#34;rules-of-thumb-for-writing-code-with-good-interfaces&#34;&gt;Rules of thumb for writing code with good interfaces&lt;/h4&gt;
&lt;ol start=&#34;27&#34;&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create explicit interfaces&lt;/strong&gt;. Be intentional and obvious when defining public and private methods. Use your language access modifiers (i.e. public, private, protected, etc). Your public methods should:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Be explicitly identified as such&lt;/li&gt;
&lt;li&gt;Be more about what than how&lt;/li&gt;
&lt;li&gt;Have names that are unlikely to change&lt;/li&gt;
&lt;li&gt;Use keyword arguments&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Respect the public interface of others&lt;/strong&gt;. Invoke only public methods on the classes that you use. Avoid circumventing their public interfaces and directly calling private members. Depending on the private interface of framework and library classes is like a ticking time bomb. The reason they are private is because they are expected to change or disappear entirely.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Minimize context&lt;/strong&gt;. Focus on &amp;ldquo;what&amp;rdquo; instead of &amp;ldquo;how&amp;rdquo; when designing public interfaces. Favor public methods that allow callers to access your classes&amp;rsquo; functionality without having to know how they do it. Use interface and duck types to name methods from the perspective of and with the vocabulary of the callers.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you have to interact with a class that does not have a clean interface, and you don&amp;rsquo;t own it or otherwise can&amp;rsquo;t refactor it so that it does, isolate it. Use the same techniques for dependency isolation mentioned in Chapter 3. Wrap the invocation in a new class or method to contain it and give that wrapper a clean public interface.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Follow the law of Demeter&lt;/strong&gt;. The law of Demeter states that you shouldn&amp;rsquo;t chain multiple method calls that navigate across many different types of objects. In other words &amp;ldquo;talk only to your close neighbors&amp;rdquo; or &amp;ldquo;use only one dot&amp;rdquo;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;Violations ot the law of Demeter look like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;customer.GetBicycle().Wheel.Rotate();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;ol start=&#34;32&#34;&gt;
&lt;li&gt;Violations of the law of Demeter make for code that&amp;rsquo;s not TRUE. Changes in the object at the end of the chain ripple through the entire chain. This is unexpected and laborious, making the code neither Transparent nor Reasonable. The class that uses the chain depends on all the objects in the chain, making it non-Usable. These chains are easy to replicate and harm changeability, making the code not Exemplary.&lt;/li&gt;
&lt;li&gt;Always evaluate the cost of violating the law of Demeter versus the cost of abiding by it. Method chains that ultimately read an attribute are generally less harmful. Also, method chains on really stable classes like those of your language library or framework have low impact.&lt;/li&gt;
&lt;li&gt;Delegation can appear to be a solution to law of Demeter violations. Unfortunately, all it does is remove the evidence that it&amp;rsquo;s there.&lt;/li&gt;
&lt;li&gt;In reality, a violation to the law of Demeter indicates that there&amp;rsquo;s an object missing or that the public interface of an object is lacking. Find the object, and its interface, by thinking more about messages and less about classes. Define the interface by thinking about what the object needs of its collaborators, and not about how it can get it by itself.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;chapter-5-reducing-costs-with-duck-typing&#34;&gt;Chapter 5: Reducing Costs with Duck Typing&lt;/h3&gt;
&lt;h4 id=&#34;about-duck-types&#34;&gt;About duck types&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Duck types&lt;/strong&gt; are public interfaces that manifest themselves across classes. When multiple classes accept the same messages (i.e. define methods with the same signature), they are said to be of the same duck type.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Duck type&amp;rdquo; is a dynamic language concept. Static languages offer equivalent features via &amp;ldquo;&lt;a href=&#34;https://en.wikipedia.org/wiki/Interface_(object-oriented_programming)&#34;&gt;interfaces&lt;/a&gt;&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;The difference is that, in statically typed languages, interfaces need to be explicitly defined in code and concrete classes need to explicitly implement them. On the other hand, duck types in dynamically typed languages need only be acknowledged in an abstract sense. They don&amp;rsquo;t have to be explicitly defined in code.&lt;/li&gt;
&lt;li&gt;Duck types and interfaces establish a contract. A set of messages that a given object is expected to be able to receive. A protocol that users of these objects can be confident that they will adhere to.&lt;/li&gt;
&lt;li&gt;Just as a class can implement multiple interfaces, an object can be of many duck types. That&amp;rsquo;s because interfaces and duck types materialize depending on the situation in which objects that implement them are used. The same object can be used in different places for different things. Each user will see the object from their own perspective, and each can expect it conform to a different interface. See the &lt;a href=&#34;https://en.wikipedia.org/wiki/Interface_segregation_principle&#34;&gt;interface segregation principle&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Moreover, code that depends on an interface or duck type is flexible enough to collaborate with any concrete class that implements that interface or duck type. See the &lt;a href=&#34;https://en.wikipedia.org/wiki/Liskov_substitution_principle&#34;&gt;Liskov substitution principle&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;As we&amp;rsquo;ve established, it&amp;rsquo;s better to depend on abstractions than to depend on concretions. So, users of an object should not care what its type is, only what it does. Behavior over identity. In other words, they should focus on messages and public interfaces, instead of specific classes. Duck types and interfaces bring to the forefront what an object does and abstracts away what it is.&lt;/li&gt;
&lt;li&gt;Applying duck types to a situation makes the code more abstract and less concrete. Concrete code is easier to understand but harder to extend. Abstract code is harder to understand at the beginning but easier to change. In the long run, abstract code tends to reduce maintenance costs.&lt;/li&gt;
&lt;li&gt;When an object invokes methods on multiple objects in order to achieve a single purpose, that&amp;rsquo;s a situation where a duck type may be helpful. Think from the perspective of the caller and what it needs to come up with a message that makes sense for it to send its many collaborators. That method should be part of the public interface of each of its collaborators. To the caller&amp;rsquo;s eyes, each of its collaborators belong in the same duck type.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;writing-code-that-leverages-duck-types&#34;&gt;Writing code that leverages duck types&lt;/h4&gt;
&lt;ol start=&#34;10&#34;&gt;
&lt;li&gt;Whenever you see conditional logic that sends a different message depending on the concrete class of a given object, that&amp;rsquo;s the code telling you that it needs a duck type or interface.&lt;/li&gt;
&lt;li&gt;Come up with a message that makes sense from the perspective of the caller and add it to each of the classes expected by your code in the conditional. These classes now share the same public interface, they are of the same duck type. Then remove the conditional and just call that method. Replace conditional logic with &lt;a href=&#34;https://en.wikipedia.org/wiki/Polymorphism_(computer_science)&#34;&gt;polymorphism&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;In general, try to avoid code that explicitly mentions concrete classes or checks for the existence of particular methods in order to determine further behavior. Instead, come up with a shared interface and send those messages to the collaborators regardless of their actual type.&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;Higly conditional and concrete logic like this&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Trip&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; IEnumerable&amp;lt;Bicycle&amp;gt; Bicycles { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; IEnumerable&amp;lt;Customer&amp;gt; Customers { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; Vehicle Vehicle { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; Prepare(IEnumerable preparers)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;foreach&lt;/span&gt; (&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;var&lt;/span&gt; preparer &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;in&lt;/span&gt; preparers)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (preparer &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;is&lt;/span&gt; Mechanic)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                ((Mechanic)preparer).PrepareBicycles(Bicycles);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;else&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (preparer &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;is&lt;/span&gt; TripCoordinator)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                ((TripCoordinator)preparer).BuyFood(Customers);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;else&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (preparer &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;is&lt;/span&gt; Driver)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                ((Driver)preparer).GasUp(Vehicle);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                ((Driver)preparer).FillWaterTank(Vehicle);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Mechanic&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; PrepareBicycles(IEnumerable&amp;lt;Bicycle&amp;gt; bicycles) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;TripCoordinator&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; BuyFood(IEnumerable&amp;lt;Customer&amp;gt; customers) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Driver&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; FillWaterTank(Vehicle vehicle) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; GasUp(Vehicle vehicle) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&amp;hellip;can be rewritten to be more abstract if we leverage polymorphism. Like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Trip&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; IEnumerable&amp;lt;Bicycle&amp;gt; Bicycles { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; IEnumerable&amp;lt;Customer&amp;gt; Customers { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; Vehicle Vehicle { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// This method can be much simpler now, and abstract.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// Ready to collaborate with any &amp;#34;TripPreparer&amp;#34;.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// The conditional logic has been replaced with polymorphism.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; Prepare(IEnumerable&amp;lt;ITripPreparer&amp;gt; preparers)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;foreach&lt;/span&gt; (&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;var&lt;/span&gt; preparer &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;in&lt;/span&gt; preparers)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            preparer.PrepareTrip(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;this&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// New interface that all preparers implement. It has a single method.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// It greatly simplifies the communication between Trip and its many&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// possible preparers.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;interface&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;ITripPreparer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; PrepareTrip(Trip trip);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Mechanic&lt;/span&gt; : ITripPreparer
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; PrepareTrip(Trip trip)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        PrepareBicycles(trip.Bicycles);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; PrepareBicycles(IEnumerable&amp;lt;Bicycle&amp;gt; bicycles) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;TripCoordinator&lt;/span&gt; : ITripPreparer
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; PrepareTrip(Trip trip)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        BuyFood(trip.Customers);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; BuyFood(IEnumerable&amp;lt;Customer&amp;gt; customers) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Driver&lt;/span&gt; : ITripPreparer
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; PrepareTrip(Trip trip)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        FillWaterTank(trip.Vehicle);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        GasUp(trip.Vehicle);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; FillWaterTank(Vehicle vehicle) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; GasUp(Vehicle vehicle) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;ol start=&#34;13&#34;&gt;
&lt;li&gt;The one exception to this rule is when dealing with exceptionally stable classes. Like those in your language libraries, where the introduction of duck types would mean modifying core language libraries. Explicit type checks against these classes are usually low cost.&lt;/li&gt;
&lt;li&gt;Duck types are abstract and less obvious in the code. That&amp;rsquo;s why they need to be well documented and tested.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;chapter-6-acquiring-behavior-through-inheritance&#34;&gt;Chapter 6: Acquiring Behavior through Inheritance&lt;/h3&gt;
&lt;h4 id=&#34;about-inheritance&#34;&gt;About inheritance&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Inheritance&lt;/strong&gt; establishes a relationship between two classes where it is said that a subclass B &amp;ldquo;is a&amp;rdquo; superclass A. Subclass and superclass are also referred to as derived class and base class, respectively.&lt;/li&gt;
&lt;li&gt;Inheritance can be more technically defined as an &amp;ldquo;automatic message forwarding mechanism&amp;rdquo;. That is, when a subclass receives a message that it cannot respond to directly (i.e. a method that it does not implement), the language runtime takes care of automatically sending the message to the superclass.&lt;/li&gt;
&lt;li&gt;That is, inheritance establishes a hierarchy where superclasses share their code with their subclasses.&lt;/li&gt;
&lt;li&gt;Subclasses are meant to be specialized versions of their superclass. Subclasses should be &amp;ldquo;the same, plus more&amp;rdquo; when compared to their superclass. They should offer the same public interface.&lt;/li&gt;
&lt;li&gt;Inheritance is ideal to solve the problem where you need a series of slightly different classes that share a lot of behavior.&lt;/li&gt;
&lt;li&gt;A telltale sign that inheritance needs to be applied is when code contains an &amp;ldquo;if&amp;rdquo; statement checking an attribute that contains the &amp;ldquo;category&amp;rdquo; of the object, and based on that determines what code to execute. Watch out for this anti-pattern and for variables with names like &amp;ldquo;type&amp;rdquo;, &amp;ldquo;category&amp;rdquo;, &amp;ldquo;style&amp;rdquo; that control branches in behavior.&lt;/li&gt;
&lt;li&gt;This is an anti-pattern that reveals that the object knows too much and needs to be broken down into smaller pieces. It increases the costs of change.&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;Here&amp;rsquo;s what the anti-pattern looks like:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Bicycle&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; Style { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; TapeColor { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; FrontShock { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; Bicycle(Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; options)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        Style = options[&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;style&amp;#34;&lt;/span&gt;];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        TapeColor  = options[&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;tape_color&amp;#34;&lt;/span&gt;];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        FrontShock = options[&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;front_shock&amp;#34;&lt;/span&gt;];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// Checking &amp;#39;style&amp;#39; starts down a slippery slope.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; GetSpares()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (Style == &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;road&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;new&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;                [&amp;#34;chain&amp;#34;]&lt;/span&gt; = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;11-speed&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;                [&amp;#34;tire_size&amp;#34;]&lt;/span&gt; = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;23&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;                [&amp;#34;tape_color&amp;#34;]&lt;/span&gt; = TapeColor
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            };
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;else&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (Style == &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;mountain&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;new&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;                [&amp;#34;chain&amp;#34;]&lt;/span&gt; = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;11-speed&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;                [&amp;#34;tire_size&amp;#34;]&lt;/span&gt; = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;2.1&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;                [&amp;#34;front_shock&amp;#34;]&lt;/span&gt; = FrontShock
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            };
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;h4 id=&#34;applying-inheritance&#34;&gt;Applying inheritance&lt;/h4&gt;
&lt;ol start=&#34;8&#34;&gt;
&lt;li&gt;Be on the lookout for existing classes that may lead you down the wrong path when it comes to inheritance. More often than not, classes that already exist in the code base are not good candidates for extension via inheritance. They are not good candidates to be superclasses.&lt;/li&gt;
&lt;li&gt;The path forward is likely to be a new class to serve as the base, and then update your existing class to be a subclass. Then add other subclasses as peers of it.&lt;/li&gt;
&lt;li&gt;For inheritance to work, the objects being modeled need to truly share a generalization-specialization relationship.&lt;/li&gt;
&lt;li&gt;The superclass needs to define the common behavior that is shared among subclasses. The subclasses define the specializations.&lt;/li&gt;
&lt;li&gt;In many cases, the superclass should be &lt;strong&gt;abstract&lt;/strong&gt;, meaning that they are not supposed to be instantiated. They represent an incomplete object which only becomes whole when looked at in the context of each of its subclasses.&lt;/li&gt;
&lt;li&gt;It almost never makes sense to create a superclass with only a single subclass. In fact, creating an inheritance hierarchy with two subclasses is often risky. You risk coming up with the wrong abstraction.&lt;/li&gt;
&lt;li&gt;Three subclasses is the sweet spot to commit to inheritance. Put off the decision to implement inheritance until that point, if you can. That&amp;rsquo;s the point when there&amp;rsquo;s enough information available to confidently determine an abstraction that will be useful and cost effective.&lt;/li&gt;
&lt;li&gt;If you put off implementing an inheritance hierarchy, then you won&amp;rsquo;t be able to share code between the highly related classes. That will likely lead to code repetition, which is also costly. Consider what costs more: having the repetition for the time being; or doing nothing and waiting for more information to avoid making the wrong decision.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Every decision you make includes two costs: one to implement it and another to change it when you discover that you were wrong&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;When refactoring towards an inheritance hierarchy, consider that &amp;ldquo;promoting&amp;rdquo; code from the concrete subclass up into the abstract superclass is often easier and less error prone.&lt;/li&gt;
&lt;li&gt;Errors in promoting are easy to identify and fix. All that can happen if you miss a promotion is that a subclass that was meant to inherit some behavior won&amp;rsquo;t have it.&lt;/li&gt;
&lt;li&gt;Going in the opposite direction and missing a &amp;ldquo;demotion&amp;rdquo; will produce design errors that are harder to spot and have dire consequences if left alone.&lt;/li&gt;
&lt;li&gt;That would mean that concrete behavior, which does not apply to all subclasses, stays incorrectly in the abstract base class. That&amp;rsquo;ll throw a wrench in the works and the whole inheritance hierarchy will be on shaky grounds. The abstract base class won&amp;rsquo;t be generic enough and subclasses will be tempted to circumvent it.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;The general rule for refactoring into a new inheritance hierarchy is to arrange code so that you can promote abstractions rather than demote concretions&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&#34;https://en.wikipedia.org/wiki/Template_method_pattern&#34;&gt;template method pattern&lt;/a&gt; provides a clean way of defining a common basic algorithm in the superclass and allowing subclasses to supply specializations for it. Superclasses can define an algorithm, and call certain methods in key points within it. These are extension points. These methods can then be implemented by subclasses, letting them control part of the overall logic.&lt;/li&gt;
&lt;li&gt;When promoting concrete code to the more abstract superclass, consider using the template method when methods cannot be promoted wholesale, and have to be broken up instead. The parts that can be promoted become the template method; the parts that can&amp;rsquo;t be become the specialization methods that each concrete subclass implements.&lt;/li&gt;
&lt;li&gt;To avoid future bugs, superclasses should provide default implementations for the specialization methods that it expects its subclasses to implement. These can be no-ops or, even better, raise errors. These errors let developers know that extending this inheritance hierarchy requires these methods to be implemented.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.geeksforgeeks.org/ruby-hook-methods/&#34;&gt;Hook methods&lt;/a&gt; are a slightly lighter iteration of the template method concept that helps alleviate superclass-subclass coupling. Same principle: let the superclass send a message that the subclass implements in order to provide a specialization.&lt;/li&gt;
&lt;li&gt;A hook method need not be a part of a common abstract algorithm, hence the slight distinction from the full fledged template method design pattern.&lt;/li&gt;
&lt;li&gt;Beware of subclasses explicitly invoking functionality on their superclasses. Languages often offer keywords such as &amp;ldquo;&lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/base&#34;&gt;base&lt;/a&gt;&amp;rdquo; or &amp;ldquo;&lt;a href=&#34;https://www.rubyguides.com/2018/09/ruby-super-keyword/&#34;&gt;super&lt;/a&gt;&amp;rdquo; that allow easily sending messages to superclasses. These are dangerous because they couple subclasses with their superclasses. They reveal that subclasses know the general algorithm.&lt;/li&gt;
&lt;li&gt;The template method pattern and hook methods invert this dependency, allowing the superclass to call the subclass. Allowing the subclass to provide specializations without knowing too much about the superclass.&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;Here&amp;rsquo;s an example of a properly factored inheritance hierarchy:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// The main purpose of the base class is to establish a basic functionality&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// that can be easily extended by subclasses.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// This class cannot be instantiated, as given by the &amp;#34;abstract&amp;#34; modifier.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// This means that our application has no need of holding onto pure Bicycle&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// instances, only the concrete subclasses are to be used.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// This abstract class is just a vehicle for sharing code between other classes.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;abstract&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Bicycle&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; Size { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; Chain { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; TireSize { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// Notice how this constructor implements the template method pattern&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// in order to allow subclasses to make changes to the overall algorithm.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// Specifically, it allows them to provide default values for the Chain and&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// TireSize attributes as well as run any additional logic after&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// initialization.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; Bicycle(Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; options)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        Size = options.GetValueOrDefault(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;size&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        Chain  = options.GetValueOrDefault(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;chain&amp;#34;&lt;/span&gt;) ?? GetDefaultChain();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        TireSize = options.GetValueOrDefault(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;tire_size&amp;#34;&lt;/span&gt;) ?? GetDefaultTireSize();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        AfterInitialize(options);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// This method establishes the basic spares information and allows&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// subclasses to supply more by calling the GetLocalSpares hook method.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; GetSpares()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;var&lt;/span&gt; defaultSpares = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;            [&amp;#34;tire_size&amp;#34;]&lt;/span&gt; = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;23&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;            [&amp;#34;chain&amp;#34;]&lt;/span&gt; = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;11-speed&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        };
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;new&lt;/span&gt;(defaultSpares.Concat(GetLocalSpares()));
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// This method, which is marked as abstract, has to be implemented by&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// subclasses. It allows subclasses to contribute specializations.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;protected&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;abstract&lt;/span&gt; &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; GetDefaultTireSize();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// These methods, marked as virtual, all have default implementations of&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// varying complexity but the important aspect is that they can be&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// overridden by subclasses. They also allow subclasses to contribute&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;// specializations.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;protected&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;virtual&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; AfterInitialize(Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; options) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;protected&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;virtual&lt;/span&gt; Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; GetLocalSpares() =&amp;gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;new&lt;/span&gt;();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;protected&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;virtual&lt;/span&gt; &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; GetDefaultChain() =&amp;gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;11-speed&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// Notice how the following concrete subclasses are very simple.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// Extending this kind of code is easy, because creating new subclasses is easy.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// They leverage their abstract base class to implement most of their features.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// Their job is to supply specializations on the core logic defined in the base&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// class. To do so, they override the hook methods defined by the base class.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;RoadBike&lt;/span&gt; : Bicycle
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; TapeColor { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; RoadBike(Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; options) : &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;base&lt;/span&gt;(options) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;protected&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;override&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; AfterInitialize(Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; options) =&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        TapeColor = options.GetValueOrDefault(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;tape_color&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;protected&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;override&lt;/span&gt; Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; GetLocalSpares() =&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;new&lt;/span&gt;() { [&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;tape_color&amp;#34;&lt;/span&gt;] = TapeColor };
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;protected&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;override&lt;/span&gt; &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; GetDefaultTireSize() =&amp;gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;23&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;MountainBike&lt;/span&gt; : Bicycle
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; FrontShock { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; RearShock { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; MountainBike(Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; options) : &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;base&lt;/span&gt;(options) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;protected&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;override&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; AfterInitialize(Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; options)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        FrontShock = options.GetValueOrDefault(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;front_shock&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        RearShock = options.GetValueOrDefault(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;rear_shock&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;protected&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;override&lt;/span&gt; Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; GetLocalSpares() =&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;new&lt;/span&gt;() { [&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;front_shock&amp;#34;&lt;/span&gt;] = FrontShock };
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;protected&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;override&lt;/span&gt; &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; GetDefaultTireSize() =&amp;gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;2.1&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;RecumbentBike&lt;/span&gt; : Bicycle
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; Flag { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;set&lt;/span&gt;; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; RecumbentBike(Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; options) : &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;base&lt;/span&gt;(options) { }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;protected&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;override&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;void&lt;/span&gt; AfterInitialize(Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; options) =&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        Flag = options.GetValueOrDefault(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;flag&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;protected&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;override&lt;/span&gt; Dictionary&amp;lt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;, &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt;&amp;gt; GetLocalSpares() =&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;new&lt;/span&gt;() { [&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;flag&amp;#34;&lt;/span&gt;] = Flag };
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;protected&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;override&lt;/span&gt; &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; GetDefaultChain() =&amp;gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;10-speed&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;protected&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;override&lt;/span&gt; &lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;string&lt;/span&gt; GetDefaultTireSize() =&amp;gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;28&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;h3 id=&#34;chapter-7-sharing-role-behavior-with-modules&#34;&gt;Chapter 7: Sharing Role Behavior with Modules&lt;/h3&gt;
&lt;h4 id=&#34;about-roles&#34;&gt;About roles&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;Using classical inheritance is always optional. Every situation that calls for inheritance could be solved using another technique that allows for sharing code between otherwise unrelated classes.&lt;/li&gt;
&lt;li&gt;The concept of &amp;ldquo;&lt;strong&gt;roles&lt;/strong&gt;&amp;rdquo; is an alternative to classical inheritance. This concept emerges from the need of multiple classes to be used in a particular context to do the same thing. So they themselves need to share behavior.&lt;/li&gt;
&lt;li&gt;Think of a role as an augmented form of a duck type. A group of classes are said to play the same role when they belong in the same duck type or implement the same interface. In addition to exposing the same public interface, roles allow them to share internal behavior.&lt;/li&gt;
&lt;li&gt;Roles are ideal for storing responsibilities that are orthogonal to classes. It allows classes that are otherwise unrelated to share behavior. They establish a &amp;ldquo;behaves like&amp;rdquo; type of relationship between objects, as opposed to the &amp;ldquo;is a&amp;rdquo; relationship that is established with inheritance.&lt;/li&gt;
&lt;li&gt;When you include a module into an existing class, all the methods defined in the module become available to the class. This is the same thing that happens when a subclass inherits from a superclass.&lt;/li&gt;
&lt;li&gt;Many languages offer native features to allow for this kind of relationship between objects. In Ruby, we use &lt;a href=&#34;http://ruby-for-beginners.rubymonstas.org/advanced/modules.html&#34;&gt;Modules&lt;/a&gt;. Other languages use &lt;a href=&#34;https://www.pythontutorial.net/python-oop/python-mixin/&#34;&gt;Mixins&lt;/a&gt;, &lt;a href=&#34;https://www.php.net/manual/en/language.oop5.traits.php&#34;&gt;Traits&lt;/a&gt;, &lt;a href=&#34;https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html&#34;&gt;Default Methods&lt;/a&gt;. Simply put, all these are ways of bundling together a group of methods that can be easily plugged into existing classes.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;writing-inheritable-code&#34;&gt;Writing inheritable code&lt;/h4&gt;
&lt;ol start=&#34;7&#34;&gt;
&lt;li&gt;The same principles, techniques, and anti patterns that apply to the design of duck types and inheritance hierarchies also apply to roles.&lt;/li&gt;
&lt;li&gt;Beware of objects that use a variable with a name like &amp;ldquo;type&amp;rdquo;, &amp;ldquo;category&amp;rdquo; or &amp;ldquo;kind&amp;rdquo; to determine what code to execute. The object is likely concealing (and acting like) two or more types. These would be subclasses or module includers.&lt;/li&gt;
&lt;li&gt;When code is checking the type of an object to decide which message to send it, that&amp;rsquo;s a signal that there&amp;rsquo;s a missing abstraction. There&amp;rsquo;s a duck type or role in there that needs to be explicitly brought to light. A public interface needs to be defined for it. If there is a need to share behavior, put it in a module, mixin, etc.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;All of the code in the abstract superclass should apply to every class that inherits it&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Beware of subclasses or module includers that override a superclass/​module method just to raise a &amp;ldquo;not implemented&amp;rdquo; error. Chances are that if only part of the superclass applies to it, then it doesn&amp;rsquo;t belong in the hierarchy. Or maybe the whole hierarchy needs a redesign.&lt;/li&gt;
&lt;li&gt;Subclasses agree to the contract specified by their superclasses. They must respond to every message in the superclass&amp;rsquo;s public interface, accept the same types of inputs and return the same types outputs.&lt;/li&gt;
&lt;li&gt;Put in other words, &amp;ldquo;subtypes must be substitutable for their supertype&amp;rdquo;. That is, all subclasses should act like their superclass. This means that any code that expects a superclass should be able to work, without change, with all its subclasses as well. That&amp;rsquo;s the Liskov substitution principle.&lt;/li&gt;
&lt;li&gt;Through the concept of &lt;a href=&#34;https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)&#34;&gt;variance&lt;/a&gt;, subclasses have a slightly higher degree of freedom. Subclasses can accept inputs of more abstract types and can return outputs of more concrete types than those specified in the superclass&amp;rsquo;s public interface while still being substitutable for their superclass.&lt;/li&gt;
&lt;li&gt;For example, given a class &amp;ldquo;Object&amp;rdquo; that is a superclass of a class &amp;ldquo;String&amp;rdquo;; if a method in a superclass &amp;ldquo;MyClass&amp;rdquo; accepts a String parameter, a subclass of MyClass could override that same method and accept Object and still be compliant. Likewise, if a method in a superclass returns an Object result, the subclass could return a String for that same method, and still be compliant. Still be substitutable.&lt;/li&gt;
&lt;li&gt;In other words, some code that sends a message with a String parameter can send the same message to a receiver that accepts Object. Likewise, some code that expects an Object as a result of sending a message can send the same message to a receiver that returns a String. Because a String &amp;ldquo;is an&amp;rdquo; Object, any code that works with an Object can work with a String, it&amp;rsquo;ll just treat it like an Object and only access Object&amp;rsquo;s public interface, which String fully supports.&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;This is what variance allows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Superclass&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;virtual&lt;/span&gt; Object DoSomething(String parameter) =&amp;gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;new&lt;/span&gt; Object();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Subclass&lt;/span&gt; : Superclass
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;override&lt;/span&gt; String DoSomething(Object parameter) =&amp;gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;the result&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Be aware that C# currently does not support variance in parameters, only in return types. So this code would not actually work as it is, since the parameter types are different.&lt;/p&gt;&lt;/blockquote&gt;
&lt;ol start=&#34;17&#34;&gt;
&lt;li&gt;The template method pattern is the ideal technique for creating superclasses that are easy to inherit from. It allows clean separation of an abstract algorithm from the concrete specializations.&lt;/li&gt;
&lt;li&gt;Be on the lookout for code that directly invokes superclass behavior with keywords like &amp;ldquo;super&amp;rdquo; or &amp;ldquo;base&amp;rdquo; etc. Instead, use hook methods to allow subclasses to contribute to parts of the common algorithm.&lt;/li&gt;
&lt;li&gt;Favor shallow hierarchies instead of deep ones. Narrow is also preferable to wide. Wide ones are easier to live with as long as they are shallow. But deep and wide ones are a maintenance nightmare. That is, keep the vertical levels of inheritance as low as you can. Hierarchies with many layers of superclasses are hard to understand and maintain.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2024/02/key-takeaways-from-poodr/hierarchies-come-in-different-shapes.webp&#34; alt=&#34;Four diagrams show hierarchies of boxes. The top left is labeled &amp;ldquo;Shallow, Narrow&amp;rdquo; and has one box on top, with two boxes beneath, each connected to the top one by a line. The bottom left is labeled &amp;ldquo;Deep, Narrow&amp;rdquo; and shows the same diagram, but the box on the bottom left has two boxes of its own beneath it, one of which has its own boxes, et cetera, for a total of five layers, each with two boxes. The top right is labeled &amp;ldquo;Shallow, Wide&amp;rdquo;, and shows one box on top, with a single line connecting to each of five boxes directly beneath it. The bottom right is labeled &amp;ldquo;Deep, Wide&amp;rdquo;, and shows a 5-layer box diagram, with anywhere from 3 to 7 boxes on each level, connected by single lines. Different boxes have their own hierarchy, so boxes on the same level are not always direct siblings.&#34;&gt;&lt;/p&gt;
&lt;h3 id=&#34;chapter-8-combining-objects-with-composition&#34;&gt;Chapter 8: Combining Objects with Composition&lt;/h3&gt;
&lt;h4 id=&#34;about-composition&#34;&gt;About composition&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Composition&lt;/strong&gt; establishes a &amp;ldquo;has a&amp;rdquo; relationship between objects. It is a technique where you combine simple, independent objects to turn them into larger, more complex ones. Composition combines distinct parts so that the resulting entity is more than the sum of its parts.&lt;/li&gt;
&lt;li&gt;In composition, the container object (or composed object) &amp;ldquo;has a&amp;rdquo; contained component (or part). Mechanically, this usually means that the container&amp;rsquo;s class has an attribute which holds a reference to the part object. It&amp;rsquo;s a dependency that&amp;rsquo;s usually injected via constructor parameter.&lt;/li&gt;
&lt;li&gt;The container communicates with the part via its public interface. The part plays a role, and the container collaborates with it. This means that containers generally interact with their parts through interfaces or duck types.&lt;/li&gt;
&lt;li&gt;Composition is generally a cheaper alternative to code sharing when compared to inheritance.&lt;/li&gt;
&lt;li&gt;When refactoring from inheritance into composition, the parts sometimes need to share some code, in addition to sharing the same public interface. This is because all possible parts play the same role for the container. In these cases, an inheritance hierarchy of parts may be what&amp;rsquo;s needed. Or, they could share behavior via modules or mixins.&lt;/li&gt;
&lt;li&gt;In technical terms, the technique of composition takes two forms: &lt;strong&gt;aggregation&lt;/strong&gt; and, well, &lt;strong&gt;composition&lt;/strong&gt;. Under composition, parts don&amp;rsquo;t have any use or value outside of their container objects. Under aggregation, on the other hand, parts can live on their own.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;factories&#34;&gt;Factories&lt;/h4&gt;
&lt;ol start=&#34;7&#34;&gt;
&lt;li&gt;When creating certain objects becomes complex, encapsulate that complexity into a factory. That way the knowledge is stored in a single place in the code base. In principle, factories are simple: They are objects that create other objects.&lt;/li&gt;
&lt;li&gt;An advantage of factories is that they make the process of turning complex data structures into objects easy. You can have a &amp;ldquo;specification&amp;rdquo;, stored as pure data in a file or database. The factory can then implement the logic that understands the meaning of the data structure and how to create living objects based on it.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;deciding-between-inheritance-and-composition&#34;&gt;Deciding between inheritance and composition&lt;/h4&gt;
&lt;ol start=&#34;9&#34;&gt;
&lt;li&gt;Inheritance and composition are fundamentally code arrangement techniques where logic is distributed among various objects. With inheritance, objects are organized into a strict hierarchical structure and get automatic message delegation. With composition, objects are independent from each other but messages need to be manually delegated.&lt;/li&gt;
&lt;li&gt;In general, &amp;ldquo;&lt;a href=&#34;https://en.wikipedia.org/wiki/Composition_over_inheritance&#34;&gt;favor composition over inheritance&lt;/a&gt;&amp;rdquo;. Composition is lower cost (i.e. fewer dependencies) than inheritance in most circumstances where both could be used to solve a problem.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;pros-and-cons-of-inheritance&#34;&gt;Pros and cons of inheritance&lt;/h4&gt;
&lt;ol start=&#34;11&#34;&gt;
&lt;li&gt;When properly applied, inheritance is excellent at producing code that is Reasonable, Usable and Exemplary.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inheritable code is Reasonable&lt;/strong&gt; because small changes in code can produce great changes in behavior. This is because code near the top of the hierarchy is defined once but used by all subclasses. Changing such code allows to alter the behavior of many subclasses.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inheritable code is Usable&lt;/strong&gt; because superclasses are literally designed to be easy to reuse. Inheritance hierarchies adhere to the &lt;a href=&#34;https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle&#34;&gt;open-closed principle&lt;/a&gt;. It&amp;rsquo;s easy to extend the hierarchy by creating new subclasses without having to touch existing code, thus, reusing it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inheritable code is Exemplary&lt;/strong&gt; because it intrinsically provides a clear path to extend it. Even novice programmers won&amp;rsquo;t have a hard time creating new subclasses when the superclasses implement template methods and hooks which guide any extension efforts.&lt;/li&gt;
&lt;li&gt;One important disadvantage of inheritance is that the cost of mistakes is considerably high. Incorrect applications of inheritance are costly, whether it be that the wrong abstraction was created or that inheritance was just the wrong tool for the job altogether.&lt;/li&gt;
&lt;li&gt;Another disadvantage is that, for other contexts outside of the hierarchy, the ways in which it&amp;rsquo;s possible to interact with the hierarchy are limited. If the behavior defined within the hierarchy needs to be used, a subclass needs to be created. Other use cases may be incapable of tolerating that dependency.&lt;/li&gt;
&lt;li&gt;If you&amp;rsquo;re writing a framework or a library, this aspect becomes even more important. You can&amp;rsquo;t know all the scenarios in which your library will be used, and forcing users to create subclasses in order to reuse the logic defined in the hierarchy may be more than what they can afford.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;pros-and-cons-of-composition&#34;&gt;Pros and cons of composition&lt;/h4&gt;
&lt;ol start=&#34;18&#34;&gt;
&lt;li&gt;&amp;ldquo;When using composition, the natural tendency is to create many small objects that contain straightforward responsibilities that are accessible through clearly defined interfaces&amp;rdquo;. &amp;ldquo;Composition results in applications built of simple, pluggable objects that are easy to extend and have a high tolerance for change&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;When properly applied, composition is excellent at producing code that is Transparent, Reasonable and Usable.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Composable code is Transparent&lt;/strong&gt; because small objects are easy to understand and changes have obvious effects. These objects also don&amp;rsquo;t necessarily form part of hierarchies, which means they are not susceptible to changes in superclasses.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Composable code is Reasonable&lt;/strong&gt; because its behavior is easy to extend by just implementing new objects that play the role of parts. All new parts need to do is implement the public interface that the container object already expects.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Composable code is Usable&lt;/strong&gt; because it&amp;rsquo;s made up of small independent objects. They don&amp;rsquo;t have any structural dependencies preventing them from being reused in different contexts, completely unrelated to the container or even the part role.&lt;/li&gt;
&lt;li&gt;One disadvantage of composition is the fact that it may be more difficult to understand how the whole application works. While the individual objects may be small and simple, how they come together to solve problems may not be.&lt;/li&gt;
&lt;li&gt;Another disadvantage is that objects need to delegate messages to each other manually, as opposed to inheritance where this happens automatically. This means that there is the explicit dependency of the container object having to know which messages to call on its parts.&lt;/li&gt;
&lt;li&gt;Composition excels at separating containers from parts and assembling such objects. However, it doesn&amp;rsquo;t have an answer for the scenario where it is necessary to handle a collection of types of parts that are very similar to each other. That&amp;rsquo;s where inheritance comes in.&lt;/li&gt;
&lt;li&gt;Use inheritance for &amp;ldquo;is a&amp;rdquo; relationships. Use duck types, interfaces, and behavior sharing via modules or mixins for &amp;ldquo;behaves like a&amp;rdquo; relationships. Use composition for &amp;ldquo;has a&amp;rdquo; relationships.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;chapter-9-designing-cost-effective-tests&#34;&gt;Chapter 9: Designing Cost-Effective Tests&lt;/h3&gt;
&lt;h4 id=&#34;the-benefits-of-testing&#34;&gt;The benefits of testing&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;The goal of design is to write code that is easy to change. In order to do that, we need good object-oriented design skills, good refactoring skills and good testing skills.&lt;/li&gt;
&lt;li&gt;Good object-oriented design skills are needed because badly designed code, by definition, is hard to change.&lt;/li&gt;
&lt;li&gt;Good refactoring skills are needed because design needs to be evolving constantly. As new requirements and new information about the domain become available, the code needs to adapt.&lt;/li&gt;
&lt;li&gt;Good testing skills are needed because high value, solid tests enable continuous refactoring without fear of breaking the code.&lt;/li&gt;
&lt;li&gt;Just like design, the true purpose of testing is to reduce costs. Tests do help reduce bugs, provide documentation, and improve the design; but those are only the means through which tests achieve their ultimate goal of reducing the cost of change.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tests help by finding bugs&lt;/strong&gt;: Test help expose bugs early in the process. Bugs are easier to find and cheaper to correct the closer in time we are to their introduction. Testing at the same time a feature is being implemented catches bugs before they go out the door. Bugs caught early are not given the chance to cause problems or have code depend on them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tests help by supplying documentation&lt;/strong&gt;: Tests represent the best and most reliable documentation of the design. When static documents and memories get outdated and/or disappear, tests remain. Write tests that tell the story of how the code works.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tests help by deferring design decisions&lt;/strong&gt;: As a code base evolves, there will be spots in the code that are less than stellar. Spots which we&amp;rsquo;re not confident enough in to commit to a particular design. So we postpone making a decision and hack together a solution that works today. However, we know that it will need to be refactored to handle the requirements of tomorrow. These spots represent a lack of knowledge. Knowledge that the design is waiting for in order to improve. While waiting for that knowledge to come, we put the hack behind a clear, stable public interface and write our tests against that. In doing so, we&amp;rsquo;ll be free to refactor into a good design when the missing information arrives. Knowing that the tests have our backs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tests help by supporting abstractions&lt;/strong&gt;: &amp;ldquo;Good design naturally progresses toward small independent objects that rely on abstractions&amp;rdquo;. One disadvantage to this is that, while small independent objects are easy to understand by themselves, the behavior of the whole application, with all the little objects working together, becomes obscured. Tests solve that problem by highlighting the abstractions, their interfaces, how to work with them, and how they work together.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tests help by exposing design flaws&lt;/strong&gt;: If tests are hard to write, that&amp;rsquo;s the perfect indicator that the code under test is hard to reuse. Which indicates high coupling, which indicates increased costs of change. If testing an object requires a lot of setup and a lot of other objects, then it requires too much context and has too many dependencies.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;what-when-and-how-to-test&#34;&gt;What, when and how to test&lt;/h4&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2024/02/key-takeaways-from-poodr/object-under-test-are-like-space-capsules.webp&#34; alt=&#34;A legend at the bottom shows solid blue and green lines labeled &amp;ldquo;depended upon by others&amp;rdquo;, and dashed green and red lines labeled &amp;ldquo;no dependents&amp;rdquo;. The main image is labeled &amp;ldquo;Origins of messages&amp;rdquo;. The left side is labeled &amp;ldquo;A. Received from others&amp;rdquo;, with three solid blue lines moving to the right, terminating at a conical object at the center. The cone is labeled &amp;ldquo;object under test&amp;rdquo;, and has a dotted gray line halfway up around the perimeter, with three dotted red lines branching off, looping around, and pointing back to the grey line. This is labeled &amp;ldquo;B. Sent to self&amp;rdquo;. Extending from the right side of the cone are three green lines, two solid and one dotted. They are labeled &amp;ldquo;C. Sent to others&amp;rdquo;.&#34;&gt;&lt;/p&gt;
&lt;ol start=&#34;11&#34;&gt;
&lt;li&gt;&amp;ldquo;One simple way to get better value from tests is to write fewer of them. The safest way to accomplish this is to test everything just once and in the proper place&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tests should focus only on the incoming messages&lt;/strong&gt; that are defined in each object&amp;rsquo;s public interface (&amp;ldquo;A&amp;rdquo; in the picture above). That is, the public methods. Public interfaces expose the services that a class offers its users. They are also stable, so depending on them is safe. Tests that cover public methods are resilient to refactorings and add value because they exercise objects in the same way that their users in application code do.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Never test private methods&lt;/strong&gt; (&amp;ldquo;B&amp;rdquo; in the picture above). They are meant to be used by the object internally. They change often and other objects should not depend on them because they will have to change with them. The same applies to tests. Tests that exercise private code break on every refactoring.&lt;/li&gt;
&lt;li&gt;An object&amp;rsquo;s test suite should &lt;strong&gt;never assert the return value of outgoing messages&lt;/strong&gt; that it sends to other objects (&amp;ldquo;C&amp;rdquo; in the picture above). These messages are part of the public interface of the receiver object, so the receiver&amp;rsquo;s test suite should be the one testing it.&lt;/li&gt;
&lt;li&gt;On the other hand, an object&amp;rsquo;s test suite should &lt;strong&gt;always assert that necessary outgoing messages are sent&lt;/strong&gt;, and with the correct parameters (&amp;ldquo;C&amp;rdquo; in the picture above).&lt;/li&gt;
&lt;li&gt;A &amp;ldquo;test of state&amp;rdquo; is a test that asserts the return value of a method.&lt;/li&gt;
&lt;li&gt;A &amp;ldquo;test of behavior&amp;rdquo; is a test that asserts whether the object under test calls a particular method on another object, how many times, and with what parameters.&lt;/li&gt;
&lt;li&gt;A &amp;ldquo;query&amp;rdquo; is a method call with no side effects that is only made to get some value back.&lt;/li&gt;
&lt;li&gt;A &amp;ldquo;command&amp;rdquo; is a method call that has side effects that are important to the overall application.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;All public methods should be covered by tests of state&lt;/strong&gt;. A test suite should only cover the public methods of its own object under test.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Queries should not be tested for state or behavior&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Commands should be tested for behavior&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Write tests first when it makes sense to do so. Writing tests before implementing the feature establishes an intention for the design from the beginning. Since tests are reused, they make sure the code to be written will have the bare minimum of reusability.&lt;/li&gt;
&lt;li&gt;Testing first is no silver bullet, though. Even though it helps steer the design in the right direction, by itself it won&amp;rsquo;t produce a well-designed application. Fundamental object-oriented design techniques still need to be applied.&lt;/li&gt;
&lt;li&gt;Well-designed applications are easy to change. Well-designed tests may never have to change. This is because they depend on abstractions and public interfaces, which are stable.&lt;/li&gt;
&lt;li&gt;Two major styles of testing exist: Behavior Driven Development and Test Driven Development.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;BDD takes an outside-in approach, creating objects at the boundary of an application and working its way inward, mocking as necessary to supply as-yet-unwritten objects&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;TDD takes an inside-out approach, usually starting with tests of domain objects and then reusing these newly created domain objects in the tests of adjacent layers of code&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Both styles can be followed to produce valuable tests&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&#34;/blog/2024/02/key-takeaways-from-poodr/bdd-and-tdd-should-be-viewed-as-on-a-continuum.webp&#34; alt=&#34;A blue spectrum line has two objects on either side. At the left end, labeled &amp;ldquo;More outside in BDD&amp;rdquo;, are three concentric green circles, with the outermost labeled &amp;ldquo;1&amp;rdquo;, the middle labeled &amp;ldquo;2&amp;rdquo;, and the innermost labeled &amp;ldquo;3&amp;rdquo;. Each label is outside of its circle, with an arrow pointing to the corresponding circle. At the right end, labeled &amp;ldquo;More inside out TDD&amp;rdquo;, are three identical concentric green circles, this time with the innermost labeled 1, the middle labeled 2, and the outer labeled 3. Each number label lies in the circle and points outward.&#34;&gt;&lt;/p&gt;
&lt;h4 id=&#34;writing-valuable-tests&#34;&gt;Writing valuable tests&lt;/h4&gt;
&lt;ol start=&#34;30&#34;&gt;
&lt;li&gt;&lt;strong&gt;Incoming messages (i.e. public methods) need to be covered by tests of state&lt;/strong&gt;. That is, the values that they return must be validated.&lt;/li&gt;
&lt;li&gt;Be on the lookout for public methods that don&amp;rsquo;t receive any calls. These are good candidates for deletion. If no other object calls it, then it needs to be private.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Objects should be tested in isolation&lt;/strong&gt;. When that&amp;rsquo;s not possible, there&amp;rsquo;s a problem with the design. It means that the object is too coupled to its collaborators and can&amp;rsquo;t be reused on its own. It needs to be refactored.&lt;/li&gt;
&lt;li&gt;It&amp;rsquo;s important that objects are tested in isolation because a test suite should care only about the one object that its testing. The other objects will be tested by their own test suites. Changes in an object should affect its own test suite, not that of other objects.&lt;/li&gt;
&lt;li&gt;When the object under test depends on another object in order to work properly, refactor into dependency injection and have the test provide the dependency that way.&lt;/li&gt;
&lt;li&gt;When using dependency injection, don&amp;rsquo;t pass in a concrete, &amp;ldquo;real&amp;rdquo; object in your tests. Instead, inject a &lt;strong&gt;test double&lt;/strong&gt; or &lt;strong&gt;mock&lt;/strong&gt; into the object under test.&lt;/li&gt;
&lt;li&gt;Dependency injection also hints at the emergence of a role, interface, or duck type. Instead of depending on a concrete class, refactor the object under test to depend on a role. The double or mock in the test suite will be one of the objects that play the collaborator role that the object under test expects.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Private methods and query method calls need not be tested at all&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Testing private methods is redundant because they are internal to the object under test and invoked by public methods, which already have tests.&lt;/li&gt;
&lt;li&gt;Private methods are also unstable. Not meant to be depended on because they change often. That will make for brittle tests.&lt;/li&gt;
&lt;li&gt;Private methods covered by tests may mislead others in thinking that the method is stable and, thus, dependable.&lt;/li&gt;
&lt;li&gt;Query method call results are not relevant to the overall application, only to the object under test. They are hidden within it. Also, the receiver of the query already includes tests for it, given that it is part of its public interface. So, they should be ignored by the test suite.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Command method calls do need to be covered by tests&lt;/strong&gt; in order to prove that they were called with the correct parameters. In other words, it is the responsibility of the object under test to send that message, so its test suite needs to prove it.&lt;/li&gt;
&lt;li&gt;Mocks are the way to test that command messages get sent. They help with tests of behavior. Using mocks injected into the object under test, a test case can validate that the method is called properly.&lt;/li&gt;
&lt;li&gt;Commands should be tested for behavior, not state. So, mocks should not be used for tests of state. That is, tests should not be concerned with asserting what they return. However, they can be configured to return some value, if the operation requires it.&lt;/li&gt;
&lt;li&gt;In dynamically typed languages that don&amp;rsquo;t have a compiler to do type checks, it is important to test objects for conformance with the public interfaces of their roles, and for proper integration with their inheritance hierarchies.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;&lt;strong&gt;Tests should document the existence of roles, prove that each of their players behave correctly, and show that dependents interact with them appropriately&lt;/strong&gt;&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Pragmatically, this means writing test cases that assert whether objects implement the specific messages defined in their roles&amp;rsquo; public interface and those that their superclasses expect from them.&lt;/li&gt;
&lt;li&gt;Multiple subclasses will undoubtedly share many of the same tests. In those cases, try to encapsulate the test cases into reusable components that every subclass&amp;rsquo;s test suite can invoke. Just like in application code, it&amp;rsquo;s better to avoid repetition.&lt;/li&gt;
&lt;li&gt;Testing abstract base classes can sometimes be challenging because they are not supposed to be instantiated. In some languages, it is downright impossible to instantiate classes marked as abstract. For these scenarios, a test-specific subclass can be created with minimal implementation that allows tests to exercise the base class.&lt;/li&gt;
&lt;li&gt;To avoid test brittleness, test doubles that play certain roles and inherit from superclasses should also be tested for conformance.&lt;/li&gt;
&lt;/ol&gt;

      </content>
    </entry>
  
    <entry>
      <title>The Pragmatic Programmer book, 20th anniversary edition</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2020/10/the-pragmatic-programmer-20th-anniversary-edition/"/>
      <id>https://www.endpointdev.com/blog/2020/10/the-pragmatic-programmer-20th-anniversary-edition/</id>
      <published>2020-10-16T00:00:00+00:00</published>
      <author>
        <name>Jon Jensen</name>
      </author>
      <content type="html">
        &lt;p&gt;&lt;img src=&#34;/blog/2020/10/the-pragmatic-programmer-20th-anniversary-edition/20201016_130906-sm.jpg&#34; alt=&#34;Photo of the original and 20th anniversary editions of The Pragmatic Programmer book, atop lawn and fall leaves&#34;&gt;&lt;/p&gt;
&lt;!-- Photo by Jon Jensen --&gt;
&lt;p&gt;The Pragmatic Programmer is a now-classic book about software development, first published in 1999. It is old enough that it predates the famous &lt;a href=&#34;https://agilemanifesto.org/&#34;&gt;Agile Manifesto&lt;/a&gt; of 2001. The authors of the book, Andy and Dave, were two of the 14 authors of that manifesto.&lt;/p&gt;
&lt;p&gt;For its 20th anniversary in 2019, Dave and Andy created a new edition. They updated things that had become dated, such as mentions of programming languages, tools, operating systems, websites, etc. That was, I imagine, the easy part. They went on to extensively revise the entire text and incorporate new lessons learned in the past two decades.&lt;/p&gt;
&lt;h3 id=&#34;a-classic&#34;&gt;A classic&lt;/h3&gt;
&lt;p&gt;This book is part of our company’s &lt;a href=&#34;/blog/2018/05/work-philosophy-canon/&#34;&gt;“work philosophy canon”&lt;/a&gt; that I ask every software developer at End Point to read, so for that reason and others I wanted to be familiar with the new edition and make sure it is still something I want to recommend so broadly.&lt;/p&gt;
&lt;p&gt;The book is also required reading for university courses at Cornell (&lt;a href=&#34;https://www.cs.cornell.edu/courses/cs3110/2020sp/reflections.html&#34;&gt;CS 3110: Data Structures and Functional Programming&lt;/a&gt;) and the University of Washington (&lt;a href=&#34;https://courses.cs.washington.edu/courses/cse331/19au/quizzes.html&#34;&gt;CSE 331: Software Design and Implementation&lt;/a&gt;), probably among others!&lt;/p&gt;
&lt;p&gt;I first read this book 19 years ago and really enjoyed it. I found that it clearly expressed many useful concepts I had stumbled upon in my own programming experience. More importantly, it gave me other helpful guidance and warned of pitfalls. Having that all collected in book form with concise, memorable chapter names and tips gave me more shared vocabulary to use with others in our work.&lt;/p&gt;
&lt;p&gt;I also enjoyed reading the new 20th anniversary edition. It did not have the same personal impact, which is to be expected since I am at a very different point in my programming career, technical reading, and life experience. But I think the new edition has as great or even increased power for new readers.&lt;/p&gt;
&lt;h3 id=&#34;overview-of-changes&#34;&gt;Overview of changes&lt;/h3&gt;
&lt;p&gt;The authors estimate that around 75% of the text has changed, and that seems about right. A few areas that stood out to me were:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The now widely-known adage “don’t repeat yourself” originally meant primarily not to duplicate knowledge, that each piece of data should appear in only one canonical location. Over time, “don’t repeat yourself” has been more often used to preach against copying and pasting code. While that is also a good general rule, it has been oversimplified and turned into a blanket prohibition. Dave &amp;amp; Andy mention cases where duplicating code is the right thing to do, because the problem space is not the same and factoring out all such code duplication will make later changes far more complicated as the code has to behave differently for different callers.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Computer security was not nearly as big of a concern when they were writing the first edition in the late 1990s, and now that almost every computer is networked and attackers are motivated to reach every system from anywhere in the world, they gave the topic more attention.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Concurrency gets much more discussion, as is sensible in a time where scaling up typically means using many more CPU cores and processors.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Unit testing was far less common in the late ’90s, and there were few good test frameworks, so they recommended you write your own. Now there are many good test frameworks for every language, so they of course recommend you choose one of those and use it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Dave writes “A Confession” on page 223: He tells us that writing tests for 30+ years made testing so much a part of the way he thinks and programs, that he now writes testable interfaces even when he doesn’t write tests. He isn’t saying that testing is no longer important, but rather that it’s not a religion, that it can and should be examined by experienced programmers, and it has important effects on the programmer aside from the tests themselves.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The old edition had checklists scattered throughout, and collected in the pull-out card at the end. The new edition doesn’t have checklists anymore, except the Debugging Checklist on page 97. I think that’s ok. They weren’t something I ever referred back to.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;tips&#34;&gt;Tips&lt;/h3&gt;
&lt;p&gt;The old edition had 70 tips that appear throughout the chapters. The new edition has 100 tips. In both cases they are extracted and collected on a pull-out card at the end of the book. What changed?&lt;/p&gt;
&lt;h4 id=&#34;removed-or-heavily-reworked-tips&#34;&gt;Removed or heavily reworked tips&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Write Code That Writes Code&lt;/li&gt;
&lt;li&gt;Use Exceptions for Exceptional Problems&lt;/li&gt;
&lt;li&gt;Design Using Services&lt;/li&gt;
&lt;li&gt;Separate Views from Models&lt;/li&gt;
&lt;li&gt;Don’t Use Wizard Code You Don’t Understand&lt;/li&gt;
&lt;li&gt;Abstractions Live Longer than Details&lt;/li&gt;
&lt;li&gt;Costly Tools Don’t Produce Better Designs&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;tips-that-changed-slightly&#34;&gt;Tips that changed slightly&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;“Use a Single Editor Well” is now “Achieve Editor Fluency”&lt;/li&gt;
&lt;li&gt;“Don’t Panic When Debugging” is now simply “Don’t Panic”&lt;/li&gt;
&lt;li&gt;“Minimize Coupling Between Modules” is now “Decoupled Code Is Easier to Change”&lt;/li&gt;
&lt;li&gt;“Configure, Don’t Integrate” is now “Parameterize Your App Using External Configuration”&lt;/li&gt;
&lt;li&gt;“Don’t Gather Requirements—Dig for Them” is now “Requirements Are Learned in a Feedback Loop”&lt;/li&gt;
&lt;li&gt;“Organize Teams Around Functionality” is now “Organize Fully Functional Teams”&lt;/li&gt;
&lt;li&gt;“Gently Exceed Your Users’ Expectations” is now “Delight Users, Don’t Just Deliver Code”&lt;/li&gt;
&lt;li&gt;“Put Abstractions in Code, Details in Metadata” is now “Policy Is Metadata”&lt;/li&gt;
&lt;li&gt;“Always Design for Concurrency” is now “Random Failures Are Often Concurrency Issues”&lt;/li&gt;
&lt;li&gt;“Listen to Nagging Doubts—Start When You’re Ready” is now “Listen to Your Inner Lizard”&lt;/li&gt;
&lt;li&gt;“Don’t Be a Slave to Formal Methods” is now “Do What Works, Not What’s Fashionable”&lt;/li&gt;
&lt;li&gt;“Some Things Are Better Done than Described” transformed to “Agile Is Not a Noun; Agile Is How You Do Things”&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;new-tips&#34;&gt;New tips&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;You Have Agency&lt;/li&gt;
&lt;li&gt;Good Design Is Easier to Change Than Bad Design&lt;/li&gt;
&lt;li&gt;Forgo Following Fads&lt;/li&gt;
&lt;li&gt;Failing Test Before Fixing Code&lt;/li&gt;
&lt;li&gt;Read the Damn Error Message&lt;/li&gt;
&lt;li&gt;Act Locally&lt;/li&gt;
&lt;li&gt;Take Small Steps—Always&lt;/li&gt;
&lt;li&gt;Avoid Fortune-Telling&lt;/li&gt;
&lt;li&gt;Tell, Don’t Ask&lt;/li&gt;
&lt;li&gt;Don’t Chain Method Calls&lt;/li&gt;
&lt;li&gt;Avoid Global Data&lt;/li&gt;
&lt;li&gt;If It’s Important Enough To Be Global, Wrap It in an API&lt;/li&gt;
&lt;li&gt;Programming Is About Code, But Programs Are About Data&lt;/li&gt;
&lt;li&gt;Don’t Hoard State; Pass It Around&lt;/li&gt;
&lt;li&gt;Don’t Pay Inheritance Tax&lt;/li&gt;
&lt;li&gt;Prefer Interfaces to Express Polymorphism&lt;/li&gt;
&lt;li&gt;Delegate to Services: Has-A Trumps Is-A&lt;/li&gt;
&lt;li&gt;Use Mixins to Share Functionality&lt;/li&gt;
&lt;li&gt;Shared State Is Incorrect State&lt;/li&gt;
&lt;li&gt;Use Actors For Concurrency Without Shared State&lt;/li&gt;
&lt;li&gt;Testing Is Not About Finding Bugs&lt;/li&gt;
&lt;li&gt;A Test Is the First User of Your Code&lt;/li&gt;
&lt;li&gt;Build End-To-End, Not Top-Down or Bottom Up&lt;/li&gt;
&lt;li&gt;Use Property-Based Tests to Validate Your Assumptions&lt;/li&gt;
&lt;li&gt;Keep It Simple and Minimize Attack Surfaces&lt;/li&gt;
&lt;li&gt;Apply Security Patches Quickly&lt;/li&gt;
&lt;li&gt;Name Well; Rename When Needed&lt;/li&gt;
&lt;li&gt;No One Knows Exactly What They Want&lt;/li&gt;
&lt;li&gt;Programmers Help People Understand What They Want&lt;/li&gt;
&lt;li&gt;Don’t Go into the Code Alone&lt;/li&gt;
&lt;li&gt;Maintain Small Stable Teams&lt;/li&gt;
&lt;li&gt;Schedule It to Make It Happen&lt;/li&gt;
&lt;li&gt;Deliver When Users Need It&lt;/li&gt;
&lt;li&gt;Use Version Control to Drive Builds, Tests, and Releases&lt;/li&gt;
&lt;li&gt;First, Do No Harm&lt;/li&gt;
&lt;li&gt;Don’t Enable Scumbags&lt;/li&gt;
&lt;li&gt;It’s Your Life. Share it. Celebrate it. Build it. &lt;strong&gt;And have fun!&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The new edition’s PDF version does not include the pull-out card with tips that comes with the printed book. That’s too bad, because the tips were what I most often referred to in the old edition after I finished reading it. At least Andy and Dave have published on their website a list of the 100 updated tips. It would be even nicer to have a PDF of the book’s pull-out card as they did for the old edition.&lt;/p&gt;
&lt;h3 id=&#34;upgrade&#34;&gt;Upgrade?&lt;/h3&gt;
&lt;p&gt;As you can see, there are many new tips. The text has been updated. It is still of excellent quality. So should you get the new edition?&lt;/p&gt;
&lt;p&gt;I mentioned earlier two university courses that use the book. In both courses the professors allow students to use either the original 1999 version or the 2019 version. That seems like the right thing to do to me as well.&lt;/p&gt;
&lt;p&gt;If you already have the old edition of the book, I don’t think it’s necessary to rush out and buy the new edition. The old one is still quite good and relevant, and you’ll be learning a bit of software development history by reading the older one.&lt;/p&gt;
&lt;p&gt;If you do not yet have the book, or if you will be going over it with others who are new to it, it is probably best for you to get the new edition as well so you can be familiar with the new tips and the ways Dave &amp;amp; Andy describe things now.&lt;/p&gt;
&lt;h3 id=&#34;summing-up&#34;&gt;Summing up&lt;/h3&gt;
&lt;p&gt;I am glad that Dave and Andy updated their book. Their updates make sense and make the book more relevant to present-day readers.&lt;/p&gt;
&lt;p&gt;Relatedly, it would be good to also see an update of the also excellent book &lt;em&gt;Practices of an Agile Developer&lt;/em&gt; by Venkat Subramaniam and Andy. That is coming up on 15 years old itself. Perhaps some of its topics have been incorporated in the new edition of &lt;em&gt;The Pragmatic Programmer&lt;/em&gt;, but as I review the table of contents, it looks like it is still mostly additive. I have cited its important maxim “Different Makes a Difference” so often that I thought it was from &lt;em&gt;The Pragmatic Programmer&lt;/em&gt; instead!&lt;/p&gt;
&lt;p&gt;I’ll close with this good observation and advice from Andy in their Changelog podcast interview:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Was it Dijkstra who had the Turing Award lecture about the very humble programmer? That is a critical piece of early literature… And you talk about things that haven’t changed. This was 1972? … And he makes the very important point that complexity will overwhelm us if we don’t take a very humble, very measured approach. And it’s been 30–40 years and everyone—present company included—has ignored this wonderful advice.&lt;/p&gt;
&lt;p&gt;Humility is difficult in our environment, in our culture, and it is probably, of all the human factorsy things that you need to be a good developer, I would submit that being humble, realizing you don’t know all the answers, that you need to find out, that you need to experiment, get feedback, try it.&lt;/p&gt;
&lt;p&gt;This part of our headlong rush into the shiny new thing is this kind of faith that “Well, that’s gonna be better. I can do it better. I’m better than this/​that.” Yeah, maybe… But you should validate that. You should try it. You should go back and read these things. You should try these other experiments.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Thanks, Andy &amp;amp; Dave!&lt;/p&gt;
&lt;h3 id=&#34;reference&#34;&gt;Reference&lt;/h3&gt;
&lt;h4 id=&#34;all-tips-from-each-edition&#34;&gt;All tips from each edition&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.codinghorror.com/a-pragmatic-quick-reference/&#34;&gt;Quick reference 70 tips (and checklists) from original edition&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://pragprog.com/tips/&#34;&gt;Quick reference 100 tips from new edition&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;interviews&#34;&gt;Interviews&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.functionalgeekery.com/episode-126-andy-hunt-and-dave-thomas/&#34;&gt;Functional Geekery Episode 126 – Andy Hunt and Dave Thomas from July 2, 2019&lt;/a&gt; by Steven Proctor&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://changelog.com/podcast/352&#34;&gt;The Changelog – Episode #352: The Pragmatic Programmers with Andy Hunt &amp;amp; Dave Thomas&lt;/a&gt; by Adam Stacoviak &amp;amp; Jerod Santo&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.codenewbie.org/podcast/why-you-should-read-the-new-edition-of-the-pragmatic-programmer&#34;&gt;CodeNewbie Podcast season 9 episode 8 from August 26, 2019: Why you should read the new edition of the Pragmatic Programmer with Andy Hunt, Dave Thomas&lt;/a&gt; by Saron Yitbarek (author of the new edition’s foreword)&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;other-comparisons-of-the-two-editions&#34;&gt;Other comparisons of the two editions&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.kevinhooke.com/2020/05/06/the-pragmatic-programmer-1st-edition-vs-20th-anniversary-edition-what-are-the-major-changes/&#34;&gt;Sections added, changed significantly, and removed&lt;/a&gt; by Kevin Hooke&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://booksoncode.com/articles/pragmatic-programmer-comparison&#34;&gt;The Pragmatic Programmer Book 2nd Edition Differences by Miranda Limonczenko&lt;/a&gt; (very detailed, but covers only the first 3 chapters)&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;book-pages&#34;&gt;Book pages&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://pragprog.com/titles/tpp20/the-pragmatic-programmer-20th-anniversary-edition/&#34;&gt;The Pragmatic Programmer, 20th Anniversary Edition&lt;/a&gt; book home page, errata, source code downloads, and links to buy&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://pragprog.com/titles/pad/practices-of-an-agile-developer/&#34;&gt;Practices of an Agile Developer&lt;/a&gt; book home page, samples, pull-out card, and &lt;a href=&#34;/blog/2006/06/review-practices-of-agile-developer/&#34;&gt;review by Ethan Rowe&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

      </content>
    </entry>
  
    <entry>
      <title>A tribute to Kyle Simpson’s JavaScript book series</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2019/07/tribute-to-kyle-simpsons-book-series/"/>
      <id>https://www.endpointdev.com/blog/2019/07/tribute-to-kyle-simpsons-book-series/</id>
      <published>2019-07-24T00:00:00+00:00</published>
      <author>
        <name>Árpád Lajos</name>
      </author>
      <content type="html">
        &lt;p&gt;&lt;img src=&#34;/blog/2019/07/tribute-to-kyle-simpsons-book-series/you-dont-know-js.jpg&#34; alt=&#34;You Don’t Know JS&#34; /&gt; &lt;a href=&#34;https://flic.kr/p/rdi2Qg&#34;&gt;Photo&lt;/a&gt; by &lt;a href=&#34;https://www.flickr.com/photos/othree/&#34;&gt;othree&lt;/a&gt;, used under &lt;a href=&#34;https://creativecommons.org/licenses/by/2.0/&#34;&gt;CC BY 2.0&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Inspired by &lt;a href=&#34;/blog/2016/08/ruby-fight-club/&#34;&gt;the Ruby Fight Club&lt;/a&gt;, a group of us have been reading Kyle Simpson’s &lt;a href=&#34;https://github.com/getify/You-Dont-Know-JS&#34;&gt;You Don’t Know JS&lt;/a&gt; series (1st edition; in 2020 Kyle started publishing drafts of the 2nd edition of the books). These books are a great source of inspiration and available for free. I meet weekly with our small group to discuss chapters from these books. Each time we have a presenter who walks us through the chapter that we all read beforehand.&lt;/p&gt;
&lt;p&gt;During these sessions we have learned a lot about JavaScript, but also about preparing presentations. The increasing quality level of the meetings was noticable each week. I think we all owe a large &lt;strong&gt;thanks&lt;/strong&gt; to Kyle Simpson. In this article I will focus on the book “You Don’t Know JS: ES6 and Beyond”.&lt;/p&gt;
&lt;h3 id=&#34;past-present-and-future&#34;&gt;Past, present and future&lt;/h3&gt;
&lt;p&gt;ECMAScript (ES for short) was versioned with a small number up until now, like 5. ES1 and ES2 were not widely known or implemented. ES3 was used by Internet Exporer 6–8 and Android 2.x. ES4 never came out. ES5 came out in 2009. ES5.1 came out in 2011 and was widely used by Firefox, Chrome, Opera, Safari, etc.&lt;/p&gt;
&lt;p&gt;Now, version names will be in the format ES&lt;year&gt;, but it might change to a per-feature basis.&lt;/p&gt;
&lt;p&gt;In the past JavaScript versions were based on major releases of ES. However, due to the importance of the language, it is too much of a hassle to wait till 20 features are ready and release them together. It is much better to make finished features available as soon as they are ready. As a result, we know what functionalities we’re gaining.&lt;/p&gt;
&lt;p&gt;It’s good to reflect on just how important the language is. JavaScript is the lingua franca for web browsers. Web developers need to be aware of JavaScript to its slightest details. While the markup of a webpage is HTML and its design is CSS, the client-side programming is done via JavaScript, more or less in a standard manner.&lt;/p&gt;
&lt;p&gt;Since JavaScript is almost completely standard for browsers, programmers would have a much easier life if they were writing JavaScript when coding on server-side as well. There is a mental leap when one works both on the client-side and server-side of a feature and has to write Java/​C++/​PHP/​Ruby or whatever server-side code and then, in the next moment, they have to change their way of thinking and switch to the client-side and write JavaScript code. This is not difficult for a seasoned programmer who’s used to doing this. But when such a switch happens 50–60 times a day, it gets tiresome, and the programmer might not even realize why the day was tiring, since all they did was implement some simple features or fix some simple bugs.&lt;/p&gt;
&lt;p&gt;It is perfectly logical that JavaScript found its way into server-side programming. Node.js is a standalone JavaScript runtime and whoever uses it for server-side web programming automatically gains the benefit of being able to work with the same language both on server side and client side. Of course, one still has to work with HTML, CSS, and a database as a web programmer, so multiple languages will be needed at some point, but there is a level of comfort given to web programmers using Node.js. Of course, the event loop used by JavaScript along with its single-threaded approach makes it less effective in doing some CPU-intensive stuff.&lt;/p&gt;
&lt;p&gt;However, for server-side calculations, I would not be surprised at all if sooner or later full support is added to Node.js for multithreaded work. A great possible benefit of using JavaScript both on server-side and client-side, especially if there is a WebSocket connection involved, is that the server and the client could use the very same object, which opens the possibility to create a new paradigm. I know it’s science fiction, but imagine how cool it would be to implement a JavaScript class/​prototype and while doing so being able to define what should be available for the client-side as well. Object state change could happen on both server-side and client-side and synchronization could be triggered in such a duplex channel. Internet connection problems could be handled as well. Let’s imagine the case when there is a grid to be shown for the user. The user wants to define filters, sort, maybe layout, the server has to find the data, possibly store the settings, also, generate the structure upon object creation. Of course, before this can be realized a lot of open questions need to be answered. However, as a utopian view, it looks great.&lt;/p&gt;
&lt;h3 id=&#34;compiling-and-transpiling&#34;&gt;Compiling and Transpiling&lt;/h3&gt;
&lt;p&gt;JavaScript is a hybrid interpreted and compiled language, since most modern runtimes compile the code, but it can be interpreted as well at runtime. Let’s see this code:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; foo = [&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;,&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;,&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; obj = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; foo  &lt;span style=&#34;color:#888&#34;&gt;// means `foo: foo`
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;obj.foo; &lt;span style=&#34;color:#888&#34;&gt;// [1,2,3]
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The code above natively assumes that the value of the foo attribute of obj is foo, because when an attribute is not defined, a value of the same name is the default, in this case, the value will be our foo variable. However, in old versions of JavaScript, this was not yet supported, so if we really need to use this code in older browsers, then we will need to convert our source-code into its oldschool equivalent, using a Transpiler (the action of transpiling is to convert a source-code to another source-code, possibly of different language, not modifying its essence).&lt;/p&gt;
&lt;p&gt;JavaScript transpilers are a big topic, but for the sake of readability, we won’t delve too much into the details. I have the habit of using &lt;a href=&#34;https://babeljs.io/&#34;&gt;Babel&lt;/a&gt; whenever I’m in doubt that the result of compiling is the one that I expect, or I suspect an error in the result, or I am interested for any other reason about the actual result.&lt;/p&gt;
&lt;h3 id=&#34;polyfilling&#34;&gt;Polyfilling&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;“A polyfill, or polyfiller, is a piece of code (or plugin) that provides the technology that you, the developer, expect the browser to provide natively. Flattening the API landscape if you will.”&lt;/em&gt; —Remy Sharp&lt;/p&gt;
&lt;p&gt;If we expect a functionality or value to be in the web browser or, more widely, in JavaScript, but it is not existing yet, or is not sure to exist everywhere we intend to use it, then we define it. In general, if we expect something defined by the name of &lt;code&gt;myCoolStuff&lt;/code&gt;, then we can do polyfilling like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (!myCoolStuff) { &lt;span style=&#34;color:#888&#34;&gt;//Here we assume that some variable called myCoolStuff exists and we check whether it&amp;#39;s falsy
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;    &lt;span style=&#34;color:#888&#34;&gt;//Define myCoolStuff
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The code above is unsafe though, because if &lt;code&gt;myCoolStuff&lt;/code&gt; is not defined at all, then an error will be thrown. A better, more reliable approach is to compare its type against &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;typeof&lt;/span&gt; myCoolStuff === &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;undefined&amp;#34;&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;//Define myCoolStuff
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;So far, so good. However, we might be tired of writing that kind of condition over and over again. An alternative is to abstract the approach, like:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; toPolyfill = [
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        context: &lt;span style=&#34;color:#038&#34;&gt;window&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        myCoolStuff: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; () {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        someOtherStuff: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;42&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        yetAnother: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; (someParameter) {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#888&#34;&gt;//...
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;    },
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        context: &lt;span style=&#34;color:#038&#34;&gt;Object&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        foo: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;bar&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;];&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;and then do something like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;for (var obj of toPolyfill) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    for (var key in obj) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        if ((key !== &amp;#34;context&amp;#34;) &amp;amp;&amp;amp; (typeof obj.context[key] === &amp;#34;undefined&amp;#34;)) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            obj.context[key] = obj[key];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;As we can see, we have an array called &lt;code&gt;toPolyfill&lt;/code&gt; whose items are all objects. Each object has a &lt;code&gt;context&lt;/code&gt; attribute, which specifies where should we check the other attributes for existence and use the default if not found.&lt;/p&gt;
&lt;p&gt;Let’s take a look at the polyfilling of &lt;code&gt;Object.is&lt;/code&gt;, which is a function to determine whether two variables hold the same values:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#038&#34;&gt;Object&lt;/span&gt;.is === &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;undefined&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#038&#34;&gt;Object&lt;/span&gt;.is = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(v1, v2) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#888&#34;&gt;// test for `-0`
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (v1 === &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; v2 === &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt; / v1 === &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt; / v2;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#888&#34;&gt;// test for `NaN`
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (v1 !== v1) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; v2 !== v2;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#888&#34;&gt;// everything else
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; v1 === v2;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    };
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#038&#34;&gt;Object&lt;/span&gt;.is(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;abc&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;abc&amp;#34;&lt;/span&gt;) &amp;amp;&amp;amp; &lt;span style=&#34;color:#038&#34;&gt;Object&lt;/span&gt;.is(&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;/&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;, &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;Infinity&lt;/span&gt;) &amp;amp;&amp;amp; &lt;span style=&#34;color:#038&#34;&gt;Object&lt;/span&gt;.is(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;NaN&lt;/span&gt;, &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;NaN&lt;/span&gt;); &lt;span style=&#34;color:#888&#34;&gt;//true
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Well, that was nice, wasn’t it? But this is always called as &lt;code&gt;Object.is()&lt;/code&gt;. Why not make it instance level?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#038&#34;&gt;Object&lt;/span&gt;.prototype.is = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(value) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#038&#34;&gt;Object&lt;/span&gt;.is(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;this&lt;/span&gt;, value);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;It’s looking great and it should work, right? Let’s test it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;abc&amp;#34;&lt;/span&gt;.is(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;abc&amp;#34;&lt;/span&gt;); &lt;span style=&#34;color:#888&#34;&gt;//false
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;What? Don’t worry, we just missed using strict, which ensures that we are in strict mode, introduced in ES5:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;use strict&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (!&lt;span style=&#34;color:#038&#34;&gt;Object&lt;/span&gt;.is) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#038&#34;&gt;Object&lt;/span&gt;.is = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(v1, v2) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#888&#34;&gt;// test for `-0`
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (v1 === &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; v2 === &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt; / v1 === &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt; / v2;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#888&#34;&gt;// test for `NaN`
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (v1 !== v1) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; v2 !== v2;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#888&#34;&gt;// everything else
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; v1 === v2;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    };
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#038&#34;&gt;Object&lt;/span&gt;.prototype.is = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(value) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#038&#34;&gt;Object&lt;/span&gt;.is(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;this&lt;/span&gt;, value);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;abc&amp;#34;&lt;/span&gt;.is(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;abc&amp;#34;&lt;/span&gt;); &lt;span style=&#34;color:#888&#34;&gt;//true
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id=&#34;block-scope&#34;&gt;Block scope&lt;/h3&gt;
&lt;p&gt;Virtually anyone with some experience in JavaScript has met a situation when variables did not behave as expected, especially when asynchronous stuff was involved. One reason is that variables created using the &lt;code&gt;var&lt;/code&gt; keyword are function-scoped, not block-scoped. Proof:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; foo() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; something = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;5&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    something; &lt;span style=&#34;color:#888&#34;&gt;//5
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;foo();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;something; &lt;span style=&#34;color:#888&#34;&gt;//error
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The example above illustrates that the variable created in the inner scope of the function can be used without a problem outside the inner scope of the function, as long as it’s inside the function and that it cannot be reached outside the function; in short, we can see that our variable is function-scoped.&lt;/p&gt;
&lt;p&gt;So let’s see an example where this is a problem. Let’s calculate the sum of natural numbers from 1 to 100, we expect, of course, 5050 as a result:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; sum = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; index = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;; index &amp;lt;= &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;100&lt;/span&gt;; index++) setTimeout(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {sum += index}, &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;100&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;setTimeout(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    alert(sum); &lt;span style=&#34;color:#888&#34;&gt;//10100
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;}, &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;200&lt;/span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Wait, what? We expected 5050 as a result, yet, it was 10100, exactly twice as much. What happened? Let’s study this carefully:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;we initialize &lt;code&gt;sum&lt;/code&gt; with 0&lt;/li&gt;
&lt;li&gt;we iterate a variable called &lt;code&gt;index&lt;/code&gt; from 1 to 100 and add functions to the event loop to be executed 100 milliseconds later than the moment we reached to them at the iteration&lt;/li&gt;
&lt;li&gt;when &lt;code&gt;index&lt;/code&gt; reaches 100, the last iteration is executed and &lt;code&gt;index&lt;/code&gt; is incremented&lt;/li&gt;
&lt;li&gt;&lt;code&gt;index&lt;/code&gt; is 101 at the end of the cycle&lt;/li&gt;
&lt;li&gt;we add a new &lt;code&gt;function&lt;/code&gt; to the event loop to be executed 200 milliseconds later, alerting the result&lt;/li&gt;
&lt;li&gt;100 milliseconds later the &lt;code&gt;function&lt;/code&gt; which increases &lt;code&gt;sum&lt;/code&gt; by &lt;code&gt;index&lt;/code&gt; (101) will be executed 100 times&lt;/li&gt;
&lt;li&gt;as a result, &lt;code&gt;sum&lt;/code&gt; will be 100 * 101 = 10100&lt;/li&gt;
&lt;li&gt;100 more milliseconds later, the &lt;code&gt;function&lt;/code&gt; which alerts &lt;code&gt;sum&lt;/code&gt; (10100) is executed&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Okay, we understand this. But why was &lt;code&gt;index&lt;/code&gt; 101 and why not its current value of the iteration? Well, the answer is simple: the cycle ran before the functions which it added to the event loop. So we clearly have a problem with the function-scoped variable in this case. Luckily, we are able to use block scope as well, using the &lt;code&gt;let&lt;/code&gt; keyword:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; sum = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;let&lt;/span&gt; index = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;; index &amp;lt;= &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;100&lt;/span&gt;; index++) setTimeout(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {sum += index}, &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;100&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;setTimeout(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    alert(sum); &lt;span style=&#34;color:#888&#34;&gt;//5050
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;}, &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;200&lt;/span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Wow, that was neat. Our cycle creates a block-scoped variable on each iteration and as a result the &lt;code&gt;function&lt;/code&gt; given to &lt;code&gt;setTimeout&lt;/code&gt; inside the same block will use the correct variable each time.&lt;/p&gt;
&lt;h3 id=&#34;defaults&#34;&gt;Defaults&lt;/h3&gt;
&lt;p&gt;JavaScript has a neat way of setting defaults for parameters, like:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; theMeaningOfLife(result = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;42&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    setTimeout(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        console.log(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;The meaning of life is &amp;#34;&lt;/span&gt; + result);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }, &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;10000000&lt;/span&gt;*&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;365.25&lt;/span&gt;*&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;24&lt;/span&gt;*&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;60&lt;/span&gt;*&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;60&lt;/span&gt;*&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1000&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This is nice, but there might be cases when the parameters are actually attributes of an object and that’s passed as parameter:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; defaultize(params, expectedParams) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;typeof&lt;/span&gt; params !== &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;object&amp;#34;&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#888&#34;&gt;//params is not an object, do something
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; key &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;in&lt;/span&gt; expectedParams) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (!(key &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;in&lt;/span&gt; params)) params[key] = expectedParams[key];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; bar(params) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    defaultize(params, {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        foo: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;fooDefault&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        bar: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;barDefault&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        lorem: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;loremDefault&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        ipsum: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;ipsumDefault&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    });
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    console.log(params);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;bar({
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    bar: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;beer bar&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    ipsum: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;dolor&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We can even use a function call as default:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; defaultize(params, expectedParams) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;typeof&lt;/span&gt; params !== &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;object&amp;#34;&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#888&#34;&gt;//params is not an object, do something
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; key &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;in&lt;/span&gt; expectedParams) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (!(key &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;in&lt;/span&gt; params)) params[key] = expectedParams[key];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; bar(params, defaults =
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    defaultize(params, {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        foo: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;fooDefault&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        bar: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;barDefault&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        lorem: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;loremDefault&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        ipsum: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;ipsumDefault&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    })) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    console.log(params);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;bar({
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    bar: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;beer bar&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    ipsum: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;dolor&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In the example above, if &lt;code&gt;defaults&lt;/code&gt; is not passed to &lt;code&gt;bar&lt;/code&gt;, then &lt;code&gt;defaultize&lt;/code&gt; will be called, passing &lt;code&gt;params&lt;/code&gt; and the &lt;code&gt;defaults&lt;/code&gt;. Since &lt;code&gt;params&lt;/code&gt; is an object, &lt;code&gt;defaultize&lt;/code&gt; changes its attributes when needed. A neat example of default parameters can be seen in the next chunk of code, where a variable actually changes when a value is not passed to the &lt;code&gt;function&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; value = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; something(x = value++) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    console.log(x);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;something(); &lt;span style=&#34;color:#888&#34;&gt;//x has a value of 0, value is incremented to 1
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;something(); &lt;span style=&#34;color:#888&#34;&gt;//x has a value of 1, value is incremented to 2
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;something(); &lt;span style=&#34;color:#888&#34;&gt;//x has a value of 2, value is incremented to 3
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;something(&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;); &lt;span style=&#34;color:#888&#34;&gt;//x has a value of 1, value remains 3
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;something(); &lt;span style=&#34;color:#888&#34;&gt;//x has a value of 3, value is incremented to 4
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id=&#34;applying-defaults&#34;&gt;Applying defaults&lt;/h3&gt;
&lt;p&gt;The book (ES6 and beyond) gives us an example of applying defaults:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; defaults = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    options: {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        remove: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;true&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        enable: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;false&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        instance: {}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    },
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    log: {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        warn: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;true&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        error: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; config = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    options: {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        remove: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;false&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        instance: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;null&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;config = &lt;span style=&#34;color:#038&#34;&gt;Object&lt;/span&gt;.assign( {}, defaults, config );&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;With the code above we see that nested values in the default are not transferred. Losing data is not a desired situation. The problem is that &lt;code&gt;Object.assign&lt;/code&gt; is shallow. The book gives this solution:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; defaults = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    options: {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        remove: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;true&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        enable: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;false&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        instance: {}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    },
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    log: {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        warn: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;true&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        error: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; config = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    options: {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        remove: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;false&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        instance: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;null&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;config.options = config.options || {};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;config.log = config.log || {};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;({
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    options: {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        remove: config.options.remove = defaults.options.remove,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        enable: config.options.enable = defaults.options.enable,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        instance: config.options.instance = defaults.options.instance
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    } = {},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    log: {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        warn: config.log.warn = defaults.log.warn,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        error: config.log.error = defaults.log.error
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    } = {}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;} = config);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This solves our problem. &lt;code&gt;enable&lt;/code&gt; is successfully set to &lt;code&gt;false&lt;/code&gt;, but I did not like this solution very much, because it is a very particular solution for this data and is not reusable for other cases, where &lt;code&gt;config&lt;/code&gt; and &lt;code&gt;options&lt;/code&gt; have different attributes, so I came up with this reusable code:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; defaults = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    options: {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        remove: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;true&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        enable: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;false&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        instance: {}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    },
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    log: {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        warn: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;true&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        error: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; config = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    options: {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        remove: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;false&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        instance: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;null&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; applyDefaults(d, t) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; ((&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;typeof&lt;/span&gt; d !== &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;object&amp;#34;&lt;/span&gt;) &amp;amp;&amp;amp; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;typeof&lt;/span&gt; d !== &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;array&amp;#34;&lt;/span&gt;)) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; d;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (t === &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;undefined&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;typeof&lt;/span&gt; d === &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;object&amp;#34;&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            t = {};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        } &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;else&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;typeof&lt;/span&gt; d === &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;array&amp;#34;&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            t = [];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; key &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;in&lt;/span&gt; d) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (t[key] === &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;undefined&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            t[key] = d[key];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        } &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;else&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            applyDefaults(d[key], t[key]);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; t;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;applyDefaults(defaults, config);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;console.log(config);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We can see that the recursive &lt;code&gt;applyDefaults&lt;/code&gt; function does not rely on the attribute names and due to its agnosticity, we can reuse it for any defaulting.&lt;/p&gt;
&lt;h3 id=&#34;es5-gettersetter&#34;&gt;ES5 Getter/Setter&lt;/h3&gt;
&lt;p&gt;A very nice example in the book about ES5 getters and setters is this one:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; o = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    __id: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;10&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    get id() { &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;this&lt;/span&gt;.__id++; },
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    set id(v) {&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;this&lt;/span&gt;.__id = v;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;console.log(o.id);                        &lt;span style=&#34;color:#888&#34;&gt;// 10
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;console.log(o.id);                        &lt;span style=&#34;color:#888&#34;&gt;// 11
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;console.log(o.id = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;20&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;console.log(o.id);                        &lt;span style=&#34;color:#888&#34;&gt;// 20
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// and:
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;console.log(o.__id);                        &lt;span style=&#34;color:#888&#34;&gt;// 21
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;console.log(o.__id);                        &lt;span style=&#34;color:#888&#34;&gt;// 21 – still!
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The getter always returns the current value of &lt;code&gt;id&lt;/code&gt; and increments it.&lt;/p&gt;
&lt;h3 id=&#34;computed-property-names&#34;&gt;Computed property names&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; myObject = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    a: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    b: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    c: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;What if we want to define some operations for it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; myObject = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    a: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    b: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    c: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &amp;amp;&amp;amp;: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    ||: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    ===: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    !==: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    ==: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    !=: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The code will of course break, because data members of an object have the same syntax constraint in their naming as variables, see more &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types&#34;&gt;here&lt;/a&gt;. You can also try out a &lt;a href=&#34;https://mothereff.in/js-variables&#34;&gt;name validator&lt;/a&gt;. We can solve the problem like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; myObject = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    a: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    b: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    c: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;myObject[&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;amp;&amp;amp;&amp;#34;&lt;/span&gt;] = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(){&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;myObject[&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;||&amp;#34;&lt;/span&gt;] = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(){&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;myObject[&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;===&amp;#34;&lt;/span&gt;] = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(){&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;myObject[&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;!==&amp;#34;&lt;/span&gt;] = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(){&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;myObject[&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;==&amp;#34;&lt;/span&gt;] = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(){&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;myObject[&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;!=&amp;#34;&lt;/span&gt;] = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(){&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;However, this doesn’t look as neat as the code which failed. After some research and experimenting I came up with this solution:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; myObject = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    a: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    b: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    c: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    [&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;amp;&amp;amp;&amp;#34;&lt;/span&gt;]: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    [&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;||&amp;#34;&lt;/span&gt;]: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    [&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;===&amp;#34;&lt;/span&gt;]: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    [&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;!==&amp;#34;&lt;/span&gt;]: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    [&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;==&amp;#34;&lt;/span&gt;]: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    [&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;!=&amp;#34;&lt;/span&gt;]: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Kyle Simpson makes sure that in the future none of the JavaScript programmers who had the blessing of reading his books will not have to suffer like me. He comes up with some very illustrative examples:&lt;/p&gt;
&lt;p&gt;We can add computed properties to an object with the assignment of &lt;code&gt;foo[&amp;quot;b&amp;quot; + &amp;quot;ar&amp;quot;] = &amp;quot;baz&amp;quot;&lt;/code&gt;, like:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; prefix = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;user_&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; o = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    baz: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(){  }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;o[ prefix + &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;foo&amp;#34;&lt;/span&gt; ] = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(){ console.log(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;foo&amp;#34;&lt;/span&gt;); };
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;o[ prefix + &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;bar&amp;#34;&lt;/span&gt; ] = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(){ console.log(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;bar&amp;#34;&lt;/span&gt;); };
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;o[prefix + &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;foo&amp;#34;&lt;/span&gt;]();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;o[prefix + &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;bar&amp;#34;&lt;/span&gt;]();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;However, we can define these properties at initialization with the syntax of:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; prefix = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;user_&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; o = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    baz: &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(){  },
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    [ prefix + &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;foo&amp;#34;&lt;/span&gt; ] : &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(){ console.log(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;foo&amp;#34;&lt;/span&gt;); },
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    [ prefix + &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;bar&amp;#34;&lt;/span&gt; ] : &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;(){ console.log(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;bar&amp;#34;&lt;/span&gt;); }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;o[prefix + &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;foo&amp;#34;&lt;/span&gt;]();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;o[prefix + &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;bar&amp;#34;&lt;/span&gt;]();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Symbol properties:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; o = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    [Symbol.toStringTag]: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;really cool thing&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;console.log(o.toString());
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; o2 = {};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;console.log(o2.toString());
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;o2[Symbol.toStringTag] = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;really cool thing&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;console.log(o2.toString());&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Computed properties can be names of concise methods or concise generators:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; o = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    [&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;f&amp;#34;&lt;/span&gt; + &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;oo&amp;#34;&lt;/span&gt;]() {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;},        &lt;span style=&#34;color:#888&#34;&gt;// computed concise method
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;    *[&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;b&amp;#34;&lt;/span&gt; + &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;ar&amp;#34;&lt;/span&gt;]() {&lt;span style=&#34;color:#888&#34;&gt;/*...*/&lt;/span&gt;}        &lt;span style=&#34;color:#888&#34;&gt;// computed concise generator
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We can even set the prototype:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; foo = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;5&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; o1 = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    foo
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;console.log(o1.foo); &lt;span style=&#34;color:#888&#34;&gt;//5
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;foo++;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; o2 = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    __proto__: o1,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;console.log(o2.foo++); &lt;span style=&#34;color:#888&#34;&gt;//5
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; o3 = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    __proto__: o2
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;console.log(o3.foo); &lt;span style=&#34;color:#888&#34;&gt;//6
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id=&#34;object-super&#34;&gt;Object super&lt;/h3&gt;
&lt;p&gt;We can set the prototype of an object and then calling &lt;code&gt;super&lt;/code&gt; inside a function can make sense. Consider this example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; o1 = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    foo() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        console.log( &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;o1:foo&amp;#34;&lt;/span&gt; );
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; o2 = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    foo() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;super&lt;/span&gt;.foo();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        console.log( &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;o2:foo&amp;#34;&lt;/span&gt; );
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#038&#34;&gt;Object&lt;/span&gt;.setPrototypeOf( o2, o1 );
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;o2.foo();  &lt;span style=&#34;color:#888&#34;&gt;// o1:foo
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;           &lt;span style=&#34;color:#888&#34;&gt;// o2:foo
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id=&#34;template-literals&#34;&gt;Template literals&lt;/h3&gt;
&lt;p&gt;JavaScript provides us with a neat way to manage long texts in the form of template literals. Let’s see some examples from the book:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; name = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;Kyle&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; greeting = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;`Hello &lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;name&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;!`&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;console.log( greeting );          &lt;span style=&#34;color:#888&#34;&gt;// &amp;#34;Hello Kyle!&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;console.log( &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;typeof&lt;/span&gt; greeting );   &lt;span style=&#34;color:#888&#34;&gt;// &amp;#34;string&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Notice that we have a template literal assigned to &lt;code&gt;greeting&lt;/code&gt; and how neatly we can put into it dynamic values. In this case, the value of the name variable.&lt;/p&gt;
&lt;p&gt;Another example is:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; text =
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;`Now is the time for all good men
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;to come to the aid of their
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;country!`&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;console.log( text );
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// Now is the time for all good men
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// to come to the aid of their
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// country!
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We can conveniently put HTML into template literals like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; myHTML = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;`
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;!DOCTYPE html&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;html&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;body&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;h2&amp;gt;An Unordered HTML List&amp;lt;/h2&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;ul&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;  &amp;lt;li&amp;gt;Coffee&amp;lt;/li&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;  &amp;lt;li&amp;gt;Tea&amp;lt;/li&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;  &amp;lt;li&amp;gt;Milk&amp;lt;/li&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;/ul&amp;gt;  
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;h2&amp;gt;An Ordered HTML List&amp;lt;/h2&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;ol&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;  &amp;lt;li&amp;gt;Coffee&amp;lt;/li&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;  &amp;lt;li&amp;gt;Tea&amp;lt;/li&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;  &amp;lt;li&amp;gt;Milk&amp;lt;/li&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;/ol&amp;gt; 
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;/body&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;/html&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;`&lt;/span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;It is as if we were looking at only HTML code. Imagine how great it is to read code like this instead of concatenated strings with lots of addition signs and quotes. Let’s implement a function which generates the options of a select tag:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; generateOptions(input) { &lt;span style=&#34;color:#888&#34;&gt;//format of [{key, value}, …] is expected
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; output = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;let&lt;/span&gt; item &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;of&lt;/span&gt; input) output += &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;`&amp;lt;option value=&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;item.key&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;gt;&lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;item.value&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;/option&amp;gt;`&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; output;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; options = generateOptions([
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {key: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;, value: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;Coffee&amp;#34;&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {key: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;, value: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;Tea&amp;#34;&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {key: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;, value: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;Milk&amp;#34;&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;]);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;I think this is very elegant. Let’s make a &lt;code&gt;select&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; select = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;`&amp;lt;select class=&amp;#34;my-class&amp;#34;&amp;gt;&lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;options&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;/select&amp;gt;`&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;//&amp;lt;select class=&amp;#34;my-class&amp;#34;&amp;gt;&amp;lt;option value=&amp;#34;1&amp;#34;&amp;gt;Coffee&amp;lt;/option&amp;gt;&amp;lt;option value=&amp;#34;2&amp;#34;&amp;gt;Tea&amp;lt;/option&amp;gt;&amp;lt;option value=&amp;#34;3&amp;#34;&amp;gt;Milk&amp;lt;/option&amp;gt;&amp;lt;/select&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;That’s not very pretty to read, is it? Let’s make it nicer:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; generateOptions(input) { &lt;span style=&#34;color:#888&#34;&gt;//format of [{key, value}, …] is expected
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; output = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;let&lt;/span&gt; item &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;of&lt;/span&gt; input) output += &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;`\n    &amp;lt;option value=&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;item.key&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;gt;&lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;item.value&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;/option&amp;gt;`&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; output;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; options = generateOptions([
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {key: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;, value: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;Coffee&amp;#34;&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {key: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;, value: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;Tea&amp;#34;&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {key: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;, value: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;Milk&amp;#34;&lt;/span&gt;},
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;]);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; select = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;`&amp;lt;select class=&amp;#34;my-class&amp;#34;&amp;gt;&lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;options&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;\n&amp;lt;/select&amp;gt;`&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;/*
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&amp;lt;select class=&amp;#34;my-class&amp;#34;&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;    &amp;lt;option value=&amp;#34;1&amp;#34;&amp;gt;Coffee&amp;lt;/option&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;    &amp;lt;option value=&amp;#34;2&amp;#34;&amp;gt;Tea&amp;lt;/option&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;    &amp;lt;option value=&amp;#34;3&amp;#34;&amp;gt;Milk&amp;lt;/option&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&amp;lt;/select&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;*/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;But wait, we do not even need the &lt;code&gt;\n&lt;/code&gt; (we can keep it though if we want, it’s a matter of preference):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; generateOptions(input) { &lt;span style=&#34;color:#888&#34;&gt;//format of [{key, value}, …] is expected
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; output = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;let&lt;/span&gt; item &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;of&lt;/span&gt; input) output += 
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;`
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;    &amp;lt;option value=&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;item.key&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;gt;&lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;item.value&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;/option&amp;gt;`&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; output;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; select = 
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;`&amp;lt;select class=&amp;#34;my-class&amp;#34;&amp;gt;&lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;options&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;/select&amp;gt;`&lt;/span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Let’s add a &lt;code&gt;button&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; generateOptions(input) { &lt;span style=&#34;color:#888&#34;&gt;//format of [{key, value}, …] is expected
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; output = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;let&lt;/span&gt; item &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;of&lt;/span&gt; input) output += &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;`
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;    &amp;lt;option value=&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;item.key&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;gt;&lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;item.value&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;/option&amp;gt;`&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; output;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; myChunk = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;`&amp;lt;select class=&amp;#34;my-class&amp;#34;&amp;gt;&lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;options&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;/select&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;lt;input type=&amp;#34;button&amp;#34; value=&amp;#34;GO&amp;#34;&amp;gt;`&lt;/span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;I’m literally (no pun intended) in awe to see that in JavaScript we can template HTML so nicely.&lt;/p&gt;
&lt;p&gt;Even some more complex problems are not problems when one uses template literals:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; upper(s) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; s.toUpperCase();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; who = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;reader&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; text =
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;`A very &lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;upper( &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;warm&amp;#34;&lt;/span&gt; )&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt; welcome
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;to all of you &lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;upper( &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;`&lt;/span&gt;&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;${&lt;/span&gt;who&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;s`&lt;/span&gt; )&lt;span style=&#34;color:#33b;background-color:#fff0f0&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;!`&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;console.log( text );
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// A very WARM welcome
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// to all of you READERS!
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id=&#34;forof-loops&#34;&gt;for&amp;hellip;of loops&lt;/h3&gt;
&lt;p&gt;The syntax looks like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; item &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;of&lt;/span&gt; collection) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;//Do something with item
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;for&lt;/code&gt;&amp;hellip;&lt;code&gt;of&lt;/code&gt; loops can only be executed for iterables. It is as if we were doing:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; key &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;in&lt;/span&gt; collection) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#888&#34;&gt;//Do something with collection[key]
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;However, there are technical differences for the loop of:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; item &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;of&lt;/span&gt; collection) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;//Do something with item
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Babel generates:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;use strict&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; _iterator = collection, _isArray = &lt;span style=&#34;color:#038&#34;&gt;Array&lt;/span&gt;.isArray(_iterator), _i = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {&lt;span style=&#34;color:#888&#34;&gt;//Do something with item
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; _ref;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (_isArray) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (_i &amp;gt;= _iterator.length) &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    _ref = _iterator[_i++];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  } &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;else&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    _i = _iterator.next();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (_i.done) &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    _ref = _i.value;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; item = _ref;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Let’s see some examples:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; a = [&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;a&amp;#34;&lt;/span&gt;,&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;b&amp;#34;&lt;/span&gt;,&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;c&amp;#34;&lt;/span&gt;,&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;d&amp;#34;&lt;/span&gt;,&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;e&amp;#34;&lt;/span&gt;];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; idx &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;in&lt;/span&gt; a) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    console.log( idx );
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// 0 1 2 3 4
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; valA &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;of&lt;/span&gt; a) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    console.log( valA );
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// &amp;#34;a&amp;#34; &amp;#34;b&amp;#34; &amp;#34;c&amp;#34; &amp;#34;d&amp;#34; &amp;#34;e&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; b = {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    key1: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;value1&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    key2: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;value2&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    key3: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;value3&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    key4: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;value4&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    key5: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;value5&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    key6: &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;value6&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;//”key1” “key2” “key3” “key4” “key5” “key6”
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; idy &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;in&lt;/span&gt; b) console.log(idy);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; valB &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;of&lt;/span&gt; b) console.log(valB);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;//Uncaught TypeError: b is not iterable
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;A pre-ES6 alternative is to get the keys of the object and iterate the set of keys:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; a = [&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;a&amp;#34;&lt;/span&gt;,&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;b&amp;#34;&lt;/span&gt;,&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;c&amp;#34;&lt;/span&gt;,&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;d&amp;#34;&lt;/span&gt;,&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;e&amp;#34;&lt;/span&gt;],
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        k = &lt;span style=&#34;color:#038&#34;&gt;Object&lt;/span&gt;.keys( a );
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; val, i = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;; i &amp;lt; k.length; i++) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    val = a[ k[i] ];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    console.log( val );
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// &amp;#34;a&amp;#34; &amp;#34;b&amp;#34; &amp;#34;c&amp;#34; &amp;#34;d&amp;#34; &amp;#34;e&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;An alternative using the iterator Symbol:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; a = [&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;a&amp;#34;&lt;/span&gt;,&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;b&amp;#34;&lt;/span&gt;,&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;c&amp;#34;&lt;/span&gt;,&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;d&amp;#34;&lt;/span&gt;,&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;e&amp;#34;&lt;/span&gt;];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; val, ret, it = a[Symbol.iterator]();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (ret = it.next()) &amp;amp;&amp;amp; !ret.done;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    val = ret.value;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    console.log( val );
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// &amp;#34;a&amp;#34; &amp;#34;b&amp;#34; &amp;#34;c&amp;#34; &amp;#34;d&amp;#34; &amp;#34;e&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Supported built-in values in JavaScript that are by default iterable:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Arrays&lt;/li&gt;
&lt;li&gt;Strings&lt;/li&gt;
&lt;li&gt;Generators&lt;/li&gt;
&lt;li&gt;Collections&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;An example with Strings:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; c &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;of&lt;/span&gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;hello&amp;#34;&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        console.log( c );
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// &amp;#34;h&amp;#34; &amp;#34;e&amp;#34; &amp;#34;l&amp;#34; &amp;#34;l&amp;#34; &amp;#34;o&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; c &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;of&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;new&lt;/span&gt; &lt;span style=&#34;color:#038&#34;&gt;String&lt;/span&gt;(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;hello&amp;#34;&lt;/span&gt;)) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    console.log( c );
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;// &amp;#34;h&amp;#34; &amp;#34;e&amp;#34; &amp;#34;l&amp;#34; &amp;#34;l&amp;#34; &amp;#34;o&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And another one with arrays and destructuring:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; o = {};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (o.a &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;of&lt;/span&gt; [&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;,&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;,&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;]);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;console.log(o);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; ({x: o.a} &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;of&lt;/span&gt; [ {x: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;}, {x: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;}, {x: &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;} ]);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;console.log(o);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And another one with generators:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; *myGenerator() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; y = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;while&lt;/span&gt; (y &amp;lt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;10&lt;/span&gt;) &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;yield&lt;/span&gt; y++;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; values = myGenerator();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (v &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;of&lt;/span&gt; values) console.log(v);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We have an upper boundary for &lt;code&gt;y&lt;/code&gt;. If there was no such boundary, the &lt;code&gt;for&lt;/code&gt;&amp;hellip;&lt;code&gt;of&lt;/code&gt; would go on forever.&lt;/p&gt;
&lt;p&gt;However, generators have a duplex channel of communication between the function and the caller. We can pass some values to a generator when we iterate it. I was thinking whether there is a way to pass values somehow to a generator while iterating it with a &lt;code&gt;for&lt;/code&gt;&amp;hellip;&lt;code&gt;of&lt;/code&gt; loop. Consider this example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; *myGenerator(input) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    console.log(input); &lt;span style=&#34;color:#888&#34;&gt;//undefined
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;while&lt;/span&gt;(input = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;yield&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        console.log(input); &lt;span style=&#34;color:#888&#34;&gt;//never gets here
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;    };
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; gen = myGenerator(&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; input &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;of&lt;/span&gt; gen);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We do not have difficulties in doing that with a &lt;code&gt;while&lt;/code&gt; cycle:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; *myGenerator(input) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    console.log(input);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;while&lt;/span&gt;(input = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;yield&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        console.log(input);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    };
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; gen = myGenerator(&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;//for (var input of gen);
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; counter = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;10&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;while&lt;/span&gt; (!gen.next(--counter).done);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;console.log(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;Finished&amp;#34;&lt;/span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If we intend to parameterize our generator using a for..of loop, then we are entering a rabbit hole and a lot of suffering awaits us. So, from our &lt;code&gt;for&lt;/code&gt;&amp;hellip;&lt;code&gt;of&lt;/code&gt; loop that we would like to parameterize:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; *myGenerator(input) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    console.log(input); &lt;span style=&#34;color:#888&#34;&gt;//undefined
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;while&lt;/span&gt;(input = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;yield&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        console.log(input); &lt;span style=&#34;color:#888&#34;&gt;//never gets here
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;    };
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; gen = myGenerator(&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; input &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;of&lt;/span&gt; gen);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Babel generates this hairy monster:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;use strict&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; _marked = &lt;span style=&#34;color:#888&#34;&gt;/*#__PURE__*/&lt;/span&gt;regeneratorRuntime.mark(myGenerator);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; myGenerator(input) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; regeneratorRuntime.wrap(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; myGenerator$(_context) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;while&lt;/span&gt; (&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;switch&lt;/span&gt; (_context.prev = _context.next) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    console.log(input);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    _context.next = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (!(input = _context.sent)) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        _context.next = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;7&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    console.log(input);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    _context.next = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;7&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    ;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;8&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;end&amp;#34;&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; _context.stop();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }, _marked, &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;this&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; gen = myGenerator();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; _iterator = gen, _isArray = &lt;span style=&#34;color:#038&#34;&gt;Array&lt;/span&gt;.isArray(_iterator), _i = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; _ref;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (_isArray) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (_i &amp;gt;= _iterator.length) &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        _ref = _iterator[_i++];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    } &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;else&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        _i = _iterator.next();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (_i.done) &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        _ref = _i.value;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; input = _ref;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This is not enough, since this strangely throws an error because &lt;code&gt;regeneratorRuntime&lt;/code&gt; does not exist, yet we try to call it. Let’s wrap a function around this code and download Babel’s polyfill:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;use strict&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; mainFunction() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; _marked = &lt;span style=&#34;color:#888&#34;&gt;/*#__PURE__*/&lt;/span&gt;regeneratorRuntime.mark(myGenerator);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; myGenerator(input) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; regeneratorRuntime.wrap(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; myGenerator$(_context) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;while&lt;/span&gt; (&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;switch&lt;/span&gt; (_context.prev = _context.next) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    console.log(input);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    _context.next = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (!(input = _context.sent)) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        _context.next = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;7&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    console.log(input);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    _context.next = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;7&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    ;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;8&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;end&amp;#34;&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; _context.stop();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }, _marked, &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;this&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; gen = myGenerator(&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; _iterator = gen, _isArray = &lt;span style=&#34;color:#038&#34;&gt;Array&lt;/span&gt;.isArray(_iterator), _i = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; _ref;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (_isArray) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (_i &amp;gt;= _iterator.length) &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        _ref = _iterator[_i++];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    } &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;else&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        _i = _iterator.next();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (_i.done) &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            _ref = _i.value;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; input = _ref;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; script = &lt;span style=&#34;color:#038&#34;&gt;document&lt;/span&gt;.createElement(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#39;script&amp;#39;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;script.onload = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; () {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    mainFunction();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;script.src = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.2.5/polyfill.min.js&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#038&#34;&gt;document&lt;/span&gt;.head.appendChild(script);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We can pass values to the iterator, like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;use strict&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; mainFunction() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; _marked = &lt;span style=&#34;color:#888&#34;&gt;/*#__PURE__*/&lt;/span&gt;regeneratorRuntime.mark(myGenerator);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; myGenerator(input) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; regeneratorRuntime.wrap(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; myGenerator$(_context) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;while&lt;/span&gt; (&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;switch&lt;/span&gt; (_context.prev = _context.next) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        console.log(input);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        _context.next = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (!(input = _context.sent)) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                            _context.next = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;7&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                            &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        console.log(input);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        _context.next = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;7&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        ;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;8&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;end&amp;#34;&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; _context.stop();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }, _marked, &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;this&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; gen = myGenerator(&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; index = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; (&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; _iterator = gen, _isArray = &lt;span style=&#34;color:#038&#34;&gt;Array&lt;/span&gt;.isArray(_iterator), _i = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; _ref;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (_isArray) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (_i &amp;gt;= _iterator.length) &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            _ref = _iterator[_i++];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        } &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;else&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            _i = _iterator.next(index = (index + &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;) % &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;10&lt;/span&gt;); &lt;span style=&#34;color:#888&#34;&gt;//passing parameters
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;&lt;/span&gt;            &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; (_i.done) &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            _ref = _i.value;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; input = _ref;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; script = &lt;span style=&#34;color:#038&#34;&gt;document&lt;/span&gt;.createElement(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#39;script&amp;#39;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;script.onload = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; () {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    mainFunction();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;script.src = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.2.5/polyfill.min.js&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#038&#34;&gt;document&lt;/span&gt;.head.appendChild(script);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;//1 2 3 4 5 6 7 8 9
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We can work with this, but we burden ourselves too much with:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;having to care about the Polyfills&lt;/li&gt;
&lt;li&gt;having to understand a bunch of unintuitive functions&lt;/li&gt;
&lt;li&gt;having to write and maintain unreadable code&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If we are not that masochistic, we will reach the conclusion that we need an alternative, a plan B here:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt; *myGenerator(input) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    console.log(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;start &amp;#34;&lt;/span&gt; + input);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;while&lt;/span&gt;((input = &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;yield&lt;/span&gt; (input * &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;)) &amp;lt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;10&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        console.log(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;inner &amp;#34;&lt;/span&gt; + input);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    };
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;false&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; index = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; gen = myGenerator(index = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;gen.next();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; tmp;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;while&lt;/span&gt;(!(tmp = gen.next(++index)).done) console.log(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;tmp &amp;#34;&lt;/span&gt; + tmp.value);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id=&#34;final-notes&#34;&gt;Final notes&lt;/h3&gt;
&lt;p&gt;I could write a lot more about Kyle’s books, notably promises, generators and their combinations are very interesting. But frankly, I think the book about asynchronous work does an excellent job explaining those. I recommend Kyle Simpson’s books to everyone. I think we owe a big &lt;strong&gt;thank you&lt;/strong&gt; to him and his effort to educate us. You can find his website at &lt;a href=&#34;https://me.getify.com/&#34;&gt;me.getify.com&lt;/a&gt;.&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>Work philosophy canon</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2018/05/work-philosophy-canon/"/>
      <id>https://www.endpointdev.com/blog/2018/05/work-philosophy-canon/</id>
      <published>2018-05-07T00:00:00+00:00</published>
      <author>
        <name>Jon Jensen</name>
      </author>
      <content type="html">
        &lt;img src=&#34;/blog/2018/05/work-philosophy-canon/pexels-photo-306534-sm.jpeg&#34; width=&#34;770&#34; height=&#34;348&#34; alt=&#34;people sitting on couch reading on tablet and laptop&#34;&gt;
&lt;h3 id=&#34;shared-culture&#34;&gt;Shared culture&lt;/h3&gt;
&lt;p&gt;Having some shared culture is important for working together well, and we can build that culture on familiar terminology, understanding, experiences, stories, and ideas.&lt;/p&gt;
&lt;p&gt;To help give all of us at End Point some common reference points, we have collected a set of valuable articles and books that we encourage everyone to read.&lt;/p&gt;
&lt;p&gt;Some of these have been standard reading at End Point for more than a decade, while others have been added over the years since we began doing this. Some are short and simple, others more in-depth. Our list is intentionally general, mostly avoiding specific technologies that only a subset of us use.&lt;/p&gt;
&lt;p&gt;No one article or book can be entirely authoritative for all situations, but each gives us more of the wisdom out there to consider and judiciously apply where it fits.&lt;/p&gt;
&lt;h3 id=&#34;slow-and-steady&#34;&gt;Slow and steady&lt;/h3&gt;
&lt;p&gt;When new employees start at End Point, we ask them to read the articles during their first week or two, and the relevant books within roughly their first year.&lt;/p&gt;
&lt;p&gt;Reading only a little at each sitting and spreading the reading out over time allows the ideas to sink in gradually and be incorporated into our work, rather than overwhelming with new information that cannot all be absorbed at once.&lt;/p&gt;
&lt;h3 id=&#34;for-everyone&#34;&gt;For everyone&lt;/h3&gt;
&lt;p&gt;Because we work in the software development industry, it is important that not only technical people such as developers, database experts, and system administrators be part of the shared culture. Everyone else at End Point including designers, project managers, sales, marketing, etc. should also be familiar with these articles and the terms and concepts they discuss:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://jsomers.net/blog/speed-matters&#34;&gt;Speed matters: Why working quickly is more important than it seems&lt;/a&gt; by James Somers&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://nohello.net/en/&#34;&gt;Please don’t just say hello in chat&lt;/a&gt; originally by Brandon High at nohello.com&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.codinghorror.com/learn-to-read-the-source-luke/&#34;&gt;Learn to Read the Source, Luke&lt;/a&gt; by Jeff Atwood—​practical reasons free software and open source matter, and why actually using the source code matters&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.gnu.org/philosophy/free-sw.html&#34;&gt;What is free software?&lt;/a&gt; by the Free Software Foundation and Richard Stallman&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://opensource.org/osd&#34;&gt;The Open Source Definition&lt;/a&gt; by the Open Source Initiative&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://web.archive.org/web/20201030161227/https://www.toolbox.com/tech/data-management/blogs/joshs-rules-of-database-contracting-062707/&#34;&gt;Josh’s Rules (of Database Contracting)&lt;/a&gt; by Josh Berkus&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;/blog/2008/08/on-excellence/&#34;&gt;On excellence&lt;/a&gt; by Ethan Rowe—​about ownership, taking responsibility for the problem at hand&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;/blog/2010/10/conventions/&#34;&gt;Conventions to know&lt;/a&gt; by Jon Jensen—​little but important things that ease communication in our work&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://web.archive.org/web/20180112070447/https://thecleverconsultant.com/how-to-sell-consulting-services-without-being-salesy/&#34;&gt;Selling Without Being Salesy&lt;/a&gt; by Jason Parks&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.startuplessonslearned.com/2008/11/five-whys.html&#34;&gt;Five Whys&lt;/a&gt; by Eric Ries (covered in more depth in his book &lt;a href=&#34;http://theleanstartup.com/book&#34;&gt;The Lean Startup&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://alanstevens.us/post/130828292006/softwareisamess&#34;&gt;Software Is a Mess and I Feel Fine&lt;/a&gt; by Alan Stevens&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://boringtechnology.club/&#34;&gt;Choose Boring Technology&lt;/a&gt; by Dan McKinley&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://basecamp.com/books/getting-real&#34;&gt;Getting Real&lt;/a&gt; book by 37signals (now Basecamp)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;for-developers&#34;&gt;For developers&lt;/h3&gt;
&lt;p&gt;These articles and books are targeted primarily at developers but enlightening for everyone:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.cl.cam.ac.uk/~mgk25/iso-time.html&#34;&gt;A summary of the international standard date and time notation&lt;/a&gt; by Markus Kuhn&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://adminzen.org/&#34;&gt;The Admin Zen&lt;/a&gt; by Michael Prokop—​in true DevOps fashion, this system administration advice applies to development too&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.joelonsoftware.com/2000/04/06/things-you-should-never-do-part-i/&#34;&gt;Things You Should Never Do, Part I&lt;/a&gt; by Joel Spolsky—​don’t rewrite things from scratch (almost never, anyway)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/michaeljones/on-commit-messages&#34;&gt;On Git Commit Messages&lt;/a&gt; by Michael Jones; to get a feel for the long history of others sermonizing on the same worthwhile topic, see also:
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://chris.beams.io/posts/git-commit/&#34;&gt;How to Write a Git Commit Message&lt;/a&gt; by Chris Beams&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://who-t.blogspot.com/2009/12/on-commit-messages.html&#34;&gt;On commit messages&lt;/a&gt; by Peter Hutterer&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html&#34;&gt;A Note About Git Commit Messages&lt;/a&gt; by Tim Pope&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://mislav.net/2014/02/hidden-documentation/&#34;&gt;Every line of code is always documented&lt;/a&gt; by Mislav Marohnić; see also &lt;a href=&#34;http://www.philandstuff.com/2014/02/09/git-pickaxe.html&#34;&gt;The git pickaxe&lt;/a&gt; by Philip Potter&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://designbygravity.wordpress.com/2009/10/23/how-to-read-other-peoples-code-and-why/&#34;&gt;How to Read Other People’s Code—​and Why&lt;/a&gt; by Christopher Schanck&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://web.archive.org/web/20190626055515/http://www.w2lessons.com/2011/04/you-dont-know-javascript.html&#34;&gt;You don’t know JavaScript&lt;/a&gt; by Michael Woloszynowicz—​the lessons apply to most technologies&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://pragprog.com/titles/tpp20/&#34;&gt;The Pragmatic Programmer&lt;/a&gt; book by Andy Hunt and Dave Thomas (see the &lt;a href=&#34;/blog/2020/10/the-pragmatic-programmer-20th-anniversary-edition/&#34;&gt;write-up on the new 20th anniversary edition by Jon Jensen&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://pragprog.com/titles/pad/practices-of-an-agile-developer/&#34;&gt;Practices of an Agile Developer&lt;/a&gt; book by Venkat Subramaniam and Andy Hunt—​kind of a sequel to The Pragmatic Programmer (see the &lt;a href=&#34;/blog/2006/06/review-practices-of-agile-developer/&#34;&gt;review by Ethan Rowe&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;any-others&#34;&gt;Any others?&lt;/h3&gt;
&lt;p&gt;We are always on the lookout for other readings that are helpful, so feel free to leave a comment with your favorites!&lt;/p&gt;
&lt;p&gt;(Updated in early 2021 with articles on Git commit messages and history spelunking, and Choose Boring Technology.)&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>Ruby Fight Club</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2016/08/ruby-fight-club/"/>
      <id>https://www.endpointdev.com/blog/2016/08/ruby-fight-club/</id>
      <published>2016-08-31T00:00:00+00:00</published>
      <author>
        <name>Greg Davidson</name>
      </author>
      <content type="html">
        &lt;p&gt;&lt;img alt=&#34;men boxing&#34; src=&#34;/blog/2016/08/ruby-fight-club/image-0.jpeg&#34; /&gt;&lt;br&gt;Photo by &lt;a href=&#34;https://www.flickr.com/photos/superwebdeveloper/&#34;&gt;Peter Gordon&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;first-rule-do-not-talk-about-ruby-fight-club&#34;&gt;First Rule: Do Not Talk About Ruby Fight Club&lt;/h3&gt;
&lt;p&gt;This post may get me kicked out for talking about the club, but…I was asked to share a few thoughts about something we tried out earlier this year at End Point. We ran an internal meetup dubbed Ruby Fight Club to read and discuss &lt;a href=&#34;https://www.poodr.com/&#34;&gt;Practical Object-Oriented Design in Ruby&lt;/a&gt; (POODR) by Sandi Metz.&lt;/p&gt;
&lt;img align=&#34;right&#34; alt=&#34;Poodr cover&#34; border=&#34;0&#34; height=&#34;250&#34; src=&#34;/blog/2016/08/ruby-fight-club/image-1.jpeg&#34; title=&#34;poodr-cover.jpg&#34; width=&#34;191&#34; /&gt;
In the past we’ve met together as a company and in smaller team or project focused groups but this was first time we used a book as the guiding, recurring topic with a smaller, committed group who made time for it. Attendance was optional and we did have some folks who opted out even though they loved the subject matter and the idea, because they knew they couldn’t make it most of the time. I think this made the group tighter-knit.
&lt;p&gt;Our group of six remote engineers met weekly for one hour to discuss one chapter from the book. We worked through each chapter together which often led to Q&amp;amp;A sessions and deeper discussions about Ruby and &lt;a href=&#34;https://en.wikipedia.org/wiki/Computer_science&#34;&gt;computer science&lt;/a&gt; theory in general. Each week, one member of the team would lead the discussion. It required some preparation in advance and gave us all a chance to work on our presenting and moderating skills. We used Google Hangouts to meet and the presenter would share their screen to show slides and example code.&lt;/p&gt;
&lt;h3 id=&#34;honing-our-craft&#34;&gt;Honing Our Craft&lt;/h3&gt;
&lt;p&gt;As consultants we have to balance technical perfection with other considerations—​most often budget and timelines/​deadlines. This reality does not lend itself well to developing and learning to apply new technical concepts. It’s also challenging to apply these new concepts in large, established projects where our role is to maintain and extend existing code. The conventions and architecture are well established and it’s hard to push against projects with inertia like this. Setting some time aside each week not tied to client projects gave us the opportunity to focus on our skills and develop them together. Although several in the group had read the POODR book before, they reported that working through each chapter and discussing it in a group setting greatly increased their understanding of the material.&lt;/p&gt;
&lt;h3 id=&#34;face-time&#34;&gt;Face Time&lt;/h3&gt;
&lt;p&gt;Our company has a large number of full-time remote engineers. At time of this writing close to 90% of us work in a location other than our head office in NYC. Remote work allows us the freedom to live where we want (I’m writing this from my home office in a small town in the interior of British Columbia, Canada) but requires extra effort for us to build team camaraderie and social connections. Ruby Fight Club was great for this. Although Hangouts, Skype and other video-conferencing apps have their challenges, everyone let us know they appreciated being able to spend time with the group each week. We’d often chat with each other for a few minutes before and after our book discussions.&lt;/p&gt;
&lt;p&gt;Discussing the book (somewhat) face-to-face over video also increased the fidelity and efficiency of our discussions. When you can see people’s faces, expressions and gestures it’s much easier to glean information and understand them. It feels silly and obvious to say this after the fact but it’s novel when the majority of your workday communication is done over IRC/​Slack, email and phone/​audio.&lt;/p&gt;
&lt;h3 id=&#34;got-meetups&#34;&gt;Got Meetups?&lt;/h3&gt;
&lt;p&gt;During one of our meetings I asked the group if anyone went to meetups local to them. I was surprised to learn that &lt;em&gt;none&lt;/em&gt; in the group did so. For every person the response was similar: “I would but there aren’t any groups meeting nearby”. I had assumed that I was the odd one out in this way because I live in a small town. The leader of our group lives in Chicago and I thought for sure there would be a meetup for him to attend but there wasn’t. The closest group to him required a long trip across town on public transit. Occasionally I &lt;em&gt;do&lt;/em&gt; travel 45-60 minutes (each way!) from home to attend meetups in &lt;a href=&#34;http://okdg.org/&#34;&gt;larger&lt;/a&gt;, &lt;a href=&#34;https://startupvernon.com/&#34;&gt;nearby&lt;/a&gt; &lt;a href=&#34;https://kamloopsinnovation.ca/&#34;&gt;towns&lt;/a&gt;. People are often surprised I travel so far but it’s worth it to me.&lt;/p&gt;
&lt;h3 id=&#34;what-worked-well&#34;&gt;What Worked Well&lt;/h3&gt;
&lt;p&gt;We stuck to the time limit (mostly) which was a good thing. We found we usually had enough time to socialize a bit, discuss the book, have a Q&amp;amp;A time and then get back to our client work. Sharing the presenting/​discussion leading role was also nice. Leading a session took a little time to prepare but because we all took turns doing this we shared the load.&lt;/p&gt;
&lt;p&gt;I’d like to personally thank Phunk (our fearless Ruby Fight Club leader) for having the idea and executing so well on it. We all really appreciate it and look forward to running more meetups like it in future.&lt;/p&gt;
&lt;h3 id=&#34;what-we-might-do-differently-next-time&#34;&gt;What We Might Do Differently Next Time&lt;/h3&gt;
&lt;p&gt;I think it would be good to allow a little more time for socializing and chat. This happened naturally in Ruby Fight Club but it would be cool to devote a block of time specifically to it.&lt;/p&gt;
&lt;p&gt;It would also be nice to allow time for people to do a show and tell/​lightning talk about something they are interested in. That said, having a book to work through was really great. Every week there is something to discuss and it was often a starting point to further discussions.&lt;/p&gt;
&lt;p&gt;What are you doing at your companies to stay sharp and connected? Let us know, we’d love to hear from you!&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>Book review: “Two Scoops of Django: Best Practices for Django 1.8”</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2016/07/book-review-two-scoops-of-django-best/"/>
      <id>https://www.endpointdev.com/blog/2016/07/book-review-two-scoops-of-django-best/</id>
      <published>2016-07-13T00:00:00+00:00</published>
      <author>
        <name>Phineas Jensen</name>
      </author>
      <content type="html">
        &lt;p&gt;&lt;em&gt;Two Scoops of Django: Best Practices for Django 1.8&lt;/em&gt; is, shockingly, a book about best practices. It’s not a Django library reference, or a book about Django fundamentals, or tips and tricks. It’s a book designed to help web developers, novices and experts alike, avoid common pitfalls in every stage of the web development process, specifically the process of developing with Django.&lt;/p&gt;
&lt;p&gt;The book can be used as a reference of best practices and a cover-to-cover guide to best practices. I’ve done both and found it to be enjoyable, accessible, and educational when read cover-to-cover and a valuable reference when setting up a new Django project or doing general Django development. It covers a huge range of material, answering questions like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Where should I store secret keys?&lt;/li&gt;
&lt;li&gt;Should I use virtualenv?&lt;/li&gt;
&lt;li&gt;How should I structure my Django project?&lt;/li&gt;
&lt;li&gt;When should I use ‘blank’ and ‘null’ in model fields?&lt;/li&gt;
&lt;li&gt;Should I use Class-Based Views or Function-Based Views?&lt;/li&gt;
&lt;li&gt;How should I structure my URLConfs?&lt;/li&gt;
&lt;li&gt;When should I use Forms?&lt;/li&gt;
&lt;li&gt;Where should templates be stored?&lt;/li&gt;
&lt;li&gt;Should I write custom template tags and filters?&lt;/li&gt;
&lt;li&gt;What package should I use to create a REST API?&lt;/li&gt;
&lt;li&gt;What core components should I replace?&lt;/li&gt;
&lt;li&gt;How can I modify or replace the User and authentication system?&lt;/li&gt;
&lt;li&gt;How should I test my app?&lt;/li&gt;
&lt;li&gt;How can I improve performance?&lt;/li&gt;
&lt;li&gt;How can I keep my app secure?&lt;/li&gt;
&lt;li&gt;How do I properly use the logging library?&lt;/li&gt;
&lt;li&gt;How do I deploy to a Platform as a Service or my own server(s)?&lt;/li&gt;
&lt;li&gt;What can I do to improve the debugging process?&lt;/li&gt;
&lt;li&gt;What are some good third-party packages?&lt;/li&gt;
&lt;li&gt;Where can I find good documentation and tutorials?&lt;/li&gt;
&lt;li&gt;Where should I go to ask more questions?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The question, then, is whether or not this book delivers this information well. For the most part, it does. It’s important to recognize that the book doesn’t cover any of these subjects in great detail, but it does do a great job explaining the “why” behind some of the simple rules that are established and referencing online resources that can be used to go much more in-depth with the subject. It does a great job showing clearly marked bad examples, making it very easy to see whether or not you are or were planning on doing something badly. The writing style is very accessible and straightforward; I read large portions of the book during breakfast or lunch.&lt;/p&gt;
&lt;p&gt;Two sections stood out to me as being very helpful for my own projects. First is Chapter 4, Fundamentals of Django App Design, which explained better than any resource I’ve found yet exactly what a Django “app” (as in ./manage.py startapp polls) should be used for. It explains what an app should or shouldn’t have in it, how much an app should do, when you should break into separate apps, and more.&lt;/p&gt;
&lt;p&gt;The next section that really helped me was Chapter 6, Model Best Practices, which explained things like what code should and shouldn’t be in a model, how to use migrations and managers, and ModelFields that should be avoided. Perhaps the most useful part of that chapter is a table in the section “When to use Null and Blank,” which makes for an easy and quick reference to which fields go well with the null and blank parameters and when you should use both or neither.&lt;/p&gt;
&lt;p&gt;The only real problem I had with Two Scoops of Django was that the illustrations rarely felt necessary or helpful. The majority of them are ice cream-themed jokes that aren’t particularly funny. Overall, I really enjoyed this book and I definitely recommend it for anybody who is or is interested in doing serious Django development.&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>Usability: Don’t Make Me Think and a Bookmarklet</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2015/08/usability-dont-make-me-think-and/"/>
      <id>https://www.endpointdev.com/blog/2015/08/usability-dont-make-me-think-and/</id>
      <published>2015-08-13T00:00:00+00:00</published>
      <author>
        <name>Steph Skardal</name>
      </author>
      <content type="html">
        &lt;p&gt;&lt;em&gt;Hi! Steph here, former long-time End Point employee now blogging from afar as a software developer for &lt;a href=&#34;https://pinholepress.com/&#34;&gt;Pinhole Press&lt;/a&gt;. While I’m no longer an employee of End Point, I’m happy to blog and share here.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I’m only about a quarter of the way into &lt;a href=&#34;https://www.sensible.com/dmmt.html&#34;&gt;Don’t Make Me Think (Revised)&lt;/a&gt; by Steve Krug, but I can already tell it’s a winner. It’s a great (and quick) book about web usability, with both high level concepts and nitty gritty examples. I highly recommend it! Even if you aren’t interested in web usability but are a web developer, it’s still a quick read and would be invaluable to whomever you are coding for these days.&lt;/p&gt;
&lt;h3 id=&#34;a-bookmarklet&#34;&gt;A Bookmarklet&lt;/h3&gt;
&lt;p&gt;The book inspired me to write a quick bookmarklet to demonstrate some high level concepts related to usability. Here’s the bookmarklet:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;javascript:(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; possible = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34; ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  $(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#39;*:not(iframe)&amp;#39;&lt;/span&gt;).contents().filter(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;this&lt;/span&gt;.nodeType == Node.TEXT_NODE &amp;amp;&amp;amp; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;this&lt;/span&gt;.nodeValue.trim() != &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  }).each(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;function&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; new_content = &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt;(&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;var&lt;/span&gt; i = &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;this&lt;/span&gt;.nodeValue.trim().length; i++) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       new_content += possible.charAt(&lt;span style=&#34;color:#038&#34;&gt;Math&lt;/span&gt;.floor(&lt;span style=&#34;color:#038&#34;&gt;Math&lt;/span&gt;.random() * possible.length));
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;this&lt;/span&gt;.nodeValue = new_content;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  });
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;})();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;To add the bookmarklet to your browser, simply copy the code in as the location for a new bookmark (and name it anything you want). Note that this particular bookmarklet assumes jQuery is installed, so it may not work on all websites. &lt;a href=&#34;https://gist.github.com/stephskardal/23112aa8e63252ac5be9&#34;&gt;Gist available here&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;what-does-it-do&#34;&gt;What does it do?&lt;/h3&gt;
&lt;p&gt;In short, the bookmarklet converts readable text on the page to jibberish (random characters of the same length). Pictures are worth a thousand words here. Here are some example pages with the bookmarklet in action:&lt;/p&gt;
&lt;img border=&#34;0&#34; src=&#34;/blog/2015/08/usability-dont-make-me-think-and/image-0.png&#34; style=&#34;margin-bottom:5px;&#34; width=&#34;800&#34;/&gt;
&lt;p&gt;End Point home page.&lt;/p&gt;
&lt;img border=&#34;0&#34; src=&#34;/blog/2015/08/usability-dont-make-me-think-and/image-1.png&#34; style=&#34;margin-bottom:5px;&#34; width=&#34;800&#34;/&gt;
&lt;p&gt;End Point client list page.&lt;/p&gt;
&lt;img border=&#34;0&#34; src=&#34;/blog/2015/08/usability-dont-make-me-think-and/image-2.png&#34; style=&#34;margin-bottom:5px;&#34; width=&#34;800&#34;/&gt;
&lt;p&gt;&lt;a href=&#34;https://www.stance.com/&#34;&gt;Stance&lt;/a&gt; popup, with item in cart.&lt;/p&gt;
&lt;img border=&#34;0&#34; src=&#34;/blog/2015/08/usability-dont-make-me-think-and/image-3.png&#34; style=&#34;margin-bottom:5px;&#34; width=&#34;800&#34;/&gt;
&lt;p&gt;&lt;a href=&#34;http://www.backcountry.com/womens-clothing&#34;&gt;Backcountry.com&lt;/a&gt; product listing page.&lt;/p&gt;
&lt;img border=&#34;0&#34; src=&#34;/blog/2015/08/usability-dont-make-me-think-and/image-4.png&#34; style=&#34;margin-bottom:5px;&#34; width=&#34;800&#34;/&gt;
&lt;p&gt;&lt;a href=&#34;http://www.citypass.com/&#34;&gt;CityPASS&lt;/a&gt; home page.&lt;/p&gt;
&lt;h3 id=&#34;why-does-this-matter&#34;&gt;Why does this matter?&lt;/h3&gt;
&lt;p&gt;The bookmarklet provokes thought related to high level usability concepts, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Is it clear which buttons are clickable?&lt;/li&gt;
&lt;li&gt;Is the visual hierarchy clear?&lt;/li&gt;
&lt;li&gt;What conventions does the user interface follow?&lt;/li&gt;
&lt;li&gt;Users browsing behavior is often to hyperfocus and click on what they are looking for while ignoring other content entirely. Does the user interface aid or hinder that behavior?&lt;/li&gt;
&lt;li&gt;How and what do images communicate on the page?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All of these ideas are great things to talk through when implementing user interface changes or rolling out an entirely new website. And if you are interested in learning more, &lt;a href=&#34;https://www.sensible.com/dmmt.html&#34;&gt;visit Steve Krug’s website&lt;/a&gt;.&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>A review of The Rails 4 Way</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2013/11/a-review-of-rails-4-way/"/>
      <id>https://www.endpointdev.com/blog/2013/11/a-review-of-rails-4-way/</id>
      <published>2013-11-27T00:00:00+00:00</published>
      <author>
        <name>Kent Krenrich</name>
      </author>
      <content type="html">
        &lt;p&gt;With a brand new project on the horizon (and a good candidate for &lt;a href=&#34;http://weblog.rubyonrails.org/2013/6/25/Rails-4-0-final/&#34;&gt;Ruby on Rails 4&lt;/a&gt; at that), I thought it would be a productive use of my time to bone up on some of the major differences introduced with this new version. My goal was to trade a little research for as many precluded that’s-not-how-we-do-it-anymore-500-errors as I could when fleshing out my first scaffold.&lt;/p&gt;
&lt;p&gt;With this goal in mind, I purchased a copy of &lt;a href=&#34;https://leanpub.com/tr4w&#34;&gt;The Rails 4 Way&lt;/a&gt; by &lt;a href=&#34;https://leanpub.com/u/obie&#34;&gt;Obie Fernandez&lt;/a&gt;, &lt;a href=&#34;https://leanpub.com/u/kfaustino&#34;&gt;Kevin Faustino&lt;/a&gt;, and &lt;a href=&#34;https://leanpub.com/u/vitalykushner&#34;&gt;Vitaly Kushner&lt;/a&gt;. Considering the free-nature of everything else Rails related, I will admit to a slight aversion to paying money for a Rails book. For those of you out there with similar proclivities, I felt compelled to share my experience.&lt;/p&gt;
&lt;p&gt;The Rails 4 Way presents itself not as a tutorial of Ruby on Rails, but as “a day-to-day reference for the full-time Rails developer.” The tone of the book and the depth of information presented hints that the authors don’t want to teach you how to write Ruby on Rails applications. They want to share insight that will help you write &lt;strong&gt;better&lt;/strong&gt; Ruby on Rails applications. Much of this is accomplished by fleshing out—​utilizing a plentiful source of examples and snippets—​the methods and features the framework has to offer.&lt;/p&gt;
&lt;p&gt;Early on the authors concede the point, “There are definitely sections of the text that experienced Rails developer will gloss over. However, I believe that there is new knowledge and inspiration in every chapter, for all skill levels.” I would classify myself as an experienced Rails developer and I found this statement to be completely true. When settling down to read the book for the first time, I scrolled through the pages until a specific topic caught my eye. As a result of this, I started my read part-way through chapter 4. Upon completion of the last section, I wrapped back around to the beginning and dutifully read everything including the foreword. I did this specifically because each of the chapters, if not sections, had contained at least one little nugget of information that I found valuable. I felt compelled to go back and look for the extra tidbits that I’d passed over with the initial, casual flicks of my mouse.&lt;/p&gt;
&lt;p&gt;I mentioned that the authors focus more on helping you produce better code, and to this end, they don’t dance around any issues. My favorite quote from the book illustrates this, “Frankly, there’s not much of a reason why that should be a problem unless you’ve made some pretty bad data-modeling decisions.” By all means, call it like it is.&lt;/p&gt;
&lt;p&gt;The book is still a work-in-progress. Somewhere around 10% of the sections contain “TBD” rather than a body. I gather that the book is based on its Rails 3 counterpart and some of the sections have yet to be enhanced with the Rails-4-specific content. A majority share of the Rails 3 content is still applicable, so this shortcoming did not mar my experience at all. Especially since I will be given access to the new content once it is added. At the time of my download, the last change was authored 12 days ago, so for that reason also, I am unconcerned.&lt;/p&gt;
&lt;p&gt;In conclusion, I took enough new information away, and enjoyed the process enough that I feel confident in recommending The Rails 4 Way to friends and coworkers. The bulk of this book reads like an API document, and in those sections, there’s nothing technical that you can’t find on the Rails API page itself. What the book does offer is back-story into what these methods were designed to do and what they pair well with. I would compare the Rails API and this book to a map in your hand and a local who knows the area. Most of the time you can figure out how to get where you need to go by carefully reading your unfolded map. But sometimes it’s faster to ask a local who can tell you, “See that red sign off in the distance? Head over to it and take a right.”&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>Book Recommendation: Ghost in the Wires</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2011/11/book-recommendation-ghost-in-wires/"/>
      <id>https://www.endpointdev.com/blog/2011/11/book-recommendation-ghost-in-wires/</id>
      <published>2011-11-29T00:00:00+00:00</published>
      <author>
        <name>Steph Skardal</name>
      </author>
      <content type="html">
        &lt;p&gt;&lt;a href=&#34;https://www.amazon.com/Ghost-Wires-Adventures-Worlds-Wanted/dp/0316037702&#34;&gt;&lt;img border=&#34;0&#34; width=&#34;200&#34; height=&#34;300&#34; src=&#34;/blog/2011/11/book-recommendation-ghost-in-wires/image-0.png&#34; style=&#34;float: right; margin: 1em;&#34; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I recently listened to &lt;a href=&#34;https://www.amazon.com/Ghost-Wires-Adventures-Worlds-Wanted/dp/0316037702&#34;&gt;Ghost in the Wires&lt;/a&gt; by Kevin Mitnick as an audiobook during my long Thanksgiving vacation drives. This non-fiction book is a first-person account about Kevin Mitnick’s phone and computer break-in (or what he claims to be ethical hacking) adventures in the late eighties and early nineties, and it touches on the following legal proceedings from 1995 on. A couple of interesting things stood out to me:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Kevin’s tactics revolve around &lt;a href=&#34;https://en.wikipedia.org/wiki/Social_engineering_(security)&#34;&gt;social engineering&lt;/a&gt;, or techniques that capitalize on flaws in “human hardware” to gain information. The book was an eye opener in terms of how easily Kevin gained access to systems, as there are countless examples of Kevin’s ability to gain credibility, pretext, introduce diversions, etc.&lt;/li&gt;
&lt;li&gt;Another highlight of the book for me was learning details of how bug reports were exploited to gain sensitive information. Kevin gained access to bug reports on proprietary software to exploit the software and gain access to the systems running the software. I don’t think of my own clients’ bug reports as an extremely valuable source of information for exploiting vulnerabilities to gain user information, but there have been a few instances in the past where bugs could have been used maliciously.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;follow-up-comments&#34;&gt;Follow-up Comments&lt;/h3&gt;
&lt;p&gt;One thing that strikes me is how the internet and technology has changed since Kevin’s infringements, specifically in the development of open source software. End Point works with open source operating systems, packages, monolithic ecommerce applications, and modular open source elements (e.g. Rails gems, CPAN modules). Bug reports on open source applications are easily accessible. For example, &lt;a href=&#34;https://weblog.rubyonrails.org/2011/11/18/rails-3-1-2-has-been-released/&#34;&gt;here&lt;/a&gt; is an article on the security vulnerabilities in recent versions of Rails.&lt;/p&gt;
&lt;p&gt;The responsibility of keeping up with security updates shifts to the website owner leveraging these open source solutions (or the hosting provider and/or developer in some cases). I spoke with a few developers a couple of years ago about how public WordPress security vulnerabilities enable unethical hackers to easily gain access to sites running WordPress without the security updates. With the increased popularity of open source and visibility of security vulnerabilities, it’s important to keep up with security updates, especially those which might make sensitive user information available.&lt;/p&gt;
&lt;p&gt;With the advancement in technology, security processes should become a normal part of development. For example, End Point has standard security processes in place such as use of ssh keys, firewalls for server access, and PGP encryption. Our clients also follow &lt;a href=&#34;https://www.pcisecuritystandards.org/&#34;&gt;PCI compliance&lt;/a&gt; regulations regarding storing credit card numbers and security numbers in encrypted form only, or in some cases not at all if a third party payment processor is used. It’s nice to use a third party service for storing credit card data since the responsibility of storing sensitive cardholder data shifts to the third party (however, the interaction between your site and the third party must be protected).&lt;/p&gt;
&lt;p&gt;This is an interesting read (or listen) that I recommend to anyone working with sensitive information in the tech field. Learning about the social engineering techniques was fascinating in itself and technical bits are scattered throughout the book which make it suitable for tech-savvy and non-tech-savvy readers.&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>Pentaho Reporting 3.5 for Java Developers</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2009/10/pentaho-reporting-35-for-java_28/"/>
      <id>https://www.endpointdev.com/blog/2009/10/pentaho-reporting-35-for-java_28/</id>
      <published>2009-10-28T00:00:00+00:00</published>
      <author>
        <name>Josh Tolley</name>
      </author>
      <content type="html">
        &lt;p&gt;I was recently asked to review a copy of Will Gorman’s Pentaho Reporting 3.5 for Java Developers, and came to a few important realizations. Principal among these is that my idea of what “reporting” means includes far too little. Reporting includes much more than just creating a document with some graphs on it—​any document or presentation including information from a “data source” comprises a “report”. This includes the typical sheaf of boardroom presentation slides, but also includes dashboards within an application, newsletters, or even form letters. I recently discovered that a local church group uses a simple reporting application to print its membership directory. In short, it’s not just the analysts and managers that can use reporting.&lt;/p&gt;
&lt;p&gt;The book gives the reader a tour of Pentaho’s newest Pentaho Reporting system, which consists of a desktop application where users define reports, and a library by which developers can integrate those reports into their own applications. So as an example, not only can Pentaho Reporting publish weekly sales printouts, but it can also produce real-time inventory information in a J2EE-based web application or even a Swing application running on a user’s desktop. Gorman describes, step-by-step, the process of building a report, integrating advanced data sources, working with graphics and visualizations, and building custom reporting components such as user-defined functions and custom report controls. Although this step-by-step description combined with Java’s native verbosity occasionally make it difficult to read cover to cover, it provides a valuable reference and starting point for users wanting to implement advanced reporting features.&lt;/p&gt;
&lt;p&gt;Shortly after having grasped the idea that “reporting”, as a concept, was broader than I’d originally assumed, I got the idea that I’d like to know how to use Pentaho to replace a reporting system I worked on a while ago, which used Jython to gather data from a JMX server. Pentaho Reporting allows users to create data sources in languages other than Java, via the &lt;a href=&#34;https://commons.apache.org/proper/commons-bsf/&#34;&gt;Apache Bean Scripting Framework&lt;/a&gt;, suggesting that my old Jython code might work mostly unchanged via Bean Scripting. Disappointingly, the book doesn’t give an example of this technique, but since the Bean Scripting integration is still considered experimental (along with, apparently, several other data source types, contributed by the Pentaho community). Perhaps I’ll figure this out one day, and make it the subject of a future blog post.&lt;/p&gt;
&lt;p&gt;This fairly slight omission notwithstanding, I enjoyed the book and the ideas it suggested about places I might apply more interesting reporting. Thanks to PacktPub for the opportunity to review it.&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>David Mamet on software development</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2009/02/david-mamet-on-software-development/"/>
      <id>https://www.endpointdev.com/blog/2009/02/david-mamet-on-software-development/</id>
      <published>2009-02-07T00:00:00+00:00</published>
      <author>
        <name>Jon Jensen</name>
      </author>
      <content type="html">
        &lt;p&gt;I recently read the book &lt;a href=&#34;https://en.wikipedia.org/wiki/True_and_False:_Heresy_and_Common_Sense_for_the_Actor&#34;&gt;True and False: Heresy and Common Sense for the Actor&lt;/a&gt; (1997) by David Mamet. (A gift from Uncle Steve. Thanks!) Mamet’s film &lt;a href=&#34;https://www.imdb.com/title/tt0120176/&#34;&gt;The Spanish Prisoner&lt;/a&gt; is one of my favorites, and I liked &lt;a href=&#34;https://www.imdb.com/title/tt0110722/&#34;&gt;Oleanna&lt;/a&gt;, &lt;a href=&#34;https://www.imdb.com/title/tt0096259/&#34;&gt;Things Change&lt;/a&gt;, and &lt;a href=&#34;https://www.imdb.com/title/tt0104348/&#34;&gt;Glengarry Glen Ross&lt;/a&gt; a lot too. Wait, looking over his &lt;a href=&#34;https://www.imdb.com/name/nm0000519/&#34;&gt;writing credits at IMDb&lt;/a&gt;, I see I’d forgotten &lt;a href=&#34;https://www.imdb.com/title/tt0155388/&#34;&gt;The Winslow Boy&lt;/a&gt;, &lt;a href=&#34;https://www.imdb.com/title/tt0120202/&#34;&gt;State and Main&lt;/a&gt;, and &lt;a href=&#34;https://www.imdb.com/title/tt0120885/&#34;&gt;Wag the Dog&lt;/a&gt;, which were good too.&lt;/p&gt;
&lt;p&gt;Enough of the fanboyism. This little book of his is packed with what sounds like good advice for actors. Not having been an actor in anything more than a school play or two, I can only imagine, but I was surprised to find myself nodding in agreement during many passages because they applied so well to my field, software development.&lt;/p&gt;
&lt;p&gt;I’ve selected a few quotations that seemed especially apt:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I was once at a marriage ceremony where the parties swore “to try to be faithful, to try to be considerate …” That marriage was, of course, doomed. Any worthwhile goal is difficult to accomplish. To say of it “I’ll try” is to excuse oneself in advance. Those who respond to our requests with “I’ll try” intend to deny us, and call on us to join in the hypocrisy—as if there were some merit in intending anything other than accomplishment. (p. 34)&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;This reminded me of Richard Stallman’s take on the same subject:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Yoda’s philosophy (“There is no ‘try’”) sounds neat, but it doesn’t work for me. I have done most of my work while anxious about whether I could do the job, and unsure that it would be enough to achieve the goal if I did. But I tried anyway, because there was no one but me between the enemy and my city. Surprising myself, I have sometimes succeeded. (from the essay, &lt;a href=&#34;https://www.gnu.org/gnu/thegnuproject.html&#34;&gt;The GNU Project&lt;/a&gt;)&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Though they appear to be contradictory, I think both approaches can apply depending on circumstances and I’ve employed each at various times. Whoa, there … nuance.&lt;/p&gt;
&lt;p&gt;I don’t have comments about the rest of these excerpts:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The simple performance of the great deed, onstage or off, is called “heroism.” The person who will not be swayed, who perseveres no matter what—that hero has the capacity to inspire us, to suggest that we reexamine our self-imposed limitations and try again. (p. 13)&lt;/p&gt;&lt;/blockquote&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;The middle-class work ethic: “But I did my preparation. It is not my fault if the truth of the moment does not conform.” That ethic is not going to avail. Nobody cares how hard you worked. Nor should they.&lt;/p&gt;
&lt;p&gt;   Acting, which takes places for an audience, is not as the academic model would have us believe. It is not a test. It is an art, and it requires not tidiness, not paint-by-numbers intellectuality, but immediacy and courage. (p. 32)&lt;/p&gt;&lt;/blockquote&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;Let us learn &lt;em&gt;acceptance&lt;/em&gt;. This is one of the greatest tools an actor can have. The capacity to accept: to wish things to happen as they do. It is the root of all happiness in life, and it is the root of wisdom for an actor. Acceptance. Because the capacity to &lt;em&gt;accept&lt;/em&gt; derives from the &lt;em&gt;will&lt;/em&gt; and the will is the source of character. Applying our intention to use only one meaning for words, character is the same onstage and off. It is habitual action. …&lt;/p&gt;
&lt;p&gt;   The habit of cheerful acceptance is an aide in the greater life in the theatre, too, because it induces truthful consideration: “The world is as it is, what can I do about it?” … (pp. 70–71)&lt;/p&gt;&lt;/blockquote&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;Carve the big tasks up into small tasks and perform these small tasks. (p. 76)&lt;/p&gt;&lt;/blockquote&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;The more you are concerned with yourself, the less you are worthy of note.&lt;/p&gt;
&lt;p&gt;   The more a person’s concentration is outward, the more naturally interesting that person becomes. …&lt;/p&gt;
&lt;p&gt;   The person with attention directed outward becomes various and provocative. The person endeavoring to become various and provocative is stolid and unmoving. (p. 95)&lt;/p&gt;&lt;/blockquote&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;“Luck,” in one’s business dealings, and “talent,” its equivalent onstage, seem to reward those with an active and practicable philosophy. … [H]ard work and perseverence &lt;em&gt;will&lt;/em&gt; be rewarded. (p. 99)&lt;/p&gt;&lt;/blockquote&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;In the theatre, as in other endeavors, correctness in the small is the key to correctness in the large. (p. 101)&lt;/p&gt;&lt;/blockquote&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;Be generous to others. … There is certainly something you can correct or improve in yourself today—over which you have control. That habit will make you strong. Yearning to correct or amend something in someone else will make you petty. …&lt;/p&gt;
&lt;p&gt;   Cultivate the habit of mutuality. Create with your peers, and you are building a true theatre. When you desire and strive to rise &lt;em&gt;from&lt;/em&gt; the ranks rather than &lt;em&gt;with&lt;/em&gt; the ranks, you are creating divisiveness and loneliness in yourself, in the theatre, and in the world. (pp. 102–103)&lt;/p&gt;&lt;/blockquote&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;It is not a sign of ignorance not to know the answers. But there is great merit in facing the questions. (p. 127)&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;That’s enough for now, but there’s much more in the book that I found useful and applicable to other areas of life as well. It’s a quick read and I really enjoyed it.&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>The Orange Code</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2009/01/orange-code/"/>
      <id>https://www.endpointdev.com/blog/2009/01/orange-code/</id>
      <published>2009-01-15T00:00:00+00:00</published>
      <author>
        <name>Jon Jensen</name>
      </author>
      <content type="html">
        &lt;p&gt;I’ve been reading the new book &lt;a href=&#34;https://www.amazon.com/Orange-Code-Direct-Succeeded-Being/dp/0470287233/&#34;&gt;The Orange Code&lt;/a&gt;, the story of &lt;a href=&#34;https://en.wikipedia.org/wiki/ING_Group#ING_Direct_United_States&#34;&gt;ING Direct&lt;/a&gt; by Arkadi Kuhlmann and Bruce Philp. Here are a few passages I liked from what I read today:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The commitment to constantly learn is the only fair way to bring everyone in the company under the same umbrella. It is a leveler. (p. 213)&lt;/p&gt;&lt;/blockquote&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;… [W]e’ve got to earn it each day, and we need to feel that we have new challenges that can make us or break us every day. … Each day’s work will last only as long as it’s relevant. … [W]e did okay in each of the last seven years, but we are only ever as good as our last year, our last day, our last transaction. We still have a lot to do, since our competition is not resting. (pp. 208–209)&lt;/p&gt;&lt;/blockquote&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;Trust and faith not only are built over time, but they actually need the passage of time to validate them. (p. 197)&lt;/p&gt;&lt;/blockquote&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;Contributing is a privilege earned, not a right. And there are, indeed, bad ideas, most of which are answers to questions the contributors didn’t really understand in the first place. There is a reason why some of the world’s finest jazz musicians were classically trained: You have to understand the rules before you can intelligently improvise on them. (p. 195)&lt;/p&gt;&lt;/blockquote&gt;

      </content>
    </entry>
  
    <entry>
      <title>Review of The Book of IMAP</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2008/08/review-of-book-of-imap/"/>
      <id>https://www.endpointdev.com/blog/2008/08/review-of-book-of-imap/</id>
      <published>2008-08-26T00:00:00+00:00</published>
      <author>
        <name>Jon Jensen</name>
      </author>
      <content type="html">
        &lt;p&gt;Former End Point employee Ryan Masters had his book review of the No Starch Press &lt;a href=&#34;http://www.osnews.com/story/20212/Book_Review_The_Book_of_IMAP&#34;&gt;published over at OSNews.com&lt;/a&gt;. Sounds like it was a decent book!&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>New edition of The Book of JavaScript reviewed</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2007/02/new-edition-of-book-of-javascript/"/>
      <id>https://www.endpointdev.com/blog/2007/02/new-edition-of-book-of-javascript/</id>
      <published>2007-02-21T00:00:00+00:00</published>
      <author>
        <name>Jeff Boes</name>
      </author>
      <content type="html">
        &lt;p&gt;The Book of JavaScript (2nd edition) is a new and comprehensive introduction to the JavaScript language presented in an entertaining, practical format. I have significant practical experience with JavaScript, so I do not consider myself in the target audience for this book; however, I still found much of it useful so it will remain as a valuable reference on my bookshelf.&lt;/p&gt;
&lt;p&gt;My full review of the book was just published at &lt;a href=&#34;https://www.osnews.com/story/17326/Book-Review-The-Book-of-JavaScript/&#34;&gt;OS News&lt;/a&gt;.&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>Review: Practices of an Agile Developer</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2006/06/review-practices-of-agile-developer/"/>
      <id>https://www.endpointdev.com/blog/2006/06/review-practices-of-agile-developer/</id>
      <published>2006-06-20T00:00:00+00:00</published>
      <author>
        <name>Ethan Rowe</name>
      </author>
      <content type="html">
        &lt;p&gt;&lt;strong&gt;Practices of an Agile Developer by Venkat Subramaniam and Andy Hunt (Pragmatic Bookshelf, 2006)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://pragprog.com/titles/pad/&#34;&gt;Practices of an Agile Developer&lt;/a&gt; is a fast, enjoyable, often-amusing read. It&amp;rsquo;s also full of wisdom and excellent advice for engineers of all levels, technical managers, and just about anyone with an interest in the software development process. The book makes for a great companion to &lt;a href=&#34;https://pragprog.com/titles/tpp20/&#34;&gt;The Pragmatic Programmer&lt;/a&gt; (also co-authored by Andy Hunt), but is more concise and focuses on bigger-picture development practices than does the often-implementation-oriented latter. The authors clearly outline a number of agile methodologies, with attention given to tasks ranging from managing teams, managing time, and keeping estimates realistic, to integration automation, release management, and test-oriented development.&lt;/p&gt;
&lt;p&gt;Of particular interest are topics that relate to developer/​client interaction, which could apply to a variety of professional relationships (consultant and client; development team and sales team; etc.). The practices outlined present a path to greater success for all parties, with a greater sense of ownership for the client and a greater sense of satisfaction for the developer. Sounds pretty good, doesn&amp;rsquo;t it?&lt;/p&gt;
&lt;p&gt;A common scenario in developer/​client requirements gathering and project planning involves the production of elaborate specifications of enormous scope; the client is supposed to approve the requirements, effectively saying “yes, this represents everything I want, the way I want it”, while the developer must then both estimate the time for completion and, assuming the estimate is accepted, move forward with implementation. In a consulting situation, the client may require a fixed price for the work, rather than just an estimate. This scenario seems perfectly rational, as the requirements represent a point of consensus around which work will be done, bills paid, and so on.&lt;/p&gt;
&lt;p&gt;Or so it may seem, until one has been down that road.&lt;/p&gt;
&lt;p&gt;Software development is really the business of change; the authors take great pains to illustrate this repeatedly, and they make their point effectively. While requirements and project scope are established, neither the client nor the developer possesses perfect information or a complete understanding of the possibilities. Usability studies may reveal a better way to approach certain problems; market research may indicate more profitable ways of selling goods; any such discovery may necessitate a requirements change on the client&amp;rsquo;s part. Furthermore, during project development, all parties may observe new possibilities implicit in the growing system &amp;ndash; possibilities that would never occur to developer or client without the benefit of actual working examples. Given tightly-specified requirements and strict budgetary constraints, these new discoveries and possibilities cannot be pursued or easily integrated into the project. Software, and its theoretical ability to accomodate real-world change, is stifled by this development approach.&lt;/p&gt;
&lt;p&gt;The Agile Developer authors instead favor a model that could be described as a “feedback loop”; the development team works in short, manageable iterations lasting between a few days to perhaps a couple of weeks, and at the end of each iteration provides tangible deliverables to the client. This provides the client with the opportunity to review the results and play a part in steering where the next iteration will go. While a master set of goals or desirables may guide the entire process, the individual iteration is the largest chunk of development work ever pursued at any one time; estimates can be based on each iteration, and each successful iteration brings the software closer to the final goals. Most critically, the process allows all parties to account for change as new information and experience inevitably brings new desires and ideas.&lt;/p&gt;
&lt;p&gt;Such an approach fits nicely into other development methodologies advocated by the authors, guided by axioms like “keep it releasable” (indicating that a developer should never go home for the day leaving code in a broken state), “integrate early; integrate often” (effectively requiring developers to work in small chunks that continuously get merged back into the main project code base), and a variety of suggestions regarding test-driven development practices (develop test cases before implementing actual systems as a means of establishing implementation/​interface requirements, automate execution of test cases as part of the continuous build process, treat failed tests as bugs, etc.).&lt;/p&gt;
&lt;p&gt;Ultimately, Practices of an Agile Developer illustrates just how subject to change all aspects of the software development process can be, and offers compelling ways to build the management of change into your systems and methodologies. Such methods become all the more valuable as companies and individuals increasingly look to the web as a means of delivering a service, and services increasingly appear as unique web-based applications which need to organically grow with their user community, rather than in discrete, versioned releases to be consumed and re-consumed by users over time. Check out this book if you haven&amp;rsquo;t already; it highlights a great approach to which anyone involved in the software development cycle can aspire.&lt;/p&gt;

      </content>
    </entry>
  
</feed>
