<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>MIT on Tom Webster</title><link>https://www.samurailink3.com/licenses/mit/</link><description>Recent content in MIT on Tom Webster</description><generator>Hugo</generator><language>en-us</language><copyright>CC-BY-4.0</copyright><lastBuildDate>Thu, 14 Nov 2024 00:00:00 -0600</lastBuildDate><atom:link href="https://www.samurailink3.com/licenses/mit/index.xml" rel="self" type="application/rss+xml"/><item><title>Software Engineering Essentials: Flags</title><link>https://www.samurailink3.com/blog-posts/2024-11-14-software-engineering-essentials-flags/</link><pubDate>Thu, 14 Nov 2024 00:00:00 -0600</pubDate><guid>https://www.samurailink3.com/blog-posts/2024-11-14-software-engineering-essentials-flags/</guid><description>&lt;p&gt;&lt;em&gt;Software Engineering Essentials&lt;/em&gt; is a series of blog posts designed to help you get started with a wide variety of software engineering topics. This post was originally part of my &lt;a href="https://gitlab.com/samurailink3/go-twitter/"&gt;Go-Twitter project&lt;/a&gt;, a project-based curriculum designed to take someone from “zero” to “competent” in the world of software engineering.&lt;/p&gt;
&lt;p&gt;All writing for this post is licensed under &lt;code&gt;CC-BY-4.0&lt;/code&gt;, while all code is licensed under the &lt;code&gt;MIT&lt;/code&gt; license.&lt;/p&gt;
&lt;h1 id="flags"&gt;Flags&lt;/h1&gt;
&lt;h2 id="flag-usage"&gt;Flag Usage&lt;/h2&gt;
&lt;p&gt;Flags are effectively &lt;em&gt;named arguments&lt;/em&gt;, with some extra features. Instead of
needing to remember the order of your program&amp;rsquo;s arguments, you can just specify
the name of the flag and what that variable should be set to. Let&amp;rsquo;s take a look
at a simple example:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;01-simple-flags/main.go&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;package&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; (
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#e6db74"&gt;&amp;#34;flag&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#e6db74"&gt;&amp;#34;fmt&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;func&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;greeting&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;greeting&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;name&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;name&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Parse&lt;/span&gt;()
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;fmt&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Printf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;%s, %s!\\n&amp;#34;&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;greeting&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;name&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, if we run this program:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/02-flags/01-simple-flags/main.go
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; !
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Huh, that looks weird. This is because our &lt;code&gt;greeting&lt;/code&gt; and &lt;code&gt;name&lt;/code&gt; variables are
empty. We never specified the flags. How do we know what the flags are? Flags
have built-in help functionality that will display all of the options available.
Most programs use &lt;code&gt;-h&lt;/code&gt; or &lt;code&gt;--help&lt;/code&gt; to display program usage text, including
flags and arguments.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/02-flags/01-simple-flags/main.go -h
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Usage of /tmp/go-build1913891522/b001/exe/main:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -greeting string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -name string
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So now we can see that this program accepts the &lt;code&gt;-greeting&lt;/code&gt; and &lt;code&gt;-name&lt;/code&gt; flags.
Let&amp;rsquo;s set some values:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/02-flags/01-simple-flags/main.go -greeting=&amp;#34;Sup&amp;#34; -name Tom
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Sup, Tom!
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Flag arguments can be set with some optional grammar to help avoid problems with
ambiguity or spaces:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;flag value&lt;/code&gt;: For one-word values
&lt;ul&gt;
&lt;li&gt;Unquoted spaces can change how your command is interpreted, leading to
missing values and skipped flags. See the appendix section &lt;em&gt;How Spaces Can
Affect Flags&lt;/em&gt; for an example.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;flag &amp;quot;value with spaces or special characters&amp;quot;&lt;/code&gt;: For multi-word values or
values that contain some special characters.
&lt;ul&gt;
&lt;li&gt;If your value has a &lt;code&gt;$&lt;/code&gt; symbol, you may need to use single-quotes (&lt;code&gt;'&lt;/code&gt;) to
avoid the shell interpreting &lt;code&gt;$&lt;/code&gt; as the start of a shell variable.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;flag=&amp;quot;value&amp;quot;&lt;/code&gt;: This is the &lt;em&gt;belt-and-suspenders&lt;/em&gt; of flag declaration.
&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;=&lt;/code&gt; just removes space from the declaration and makes it &lt;em&gt;very&lt;/em&gt; clear
that this particular value belongs to that particular flag. This can be
helpful to aid in readability, especially if you&amp;rsquo;re writing out examples
or documentation.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We can also specify the flags in any order:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/02-flags/01-simple-flags/main.go -name=&amp;#34;General&amp;#34; -greeting=&amp;#34;Hello There&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Hello There, General!
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Or not specify a value for &lt;code&gt;-name&lt;/code&gt; at all!&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/02-flags/01-simple-flags/main.go -greeting=&amp;#34;Hello There&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Hello There, !
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can even abuse the flags to make the program finish the meme:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/02-flags/01-simple-flags/main.go -greeting=&amp;#34;General Kenobi\\!&amp;#34; -name=&amp;#34;You are a bold one&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;General Kenobi!, You are a bold one!
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="defaults"&gt;Defaults&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s re-create the program that inserted profiles into a database from the end
of the &lt;em&gt;Command Line Arguments&lt;/em&gt; chapter, but with flags instead:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;02-profile-saver/main.go&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;package&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; (
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#e6db74"&gt;&amp;#34;flag&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#e6db74"&gt;&amp;#34;fmt&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;func&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;firstName&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;first-name&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;lastName&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;last-name&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favFruit&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;fruit&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favVeg&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;veg&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favPasta&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;pasta&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favMeal&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;meal&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;riceOrBeans&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;rice-or-beans&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favDesert&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;desert&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favDessert&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;dessert&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Parse&lt;/span&gt;()
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;fmt&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Printf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;`Profile Name: %s %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;	Rice or Beans: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;	Favorites:
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Fruit: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Vegetable: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Pasta: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Desert: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Dessert: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Meal: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;`&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;firstName&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;lastName&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;riceOrBeans&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favFruit&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favVeg&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favPasta&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favDesert&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favDessert&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favMeal&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Right now if we run this program with no flags set, we get this results:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/02-flags/02-profile-saver/main.go
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Profile Name:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Rice or Beans:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Favorites:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Fruit:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Vegetable:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Pasta:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Desert:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Dessert:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Meal:
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Lots of blank spaces here. We don&amp;rsquo;t want to commit empty values to the database,
it can introduce &lt;em&gt;ambiguity&lt;/em&gt;. Did this person not have a favorite pasta or did
we just forget to add the data? Being &lt;em&gt;explicit&lt;/em&gt; in programming has several
benefits, including clarity-of-intent, so let&amp;rsquo;s add some &lt;em&gt;defaults&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Default values can provide the &lt;em&gt;usual&lt;/em&gt; options or placeholder data. Flags make
this easy. For now, let&amp;rsquo;s just use &lt;code&gt;UNKNOWN&lt;/code&gt; as the profile placeholder. With
the stanadrd &lt;code&gt;flag&lt;/code&gt; package, setting defaults is easy. Let&amp;rsquo;s take a look at the
GoDocs for &lt;code&gt;flag.String&lt;/code&gt;, available &lt;a href="https://pkg.go.dev/flag#String"&gt;here&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;func String&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;func String(name string, value string, usage string) *string
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;String defines a string flag with specified name, default value, and usage
string. The return value is the address of a string variable that stores the
value of the flag.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So the &lt;em&gt;second&lt;/em&gt; function argument allows us to specify a default value for that particular flag. Let&amp;rsquo;s do that now:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;02-profile-saver/main.go&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;package&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; (
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#e6db74"&gt;&amp;#34;flag&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#e6db74"&gt;&amp;#34;fmt&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;func&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;firstName&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;first-name&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;lastName&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;last-name&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favFruit&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;fruit&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favVeg&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;veg&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favPasta&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;pasta&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favMeal&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;meal&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;riceOrBeans&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;rice-or-beans&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favDesert&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;desert&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favDessert&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;dessert&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Parse&lt;/span&gt;()
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;fmt&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Printf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;`Profile Name: %s %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;	Rice or Beans: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;	Favorites:
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Fruit: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Vegetable: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Pasta: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Desert: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Dessert: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Meal: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;`&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;firstName&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;lastName&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;riceOrBeans&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favFruit&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favVeg&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favPasta&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favDesert&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favDessert&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favMeal&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now when we run this program without any flags set:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/02-flags/02-profile-saver/main.go
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Profile Name: UNKNOWN UNKNOWN
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Rice or Beans: UNKNOWN
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Favorites:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Fruit: UNKNOWN
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Vegetable: UNKNOWN
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Pasta: UNKNOWN
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Desert: UNKNOWN
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Dessert: UNKNOWN
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Meal: UNKNOWN
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;There we go, that at least looks more complete.&lt;/p&gt;
&lt;p&gt;Now let&amp;rsquo;s actually use those flags to set some values&amp;hellip; but wait, what were the
flags again? Let&amp;rsquo;s use &lt;code&gt;-h&lt;/code&gt; to see what options we have:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/02-flags/02-profile-saver/main.go -h
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Usage of /tmp/go-build261536590/b001/exe/main:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -desert string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -dessert string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -first-name string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -fruit string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -last-name string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -meal string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -pasta string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -rice-or-beans string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -veg string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Ah, got it. Now let&amp;rsquo;s actually use these:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/02-flags/02-profile-saver/main.go -first-name Bob -last-name Sacamano -fruit Apple -veg &lt;span style="color:#e6db74"&gt;&amp;#34;Green Beans&amp;#34;&lt;/span&gt; -pasta Manicotti -meal Steak -desert Sahara -dessert Sundae -ri
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ce-or-beans Rice
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Profile Name: Bob Sacamano
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Rice or Beans: Rice
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Favorites:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Fruit: Apple
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Vegetable: Green Beans
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Pasta: Manicotti
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Desert: Sahara
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Dessert: Sundae
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Meal: Steak
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So now we&amp;rsquo;re able to print out all of the profile information using flags. Its
still a lot of flags to remember, but at least we have the default help text and
the order of options doesn&amp;rsquo;t matter.&lt;/p&gt;
&lt;h2 id="help-text"&gt;Help Text&lt;/h2&gt;
&lt;p&gt;As we saw above, &lt;code&gt;-h&lt;/code&gt; is pretty helpful to understand which flags are available,
what type is expected, and what the defaults are, but we can add some more
context through &lt;em&gt;help text&lt;/em&gt;. As always, &lt;a href="https://pkg.go.dev/flag#String"&gt;reading the documentation&lt;/a&gt; can help us find the right place to add help text to our flags. For
now, let&amp;rsquo;s just add one piece of help text and see how it compares to the rest
of the flags:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;02-profile-saver/main.go&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;package&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; (
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#e6db74"&gt;&amp;#34;flag&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#e6db74"&gt;&amp;#34;fmt&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;func&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;firstName&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;first-name&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the first name of the user profile&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;lastName&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;last-name&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favFruit&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;fruit&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favVeg&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;veg&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favPasta&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;pasta&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favMeal&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;meal&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;riceOrBeans&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;rice-or-beans&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favDesert&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;desert&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favDessert&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;dessert&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Parse&lt;/span&gt;()
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;fmt&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Printf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;`Profile Name: %s %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;	Rice or Beans: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;	Favorites:
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Fruit: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Vegetable: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Pasta: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Desert: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Dessert: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Meal: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;`&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;firstName&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;lastName&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;riceOrBeans&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favFruit&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favVeg&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favPasta&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favDesert&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favDessert&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favMeal&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now let&amp;rsquo;s check out the help text:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/02-flags/02-profile-saver/main.go -h
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Usage of /tmp/go-build1166983742/b001/exe/main:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -desert string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -dessert string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -first-name string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; the first name of the user profile &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -fruit string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -last-name string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -meal string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -pasta string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -rice-or-beans string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -veg string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;(&lt;/span&gt;default &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Neat! Now let&amp;rsquo;s add the rest:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;02-profile-saver/main.go&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;package&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; (
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#e6db74"&gt;&amp;#34;flag&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#e6db74"&gt;&amp;#34;fmt&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;func&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;firstName&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;first-name&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the first name of the user profile&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;lastName&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;last-name&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the last name of the user profile&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favFruit&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;fruit&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s favorite fruit&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favVeg&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;veg&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s favorite vegetable&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favPasta&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;pasta&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s favorite type of pasta&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favMeal&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;meal&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s all-time favorite meal&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;riceOrBeans&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;rice-or-beans&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;whether the user prefers a side of rice or beans&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favDesert&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;desert&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s favorite desert (usually hot and sandy)&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favDessert&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;dessert&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s favorite dessert (usually a sweet after-meal treat)&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Parse&lt;/span&gt;()
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;fmt&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Printf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;`Profile Name: %s %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;	Rice or Beans: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;	Favorites:
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Fruit: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Vegetable: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Pasta: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Desert: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Dessert: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;		Meal: %s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#e6db74"&gt;`&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;firstName&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;lastName&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;riceOrBeans&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favFruit&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favVeg&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favPasta&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favDesert&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favDessert&lt;/span&gt;, &lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;favMeal&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And if we check out help text:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/02-flags/02-profile-saver/main.go -h
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Usage of /tmp/go-build2677080627/b001/exe/main:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -desert string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; the user&amp;#39;s favorite desert (usually hot and sandy) (default &amp;#34;UNKNOWN&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -dessert string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; the user&amp;#39;s favorite dessert (usually a sweet after-meal treat) (default &amp;#34;UNKNOWN&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -first-name string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; the first name of the user profile (default &amp;#34;UNKNOWN&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -fruit string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; the user&amp;#39;s favorite fruit (default &amp;#34;UNKNOWN&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -last-name string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; the last name of the user profile (default &amp;#34;UNKNOWN&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -meal string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; the user&amp;#39;s all-time favorite meal (default &amp;#34;UNKNOWN&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -pasta string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; the user&amp;#39;s favorite type of pasta (default &amp;#34;UNKNOWN&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -rice-or-beans string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; whether the user prefers a side of rice or beans (default &amp;#34;UNKNOWN&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -veg string
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; the user&amp;#39;s favorite vegetable (default &amp;#34;UNKNOWN&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So much better. Now our program has clear flagged arguments, defaults set, and
some help text to explain what each flag is intended for. However, this could be
cleaned up a bit more. To clean up the help text, let&amp;rsquo;s dig into &lt;em&gt;constants&lt;/em&gt;.&lt;/p&gt;
&lt;h2 id="constants"&gt;Constants&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Constants&lt;/em&gt; work very similarly to variables, but with one critical difference:
They cannot be changed at runtime. Constants are set in your source code and
compiled-in, after that, the value cannot be changed. Constants are helpful to
document and organize variables that control large pieces of your application or
that are used in a variety of places, but the values won&amp;rsquo;t change.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s dig in with an example. Let&amp;rsquo;s say you were making a program that talks to
a website to get information. The functions you write to talk to the website are
all going to use the same address over and over and over again. Instead of
typing &lt;code&gt;https://www.example.com&lt;/code&gt; over and over again, you can put this address
in a &lt;em&gt;constant declaration&lt;/em&gt; near the top of your file, then just reference it
using the constant name:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;package&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; (
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#e6db74"&gt;&amp;#34;fmt&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;const&lt;/span&gt; (
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;website&lt;/span&gt; = &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;lt;https://www.example.com&amp;gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;func&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;fmt&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Println&lt;/span&gt;(&lt;span style="color:#a6e22e"&gt;website&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So constants work kinda like variables, but let&amp;rsquo;s see what happens when we try
to change the value in our &lt;code&gt;main&lt;/code&gt; function:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;package&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; (
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#e6db74"&gt;&amp;#34;fmt&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;const&lt;/span&gt; (
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;website&lt;/span&gt; = &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;lt;https://www.example.com&amp;gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;func&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;fmt&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Println&lt;/span&gt;(&lt;span style="color:#a6e22e"&gt;website&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;website&lt;/span&gt; = &lt;span style="color:#e6db74"&gt;&amp;#34;A new value&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;fmt&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Println&lt;/span&gt;(&lt;span style="color:#a6e22e"&gt;website&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;When we run it, we get this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;main.go:13:2: cannot assign to website &lt;span style="color:#f92672"&gt;(&lt;/span&gt;untyped string constant &lt;span style="color:#e6db74"&gt;&amp;#34;&amp;lt;https://www.example.com&amp;gt;&amp;#34;&lt;/span&gt;&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The constants must remain constant. Trying to change them results in the program
refusing to build.&lt;/p&gt;
&lt;p&gt;So, constants can be useful to help avoid re-typing, but they can also help
generally clean up your code. Right now in our profile-saver program, we have a
lot of loose help text that we can clean up by moving those help strings from
the &lt;code&gt;flag.String&lt;/code&gt; functions into a constant declaration. So we can turn this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;func&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;firstName&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;first-name&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the first name of the user profile&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;lastName&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;last-name&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the last name of the user profile&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favFruit&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;fruit&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s favorite fruit&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favVeg&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;veg&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s favorite vegetable&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favPasta&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;pasta&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s favorite type of pasta&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favMeal&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;meal&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s all-time favorite meal&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;riceOrBeans&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;rice-or-beans&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;whether the user prefers a side of rice or beans&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favDesert&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;desert&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s favorite desert (usually hot and sandy)&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favDessert&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;dessert&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s favorite dessert (usually a sweet after-meal treat)&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&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="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;const&lt;/span&gt; (
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;firstNameHelp&lt;/span&gt; = &lt;span style="color:#e6db74"&gt;&amp;#34;the first name of the user profile&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;lastNameHelp&lt;/span&gt; = &lt;span style="color:#e6db74"&gt;&amp;#34;the last name of the user profile&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;fruitHelp&lt;/span&gt; = &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s favorite fruit&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;vegHelp&lt;/span&gt; = &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s favorite vegetable&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;pastaHelp&lt;/span&gt; = &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s favorite type of pasta&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;mealHelp&lt;/span&gt; = &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s all-time favorite meal&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;riceOrBeansHelp&lt;/span&gt; = &lt;span style="color:#e6db74"&gt;&amp;#34;whether the user prefers a side of rice or beans&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;desertHelp&lt;/span&gt; = &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s favorite desert (usually hot and sandy)&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;dessertHelp&lt;/span&gt; = &lt;span style="color:#e6db74"&gt;&amp;#34;the user&amp;#39;s favorite dessert (usually a sweet after-meal treat)&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;func&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;firstName&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;first-name&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;firstNameHelp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;lastName&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;last-name&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;lastNameHelp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favFruit&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;fruit&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;fruitHelp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favVeg&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;veg&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;vegHelp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favPasta&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;pasta&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;pastaHelp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favMeal&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;meal&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;mealHelp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;riceOrBeans&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;rice-or-beans&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;riceOrBeansHelp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favDesert&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;desert&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;desertHelp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;favDessert&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;flag&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;String&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;dessert&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;UNKNOWN&amp;#34;&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;dessertHelp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;...&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;There&amp;rsquo;s still a lot of text, but its a bit more organized and easier to work
with. This is one of the nicest bonus features of constants: They make great
organizational tools. If you have certain aspects of your program that can be
tuned by yourself or another developer, it may be a good idea to put them in a
&lt;code&gt;const&lt;/code&gt; declaration at the top of the file so they&amp;rsquo;re easy to access and
conveniently grouped.&lt;/p&gt;
&lt;p&gt;Its worth keeping in mind that not everything can be a constant. Due to the way
the Go compiler works, complex expressions cannot be pre-evaluated. Said another
way: Constants are &lt;em&gt;baked into&lt;/em&gt; your application when you run &lt;code&gt;go build&lt;/code&gt;.
According to the &lt;a href="https://go.dev/ref/spec#Constants"&gt;Go language spec&lt;/a&gt;, the only
valid constant types are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Runes (characters)&lt;/li&gt;
&lt;li&gt;Strings&lt;/li&gt;
&lt;li&gt;Booleans (&lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Numeric types (&lt;code&gt;int&lt;/code&gt;s, &lt;code&gt;float&lt;/code&gt;s, etc&amp;hellip;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you want the same style of organization for types that don&amp;rsquo;t work as
constants, you can use a &lt;code&gt;var&lt;/code&gt; declaration instead:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;var&lt;/span&gt; (
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#a6e22e"&gt;aMap&lt;/span&gt; = &lt;span style="color:#66d9ef"&gt;map&lt;/span&gt;[&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt;]&lt;span style="color:#66d9ef"&gt;string&lt;/span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;		&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;one&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;		&lt;span style="color:#ae81ff"&gt;2&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;two&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;		&lt;span style="color:#ae81ff"&gt;3&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;three&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="appendix-and-references"&gt;Appendix and References&lt;/h2&gt;
&lt;h3 id="references"&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pkg.go.dev/flag#String"&gt;GoDocs: flag.String&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://go.dev/ref/spec#Constants"&gt;Go Language Reference: Constants&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="appendix"&gt;Appendix&lt;/h3&gt;
&lt;h3 id="how-spaces-can-affect-flags"&gt;How Spaces Can Affect Flags&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/02-flags/01-simple-flags/main.go -greeting Hello There -name General
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Hello, !
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/02-flags/01-simple-flags/main.go -greeting &lt;span style="color:#e6db74"&gt;&amp;#34;Hello There&amp;#34;&lt;/span&gt; -name General
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Hello There, General!
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/02-flags/01-simple-flags/main.go -greeting&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;Hello There&amp;#34;&lt;/span&gt; -name General
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Hello There, General!
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>Software Engineering Essentials: Command Line Arguments</title><link>https://www.samurailink3.com/blog-posts/2024-11-13-software-engineering-essentials-command-line-arguments/</link><pubDate>Wed, 13 Nov 2024 00:00:00 -0600</pubDate><guid>https://www.samurailink3.com/blog-posts/2024-11-13-software-engineering-essentials-command-line-arguments/</guid><description>&lt;p&gt;&lt;em&gt;Software Engineering Essentials&lt;/em&gt; is a series of blog posts designed to help you get started with a wide variety of software engineering topics. This post was originally part of my &lt;a href="https://gitlab.com/samurailink3/go-twitter/"&gt;Go-Twitter project&lt;/a&gt;, a project-based curriculum designed to take someone from “zero” to “competent” in the world of software engineering.&lt;/p&gt;
&lt;p&gt;All writing for this post is licensed under &lt;code&gt;CC-BY-4.0&lt;/code&gt;, while all code is licensed under the &lt;code&gt;MIT&lt;/code&gt; license.&lt;/p&gt;
&lt;h1 id="command-line-arguments"&gt;Command Line Arguments&lt;/h1&gt;
&lt;h2 id="what-are-command-line-arguments"&gt;What are command line arguments?&lt;/h2&gt;
&lt;p&gt;Command line arguments are one way to pass user input into your application.
Let&amp;rsquo;s take a look at the common Unix utility &lt;code&gt;ls&lt;/code&gt;. &lt;code&gt;ls&lt;/code&gt; is a small application
that lists files and directories, just like double-clicking on a folder in
Windows Explorer, &lt;code&gt;ls&lt;/code&gt; allows you to peer into directories and get additional
information about files, like ownership information, size, last modification
timestamps, and more. &lt;code&gt;ls&lt;/code&gt;, like many command line applications, can take in
&lt;em&gt;arguments&lt;/em&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ls some-directory
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In this example &lt;code&gt;ls&lt;/code&gt; is the application you are running and &lt;code&gt;some-directory&lt;/code&gt; is
the &lt;em&gt;argument&lt;/em&gt;. What you&amp;rsquo;re asking &lt;code&gt;ls&lt;/code&gt; to do is give you a listing of all files
and folders inside of &lt;code&gt;some-directory&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="how-can-my-program-use-arguments"&gt;How can my program use arguments?&lt;/h2&gt;
&lt;p&gt;Because programming is generally open-ended, you can utilize command line
arguments to control any aspect of your program. You could use an argument to
control which IP address and port your application listens for requests on, or
what to print, or if an operation should target your test or production
environments. Let&amp;rsquo;s take a look at a simple example:&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a simple Go program that will print a person&amp;rsquo;s name and age on the
command line:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;01-simple-arguments/main.go&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;package&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; (
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;fmt&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;os&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;func&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;fmt&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Printf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;My name is %s and my age is %s.&amp;#34;&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;os&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Args&lt;/span&gt;[&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;], &lt;span style="color:#a6e22e"&gt;os&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Args&lt;/span&gt;[&lt;span style="color:#ae81ff"&gt;2&lt;/span&gt;])
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So if we run &lt;code&gt;go run example-code/02-command-line-arguments-and-flags/01-command-line-arguments/01-simple-arguments/main.go Bob 99&lt;/code&gt;, we&amp;rsquo;ll see: &lt;code&gt;My name is Bob and my age is 99.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;In this example, we use the &lt;code&gt;os&lt;/code&gt; package to get an array of arguments provided
on the command line. Arrays in Go start at &lt;code&gt;0&lt;/code&gt;, so we&amp;rsquo;re actually printing the
second and third argument. The first argument is the location of the program
we&amp;rsquo;re running. Since we&amp;rsquo;re using &lt;code&gt;go run&lt;/code&gt;, it will be in a temporary,
auto-generated location. Let&amp;rsquo;s add this block of code to our program and look at
each argument individually:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#a6e22e"&gt;fmt&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Println&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Our program&amp;#39;s arguments:&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;i&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;arg&lt;/span&gt; &lt;span style="color:#f92672"&gt;:=&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;range&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;os&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Args&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;fmt&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Printf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;os.Args[%d]: &amp;#39;%s&amp;#39;\\n&amp;#34;&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;i&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This code will print out each argument and its number:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Our program&amp;#39;s arguments:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;os.Args[0]: &amp;#39;/tmp/go-build201851007/b001/exe/main&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;os.Args[1]: &amp;#39;Bob&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;os.Args[2]: &amp;#39;99&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So &lt;code&gt;/tmp/go-build201851007/b001/exe/main&lt;/code&gt; is the temporary compiled version of
our program, made by the &lt;code&gt;go run&lt;/code&gt; command. The other arguments, &lt;code&gt;Bob&lt;/code&gt; and &lt;code&gt;99&lt;/code&gt;
are the arguments we provided on the command line.&lt;/p&gt;
&lt;p&gt;So, what happens if we provide less than 2 arguments to our program?&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/01-command-line-arguments/01-simple-arguments/main.go Bob
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;panic: runtime error: index out of range [2] with length 2
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;goroutine 1 [running]:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;main.main()
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; /home/samurailink3/git/go-twitter/example-code/02-command-line-arguments-and-flags/01-command-line-arguments/01-simple-arguments/main.go:9 +0x21c
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;exit status 2
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Uh oh&amp;hellip; &lt;code&gt;panic: runtime error: index out of range [2] with length 2&lt;/code&gt;&amp;hellip; That
doesn&amp;rsquo;t look good. What happened is we tried to access a variable that was
outside of the array. Here&amp;rsquo;s a simple diagram of the &lt;code&gt;os.Args&lt;/code&gt; array and what we&amp;rsquo;re trying to access:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Arg 0: Our program Arg 1: Our provided name Arg 2: What we&amp;#39;re trying to access
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; | | |
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; v v v
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[ &amp;#34;/tmp/go-build201851007/b001/exe/main&amp;#34;, &amp;#34;Bob&amp;#34; ]
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;os.Args&lt;/code&gt; array only contains 2 items (&lt;code&gt;os.Args[0]&lt;/code&gt; and &lt;code&gt;os.Args[1]&lt;/code&gt;), but
we&amp;rsquo;re trying to access something in the &lt;em&gt;third&lt;/em&gt; place (&lt;code&gt;os.Args[2]&lt;/code&gt;), beyond the
end of the array. This is an issue, so the code &lt;code&gt;panic&lt;/code&gt;s. How can we defend
against that? We want to avoid &lt;code&gt;panic&lt;/code&gt;ing and let the user know they&amp;rsquo;re missing
a required field.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;len&lt;/code&gt; check:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; len(&lt;span style="color:#a6e22e"&gt;os&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Args&lt;/span&gt;) &amp;lt; &lt;span style="color:#ae81ff"&gt;3&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;// Do something here&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can get the number of items present in the &lt;code&gt;os.Args&lt;/code&gt; array and do something
if we don&amp;rsquo;t have enough. First, let&amp;rsquo;s print out a helpful message for the user:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; len(&lt;span style="color:#a6e22e"&gt;os&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Args&lt;/span&gt;) &amp;lt; &lt;span style="color:#ae81ff"&gt;3&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;fmt&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Println&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;This program requires two arguments: Name and Age, you have&amp;#34;&lt;/span&gt;, len(&lt;span style="color:#a6e22e"&gt;os&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Args&lt;/span&gt;)&lt;span style="color:#f92672"&gt;-&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;When we run this with only the first argument, we get:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/01-command-line-arguments/01-simple-arguments/main.go Bob
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;This program requires two arguments: Name and Age, you have 1
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;panic: runtime error: index out of range [2] with length 2
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;goroutine 1 [running]:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;main.main()
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; /home/samurailink3/git/go-twitter/example-code/02-command-line-arguments-and-flags/01-command-line-arguments/01-simple-arguments/main.go:13 +0x29b
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;exit status 2
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Generally, we don&amp;rsquo;t want to show panics to the user, so let&amp;rsquo;s exit with a
non-successful error code (to learn more about error codes, check out &lt;a href="https://tldp.org/LDP/abs/html/exitcodes.html"&gt;the
Advanced Bash-Scripting Guide&lt;/a&gt;):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	&lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; len(&lt;span style="color:#a6e22e"&gt;os&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Args&lt;/span&gt;) &amp;lt; &lt;span style="color:#ae81ff"&gt;3&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;		&lt;span style="color:#a6e22e"&gt;fmt&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Println&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;This program requires two arguments: Name and Age, you have&amp;#34;&lt;/span&gt;, len(&lt;span style="color:#a6e22e"&gt;os&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Args&lt;/span&gt;)&lt;span style="color:#f92672"&gt;-&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;		&lt;span style="color:#75715e"&gt;// See &amp;#34;Advanced Bash-Scripting Guide: Exit Codes With Special Meanings&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;		&lt;span style="color:#75715e"&gt;// in the References section for why we use &amp;#34;2&amp;#34; here.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;		&lt;span style="color:#a6e22e"&gt;os&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;Exit&lt;/span&gt;(&lt;span style="color:#ae81ff"&gt;2&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;	}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now when we run our program with the missing argument, we get:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/01-command-line-arguments/01-simple-arguments/main.go Bob
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;This program requires two arguments: Name and Age, you have 1
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;exit status 2
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;That&amp;rsquo;s &lt;em&gt;way&lt;/em&gt; cleaner. Now if we run it with the right number of arguments, we see:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;go run example-code/02-command-line-arguments-and-flags/01-command-line-arguments/01-simple-arguments/main.go Bob 99
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;My name is Bob and my age is 99.
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Our program&amp;#39;s arguments:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;os.Args[0]: &amp;#39;/tmp/go-build1771918657/b001/exe/main&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;os.Args[1]: &amp;#39;Bob&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;os.Args[2]: &amp;#39;99&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="when-should-i-use-arguments"&gt;When should I use arguments?&lt;/h2&gt;
&lt;p&gt;Arguments are best used when an application has a limited number of distinct
options or your program operates on an unlimited number of the same argument.
Let&amp;rsquo;s expand that previous statement:&lt;/p&gt;
&lt;p&gt;So &lt;code&gt;git&lt;/code&gt; is a great example of having a limited (and segmented) number of
distinct options. It can do &lt;strong&gt;a lot&lt;/strong&gt;, but the options are &lt;em&gt;segmented&lt;/em&gt; by
sub-command. So, something &lt;code&gt;git branch&lt;/code&gt; would have pretty simple arguments, like
&lt;code&gt;git branch -D branch-name&lt;/code&gt; and &lt;code&gt;git branch --track local-branch remote-branch&lt;/code&gt;.
There are a couple of arguments to keep in your head, not too bad.&lt;/p&gt;
&lt;p&gt;Another program we talked about earlier, &lt;code&gt;ls&lt;/code&gt;, is a great example of having an
unlimited number of the same argument. So you can run &lt;code&gt;ls&lt;/code&gt; with zero arguments,
which just shows the files and folders present in your current directory, but we
can also run &lt;code&gt;ls some-directory and-another-one but-also-a-third&lt;/code&gt; to see what&amp;rsquo;s
inside those three distinct directories. &lt;code&gt;ls&lt;/code&gt; supports an unlimited number of
arguments, but each one does the same thing, so its not hard to remember or
think about.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s say you had a program to insert profile information into a database. You
track the following information about people:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First Name&lt;/li&gt;
&lt;li&gt;Last Name&lt;/li&gt;
&lt;li&gt;Favorite Fruit&lt;/li&gt;
&lt;li&gt;Favorite Vegetable&lt;/li&gt;
&lt;li&gt;Favorite Pasta&lt;/li&gt;
&lt;li&gt;Favorite Meal&lt;/li&gt;
&lt;li&gt;Rice or Beans&lt;/li&gt;
&lt;li&gt;Favorite Desert&lt;/li&gt;
&lt;li&gt;Favorite Dessert&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Your application in use may look like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;new-profile Bob Sacamano Apple GreenBeans Manicotti Steak Sahara Sundae
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Your users will need to keep this whole list in their heads &lt;em&gt;in order&lt;/em&gt;. That&amp;rsquo;s a
pretty bad user experience and its likely that someone will forget a field or
worse, get the order of the arguments wrong. This would add data into the wrong
fields in your database. There are too many options to keep track of here,
arguments aren&amp;rsquo;t a good choice for this program. Case-in-point: The above
example forgets the &amp;ldquo;Rice or Beans&amp;rdquo; field. Did you catch it?&lt;/p&gt;
&lt;p&gt;This application would be perfect for &lt;em&gt;flags&lt;/em&gt;, so we&amp;rsquo;ll cover that in the next
section.&lt;/p&gt;
&lt;h2 id="appendix-and-references"&gt;Appendix and References&lt;/h2&gt;
&lt;h3 id="references"&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://tldp.org/LDP/abs/html/exitcodes.html"&gt;Advanced Bash-Scripting Guide: Exit Codes With Special Meanings&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;There are few hard rules for exit codes. Exit 0 usually means everything
worked as expected, no errors. Exit 1 usually means something went wrong.
Exit 2 is commonly used to indicate a problem with the command itself (too
many arguments, too few, etc). These &amp;ldquo;rules&amp;rdquo; and prefaced with
&amp;ldquo;usually/commonly&amp;rdquo; because exit codes are ultimately up to the whims of
the developer.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Software Engineering Essentials: Working with GitLab (and GitHub)</title><link>https://www.samurailink3.com/blog-posts/2024-11-12-software-engineering-essentials-working-with-gitlab-and-github/</link><pubDate>Wed, 13 Nov 2024 00:00:00 -0600</pubDate><guid>https://www.samurailink3.com/blog-posts/2024-11-12-software-engineering-essentials-working-with-gitlab-and-github/</guid><description>&lt;p&gt;&lt;em&gt;Software Engineering Essentials&lt;/em&gt; is a series of blog posts designed to help you get started with a wide variety of software engineering topics. This post was originally part of my &lt;a href="https://gitlab.com/samurailink3/go-twitter/"&gt;Go-Twitter project&lt;/a&gt;, a project-based curriculum designed to take someone from “zero” to “competent” in the world of software engineering.&lt;/p&gt;
&lt;p&gt;All writing for this post is licensed under &lt;code&gt;CC-BY-4.0&lt;/code&gt;, while all code is licensed under the &lt;code&gt;MIT&lt;/code&gt; license.&lt;/p&gt;
&lt;h1 id="gitlab"&gt;GitLab&lt;/h1&gt;
&lt;h2 id="branch-etiquette"&gt;Branch Etiquette&lt;/h2&gt;
&lt;p&gt;Git makes working in groups much easier than manually copying and pasting code
together from multiple sources. A centralized Git hosting service can make it
even easier. Most of the time when multiple people work on a project, changes
are committed to feature-specific branches. These can be bug-fixes, new
features, refactors, or anything else. The important thing to keep in mind is to
keep your changes organized in the proper branches.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;re working on a bug-fix on a branch named &lt;code&gt;front-page-css-bugfix&lt;/code&gt;, don&amp;rsquo;t
pollute that branch with unnecessary changes like fixing test cases in an
unrelated function. The changes in a branch should correspond to that branch. If
you &lt;em&gt;really&lt;/em&gt; want to do that work and save it somewhere, feel free to create a
new branch. Branches are free and easy to use, feel free to make new ones as you
need.&lt;/p&gt;
&lt;h2 id="merge-requests"&gt;Merge Requests&lt;/h2&gt;
&lt;p&gt;Merge Requests (or Pull Requests in GitHub lingo) are a mechanism in most Git
hosting services designed to make it easier to handle merging in new changes.
While Git has a lot of tools for managing changes and merges, the web interface
is a bit easier to get started with for newcomers.&lt;/p&gt;
&lt;p&gt;More important than the change itself is the Code Review process that merge
requests assist with. Chances are, your merge request won&amp;rsquo;t be accepted
immediately and without question. Most of the time, we have something to fix or
something to change. The merge request view allows other team members to comment
on your diff and even highlight individual lines or blocks of changes to leave
comments. If you&amp;rsquo;ve ever used the &amp;ldquo;Track Changes&amp;rdquo; feature of Microsoft Office
product, you&amp;rsquo;ll be well-acquainted with this interface.&lt;/p&gt;
&lt;p&gt;When a merge request is accepted, your commits in the merge request will be
applied to the branch your request targets (usually the main development
branch). Then, whenever people fetch and pull changes, your commits will be
pulled down to their local repositories. This keeps everyone in lock-step with
each other while you all work on the same codebase.&lt;/p&gt;
&lt;p&gt;Your old branches should be deleted once merged. This isn&amp;rsquo;t a technical
requirement, it just keeps things clean.&lt;/p&gt;
&lt;h2 id="protecting-branches"&gt;Protecting Branches&lt;/h2&gt;
&lt;p&gt;Because the main development branch is used for collaboration and keeping
everyone on the project on the same page, you usually don&amp;rsquo;t want to commit
changes directly to it. Instead, you commit changes to the main development
branch through &lt;em&gt;merge requests&lt;/em&gt;. This ensures that the commits people are adding
are reviewed and communicated before they are added to the main branch.&lt;/p&gt;
&lt;p&gt;Most Git hosting services have a feature that will allow you to &lt;em&gt;protect&lt;/em&gt;
certain branches. Protecting a branch can prevent things like deletion and/or
directly pushing changes onto that branch. Instead changes are added in through
merge requests.&lt;/p&gt;</description></item><item><title>Software Engineering Essentials: Version Control with Git</title><link>https://www.samurailink3.com/blog-posts/2024-11-11-software-engineering-essentials-version-control-with-git/</link><pubDate>Mon, 11 Nov 2024 00:00:00 -0600</pubDate><guid>https://www.samurailink3.com/blog-posts/2024-11-11-software-engineering-essentials-version-control-with-git/</guid><description>&lt;p&gt;&lt;em&gt;Software Engineering Essentials&lt;/em&gt; is a series of blog posts designed to help you get started with a wide variety of software engineering topics. This post was originally part of my &lt;a href="https://gitlab.com/samurailink3/go-twitter/"&gt;Go-Twitter project&lt;/a&gt;, a project-based curriculum designed to take someone from “zero” to “competent” in the world of software engineering.&lt;/p&gt;
&lt;p&gt;All writing for this post is licensed under &lt;code&gt;CC-BY-4.0&lt;/code&gt;, while all code is licensed under the &lt;code&gt;MIT&lt;/code&gt; license.&lt;/p&gt;
&lt;h1 id="git"&gt;Git&lt;/h1&gt;
&lt;h2 id="what-is-git"&gt;What is Git?&lt;/h2&gt;
&lt;p&gt;&amp;ldquo;Git is a free and open source distributed version control system designed to
handle everything from small to very large projects with speed and efficiency.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Git is an application designed to manage your source code and make it easy to
keep version history, but why would you want this? Programming gets messy,
especially in large projects. Let&amp;rsquo;s say you&amp;rsquo;re testing an experimental bugfix,
you may be tempted to copy/paste your code into a different folder and name it,
&lt;code&gt;my-project_bugfix&lt;/code&gt;, but what happens when you have &lt;code&gt;my-project_bugfix2&lt;/code&gt; or
&lt;code&gt;my-project_bugfix_real&lt;/code&gt;. Copying around folders of source code might work
initially, but will quickly get messy, especially if you need to work with other
people. Git provides a system to help keep your code organized, easy to work
with, and easy to collaborate on.&lt;/p&gt;
&lt;p&gt;A Git repository is essentially a place where you can store files to track and
share changes to those files. Git repositories (or &lt;em&gt;repos&lt;/em&gt;, for short) are
usually used to store and track changes to source code files.&lt;/p&gt;
&lt;h2 id="installing-git"&gt;Installing Git&lt;/h2&gt;
&lt;p&gt;Git is available on a wide variety of platforms and you can find an installer
&lt;a href="https://git-scm.com/download/"&gt;here&lt;/a&gt;. There are some options to pick during setup:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Select Components:&lt;/strong&gt; Default&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Choosing the default editor used by Git:&lt;/strong&gt; Use Visual Studio Code as Git&amp;rsquo;s
default editor
&lt;ul&gt;
&lt;li&gt;If you don&amp;rsquo;t have Visual Studio Code, exit the Git installer, &lt;a href="https://code.visualstudio.com/Download"&gt;install
vscode&lt;/a&gt;, then re-launch the Git
installer.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Adjusting the name of the initial branch in new repositories:&lt;/strong&gt; Override the
default branch name for new repositories: &lt;code&gt;main&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Adjusting your PATH environment:&lt;/strong&gt; Git from the command line and also from
3rd-party software&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Choosing the SSH executable:&lt;/strong&gt; Use external OpenSSH
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/windows/terminal/tutorials/ssh"&gt;SSH is now included in Windows 10 and Windows 11 by
default&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Choosing HTTPS transport backend:&lt;/strong&gt; UUse the OpenSSL library&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Configuring the line ending conversions:&lt;/strong&gt; Checkout as-is, commit as-is&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Configuring the terminal emulator to use with Git Bash:&lt;/strong&gt; Use MinTTY (the
default terminal of MSYS2)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Choose the default behavior of &lt;code&gt;git pull&lt;/code&gt;:&lt;/strong&gt; Only ever fast-forward&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Choose a credential helper:&lt;/strong&gt; Git Credential Manager&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Configuring extra options:&lt;/strong&gt; Check both &lt;em&gt;Enable file system caching&lt;/em&gt; and
&lt;em&gt;Enable symbolic links&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Configuring experimental options:&lt;/strong&gt; Leave all options unchecked&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="configuring-ssh-and-setting-up-your-gitlab-account"&gt;Configuring SSH and Setting Up Your GitLab Account&lt;/h2&gt;
&lt;p&gt;First &lt;a href="https://gitlab.com/users/sign_up"&gt;register for GitLab&lt;/a&gt;. Next, we need to create an SSH
key so we can authenticate to GitLab.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Press &lt;code&gt;Windows+R&lt;/code&gt; to bring up the &amp;ldquo;Run&amp;rdquo; dialog box.&lt;/li&gt;
&lt;li&gt;Type &lt;code&gt;powershell&lt;/code&gt; and press &lt;code&gt;Enter&lt;/code&gt; to open up the PowerShell prompt.&lt;/li&gt;
&lt;li&gt;Type &lt;code&gt;ssh-keygen&lt;/code&gt; and press &lt;code&gt;Enter&lt;/code&gt; to start the key creation process
&lt;ul&gt;
&lt;li&gt;Press &lt;code&gt;Enter&lt;/code&gt; to accept the default file path&lt;/li&gt;
&lt;li&gt;Type a passphrase to protect your key and press &lt;code&gt;Enter&lt;/code&gt;.
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; Your passphrase will not appear in the terminal window as
you type it. This is a security feature.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Re-type your passphrase and press &lt;code&gt;Enter&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The key is generated and a list of file paths is printed out. Make note of
where the public key has been saved.&lt;/li&gt;
&lt;li&gt;Use VSCode to open that &lt;strong&gt;public key&lt;/strong&gt; file. Keep powershell and vscode
open for the next section.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://gitlab.com/-/profile/keys"&gt;Click here&lt;/a&gt; to go to your GitLab User Settings to
manage your SSH keys. In the &lt;em&gt;Add an SSH key&lt;/em&gt; section, copy and paste the entire
&lt;em&gt;public key file&lt;/em&gt; from before into the &lt;em&gt;Key&lt;/em&gt; text box, then click &lt;em&gt;Add key&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Now bring up the &lt;code&gt;powershell&lt;/code&gt; window you had open before and use the &lt;code&gt;ssh-add&lt;/code&gt;
command. Type your key passphrase and press &lt;code&gt;Enter&lt;/code&gt;. Remember: Your passphrase
will not be shown here as you type it.&lt;/p&gt;
&lt;p&gt;This command will add your key to an &lt;code&gt;ssh-agent&lt;/code&gt;. This program just makes it
easier to use your key. Instead of needing to type your passphrase every time
you use the key, you just add it to the agent and use the passphrase only once.
You&amp;rsquo;ll need to do this each time the computer reboots.&lt;/p&gt;
&lt;p&gt;You can see what keys the agent has with the command: &lt;code&gt;ssh-add -l&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;You can remove keys from the agent, thereby &amp;ldquo;re-locking&amp;rdquo; them, with the command:
&lt;code&gt;ssh-add -D&lt;/code&gt;&lt;/p&gt;
&lt;h2 id="how-git-views-the-world"&gt;How Git views the World&lt;/h2&gt;
&lt;h3 id="a-brief-introduction-to-hashes"&gt;A Brief Introduction to Hashes&lt;/h3&gt;
&lt;p&gt;Git&amp;rsquo;s view of the world is through &lt;em&gt;hashes&lt;/em&gt;. A hash function is a way to &amp;ldquo;boil
down&amp;rdquo; data to a fixed-length value. This sounds complex, but its simple in
practice. Let&amp;rsquo;s look at the current hash of this file I&amp;rsquo;m writing now:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;~ sha1sum Handouts/01-source-code-version-control-and-hosting/01-git.md
0b4597c1d9294a633ea584d715ce6681e57cb82a Handouts/01-source-code-version-control-and-hosting/01-git.md
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But as I write more, change the content, and save, the hash will change:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;~ sha1sum Handouts/01-source-code-version-control-and-hosting/01-git.md
8393d5018367212dcfe4fa6e477fdf5deff28576 Handouts/01-source-code-version-control-and-hosting/01-git.md
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So hashing is a way to take data of any amount and get a fixed-length value that
is unique to that data&amp;rsquo;s content. Some practical uses involve things like &lt;em&gt;error
checking, data deduplication, and protection against corruption or tampering&lt;/em&gt;.
Git uses hashes to identify individual objects like files, directories,
references, commits, and more.&lt;/p&gt;
&lt;h3 id="diffs-on-diffs-on-diffs"&gt;Diffs on Diffs on Diffs&lt;/h3&gt;
&lt;p&gt;Git heavily utilizes the concept of &lt;code&gt;diff&lt;/code&gt;s as a way to understand the
differences between files (and multiple historical versions of the same file).
This makes merges easier to manage and makes for more efficient file storage.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s check out &lt;code&gt;diff&lt;/code&gt; in action:&lt;/p&gt;
&lt;p&gt;I have two files, &lt;code&gt;a.txt&lt;/code&gt; and &lt;code&gt;b.txt&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;a.txt:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;Test
This is file a
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;b.txt:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;Test
This is file b
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Here&amp;rsquo;s what I get when I run &lt;code&gt;diff a.txt b.txt&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;2c2
&amp;lt; This is file a
---
&amp;gt; This is file b
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;diff&lt;/code&gt; only shows us the differences between the files. Git can use this to
figure out what changed between different objects. A &lt;em&gt;commit&lt;/em&gt; in Git is like
taking a snapshot of the diff of the entire repository. As you make more
commits, you are creating historical records of what changed in that repository
at that moment in time. By playing the diffs in reverse, you can effectively
wind back the clock and travel to past, undoing changes.&lt;/p&gt;
&lt;p&gt;So how does git &amp;ldquo;play back&amp;rdquo; those diffs? This is an operation called &lt;em&gt;patching&lt;/em&gt;.
A patch is a series of changes intended to be applied to an existing system.&lt;/p&gt;
&lt;p&gt;So if I had a program and someone found a typo: &lt;code&gt;hello.go&lt;/code&gt;&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;package main

import &amp;#34;fmt&amp;#34;

func main() {
	fmt.Println(&amp;#34;henlo world&amp;#34;)
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;They could send me a small patch to fix it:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;typo-fix.patch&lt;/code&gt;&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;--- hello.go	2023-01-01 21:25:05.694853862 +0000
+++ hello.go	2023-01-01 21:26:15.863385402 +0000
@@ -3,5 +3,5 @@
 import &amp;#34;fmt&amp;#34;

 func main() {
-	fmt.Println(&amp;#34;henlo world&amp;#34;)
+	fmt.Println(&amp;#34;hello world&amp;#34;)
 }
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And I could use &lt;code&gt;patch hello.go typo-fix.patch&lt;/code&gt; or &lt;code&gt;git apply typo-fix.patch&lt;/code&gt; to
apply the diff. Now my application will print &lt;code&gt;hello world&lt;/code&gt;!&lt;/p&gt;
&lt;p&gt;A Git repository is just hashed objects and diffs stacked on top of diffs.&lt;/p&gt;
&lt;h3 id="extra-reading"&gt;Extra Reading&lt;/h3&gt;
&lt;p&gt;If you enjoyed this section, feel free to check out &lt;a href="https://git-scm.com/book/en/v2/Git-Internals-Plumbing-and-Porcelain"&gt;Git Internals&lt;/a&gt; chapter in the official book for an ever deeper dive.&lt;/p&gt;
&lt;h2 id="using-git-on-the-command-line"&gt;Using Git on the Command Line&lt;/h2&gt;
&lt;p&gt;Git is an open source application and there are a ton of products and graphical
interfaces designed to make working with it easier. While these can work well in
some straight-forward circumstances, they all tend to fall apart pretty badly
when things go off the &amp;ldquo;happy path&amp;rdquo;, and &lt;a href="https://xkcd.com/1597/"&gt;it can be difficult to get back to a
good state&lt;/a&gt;. For this reason, we&amp;rsquo;ll focus on using the command-line
version of Git. Once you&amp;rsquo;re comfortable with this interface, you can absolutely
use any Git-compatible application you want, including &lt;a href="https://code.visualstudio.com/docs/sourcecontrol/overview"&gt;VS Code&amp;rsquo;s excellent Git
integration&lt;/a&gt;, just don&amp;rsquo;t skip learning the CLI basics first.&lt;/p&gt;
&lt;h3 id="project-creation"&gt;Project Creation&lt;/h3&gt;
&lt;p&gt;A Git repository is just a folder with another &lt;code&gt;.git&lt;/code&gt; folder inside of it. In
the &lt;code&gt;.git&lt;/code&gt; folder are a bunch of directories and files that Git uses to make
sense of your codebase. These include hashed objects, diffs, and metadata used
to keep things organized and human-compatible. You shouldn&amp;rsquo;t need to dive into
this directory or change anything.&lt;/p&gt;
&lt;p&gt;The command to instantiate a new Git repository on your local system is: &lt;code&gt;git init my-project-name&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Once you run this command, you&amp;rsquo;ll need a folder named &lt;code&gt;my-project-name&lt;/code&gt;. All of
your code, as well as anything you want to keep under version control (like
documentation files), should go here.&lt;/p&gt;
&lt;h3 id="cloning-an-existing-project"&gt;Cloning an Existing Project&lt;/h3&gt;
&lt;p&gt;Git is a distributed system, which means projects don&amp;rsquo;t have to live purely on
your local system. Many programmers utilize a Git-hosting service to store and
share their code with other contributors. These include services like
&lt;a href="https://github.com/"&gt;GitHub&lt;/a&gt;, &lt;a href="https://about.gitlab.com/"&gt;GitLab&lt;/a&gt;, and &lt;a href="https://bitbucket.org/product"&gt;Bitbucket&lt;/a&gt;. Don&amp;rsquo;t worry
about signing up for any of these services just yet, the next section will walk
you through the basics of &lt;a href="https://about.gitlab.com/"&gt;GitLab&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Git hosting services give you an easy way to interact with other contributors,
report and accept issues, manage merge requests, and most importantly: Share
your code with the world. Its important to understand that Git is a distributed
system &lt;em&gt;by default&lt;/em&gt;, you don&amp;rsquo;t &lt;em&gt;need&lt;/em&gt; these hosting sites to share or
collaborate on code, but they do make it easier.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;You can think about Git hosting services like YouTube or Vimeo. You can
absolutely share video files with people or even make your own video hosting
service, but using someone else&amp;rsquo;s service is so much easier. It is important to
keep in mind that Git is not GitHub. GitHub can be used to host a Git
repository, just like YouTube can be used to host a video. The hosting service
and the core technology are two different things.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Most Git hosting sites will give you one or two &lt;em&gt;Clone&lt;/em&gt; addresses you can use to
copy down the project locally. Most often these addresses are &lt;em&gt;SSH&lt;/em&gt; and/or
&lt;em&gt;HTTPS&lt;/em&gt; links. You can use these addresses in this command:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git clone &amp;lt;https://github.com/torvalds/linux.git&lt;/code&gt;&amp;gt;&lt;/p&gt;
&lt;p&gt;or like this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git clone git@github.com:torvalds/linux.git&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Typically&lt;/em&gt;, an &lt;code&gt;https&lt;/code&gt; repository link is going to be &lt;em&gt;read-only&lt;/em&gt;. You can pull
down changes, but won&amp;rsquo;t be able to push your own changes (unless you set up
HTTPS authentication). An &lt;code&gt;ssh&lt;/code&gt; repository link (the one that looks like
&lt;code&gt;git@gitlab&lt;/code&gt;) is &lt;em&gt;typically&lt;/em&gt; going to be &lt;em&gt;read+write&lt;/em&gt;. You will be able to push
your changes to the remote repository.&lt;/p&gt;
&lt;p&gt;This will clone the repository hosted on &lt;em&gt;GitHub&lt;/em&gt;, by the user &lt;em&gt;torvalds&lt;/em&gt;, with
the project name &lt;em&gt;linux&lt;/em&gt;, into a directory on your local system called &lt;em&gt;linux&lt;/em&gt;.
After you run that command, you can browse the Linux source code on your own
system. Because Git is decentralized, you obtain a &lt;em&gt;full copy&lt;/em&gt; of the source
code repository, including history, commits, branches, tags, and other Git
metadata. If you want, you can see what the code looked like last year, or even
before then. You can see when certain features were merged in, or when a certain
version-number was tagged.&lt;/p&gt;
&lt;p&gt;One thing to keep in mind is some data found on the Git host site &lt;em&gt;isn&amp;rsquo;t
included with the repository&lt;/em&gt;. These would be things like merge request
discussions, issues and bug reports, and project milestones and planning
features. By default, Git does not track these items in the repository, so they
are instead hosted directly by the Git hosting service.&lt;/p&gt;
&lt;h3 id="viewing-and-committing-changes"&gt;Viewing and Committing Changes&lt;/h3&gt;
&lt;p&gt;Git&amp;rsquo;s version control isn&amp;rsquo;t automated, users need to manually make &amp;ldquo;checkpoints&amp;rdquo;
of their changes to let Git know &amp;ldquo;these changes are important to track&amp;rdquo;. In Git,
these &amp;ldquo;checkpoints&amp;rdquo; are called &lt;em&gt;commits&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;A &lt;em&gt;commit&lt;/em&gt; is a way to tell Git &amp;ldquo;here are the changes I want to track&amp;rdquo;. Not
everything in a repository folder is automatically tracked. We need to tell Git
what files we want to track. For now though, let&amp;rsquo;s see how Git see&amp;rsquo;s the world:&lt;/p&gt;
&lt;p&gt;In this example, I have a new repository and I&amp;rsquo;ve created my first file with
some &amp;ldquo;Hello, World!&amp;rdquo; text in it. I can use &lt;code&gt;git status&lt;/code&gt; to see what Git thinks
of the files in the repository:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;~/git/my-project-name git status
On branch main

No commits yet

Untracked files:
 (use &amp;#34;git add &amp;lt;file&amp;gt;...&amp;#34; to include in what will be committed)
 my-first-file.txt

nothing added to commit but untracked files present (use &amp;#34;git add&amp;#34; to track)&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Git sees a new file that it has never tracked before: &lt;code&gt;my-first-file.txt&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Now, let&amp;rsquo;s follow Git&amp;rsquo;s helpful advice, add the file, and re-run the status
command to see what changes:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;~/git/my-project-name git add my-first-file.txt
~/git/my-project-name git status
On branch main

No commits yet

Changes to be committed:
 (use &amp;#34;git rm --cached &amp;lt;file&amp;gt;...&amp;#34; to unstage)
 new file: my-first-file.txt
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now it looks like we have added the file to our &lt;em&gt;staging area&lt;/em&gt;, but we haven&amp;rsquo;t
committed. We&amp;rsquo;re only preparing the files for commit, we haven&amp;rsquo;t made the
&amp;ldquo;checkpoint&amp;rdquo; yet. To do that, let&amp;rsquo;s use &lt;code&gt;git commit&lt;/code&gt;. By default, a text editor
will pop up or display in your terminal. This is used for writing a &lt;em&gt;commit
message&lt;/em&gt;. A &lt;em&gt;commit message&lt;/em&gt; is what will be logged with your code changes into
Git history. So if you&amp;rsquo;re working on a shared project, what you write here will
be viewable by anyone with access to the repository.&lt;/p&gt;
&lt;p&gt;Writing good commit messages is an art form and practice makes perfect. Try to
include enough context with your messages, so a &amp;ldquo;code detective&amp;rdquo; down the line
can figure out what your change did without needing to read the code itself.
Keep in mind that &lt;strong&gt;you&lt;/strong&gt; will be that &amp;ldquo;code detective&amp;rdquo; one day, and &lt;strong&gt;the code
you&amp;rsquo;ll be digging into may very well be your own&lt;/strong&gt;. Trying to track down a bug
and running into a commit that just says &amp;ldquo;fix&amp;rdquo; is infuriating. Make it easy on
yourself, write good commit messages.&lt;/p&gt;
&lt;p&gt;A good Git commit message explains &lt;em&gt;what changed&lt;/em&gt; and &lt;em&gt;why&lt;/em&gt;. The first line is
reserved for a title, the second line skipped, and the third line and beyond is
for your longer write-up. This is so &lt;code&gt;git log --oneline&lt;/code&gt; and other Git tools can
display text nicely. This isn&amp;rsquo;t a hard rule though, people can (and will)
disregard good commit message etiquette, the software will work with it all the
same. &lt;a href="https://zachholman.com/posts/git-commit-history/"&gt;Zach Holman has a great post about commit messages and why they just
don&amp;rsquo;t matter&lt;/a&gt;, so there are
multiple schools of thought on the subject.&lt;/p&gt;
&lt;p&gt;Back to the example. So I&amp;rsquo;ve written this as my commit message:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;Added my-first-file.txt to use in a Git example

I&amp;#39;ve added this file with default text in order to show Git examples
using commit messages.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I saved the file and exited the text editor. Git then uses this to construct a
commit. It returned this text:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;[main (root-commit) 3fa8cef] Added my-first-file.txt to use in a Git example
 1 file changed, 1 insertion(+)
 create mode 100644 my-first-file.txt
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now I can use &lt;code&gt;git log&lt;/code&gt; to see my history:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;commit 3fa8cefb1c854a550158a58d6443ec2b27e957fe (HEAD -&amp;gt; main)
Author: Tom Webster &amp;lt;tom@samurailink3.com&amp;gt;
Date: Wed Jan 4 00:17:48 2023 +0000

 Added my-first-file.txt to use in a Git example

 I&amp;#39;ve added this file with default text in order to show Git examples
 using commit messages.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To get a more compact view, you can use &lt;code&gt;git log --oneline&lt;/code&gt; and that will
display your commit titles in a list:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;3fa8cef (HEAD -&amp;gt; main) Added my-first-file.txt to use in a Git example
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You may have noticed that long string of jumbled text above:
&lt;code&gt;3fa8cefb1c854a550158a58d6443ec2b27e957fe&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This is a &lt;em&gt;commit ID&lt;/em&gt;. A &lt;code&gt;commit ID&lt;/code&gt; is a hash used to identify the change
you&amp;rsquo;ve added to history. Since hashes are designed to be unique, we only need to
display enough characters to identify a single commit, we don&amp;rsquo;t need to display
the full ID from above, we can just display &lt;code&gt;3fa8cef&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A simple example of this is like an ID system with too many digits. Let&amp;rsquo;s say
you have a list of the best fruits, but each ID has 10 digits, so you end up
with a table like this:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;Fruit - ID Number

Apple - 0000000001
Orange - 0000000002
Banana - 0000000003
Strawberry - 0000000004
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So much wasted space in that ID number. If we think we&amp;rsquo;ll have less than 100
fruits in this list, we can just use 2 digits to display the ID instead of the
full 10:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;Fruit - ID Number

Apple - 01
Orange - 02
Banana - 03
Strawberry - 04
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Hashes in Git operate in mostly the same way: It will give you the shortest
unambiguous hash, but the minimum number of digits is &lt;strong&gt;4&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id="git-remotes"&gt;Git Remotes&lt;/h3&gt;
&lt;p&gt;Git Remotes are &lt;em&gt;remote repositories&lt;/em&gt;. Because Git is a distributed system, you
can have multiple remote repositories you can read from or write to. If you
cloned this course repository from GitLab, you&amp;rsquo;ll probably see this when you run
&lt;code&gt;git remote -v&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;origin &amp;lt;https://gitlab.com/samurailink3/go-twitter&amp;gt; (fetch)
origin &amp;lt;https://gitlab.com/samurailink3/go-twitter&amp;gt; (push)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;By convention, the first remote added to a Git repository is named &lt;em&gt;origin&lt;/em&gt;, but
this is only a general convention, not a hard rule.&lt;/p&gt;
&lt;p&gt;You can have multiple remotes and custom rules for pushing and pulling changes
for each of them if you want. Most often you&amp;rsquo;ll just have one remote, hosted by
one of the popular Git hosting services. This setup will allow you to push
changes to an online repository and/or pull changes that have been pushed, but
you haven&amp;rsquo;t pulled to your local repository.&lt;/p&gt;
&lt;p&gt;If your repository was created on your local system only, without cloning from a
Git hosting service, you won&amp;rsquo;t have any remotes configured initially. You can
always add a remote with:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git remote add remote-name remote-address&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Like this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git remote add origin git@gitlab.com:samurailink3/go-twitter.git&lt;/code&gt;&lt;/p&gt;
&lt;h3 id="pulling-changes"&gt;Pulling Changes&lt;/h3&gt;
&lt;p&gt;Git has two different methods to pull changes into your local repository:
&lt;code&gt;fetch&lt;/code&gt; and &lt;code&gt;pull&lt;/code&gt;. Fetching changes pulls down new objects, diffs, and
references from a Git remote down to your local repository. &lt;em&gt;Its important to
keep keep in mind that fetching won&amp;rsquo;t change files in your local workspace.&lt;/em&gt; The
changes are instead cached as part of that Git remote.&lt;/p&gt;
&lt;p&gt;To fetch changes from the &lt;code&gt;origin&lt;/code&gt; remote, you can run:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git fetch origin&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;d like to fetch changes from &lt;em&gt;all&lt;/em&gt; remotes, you can use:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git fetch --all&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;To actually update files in your local workspace, you would use &lt;code&gt;git pull&lt;/code&gt;. This
will import changes from the configured remote branch into your local branch.
This means things like viewing history or checking diffs is near-instantaneous
because all of the changes are cached locally, Git doesn&amp;rsquo;t need to go back to
the internet to get more data. Once you fetch, those changes are stored locally.&lt;/p&gt;
&lt;h3 id="pushing-changes"&gt;Pushing Changes&lt;/h3&gt;
&lt;p&gt;Once you have commits you would like to push to your configured remote, you can
use:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git push remote-name branch-name&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Like this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git push origin main&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This tells Git, &amp;ldquo;Take my local commits and push them to the &lt;code&gt;origin&lt;/code&gt; remote on
the &lt;code&gt;main&lt;/code&gt; branch. Git will automatically figure out which commits are missing
on the remote and push only what&amp;rsquo;s needed to make them match.&lt;/p&gt;
&lt;h3 id="branches-and-checkouts"&gt;Branches and Checkouts&lt;/h3&gt;
&lt;p&gt;Branches in Git are a way to create other &amp;ldquo;timelines&amp;rdquo; of history in your
repository. So, if your main development branch is &lt;code&gt;main&lt;/code&gt;, but you want to work
on a complex feature without introducing bugs or breakages on the &lt;code&gt;main&lt;/code&gt; branch,
you can create a new branch named &lt;code&gt;my-new-feature&lt;/code&gt; and start committing changes
to that branch. By default, the first branch of a new Git repository is called
&lt;code&gt;main&lt;/code&gt;, or in older versions of Git, &lt;code&gt;master&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To see a list of branches in your local repository, you can use:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git branch&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;To see &lt;em&gt;all&lt;/em&gt; branches, even those present on remotes, you can use:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git branch --all&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;To create a new branch, you can just use:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git branch my-new-branch&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Now, if you look at your list of branches with &lt;code&gt;git branch&lt;/code&gt;, you&amp;rsquo;ll see it in
your list of local branches:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;* main
 my-new-branch
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But if you look, you can see the &lt;code&gt;*&lt;/code&gt; next to &lt;code&gt;main&lt;/code&gt;, and if you run &lt;code&gt;git status&lt;/code&gt;, you&amp;rsquo;ll see that you&amp;rsquo;re still on the &lt;code&gt;main&lt;/code&gt; branch:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;On branch main
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So how do we switch branches?&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git checkout my-new-branch&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Now when you run &lt;code&gt;git status&lt;/code&gt;, you&amp;rsquo;ll see:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;On branch my-new-branch
nothing to commit, working tree clean
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now, when you commit changes, you&amp;rsquo;ll be committing to &lt;code&gt;my-new-branch&lt;/code&gt; instead of
&lt;code&gt;main&lt;/code&gt;. To get back to the &lt;code&gt;main&lt;/code&gt; branch, run &lt;code&gt;git checkout main&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To save time, you can create and check out a new branch with one command:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git checkout -b my-new-branch&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;d like to base your branch on a specific branch, you can use:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git checkout -b my-new-branch main&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git checkout -b my-new-branch origin/some-other-branch&lt;/code&gt;&lt;/p&gt;
&lt;h3 id="additional-reading-and-git-workflows"&gt;Additional Reading and Git Workflows&lt;/h3&gt;
&lt;p&gt;There are many strategies and theories on when you should make new branches and
how you should organize them. When starting out: simpler is better. I&amp;rsquo;d
recommend reading about &lt;a href="https://docs.github.com/en/get-started/quickstart/github-flow"&gt;GitHub Flow&lt;/a&gt;. The quick reference for this
workflow is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a new branch for your specific change&lt;/li&gt;
&lt;li&gt;Make your commits&lt;/li&gt;
&lt;li&gt;Push your branch to your remote&lt;/li&gt;
&lt;li&gt;Create a merge request (called a Pull Request in GitHub&amp;rsquo;s terminology)&lt;/li&gt;
&lt;li&gt;If you&amp;rsquo;re working in a group: Get sign off from your team and address any
comments or requests&lt;/li&gt;
&lt;li&gt;Merge your changes&lt;/li&gt;
&lt;li&gt;Delete your branch&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are working on software that needs multiple versions and maintenance
releases (like operating systems or desktop software), something a bit more
complex, like &lt;a href="https://nvie.com/posts/a-successful-git-branching-model/"&gt;git-flow&lt;/a&gt;, could help.&lt;/p&gt;
&lt;h2 id="appendix-and-references"&gt;Appendix and References&lt;/h2&gt;
&lt;h3 id="references"&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/"&gt;The Git Website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/download/"&gt;Download Git&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository"&gt;Git Basics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.codecademy.com/learn/learn-git-introduction"&gt;Codecademy Interactive Git Course&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gitlab.com/users/sign_up"&gt;Register for GitLab&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gitlab.com/-/profile/keys"&gt;GitLab Profile SSH Keys&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/book/en/v2/Git-Internals-Plumbing-and-Porcelain"&gt;Git Internals&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://xkcd.com/1597/"&gt;XKCD: Git&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://code.visualstudio.com/docs/sourcecontrol/overview"&gt;VS Code: Git&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://about.gitlab.com/"&gt;GitLab&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bitbucket.org/product"&gt;Bitbucket&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://zachholman.com/posts/git-commit-history/"&gt;Zach Holman: Utter Disregard for Git Commit History&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/get-started/quickstart/github-flow"&gt;GitHub Flow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nvie.com/posts/a-successful-git-branching-model/"&gt;git-flow&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>