<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tim Estes on Medium]]></title>
        <description><![CDATA[Stories by Tim Estes on Medium]]></description>
        <link>https://medium.com/@tim-estes?source=rss-59c7e7690766------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uneeGdDTj_tXAth3CjcX1w.png</url>
            <title>Stories by Tim Estes on Medium</title>
            <link>https://medium.com/@tim-estes?source=rss-59c7e7690766------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 16:06:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tim-estes/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Elasticsearch For Dummies Part 2: Datatypes]]></title>
            <link>https://tim-estes.medium.com/elasticsearch-for-dummies-part-2-datatypes-c7a9494b48e8?source=rss-59c7e7690766------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7a9494b48e8</guid>
            <category><![CDATA[elasticsearch]]></category>
            <dc:creator><![CDATA[Tim Estes]]></dc:creator>
            <pubDate>Fri, 14 Oct 2022 17:53:46 GMT</pubDate>
            <atom:updated>2022-10-20T17:49:21.085Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cMsBRjoiXS1m_lDZhAIOiQ.png" /></figure><p>In <a href="https://medium.com/codex/elasticsearch-for-dummies-part-1-be184a739b60">part one</a>, we looked at the basics: an introduction to documents, indexes, and querying.</p><p>Today we’ll be delving a bit deeper into the world of Elastic by examining the different datatypes of Elastic and how they fit into the beautiful ecosystem of search.</p><h3>Datatypes</h3><p>When you index a document, each field in that document requires a <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html"><strong>datatype</strong></a><strong><em>.</em></strong></p><p>For example, a “string” is a data type that is typically used to classify text , while “integer” is a data type used to classify whole numbers. Data types are critically important to an index because they unlock powerful capabilities if used properly (and can cause great headaches if ignored).</p><p>If no data types are declared ahead of time, Elastic will make an educated guess about what data type we would want to use at the time of document creation. This is called <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-field-mapping.html">dynamic mapping</a>.</p><p>Let’s revisit our hello_world index and the document that we indexed earlier and check to see what kind of datatype dynamic mappings Elastic inferred for our index.</p><ol><li>If you haven’t already, create the index hello_world by running the following command against your cluster. I’m using VS Code to run the commands (see <a href="https://medium.com/codex/elasticsearch-for-dummies-part-1-be184a739b60">Part 1</a> for instructions on how to setup a local instance of Elastic and connect to it).</li></ol><pre>PUT hello_world</pre><p>2. <a href="https://github.com/timothestes/elastic-for-dummies/blob/main/part_2/explore_mappings.es#L1">Add a document</a> to the index if you haven’t already. You should see the following result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZpITzY9aoEsmeNPNRlf6Gg.png" /></figure><p>3. Now run a <a href="https://github.com/timothestes/elastic-for-dummies/blob/main/part_2/explore_mappings.es#L12">GET _mappings</a> command to view the assigned mappings of the hello_world index:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RI-TbDvBarDpI-d3CXXF0A.png" /></figure><p>Take a look at the “type” field in the mapping properties and observe how each field in the document has been assigned a data type.</p><p>In this case, two types have been chosen for our different field: “text” and “long.” This makes sense because our data consists of numbers and letters, with the number fields being assigned “long” and the text field being assigned “text.”</p><h3>Numeric Datatypes</h3><p>Numeric datatypes are present in all databases. They allow for efficient and flexible storage options while allowing users to perform numeric operations on them.</p><p>For example, with these fields, we can run <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-range-query.html">range</a> queries. The following query searches for all documents with a speech_number greater than 5:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eM-UyfJnlj2VHLGEQophqw.png" /></figure><p>This <a href="https://github.com/timothestes/elastic-for-dummies/blob/main/part_2/explore_mappings.es#L15">next query</a> lets us find all documents that have a speech_number greater than 5, but less than 10. Pretty straightforward so far, right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VyFQe3kwpXgHPV8mrMkjgA.png" /></figure><p>And if you are wondering, yes we can perform addition with these fields. Later on in the series, we’ll learn how to run aggregations that calculate sums of fields from a large quantity of documents (which would be useful in a financial workspace, as you can imagine).</p><h3>Text Datatypes</h3><p>The text incredibly flexible and powerful. All text fields are passed through an <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis.html"><strong>analyzer</strong> </a>to break up the string into individual pieces. This allows us to search for individual words in a sentence, for example.</p><p>The text field is best suited for human-readable strings, such as sentences and twitter tweets. If you are indexing email addresses or machine generated log messages, Elastic recommends using <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html#keyword">keyword</a> or <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/wildcard.html">wildcard</a> data types. For further reading, see the docs about <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html#mapping-unstructured-content">deciding how to map unstructured content</a>.</p><p>In our document, the text field is perfectly suitable for our text_entry and speaker fields! However, for the other string fields, I would use a <strong>keyword</strong> datatype. Keywords are best suited for structured content such as tags, static labels, and email addresses. Keywords are primarily used in aggregations, sorting and term queries.</p><h3>Explicit Mappings</h3><p>Let’s try our hand at adding some <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/explicit-mapping.html"><strong>explicit mappings</strong></a> to our index. We can do this using the following commands:</p><ul><li>First, <a href="https://github.com/timothestes/elastic-for-dummies/blob/main/part_2/explore_mappings.es#L27">delete</a> the existing index by running DELETE hello_world.It’s hard to change mappings of an index after it’s already created, so for now we will just delete and recreate the index)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sBiQtrlqkitvsTCxQthMhA.png" /></figure><ul><li>Then we will <a href="https://github.com/timothestes/elastic-for-dummies/blob/main/part_2/explore_mappings.es#L30">create</a> the index and use a PUT hello_world/_mappings command to add our own mappings:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jifd21n6TX7O33oG_UlYUw.png" /></figure><ul><li>To <a href="https://github.com/timothestes/elastic-for-dummies/blob/main/part_2/explore_mappings.es#L45">confirm</a> our new mappings, run the GET hello_world/_mappings command:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-3z-48wXbY_mgkW7vSbiPQ.png" /><figcaption>Beautiful!</figcaption></figure><p>Now when we index a document, it will be mapped explicitly instead of having guesswork involved.</p><h3>Date Datatypes</h3><p>Lastly, let’s take a look at another important type of data: time-based data. The <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html"><strong>date</strong></a> field type holds date and time values and are very helpful when dealing with time sensitive data, such as logs and chat messages.</p><p>Imagine you are in charge of indexing the works of Shakespeare into a database. But your boss wants you to attach a timestamp to each document marking the exact time the document was put into the index. How would you go about doing this?</p><p>One approach would be to use another programming language (like Python) to create a script that would bulk index the document and tag each doc a timestamp at index time. But what if there was an easier way to do this natively in Elastic?</p><p>Enter <a href="https://www.elastic.co/guide/en/elasticsearch/reference/8.3/ingest.html"><strong>ingest pipelines</strong></a>. From docs:</p><blockquote>Ingest pipelines let you perform common transformations on your data before indexing. For example, you can use pipelines to remove fields, extract values from text, and enrich your data.</blockquote><p>In this case, we’ll want to enrich our data by adding a timestamp value to all docs. Any time we make an index request against our target index, the document will first be processed by the ingest pipeline:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JEXAw4CykHrGFJLHj8fyEA.png" /></figure><p>To setup this ingest pipeline, we’ll need to run the <a href="https://github.com/timothestes/elastic-for-dummies/blob/main/part_2/explore_mappings.es#L58">following command</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CH6zHsh42BF3jdI19bO_MQ.png" /></figure><p>This will add a processor that adds a new field called @timestamp to each document that contains a timestamp value.</p><p>Then we need to <a href="https://github.com/timothestes/elastic-for-dummies/blob/main/part_2/explore_mappings.es#L71">attach</a> the pipeline to our index:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O8q6F1zkAup8twAwvGUFVg.png" /></figure><p>To <a href="https://github.com/timothestes/elastic-for-dummies/blob/main/part_2/explore_mappings.es#L78">test</a> the pipeline, let’s add another document and then look at it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IXn_x4dYCSYoaCxheB8_OQ.png" /></figure><p>Beautiful! It seems to be working perfectly.</p><p>Now for the finale, let’s <a href="https://github.com/timothestes/elastic-for-dummies/blob/main/part_2/explore_mappings.es#L94">run</a> a date range query to find all documents that were indexed in the last hour:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NR7PQ1rWjSDYAkMCdOb7iw.png" /></figure><p>Timestamp fields are some of the most useful fields practically speaking and come in clutch when trying to setup index lifecycle policies and data streams. Index lifecycle polices help users prevent indexes from growing too large and eating up infinite storage space over time. We shall touch upon this subject at a later time.</p><p>Well that’s enough information for one article! Thanks for making it this far. If you are enjoying the series, leave a like and a comment. The encouragement really helps with my motivation for writing these.</p><p>Also, if you have any topics that you’d want to see me cover in future articles, leave me a message!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7a9494b48e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 More Mistakes to Avoid as a Software Engineer]]></title>
            <link>https://tim-estes.medium.com/5-more-mistakes-to-avoid-as-a-software-engineer-7383fbb1a059?source=rss-59c7e7690766------2</link>
            <guid isPermaLink="false">https://medium.com/p/7383fbb1a059</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[mistakes]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Tim Estes]]></dc:creator>
            <pubDate>Tue, 22 Feb 2022 00:46:08 GMT</pubDate>
            <atom:updated>2022-02-22T01:04:55.161Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*VD3qQPhliIskkvb_.jpg" /></figure><p>Traveling the software developer road isn’t an easy one. There are a lot of small decisions that can lead to unforeseen consequences later on. On this series, I talk about the mistakes I’ve made on my journey so you don’t have to.</p><p>It’s been almost a year since I published my last Medium article about <a href="https://medium.com/codex/10-mistakes-to-avoid-as-a-software-engineer-b50a2bb1956f">mistakes to avoid</a>. I thought it would be appropriate to curate another list of mistakes I worked through this year. Who knows, maybe it will become a yearly tradition!</p><p>For those farther down the developer path than I, some of the mistakes I will be talking about seem obvious. Perhaps they are. But to the uninitiated, some of these things are hard to see or anticipate.</p><p>Look forward to Part 2 where I talk about some less technical (but more personal) mistakes.</p><p>Let’s jump into it.</p><h3>Mistake 1: Not Writing API specs</h3><p>I’ve built a lot of Flask APIs for my job. I did an “ok” job of trying to document all the endpoints, but when it came down to having other developers actually <em>use</em> the API, I had to spend a lot of time in Slack answering questions.</p><p>A couple months ago, my friend introduced me to the <a href="https://swagger.io/specification/">OpenAPI specification</a>. OpenAPI uses a yaml or json file to precisely describe how an API behaves. My favorite part about OpenAPI is the Swagger UI that allows you to visualize the specs in style. The coolest part is that this can double as documentation for your API!</p><p>The following is a screenshot of an API that should be familiar to anyone that has used Swagger: the Petstore API. You can interact with it <a href="https://petstore.swagger.io/">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ky_Vdv8d5pgkwzxQtmjnXw.png" /></figure><p>I’ve fallen in love with Swagger UI and use it whenever I’m developing a new API. My favorite combo is VSCode and the <a href="https://marketplace.visualstudio.com/items?itemName=42Crunch.vscode-openapi">Open API extension</a>. It allows you to code your specs on one side and see them update on the right!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a5je90xcV6HM-V5x_vGHBQ.png" /></figure><p>Don’t be intimidated by the ugly looking <a href="https://petstore.swagger.io/v2/swagger.json">json files</a>. If you follow some <a href="https://swagger.io/tools/open-source/getting-started/">quickstarts</a> and understand the <a href="https://idratherbewriting.com/learnapidoc/pubapis_swagger.html">petstore example</a>, you’ll be just fine.</p><p>It adds some time to development, but you’ll be saving it later on by not having to repeat yourself. Plus, your fellow devs will thank you and be impressed!</p><h3>Mistake 2: Not Writing Unit Tests</h3><p>I remember I used to think unit-tests were optional. I don’t believe that anymore. (Cue eerie music)</p><p>Once upon a time, a junior dev was tasked with building a pipeline to ingest CSV data. Over many months and man-hours, a pipeline was cobbled together that met the requirements and scope of the project. And everyone lived happily ever after.</p><p>Well, I wish that’s how the story went. I was the developer in this story. And unlike our fairy tales, some stories don’t wind up with satisfying and conclusive endings.</p><p>As our company matured, so did the requirements for the data pipeline. Things were added on, parts were re-hauled. I started spending a lot of time fixing and maintaining the pipeline.</p><p>I could have saved myself a lot of pain and suffering if I had taken the extra time up front to add unit-tests to my code. I had many moments where I pushed up a “fix” to the pipeline, only to watch the it break something else in production.</p><p>My brain is finite, and it can’t keep track of all the variables and moving pieces inherent to complex systems. Unit-tests can help cover your bases and force you to become proactive in identifying and fixing problems.</p><p>Don’t neglect or ignore unit-testing! Unless you like to live on the edge…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*XOGBm8OFrprrKdyeo0LBFQ.gif" /><figcaption>I used to live like this, until I pushed an extra comma to production and crashed everything</figcaption></figure><h3>Mistake 3: Using Only One Deployment Environment</h3><p>When developing software for industrial use, it’s common to have separate environments (i.e. one for development, one for end-users, etc.). In my current company, we have four environments, but I remember when this didn’t used to be the case.</p><p>In systems where you need to go fast, it’s easy to neglect the common practice of building and maintaining four development environments. I mean, who has time to set up <em>four </em>MongoDB databases. Who has time to set up <em>four </em>clusters in Kubernetes? We need this done on Friday. Can’t we just use one environment for now?</p><p>I like analogies. If I had to think of one for this, I’d say that using only one environment for deployment is like trying to build a house while someone is already living in it. One person is just trying to live in the house, but good luck. The carpet just got ripped out, the living room is being fumigated for bugs, and the power is out until the electrician comes back from his 4 day vacation. No wonder the house keeps falling down!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/0*QCZG8xJtZzi0UVDF.jpg" /></figure><p>Without separate development branches, its nigh impossible to create a stable production environment that’s usable.</p><p>I’m happy to say that things are much better now. The environments are becoming more and more separated day by day.</p><p>Testers blissfully ravage the testing deployment.</p><p>Devs push new code to development every day.</p><p>In staging, internal users make sure things are stable before pushing the new release to production.</p><p>Such is the development life.</p><h3>Mistake 4: Hardcoding Variables</h3><p>In the attempt to create four different development branches on a project, I decided to have one variable called ENVIRONMENT that would let the service know which deployment environment it was in.</p><p>On the dev branch, I hardcoded it to be &quot;dev&quot;.</p><p>On the prod branch, I hardcoded it to be &quot;prod&quot;.</p><p>Iterate through the other branches:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*01GZE_y-mpg1UeyN.gif" /><figcaption>Yay I’m coding! Aren’t I doing it well!?</figcaption></figure><p>What I was left with were some headaches when it came to merging. Every time development was merged into production, I had to make sure that the ENVIRONMENT variable wasn’t overwritten with the wrong value.</p><p>When it comes to dealing with dynamic or sensitive variables, instead of hardcoding them, it’s often better to figure out a strategy for smuggling them into your OS at runtime instead of trying to control them explicitly.</p><p>A teammate added some code to our GitLab CI/CD pipelines that would automatically set the ENVIRONMENT variable depending upon what the branch was. For example, any pushes to production automatically had ENVIRONMENT=&quot;prod&quot; as an environment variable. Now I don’t even have to think about it!</p><p>In the case where you have a secretive variable (think auth-tokens and the like), its crucial to not hardcode. The damage done by a potential breach will be greatly lessened if the attackers are unable to obtain your keys just by looking at your source-code.</p><p>We still have to yell at devs who store auth keys in their variables.py files. This is a horrible habit and can compromise the integrity of your code, especially if you are sharing it with other people.</p><p>Here are some practical steps for moving away from hardcoding (via Python3):</p><ol><li>Install <a href="https://pypi.org/project/python-dotenv/">python dotenv</a>.</li><li>Create a .envfile and store your variables in there</li><li>Use the dotenv.load_dotenv()method to load the variables stored in your .env into your current session.</li><li>Access them via os.getenv(&quot;YOUR_VARNAME&quot;).</li></ol><h3>Mistake 5: Being Ignorant of Design Patterns</h3><p>I didn’t take a bunch of computer classes in college. While others where learning about data structures, I was learning about Bayesian inference and Binomial distributions.</p><p>Not to say that what I learned in college is meaningless. Far from it! However when it came to software and programming, I had a lot of catching up to do.</p><p>When designing new systems or microservices, I would try to hack things together until it just worked. No real blueprint in my mind, just winging it. The solutions I designed would often work, but were too complicated.</p><p>My coworker saw this and introduced me to an <a href="https://refactoring.guru/design-patterns">excellent website </a>that opened my eyes to the wonderful world of Design Patterns.</p><p>The <a href="https://refactoring.guru/design-patterns">refactoring.guru</a> website contains a treasure trove of solutions to common problems encountered in software.</p><p>For example, say you are creating a Sims-like video game that needs to generate digital people. People are insanely diverse, and manually creating code for each person would be exhausting.</p><p>This is where the <a href="https://refactoring.guru/design-patterns/factory-method">factory method</a> can come to the rescue! It suggests to use a Factory class. By calling the factory class, you can create people while also having great control over the attributes of the different type of people.</p><p>The following is an implementation in Python:</p><pre>from abc import ABCMeta, abstractmethod<br>from dataclasses import dataclass</pre><pre><a href="http://twitter.com/dataclass">@dataclass</a><br>class Person(metaclass=ABCMeta):</pre><pre>    name: str<br>    age: int</pre><pre><a href="http://twitter.com/abstractmethod">    @abstractmethod</a><br>    def personality_type(self) -&gt; str:<br>        pass</pre><pre><a href="http://twitter.com/abstractmethod">    @abstractmethod</a><br>    def talk(self) -&gt; str:<br>        pass</pre><pre>class Introvert(Person):<br>    def personality_type(self) -&gt; str:<br>        return &quot;introvert&quot;</pre><pre>    def talk(self) -&gt; str:<br>        return &quot;mhhmm.&quot;</pre><pre>class Extrovert(Person):<br>    def personality_type(self) -&gt; str:<br>        return &quot;extrovert&quot;</pre><pre>    def talk(self) -&gt; str:<br>        return &quot;lorem ipsum dolor sit amet. consectetur adipiscing elit! bla bla bla.&quot;</pre><pre>class God:<br>    <a href="http://twitter.com/staticmethod">@staticmethod</a><br>    def create_person(name: str, age: int, personality: str) -&gt; Person:<br>        if personality == &quot;introvert&quot;:<br>            return Introvert(name, age)<br>        elif personality == &quot;extrovert&quot;:<br>            return Extrovert(name, age)<br>        else:<br>            return Person(name, age)</pre><pre>if __name__ == &quot;__main__&quot;:<br>    person_1 = God.create_person(&quot;John&quot;, 30, &quot;introvert&quot;)<br>    person_2 = God.create_person(&quot;Jane&quot;, 25, &quot;extrovert&quot;)</pre><pre>    print(person_1.talk())<br>    # &gt; mhhmm.</pre><pre>    print(person_2.talk())<br>    # &gt; lorem ipsum dolor sit amet. consectetur adipiscing elit! bla bla bla.</pre><p>In this example, God() was the factory class and it created People() with different attributes accessed by the same method.</p><p>Well that’s all I have for this article. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7383fbb1a059" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elasticsearch for Dummies: Part 1]]></title>
            <link>https://medium.com/codex/elasticsearch-for-dummies-part-1-be184a739b60?source=rss-59c7e7690766------2</link>
            <guid isPermaLink="false">https://medium.com/p/be184a739b60</guid>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[for-dummies]]></category>
            <dc:creator><![CDATA[Tim Estes]]></dc:creator>
            <pubDate>Sun, 25 Apr 2021 01:55:45 GMT</pubDate>
            <atom:updated>2022-10-14T18:01:34.670Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*MF4PZLr8lc5DjuJJnDXBAw.png" /></figure><p>One of my favorite technologies that I have gotten the pleasure to work with is called Elasticsearch (which I will refer to as Elastic from now on). Elastic is an open-sourced search engine that is quite flexible and powerful. I could give countless <a href="https://www.elastic.co/customers/">use-cases</a> of where and why Elastic is used, but that would detract from the purpose of this article.</p><p>This series is dedicated to the dummies out there. It’s for those who’ve realized that they know nothing about Elastic and are willing to admit it. For those who embody the following Shakespeare quote:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YmD5Egizw5Itw4IVS6D3ZQ.png" /><figcaption>-William Shakespeare. Credit: <a href="https://www.tymoff.com/the_fool_doth_think_he_is_wise_but_the_wise_man_knows_himsel_e_to_be_a_fool_william_shakespeare_6_quotefancy/content/MzcwMQ">tymoff.com</a></figcaption></figure><p>These articles are a resource I wish existed when I was trying to figure all this out on my own. My hope is that this will help, inspire, and simplify your journey thought the vast world of software engineering.</p><p>Let’s get started, shall we?</p><h3>Setting the Stage</h3><p>Time to put on your imagination cap: You’ve just been handed <a href="https://github.com/timothestes/elastic-for-dummies/tree/main/shakespeare_hard_drive">a hard drive</a> which contains the entire published works of William Shakespeare and it’s up to YOU to put it into Elastic.</p><p>We will get to indexing the entire works of Shakespeare, but let’s start small for now with a line from the play “As You Like It” that I quoted earlier. The data is in JSON format, which will make it easier to put into Elastic.</p><pre>{<br>    &quot;type&quot;: &quot;line&quot;,<br>    &quot;line_id&quot;: 18122,<br>    &quot;play_name&quot;: &quot;As you like it&quot;,<br>    &quot;speech_number&quot;: 19,<br>    &quot;line_number&quot;: &quot;5.1.28&quot;,<br>    &quot;speaker&quot;: &quot;TOUCHSTONE&quot;,<br>    &quot;text_entry&quot;: &quot;The fool doth think he is wise, but the wise man knows himself to be a fool.&quot;<br>}</pre><p>For those who are not familiar, JSON is simply a way of storing data using key-value pairs (which you Python people may recognize as a <a href="https://realpython.com/lessons/dictionary-python/">Python Dictionary</a>!)</p><p>Looking at the data, we can see that this line belongs to a fellow by the name of Touchstone, and the line number is 5.1.28. Not super useful information right now, but perhaps we can do some cool stuff with it later.</p><p>Let’s form a game plan. We need to do the following things (and its ok if you don’t know what each step means):</p><ol><li>Spin up a sandbox Elastic cluster.</li><li>Create an index that will store our data.</li><li>Insert our document into the index.</li></ol><h3>Spinning Up Your First Cluster</h3><p>Firstly, download Elastic onto your local computer, choosing the appropriate download file for your system (you can find the downloads <a href="https://www.elastic.co/downloads/elasticsearch">here</a>).</p><p>To get Elastic up and running on Mac:</p><ul><li>Download and unzip the file you’ve downloaded and cd into the unzipped directory.</li><li>Edit the elasticsearch.yml file in the config directory and disable the xpack-security feature flag. For learning about Elasticsearch, I don’t want to bog us down in the details about authentication and security. Only do this step for developing locally and for easy testing and never in a production use-case.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HVRGH_9ZRny01cCSv499Kg.png" /><figcaption>Disabling xpack authentication (for now)</figcaption></figure><ul><li>To start elasticsearch, run bin/elasticsearch (or bin\elasticsearch.bat on Windows)</li><li>To verify that the cluster is up and running, let’s make an unauthenticated request tohttp://localhost:9200/ in a separate terminal session:</li></ul><pre>➜ curl <a href="http://localhost:9200/">http://localhost:9200</a><br>{<br>  &quot;name&quot; : &quot;Tims-MacBook-Pro.local&quot;,<br>  &quot;cluster_name&quot; : &quot;elasticsearch&quot;,<br>  &quot;cluster_uuid&quot; : &quot;JZcAF-F1S-y-CmBtQ-roOQ&quot;,<br>  &quot;version&quot; : {<br>    &quot;number&quot; : &quot;8.4.3&quot;,<br>    &quot;build_flavor&quot; : &quot;default&quot;,<br>    &quot;build_type&quot; : &quot;tar&quot;,<br>    &quot;build_hash&quot; : &quot;42f05b9372a9a4a470db3b52817899b99a76ee73&quot;,<br>    &quot;build_date&quot; : &quot;2022-10-04T07:17:24.662462378Z&quot;,<br>    &quot;build_snapshot&quot; : false,<br>    &quot;lucene_version&quot; : &quot;9.3.0&quot;,<br>    &quot;minimum_wire_compatibility_version&quot; : &quot;7.17.0&quot;,<br>    &quot;minimum_index_compatibility_version&quot; : &quot;7.0.0&quot;<br>  },<br>  &quot;tagline&quot; : &quot;You Know, for Search&quot;<br>}</pre><p>Now let’s connect our trusty <a href="https://code.visualstudio.com/">VSCode IDE</a> to our local cluster so we can start talking to it via some simple REST APIs.</p><p>To connect your local Elastic cluster to VSCode:</p><ul><li>Download the <a href="https://marketplace.visualstudio.com/items?itemName=ria.elastic">Elasticsearch for VSCode</a> extension.</li><li>Create a new file in VSCode called hello_world.es.</li><li>When you create an .es file with the extension enabled, it will prompt you to specify the connection (which you can leave localhost:9200):</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l_E8woum7dDFRnHTb416NQ.png" /></figure><ul><li>To verify that we’ve connected to our sandbox cluster, type GET _cluster/health into your new file and press ctrl+enter to run the command. You should see something like this:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nAyz11MB2OrpfFfHb-J9Rw.png" /></figure><p>Congrats: you just created your first cluster!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*WxcI8dJPfJ9ZgpZY4-uSPA.gif" /><figcaption>Your first cluster is ALIVEEEEE!</figcaption></figure><h3>Creating Your First Index</h3><p>First, some vocabulary:</p><ul><li>Simply put, an <em>index</em> is an extremely optimized place where we store <em>documents</em>. An index is usually composed of many documents.</li><li><em>Documents</em> are a collection of one or more key-value pairs that we can search and filter through (think things that look like that Shakespeare JSON object we talked about earlier).</li><li>A <em>cluster</em> is a place where we store and manage <em>indexes</em>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*YfwY-jK_Q2pRI6xCa9MgSw.png" /><figcaption>Relationship between Documents, Indexes, and Clusters</figcaption></figure><p>Before we can put documents into our cluster, we first have to create an index. To create your first index, run PUT hello_world in your hello_world.es file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*Kw73Z2iCiXnVezZs5lSvHA.png" /></figure><p>In the real world, setting up an index is usually more complicated than this, but we are trying to stay simple for now. I want you to focus on the concepts, not the nitty gritty (which can come later).</p><p>Now that we’ve created an index, we are ready to start indexing documents.</p><h3>Inserting a Document into Your First Cluster</h3><p>If you don’t like typing, copy and paste the <a href="https://github.com/timothestes/elastic-for-dummies/blob/main/part_1/put_document.es">put_document.es</a> file and run the PUT hello_world/_doc/1 command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AYbmflSbqFb6f6QM-5iyOQ.png" /></figure><p>Let’s break down the command we just made: PUT hello_world/_doc/1</p><ul><li>PUT specifies the action type. We want to <em>PUT </em>a document.</li><li>hello_world is the index which we want to PUT the document into</li><li>_doc/1 is the syntax to specify the doc_id (which is the unique id associated with the document in the index)</li></ul><p>But how do we know that the document made it into the index? Well, we got a success response from the cluster, but to be certain, let’s make our first Elastic query and manually find that document.</p><h3>Making Your First Elastic Query</h3><p>Elastic uses a specialized Query DSL (Domain Specific Language) based on JSON to define queries. Getting yourself used to the query syntax will help a lot down the road, so don’t just mindlessly copy and paste the snippets into your files! Typing a few out can go a long way to helping you understand their structure.</p><p>To make a query, we first have to decide what fields to query on. The quote is the most memorable part of the document we want to find, so let’s make a text match phrase query on the text_entry field.</p><p>The <a href="https://github.com/timothestes/elastic-for-dummies/blob/main/part_1/find_document.es">following query</a> will search for docs whose text_entry field contains the phrase “the fool doth think” (plus some highlighting to show exactly what we found):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HDrXnCf4FoDrhSi2a1clhg.png" /></figure><p>And because we asked for highlights, we can see the phrase we searched for in the response.json! Super cool.</p><p>Let’s switch it up: what do you think will happen if we search for the phrase “the brave fool doth think”? (Notice I added an extra word into the query)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lFUoraFXu6FpvB-88s2icQ.png" /></figure><p>If you guessed we would get no results, you would be right! That’s because the match_phrase query only looks for exact phrase matches.</p><p>Well that wraps up our first session. To cleanup, use the command ctrl+c in the terminal that’s running the cluster to to stop it.</p><p>I’m proud of you if you’ve made it this far! Hopefully, you understand at the conceptual level what documents, indexes, and clusters are. And you were able to successfully create your first index, index your first document, and then make your first Elastic query.</p><p>This is just the tip of the iceberg, and there is so much more to learn. In my <a href="https://tim-estes.medium.com/elasticsearch-for-dummies-part-2-datatypes-c7a9494b48e8">next post</a>, I’ll talk about Elasticsearch mappings and data types for dummies…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be184a739b60" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/elasticsearch-for-dummies-part-1-be184a739b60">Elasticsearch for Dummies: Part 1</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 Mistakes to Avoid as a Software Engineer]]></title>
            <link>https://medium.com/codex/10-mistakes-to-avoid-as-a-software-engineer-b50a2bb1956f?source=rss-59c7e7690766------2</link>
            <guid isPermaLink="false">https://medium.com/p/b50a2bb1956f</guid>
            <category><![CDATA[mistakes]]></category>
            <category><![CDATA[beginner-coding]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Tim Estes]]></dc:creator>
            <pubDate>Thu, 01 Apr 2021 00:01:41 GMT</pubDate>
            <atom:updated>2021-04-03T01:20:59.150Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*d-rqvON88ypnRXGj.png" /><figcaption>Picture credit: <a href="https://www.searchenginejournal.com/10-common-seo-mistakes/178734/">searchenginejournal.com</a></figcaption></figure><p>We all have to start somewhere. For me, that was June 2019 when I fired up a python crash course at <a href="https://www.datacamp.com/">Datacamp</a>. After graduating with a B.S. degree in applied statistics, I was bright, starry eye, and full of pent up energy from years spent in the classroom. I knew nothing about “best practice.” I only wanted to stop learning and start <em>doing.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*j_RC5YfRtw0tYeyB72Lt2g.gif" /><figcaption>Me in my job interviews</figcaption></figure><p>But I quickly found that you never stop learning in real life. Each day holds a lesson to take notes on, and each mistake can teach us more than any professor. Starting out, I knew more about <a href="https://en.wikipedia.org/wiki/Poisson_distribution">Poisson distributions</a> than software engineering.</p><p>I’ve grown a lot since then, but I’ve had to learn many lessons the hard way. While some of these lessons can seem obvious to those who have been programming for a while, “hindsight is 20/20” as they say. This article is dedicated to those young bucks who were in the same place where I was a year ago. I hope these 10 mistakes I’ve made can help you in your journey towards greatness.</p><h3>Mistake 1: Thinking Too Small</h3><p>It’s pretty easy to make the assumption that if something is working on your local machine, it will work well in production.When I built my first microservices, I didn’t think about how well they would scale and perform.</p><p>Using a python dictionary and regex expressions to power a primitive search engine works well if you are searching over one document. Trying to use the same tools to search over thousands of documents is the definition of futility. Something I wish I did earlier in my projects was to stop and ask myself “will this scale?” Most of the time, the answer was a solid no.</p><p>Finding solutions and architectures that work well at scale is a foundational part of software development. The first thing I do when evaluating a potential answer to a problem is to think about how performant it would be in the bigger picture. With time and practice, I was able to anticipate problems that arise due to scale and complexity. Here are a few examples:</p><ul><li>The choice of database can make or break a product. If you choose a weak option, you’ll be knee deep in tech debt until you pay off your student loans (if <em>that</em> ever happens).</li><li>When dealing with volume, threading &amp; concurrent tasks can cause unexpected behaviour. I’ve embarked on many Scooby-Doo debug sessions, which lead to an unmasking of the culprit at the end. The usual suspects? Race conditions, out of memory errors, and throttling.</li><li>Having a design or a naming convention that is too brittle can make later changes painful. Refactoring happens more often than you think, especially if you work at a startup. Building microservices with the perspective that each service is a replaceable Lego block makes changing them a thousand times easier. My first services worked more like intertwined threads in a quilt than anything that resembled a modular design.</li><li>Having a system that requires manual changes and updates to work is not sustainable. Automating theses types of tasks frees up your time and helps avoid user error later on. We used to have a product that required me going in and adding some regex to a list each time a new client was added. <strong>Not scalable!</strong></li></ul><h3>Mistake 2: Thinking Too Large</h3><p>On the other side of the thinking-too-small coin is thinking too large. Trying to imagine every edge-case in a problem set can quickly become overwhelming and often paralyzing.</p><p>After learning not to think about things in isolation, I overcompensated by trying to think about all the interconnections at once. Once I hit my comprehension threshold, my brain froze up and became overwhelmed because I didn’t know where to start.</p><figure><img alt="https://www.youtube.com/watch?v=y8OnoxKotPQ" src="https://cdn-images-1.medium.com/max/690/1*VNBczmh4TbLGDr1OwKRuNA.gif" /><figcaption>Me trying to think about our microservice architecture</figcaption></figure><p>With the help of my coworkers, I learned the value of breaking large, complex problems into bite-sized ones. Whenever I was stuck, they helped me ask “How can this problem be broken down?” Once I was able to break the mammoth task down into a couple of comprehensible ones, I became unstuck and much more productive.</p><p>One of the most valuable tools that has helped me here is flowcharting. I’m a visual thinker, so having a picture to go along with an abstract concept increases my understanding of the problem significantly.</p><p>I’ll share an example diagram I made to model a data pipeline I helped build. Whenever I discuss this pipeline with other developers on my team, I always pull this out because it helps me explain it. A picture is truly worth 1,000 words:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EKHOG7b-v9vdkT5H7kJ8Gw.png" /><figcaption>Sorry for those who don’t use dark mode…</figcaption></figure><p>I’m not going to go into detail and explain the whole pipeline, but you can imagine how useful this has been. I can come back to this diagram for a quick refresher of how the pipeline works and the basic idea of what each service does and how it fits into the bigger picture. Imagine trying to keep track of all this in your head! Plus, if I get run over by a bus, someone can figure out how the autodocs pipeline works…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*ZqtD8xy2aBbdj1Zmmqapiw.jpeg" /><figcaption>It was actually cheaper to put in a screenshot than chisel in a QR code…</figcaption></figure><h3>Mistake 3: Re-enacting the Tower of Babel</h3><p>For those not familiar, the Tower of Babel is synonymous with miscommunication and the barriers caused by different languages. The struggles that apply to human languages also apply to coding languages as well. Using different coding languages might seem more productive in the short term, but in the long term, can prove costly to productivity.</p><figure><img alt="Have microservices gone too far?" src="https://cdn-images-1.medium.com/max/800/1*88pogTWeXRMVQ1sDGQBVAw.jpeg" /><figcaption>Photo Credit: <a href="https://medium.com/the-infinite-universe/the-tower-of-babel-project-how-human-beings-must-prepare-for-the-approaching-singularity-36355b908aed">Tim Anderson</a></figcaption></figure><p>Each person has their favorite coding language. For some (like me), its Python. For others it’s Ruby. When asked to complete a task, it’s tempting to pave the way in a language you are comfortable and competent with. But if that language is different than the other pieces in your puzzle, this can actually become a pain point in the development process.</p><p>Most of our microservices and APIs were built with Python, but we had a few made in Ruby. The services made in Ruby quickly became black boxes to the other devs (who were junior like me and only knew Python), and the only person who could fix the service if it went down was the dev who built it.</p><p>After this problem kept happening, we standardized the languages we used in our infrastructure:</p><ul><li>Automation services use Java</li><li>Microservices, APIs, and cloud functions use Python</li><li>Front-End application uses NodeJs</li></ul><p>This had the added effects of unifying our respective code bases, and improving the hiring process for potential devs. Those with Python and NodeJs on their resume were more likely to be successful.</p><p>Yes, this has forced some people to adapt and inwardly cringe each time they have to type self.my_python_variable, but those who don’t adapt don’t last long in this industry.</p><p>I acknowledge there are exceptions to this rule because sometimes a certain task can only be accomplished in a certain language. For example, if you are trying to decrease the processing time it takes to process a large csv file, C++ is going to be more performant than Python. But in general, the more consistent your code base, the better off you’ll be.</p><h3>Mistake 4: Not Documenting My Code</h3><p>Looking at code I’ve written six months ago usually becomes an exercise of deciphering ancient Egyptian hieroglyphs. Things that seemed so clear in the moment can quickly become obscure in the fog of time and imperfect memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BzNeQNoLGGx3MoaFH4al_Q.jpeg" /><figcaption># They should have really left some comments… Photo Credit: <a href="https://medium.com/@alex.dovr00/hieroglyphics-language-the-history-of-ancient-egypt-5a6385185952">Alex Donvour</a></figcaption></figure><p>Leaving code comments and spending time to document the code I’ve worked on are important parts of my workflow, but they didn’t used to be. Early on, when people had questions about a service I worked on, I answered their questions as they came, and most of the knowledge I had about the service stayed at the <a href="https://en.wikipedia.org/wiki/Tribal_knowledge#:~:text=Tribal%20knowledge%20is%20any%20unwritten,produce%20quality%20products%20or%20services.">tribal-knowledge</a> level.</p><p>As time went on, I built more and more services, and I started having to answer more and more questions. I realized that documenting the things I’ve worked on would answer a lot of the questions I was getting, and would also help me remember what the service actually did.</p><p>Spending the time to document your code can feel tedious and wasteful, especially if you are pressured to move fast. But I’ve found that documentation actually saves time in the long run. It saves me time that would normally be spent answering simple questions, and I can get back up to speed with an old project 10 times faster if I’ve documented it.</p><p>I always appreciate team members who document their code (leaving good comments is a part of it). And your team will appreciate you too, trust me.</p><p>Having a good platform to host your documentation is key too. Look for a platform that allows you to perform full-text search over documents. Trust me, it will come in handy when you can’t remember exact variables. My team uses <a href="https://www.atlassian.com/">Atlassian</a>, which I would endorse. Its slightly clunky at times, but looks great and is much easier to manipulate than a README.md file.</p><h3>Mistake 5: Not Using Pub/Sub</h3><p>At its core, pub/sub is a messaging system that can <strong>publish</strong> messages to <strong>subscribers</strong>. Publishers push messages to a queue (called a topic), which are in-turn ingested by subscribers, who are hooked up to the queue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*hupP1rfpFllKdFuoWuR9dQ.png" /></figure><p>This design is very flexible, scalable, and powerful, especially in data pipelines. However, I didn’t even know it existed until a coworker acquainted me with it, and I’ve been in love ever since. If you want to build scalable solutions, pub/sub should be a part of it.</p><p>There are different implementations of pub/sub, and its a pick-your-flavor scenario at an ice cream parlor: you really can’t go wrong. Google has <a href="https://cloud.google.com/pubsub">Cloud Pub/Sub</a>, Amazon has <a href="https://aws.amazon.com/pub-sub-messaging/">Pub/Sub Messaging</a>. And there’s a really powerful one called <a href="https://kafka.apache.org/">Apache Kafka</a> (but I haven’t had much experience with it yet).</p><p>The best resource I’ve found for learning about pub/sub is the following video produced by <a href="https://www.youtube.com/channel/UC_ML5xP23TOWKUcc-oAE_Eg">Hussein Nasser</a>. He gives some great examples of why pub/sub is awesome and how it can be better than the traditional request/response architecture.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FO1PgqUqZKTA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DO1PgqUqZKTA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FO1PgqUqZKTA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2e1ef9e3f23131dd41d50127fe2e9d5/href">https://medium.com/media/c2e1ef9e3f23131dd41d50127fe2e9d5/href</a></iframe><h3>Mistake 6: Not Using an Auto-Formatter</h3><p>Even if you do speak the same language as someone else, there can be differences in dialects and accents. I always love a good Australian or British accent. Sure, it’s fun to listen to, but hard to understand sometimes:</p><ul><li>Crumpets and tea govenah? Croickey! Oi think oi I will.</li></ul><p>Dialects form in coding languages when people use different formatting and indentations. Consider the following Python code produced by two different devs. They both do the same thing, but look very different.</p><pre># Dev A (multiline method chaining, 4 space indentation)<br>my_documents = db.collection(&quot;users&quot;).document(&quot;tim_estes&quot;).\<br>    collection(&quot;documents&quot;).where(&quot;createdAt&quot;, &quot;&lt;&quot;, yesterday).get()</pre><pre>for doc in my_documents:<br>    doc.reference.update({<br>        &quot;first_name&quot;: &quot;tim&quot;,<br>        &quot;last_name&quot;: &quot;estes&quot;,<br>        &quot;edited_at&quot;: now,<br>        &quot;edited_by&quot;: &quot;admin&quot;<br>    })</pre><p>_____________________________________</p><pre># Dev B (no dict indenting, 2 space indentation, but better method chaining)<br>my_documents = (<br>  db.collection(&quot;users&quot;)<br>  .document(&quot;tim_estes&quot;)<br>  .collection(&quot;documents&quot;)<br>  .where(&quot;createdAt&quot;, &quot;&lt;&quot;, yesterday)<br>  .get()<br>)</pre><pre>for doc in my_documents:<br>  doc.reference.update({&quot;first_name&quot;: &quot;tim&quot;, &quot;last_name&quot;: &quot;estes&quot;, &quot;edited_at&quot;: now, &quot;edited_by&quot;: &quot;admin&quot;})</pre><p>Usually, these small differences are not a problem. But once you start working on a team with people who all have different formatting preferences, merge conflicts arise and your code base starts to look like my grandma’s old family scrapbook. There’s no consistency and it just looks ugly (sorry grandma!)</p><p>I used to spend a lot of time trying to format my code, until a teammate suggested we start using <a href="https://black.readthedocs.io/en/latest/">Black</a>. Black is a no-frills, opinionated code formatter that lets me focus on the part of coding that matters instead of the parts that don’t.</p><p>Here’s an example of Black in action. After doing a pip install of Black, simply run black my_python_file.py and it will do all the formatting for you! Here’s that same python script from earlier but formatted into Black’s PEP-8 style:</p><pre># ah, much better!<br>my_documents = (<br>    db.collection(&quot;users&quot;)<br>    .document(&quot;tim_estes&quot;)<br>    .collection(&quot;documents&quot;)<br>    .where(&quot;createdAt&quot;, &quot;&lt;&quot;, yesterday)<br>    .get()<br>)</pre><pre>for doc in my_documents:<br>    doc.reference.update(<br>        {<br>            &quot;first_name&quot;: &quot;tim&quot;,<br>            &quot;last_name&quot;: &quot;estes&quot;,<br>            &quot;edited_at&quot;: now,<br>            &quot;edited_by&quot;: &quot;admin&quot;,<br>        }<br>    )</pre><p>For those who want to give Black a spin right now, check out the <a href="https://black.now.sh/">interactive playground</a>. And if you are not sold yet, you should watch a <a href="https://www.youtube.com/watch?v=esZLCuWs_2Y">presentation</a> by the guy who made Black.</p><p>As part of the merge request process, devs are highly encouraged to run their code through Black. The result being a professional and consistent code-base free of dialects and silly merge conflicts.</p><p>While I wouldn’t recommend using a machine that would strip out all the accents in human voices, I <em>would</em> recommend Black or equivalent packages that do the same thing for code languages (<a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode">Prettier</a> for Javascript, <a href="http://astyle.sourceforge.net/">Astyle</a> for C++).</p><h3>Mistake 7: Not Reusing Code</h3><p>Imagine the folly of a worker who went out and bought a new shovel each time they needed to dig a hole! We’d call them crazy for not reusing the tools they already had.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*FI8RN6BousUVRPPvJGB-MA.png" /></figure><p>Well, I used to be that guy. I had a directory of functions that were super useful in the projects I worked on, and the first thing I did when starting a new one was to take that directory and copy it over to the new code repository.</p><p>Not only did I have a bunch of duplicated code, I also needed to update every single repo if one of those functions needed a patch. Eventually, a coworker realized my error and suggested I put these functions into a Python package that could be used internally and exported to the projects that need them.</p><p>Those functions became much easier to manage, and more accessible to others who wanted to use the functions in their own project. This marked the beginning of me becoming a force to be reckoned with on our dev team, and the package is small but also something I’m really proud of.</p><p>If you are worried about having your code be open-source, there are ways you can host private packages. Gitlab has an option where you can upload packages to a code repository and use private tokens to access said package. Steps about how to use this can be found <a href="https://medium.com/maisonsdumonde/gitlab-ci-cd-and-gitlab-pypi-repository-4916a51d22eb">here</a>.</p><h3>Mistake 8: Not Abstracting Database Requests</h3><p>When an application communicates with a database, you have a couple options:</p><ol><li>Communicate with the database directly</li><li>Communicate with the database through an abstraction layer</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*oROwuOGaeVQ3_bvYjR4oiA.png" /></figure><p>Abstraction layers might seem unnecessary at first, but I’ve learned not using them can be a big mistake. I’ll briefly list out the benefits of employing one and the consequences of not.</p><p>Benefits:</p><ul><li>An abstraction layer is more secure because you can have greater control over what requests can access the database.</li><li>Abstraction layers let you throttle requests in times of heavy traffic.</li><li>You can simplify the queries made by the app by hiding the uglier query semantics in the abstraction layer.</li><li>The code for creating, updating, and deleting data from the database is centralized instead of spread-out in the app.</li><li>You could put a cache into the abstraction layer and increase the read speed for frequently accessed data while reducing money spent on database read operations.</li></ul><p>Consequences:</p><ul><li>If you need to migrate to a different database, an app refactor will be much more expensive than an abstraction layer refactor. If you used an abstraction layer, you could have just switched the layer service out while preserving the app code. My team has experienced this first-hand, and now our app is essentially married to a database and divorce is not a feasible option. Don’t let this happen to you!</li></ul><h3>Mistake 9: Ignoring Idempotency</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/0*4sNUxl9pykTNCwqe" /><figcaption>The scholar pigeon knows all. Photo Credit: <a href="https://thesaurus.plus/">Thesaurus.plus</a></figcaption></figure><p>Idempotency is a fun word. As defined by Stack Overflow:</p><blockquote>“In computing, an idempotent operation is one that has no additional effect if it is called more than once with the same input parameters. For example, removing an item from a set can be considered an idempotent operation on the set.”</blockquote><p>For the more mathematically inclined out there, here’s an example of an idempotent function (which some of you might recognize as the <a href="http://Identity Function">Identity Function</a>):</p><p><em>Let f</em>(<em>x</em>) = <em>x</em></p><p>A function is said to be idempotent if <em>f</em>(<em>f</em>(<em>x</em>)) = <em>f</em>(<em>x</em>). Putting the input into our function always yields the same output<em>, </em>hence <em>f</em>(<em>x</em>) = <em>x </em>is an idempotent function.</p><p>Bringing it back to the real world, idempotency is important when dealing with network protocols. Many services have an “at-least-once” delivery policy, meaning requests are guaranteed to happen at least once, but might also happen more than once. This is to hedge in case of timeouts or failures that lead to message loss. The requests are retransmitted to assure they are delivered at least once.</p><p>If you are working with an “at-least-once” delivery policy, its important that the operations involved are idempotent. Consider the following scenario:</p><ul><li>A user places an order on a website. The order request goes out with an at-least-once delivery policy.</li></ul><p>If the backend is not set up correctly, people could end up getting charged for their order twice! This is because the order request could be delivered multiple times, and if you treat each request as a new order, you’ll duplicate the order each time the at-least-once policy kicks in.</p><p>Here’s a tip to help you make your services idempotent:</p><ul><li>Create a hash out of the incoming request and use it as the transaction id. Instead of creating a new transaction, it will harmlessly overwrite the already existing one.</li></ul><p>For those who are hungry for more, check out this video about <a href="https://www.youtube.com/watch?v=4OuaONkZw1I">Why Idempotency is Important</a>.</p><h3>Mistake 10: Not-CRUDing Completely</h3><p>C.R.U.D. is an acronym that stands for Create, Read, Update, and Delete. When dealing with a database, it is <em>essential</em> that you have the ability to perform these four operations.</p><p>In my early projects, I was super-focused on Creating and Reading data from the database I was working on, and there was a lot of pressure to get the project into production. Things went great … until a user wanted to Update and Delete documents from the database! Uh oh! I should have thought of that!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/0*6AvgvohwZR0s32MC.gif" /></figure><p>I acknowledge that there are scenarios where updating and destroying records will not be important and it doesn’t make sense to add the “UD” in CRUD (think audit-trail data and other types of read-only data). But in the other scenarios, it’s easy to neglect the Update and Delete operations.</p><p>Without great delete operations, databases can become cluttered with data that shouldn’t be there. When dealing with huge data-lakes, this data can become very hard to find and adds to your overhead.</p><p>A great strategy is utilizing Object Lifecycles to help you manage your files. In Google Cloud Storage and AWS, you can let files expire if they reach a certain age or meet a given condition. Or if dealing with an index, you can set an index lifecycle policy that will purge old documents in the index. I’ve had experience doing this in Elasticsearch, which is the topic of a different Medium article…</p><p>Don’t neglect your CRUD operations kids!</p><h3>Conclusion</h3><p>Don’t be afraid of mistakes and jumping into things head first. It’s a part of being a beautiful human being and growing. I’ve learned a great deal from all the mistakes I’ve made in my life (not just the software related ones), but I also don’t want to minimize their consequences.</p><p>Instead of getting mad at myself when I mess up, I try to take a step back and listen to the wisdom that echos in the footsteps of every mistake. Because I think the greatest one we can commit is <em>making the same mistake twice</em>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b50a2bb1956f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/10-mistakes-to-avoid-as-a-software-engineer-b50a2bb1956f">10 Mistakes to Avoid as a Software Engineer</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>