<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nic Hartley</title>
    <description>The latest articles on DEV Community by Nic Hartley (@nichartley).</description>
    <link>https://dev.to/nichartley</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F17870%2Fddf32c41-6582-4fb1-8839-b9c48cd0b8f7.png</url>
      <title>DEV Community: Nic Hartley</title>
      <link>https://dev.to/nichartley</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nichartley"/>
    <language>en</language>
    <item>
      <title>Set up a Pi with no router, no cable, and no peripherals</title>
      <dc:creator>Nic Hartley</dc:creator>
      <pubDate>Wed, 03 Apr 2019 00:46:21 +0000</pubDate>
      <link>https://dev.to/nichartley/set-up-a-pi-with-no-router-no-cable-and-no-peripherals-4312</link>
      <guid>https://dev.to/nichartley/set-up-a-pi-with-no-router-no-cable-and-no-peripherals-4312</guid>
      <description>&lt;p&gt;If you're at uni and you've tried to set up a Raspberry Pi, you've probably hit an error. Ditto if you don't own your router and your ISP (or landlord) won't give you access to the control page. That issue is that you somehow need to get your RPi's IP address, but you don't have any way to get it!&lt;/p&gt;

&lt;p&gt;So instead of using your normal router, well... why not make your own? Sure, you could go out and buy one, but chances are you already have a device capable of generating a hotspot. Your laptop can probably do it, as can your phone. Why not use them?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: if you're already experienced with setting up RPis headlessly, you can probably skip the rest of the tutorial. That last paragraph was the big secret. The rest of this is just applying the normal techniques to this specific case.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Requires
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;An RPi. I'll be using a Raspberry Pi 3 Model B+, but this should work with any Raspbian-capable machine. This should work on any Raspbian machine, though. Also, you &lt;em&gt;will&lt;/em&gt; still need the normal mandatory accessories for your RPi -- a power cable, an SD card, etc.&lt;/li&gt;
&lt;li&gt;Any device which supports mobile hotspots. I'm using my Android phone for this tutorial, but the instructions will be similar regardless.&lt;/li&gt;
&lt;li&gt;An SSH client. I use the CLI packaged with the Windows Subsystem for Linux because it's convenient, but there are dozens, and literally any will work.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Instructions
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Get your Pi ready
&lt;/h2&gt;

&lt;p&gt;The first thing you need to do is get your Pi ready. There are a &lt;em&gt;ton&lt;/em&gt; of tutorials on flashing Raspbian to your SD card; you can follow literally any of them.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: &lt;em&gt;Do not&lt;/em&gt; install NOOBS! NOOBS is great if you have a monitor and keyboard to attach to your Pi. If you do, you should use it! This tutorial, however, is built on the premise that you don't, so make sure that you install &lt;em&gt;Raspbian&lt;/em&gt;, not NOOBS.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once you have Raspbian installed on the SD card, you'll need to add two files, both in the root directory of the SD card:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An empty file called &lt;code&gt;ssh&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;wpa_supplicant.conf&lt;/code&gt; (see below)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Open up &lt;code&gt;wpa_supplicant.conf&lt;/code&gt; in your favorite editor, and&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US

network={
     ssid="TODO"
     psk="TODO"
     key_mgmt=WPA-PSK
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Keep that text editor open. We'll be setting the values of &lt;code&gt;ssid&lt;/code&gt; and &lt;code&gt;psk&lt;/code&gt; by replacing the &lt;code&gt;TODO&lt;/code&gt;s on those lines.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: If you're not in the US, you should change the &lt;code&gt;country=&lt;/code&gt; line to match your country's &lt;a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements"&gt;ISO 3155-1 alpha-2 code&lt;/a&gt;. I have yet to see things break when the wrong country is supplied, but that doesn't mean they can't.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Setting up your router
&lt;/h2&gt;

&lt;p&gt;The exact steps for this vary by the product you're using as your router. I'll describe the process for a couple of common systems, but there are definitely tutorials online for what you're using, even if it's not here.&lt;/p&gt;

&lt;p&gt;In general, though:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a hotspot.&lt;/li&gt;
&lt;li&gt;Set &lt;code&gt;ssid&lt;/code&gt; to the SSID of the network.&lt;/li&gt;
&lt;li&gt;Set &lt;code&gt;psk&lt;/code&gt; to the network's password.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Windows
&lt;/h3&gt;

&lt;p&gt;A Windows 10 machine will require an internet connection or &lt;a href="https://superuser.com/a/1229057/394502"&gt;some fiddling&lt;/a&gt; to create a hotspot, but it gives you the same benefits: Open your WiFi menu and look in the bottom-right or bottom-middle for a button labeled "Mobile Hotspot". Click it. You now have a hotspot starting.&lt;/p&gt;

&lt;p&gt;Once that turns blue, right-click it, click "Go to Settings"&lt;sup&gt;1&lt;/sup&gt;, and find the section showing the network name and password. Back in &lt;code&gt;wpa_supplicant.conf&lt;/code&gt;, set &lt;code&gt;ssid&lt;/code&gt; to the value next to "Network name", and &lt;code&gt;psk&lt;/code&gt; to the value next to "Network password". Make sure you get all of the characters exactly right, including case.&lt;/p&gt;

&lt;h3&gt;
  
  
  Android
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Most phones allow this; however, yours might not, or might have slightly different names for things. Use your best judgement.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Open Settings. Find the category labeled "Connections" or "Network &amp;amp; internet" and tap it. Tap the option labeled "Mobile Hotspot and Tethering", or something similar. Tap the switch next to the option labeled "Mobile Hotspot" or "Wi-Fi Hotspot". Before you connect to it, go into the settings and try to find something labeled "WiFi sharing" -- this will keep you from accidentally using mobile data while you have your RPi connected. With my phone, once I turn WiFi sharing on, I can actually turn WiFi entirely off (or at least disconnect from my local WiFi) and still use it, but this may not work with yours.&lt;/p&gt;

&lt;p&gt;As before, you'll nede to set &lt;code&gt;ssid&lt;/code&gt; and &lt;code&gt;psk&lt;/code&gt; to the network name and password, respectively. Both should be visible on the main screen, but if you're having trouble finding them, try tapping the three-dot menu icon in the top corner, then "Configure Mobile Hotspot". Each of the fields will be labeled nicely.&lt;/p&gt;

&lt;p&gt;You should also look at the Security dropdown. Chances are it'll be WPA2-PSK, and if that's the case, you don't need to do anything. If it's something else, you'll need to learn more about &lt;code&gt;wpa_supplicant.conf&lt;/code&gt; to correctly configure your RPi.&lt;/p&gt;

&lt;h2&gt;
  
  
  Putting the two together
&lt;/h2&gt;

&lt;p&gt;Now that you have your 'router' running and your RPi's SD card configured, put the SD card in the RPi and plug in the power cable. Give it some time to start up -- it'll take a little while. &lt;/p&gt;

&lt;p&gt;Eventually, you should see the RPi pop up on the list of devices connected to your network. On a Windows 10 hotspot, you'll see the device's name, IP address, and MAC address in a table. On your phone, you might just see a name -- try tapping it or tapping-and-holding to bring up extra information about it.&lt;/p&gt;

&lt;p&gt;You need to get your RPi's IP address for the next step. It should be clearly labeled. Be sure to copy it exactly; any typos will be annoying to spot.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connecting to the Pi
&lt;/h2&gt;

&lt;p&gt;This is actually the easiest step. Using the machine you'll control the RPi with, connect to the same network that the RPi is on. SSH into the IP address you just got, as the user &lt;code&gt;pi&lt;/code&gt; with password &lt;code&gt;raspberry&lt;/code&gt;. Congratulations! You're now in the RPi, and can do anything with it that you could with a normal terminal setup. &lt;/p&gt;

&lt;p&gt;Remember to change the default username and password for your RPi, by the way! Even if you don't now plan on using it for anything that's accessible to others, it's better to get into the habit of changing default passwords than to learn the hard way that you forgot.&lt;/p&gt;

&lt;p&gt;One important caveat, by the way: Connecting to a different network with either the RPi or your man machine will break the SSH connection. If you change the network your RPi is on, &lt;em&gt;your connection will break before the other connection is established&lt;/em&gt;. &lt;/p&gt;

&lt;h1&gt;
  
  
  Next steps
&lt;/h1&gt;

&lt;p&gt;From here, you have full control over your RPi. If your router connects to the internet, you can even install things from the internet. If you're brave, you could even set up X11 forwarding so you can &lt;em&gt;graphically&lt;/em&gt; control your RPi. You can even walk away and leave the RPi to do its own thing for a while -- when you come back, it'll automatically reconnect to the WiFi in its &lt;code&gt;wpa_supplicant.conf&lt;/code&gt; and you can access it like before.&lt;/p&gt;

&lt;p&gt;It's trickier if you want it to connect to another network, though. You can, of course, just change &lt;code&gt;wpa_supplicant.conf&lt;/code&gt; to point to the other network, reboot, and leave it be -- assuming you got all the details right, it'll connect to &lt;em&gt;that&lt;/em&gt; network perfectly well. The trouble is when you want to get control over it.&lt;/p&gt;

&lt;p&gt;If you have your RPi phoning home, you can of course write that system such that it can deliver commands like "reconnect to my hotspot" from your server. You could also have a script scanning the locally available WiFi and, if your hotspot is available, reconnecting to it. There are quite a few ways, and none of them are necessarily better than the others. It just depends on what you're trying to do, and what your resources are. &lt;/p&gt;

&lt;p&gt;Good luck!&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>setup</category>
      <category>headless</category>
    </item>
    <item>
      <title>What's a git tree?</title>
      <dc:creator>Nic Hartley</dc:creator>
      <pubDate>Wed, 27 Feb 2019 04:21:55 +0000</pubDate>
      <link>https://dev.to/nichartley/whats-a-git-tree-5149</link>
      <guid>https://dev.to/nichartley/whats-a-git-tree-5149</guid>
      <description>&lt;p&gt;I made a tool recently called &lt;a href="https://nic-hartley.github.io/git-gud/"&gt;Git Gud&lt;/a&gt;, and wrote &lt;a href="https://dev.to/nichartley/git-gud-at-git-5d9k"&gt;a blogpost&lt;/a&gt;. Y'all seemed to really like that, so hey, why not milk it for a little more?&lt;/p&gt;

&lt;p&gt;More seriously, though, how git works internally has fascinated me for a while. It's not actually that complicated, but there are two big chunks. I'll cover the abstraction git operates on first, and next week I'll go over how that's stored on disk. Trust me, it'll be easier to understand how it's stored if you understand what's being stored first.&lt;/p&gt;

&lt;p&gt;Note that this &lt;em&gt;is not&lt;/em&gt; a git tutorial. I'm assuming you have some familiarity with git -- you don't need to know what commits are, but you do need to know what version control is, and &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Pointers make an appearance here, as an analogy. If you don't know what they are, there are plenty of &lt;em&gt;incredible&lt;/em&gt; resources online to explain them, but that's far beyond the scope of this article. And probably my abilities, too.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I'm gonna break git down into three pieces:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The repository&lt;/li&gt;
&lt;li&gt;Commits&lt;/li&gt;
&lt;li&gt;Branches&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Repository
&lt;/h1&gt;

&lt;p&gt;The repository, "repo" for short, is the "container" of git. Git doesn't operate on your entire filesystem, as you probably know. It's limited to just one directory, and all the directories that are recursively in that directory. In the root of the repository is the &lt;code&gt;.git&lt;/code&gt; folder, which stores all of git's internal files.&lt;/p&gt;

&lt;p&gt;You can actually have a repository inside a repository -- if you've ever been told to &lt;code&gt;git clone --recursive&lt;/code&gt; something, that's what it relates to. This article is just going over the basic concepts of git, though, so I won't cover them here.&lt;/p&gt;

&lt;p&gt;There are some more corner cases, like &lt;code&gt;.gitignore&lt;/code&gt;. I &lt;em&gt;highly&lt;/em&gt; recommend looking into &lt;code&gt;.gitignore&lt;/code&gt;s for your git repos if you don't already have them. They might have been autogenerated by your IDE or in place from your template, but you should take a peek, learn the syntax, and see if you can't make them better. There's usually &lt;em&gt;some&lt;/em&gt; stuff that can safely be omitted from your build.&lt;/p&gt;

&lt;h1&gt;
  
  
  Commits
&lt;/h1&gt;

&lt;p&gt;A commit is a snapshot of the state of the repository. It stores the contents of every file as they are at the moment of a commit -- this is why &lt;code&gt;.git&lt;/code&gt; folders can sometimes get so big. Each commit is basically a tarball of the entire repository! Git doesn't use the &lt;code&gt;tar&lt;/code&gt; format internally, it uses a format that's way more space-efficient and doesn't clone identical data repeatedly, but that's a digression for next week.&lt;/p&gt;

&lt;p&gt;If you've used git a lot, you might notice that's not how they're typically displayed, though. They're normally displayed as diffs. And when you do things like merging (which we'll get to in a minute, I promise) you merge sets of differences, not two entire files. So... how does that work?&lt;/p&gt;

&lt;p&gt;Don't worry. We'll get to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Metadata
&lt;/h2&gt;

&lt;p&gt;The snapshot of your directory is accompanied by some metadata. The most important, in my opinion, are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;strong&gt;Commit message&lt;/strong&gt;. This tells people about your commit, and is vital to making your code's history easy to understand. Write good commit messages and you'll inevitably thank your past self.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Author&lt;/strong&gt;: The person who wrote the code. Almost definitely you, though some projects do accept patches and change the author to reflect the actual source of the code.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Parents&lt;/strong&gt;: The commit (or, occasionally, commit*s*) which this commit follows. This concept will be explored more in the &lt;strong&gt;Branches&lt;/strong&gt; section.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These metadata (along with the rest that git stores) are bundled together with the 'tarball' into a "commit object".&lt;/p&gt;

&lt;h2&gt;
  
  
  Commit names
&lt;/h2&gt;

&lt;p&gt;Commits don't quite have names. What they have is a hash. Today, that's generated with SHA-1, though it's expected that git will start to migrate to SHA-256... sometime soon. Whatever the algorithm, it's applied to the commit object, and the result is the commit's "name".&lt;/p&gt;

&lt;p&gt;The name, with SHA-1, looks something like this: &lt;code&gt;e9f8ebe40fadf3a644f92c4a5e4af70f92d29347&lt;/code&gt;. That's usually condensed down to the first 7 or 8 characters, so &lt;code&gt;e9f8ebe&lt;/code&gt; instead, though you can use any number of characters, so long as it's more than 7 and enough to uniquely identify the commit's hash.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stashes
&lt;/h2&gt;

&lt;p&gt;You might or might not know about &lt;code&gt;git stash&lt;/code&gt;. It's &lt;em&gt;really&lt;/em&gt; helpful, and I love it a lot. It lets you save the current state of your repo without making any changes to history, and easily reapply the changes. A stash is basically a commit object, but not pointed to by a branch (we'll get into that in a second). When you pop what's on your stash, it gets merged in basically like a branch (again, in a second).&lt;/p&gt;

&lt;h1&gt;
  
  
  Branches
&lt;/h1&gt;

&lt;p&gt;Branches are interesting. In a sense, they don't actually exist. They're just pointers (told you they'd crop up!) to commit objects. When you add a new commit to a branch, the commit's &lt;em&gt;parent&lt;/em&gt; is set to what the branch is currently pointing to, and the branch is set to point to the commit you just made.&lt;/p&gt;

&lt;p&gt;The "branch", then, is just the parents, grandparents, etc. of the commit that the branch is pointing to. This is, as you may guess, somewhat confusing to define. Where does a branch start? When it 'splits off' from another? How can you tell that the branch you're looking at split off, and not the other?&lt;/p&gt;

&lt;p&gt;Good question. A very good question. Such a good one, in fact, that I don't actually know the answer -- it seems to be a mix of convention and just sort of letting things work themselves out. By all means, if you can shed some light on this, please comment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tags and &lt;code&gt;HEAD&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Tags and &lt;code&gt;HEAD&lt;/code&gt; are the same thing as branches: Pointers to a commit. The difference is that tags never move, even when you commit -- they're fixed pointers to a single commit object in the tree.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;HEAD&lt;/code&gt;, on the other hand, moves a lot. When you commit, it moves to point to that new commit object. When you &lt;code&gt;git checkout&lt;/code&gt; another branch, it moves to point to the same place that branch is pointing (...mostly). You can even &lt;code&gt;git checkout&lt;/code&gt; individual commits or tags, and your &lt;code&gt;HEAD&lt;/code&gt; will point to those commits.&lt;/p&gt;

&lt;p&gt;As a side note, the commits branches are pointing to are often called the heads (lowercase) of those branches. I personally prefer the term "tips", because it's less likely to get confused with &lt;code&gt;HEAD&lt;/code&gt;, but calling them "branch heads" is much more common.&lt;/p&gt;

&lt;h2&gt;
  
  
  Merges
&lt;/h2&gt;

&lt;p&gt;I did promise I'd get to merges eventually. How do they work, if commits are just tarballs of files?&lt;/p&gt;

&lt;p&gt;Well, it has to do with one key invariant of a git repo that I've kinda glossed over up until this point: The root commit.&lt;/p&gt;

&lt;p&gt;In a repo, every commit, if you follow the chain of parents back far enough, points to the same, original commit. Because of that, if you start at two disparate commits in the repo and follow their parents back far enough, you will &lt;em&gt;eventually&lt;/em&gt; find a common ancestor. It might well be the root commit itself, but there'll be &lt;em&gt;a&lt;/em&gt; commit that both commits came from.&lt;/p&gt;

&lt;p&gt;Once you have that commit, you look at the state of the filesystem in it, compare it to the filesystem in the two child commits, and get the differences. If only one commit touched a given area, then you can merge those changes in 'safely'. If both commits touched an area, but made the same changes -- say, a commit was &lt;code&gt;cherry-pick&lt;/code&gt;ed between them to apply a security fix -- then you just apply those changes. If they made different changes to the same bit, then you flag it as a merge conflict and ask a human to handle it.&lt;/p&gt;

&lt;p&gt;That's obviously just an overview, and there are multiple merge algorithms with different strengths and weaknesses. They all operate fundamentally the same, but the actual algorithms used to find the diff, decide what counts as a merge conflict, etc. are different.&lt;/p&gt;

&lt;p&gt;Once all that is done, a new commit is made, with the changes from both branches integrated into the new snapshot. Generally, you're merging &lt;em&gt;from&lt;/em&gt; one branch &lt;em&gt;onto&lt;/em&gt; another, and the branch you're merging &lt;em&gt;onto&lt;/em&gt; is the one whose tip advances. The new commit has two parents: The two commits that the branches pointed to when you started the merge.&lt;/p&gt;

&lt;h3&gt;
  
  
  Squashed merge
&lt;/h3&gt;

&lt;p&gt;There's actually a different type of merge, which you may have heard of, called a squashed merge. It's just like a normal merge, but rather than retaining the "from" branch as a parent, it &lt;em&gt;only&lt;/em&gt; has the changes, all "squashed together" into a single commit. This is generally used when a very compact, very clean commit history is desired, but it loses the history which can be so useful in tracking down when a regression was introduced.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rebase
&lt;/h2&gt;

&lt;p&gt;So what's a rebase then?&lt;/p&gt;

&lt;p&gt;It's actually pretty dissimilar to a merge, even though they have the same end result of combining two sets of changes. While a merge leaves the branches as they are and adds a new commit with the new files, a rebase keeps the same number of commits, and moves them around.&lt;/p&gt;

&lt;p&gt;When you rebase, you again need to pick a branch to rebase &lt;em&gt;from&lt;/em&gt; and a branch to rebase &lt;em&gt;onto&lt;/em&gt;. Again, their common base is found, and again, diffs are computed.&lt;/p&gt;

&lt;p&gt;This time, though, the diffs are computed for every commit starting at the "from" branch tip and ending at the commit just ahead of the common base. Each of those diffs is then applied to the tip of the "onto" branch, each on its own commit. When the rebase is done, all of the old commits of the "from" branch (and the "from" branch itself) are deleted, leaving only the new commits on the "onto" branch.&lt;/p&gt;

&lt;p&gt;All in all, not very complex, and nowhere near as scary as it might seem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deleting a branch
&lt;/h2&gt;

&lt;p&gt;You may wonder -- if there's no marker saying when a branch ends, how does deleting a branch work?&lt;/p&gt;

&lt;p&gt;I refer you back to the beginning of this section on branches, where I talk about how to determine what the root of a branch is.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;So, in short:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Repos are folders with some git metadata in them.&lt;/li&gt;
&lt;li&gt;Commits are basically tarballs of the whole repo, plus some extra metadata.&lt;/li&gt;
&lt;li&gt;Branches are really just pointers and you shouldn't think about that too much.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hope you enjoyed! If you have questions, feel free to ask. This is a generic overview and probably didn't hit everything you might be curious about.&lt;/p&gt;

</description>
      <category>git</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Git Gud at git</title>
      <dc:creator>Nic Hartley</dc:creator>
      <pubDate>Thu, 21 Feb 2019 03:18:12 +0000</pubDate>
      <link>https://dev.to/nichartley/git-gud-at-git-5d9k</link>
      <guid>https://dev.to/nichartley/git-gud-at-git-5d9k</guid>
      <description>&lt;p&gt;Show of hands, everyone, who knows git?&lt;/p&gt;

&lt;p&gt;Not just the standard &lt;code&gt;git pull&lt;/code&gt; / &lt;code&gt;git commit&lt;/code&gt; / &lt;code&gt;git push&lt;/code&gt; arcanery that you go through to magically make your changes public, who actually &lt;em&gt;understands&lt;/em&gt; git? Who here understands its internal tree model, the thing that makes it work so well?&lt;/p&gt;

&lt;p&gt;If your hand is still up, you can feel free to skip this post, or pop over to &lt;a href="https://github.com/nic-hartley/git-gud" rel="noopener noreferrer"&gt;the source&lt;/a&gt; and help implement more features. You may want to hold off for a little while before you contribute, though; I'm porting it from WASM to JavaScript.&lt;/p&gt;

&lt;p&gt;If you &lt;em&gt;don't&lt;/em&gt; know how it works, though, can I recommend something I made? It's called &lt;a href="https://nic-hartley.github.io/git-gud/" rel="noopener noreferrer"&gt;Git Gud&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is it?
&lt;/h1&gt;

&lt;p&gt;Git Gud is a web-based Git simulator. It shows you the git tree visually, and you can run commands to show you what they do to the tree. You start out with an initial commit:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fop6Yn3B.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fop6Yn3B.png" alt="initial state"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You'll notice it's labeled "c0". That's the commit ID. Because we don't have any actual files to track -- that's for a much later version -- we don't have anything to hash, and on our initial build, we just ordered commits sequentially. The first, automatically generated commit is "c0", the second is "c1", and so on. Speaking of the second commit, click in the bottom area and try typing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll see another commit get added:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FQb7ZDrd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FQb7ZDrd.png" alt="first commit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just like in Git, you can checkout individual commits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;checkout c0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FZsQVEp1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FZsQVEp1.png" alt="checked out"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also make a new branch with &lt;code&gt;branch&lt;/code&gt;, check it out with &lt;code&gt;checkout b1&lt;/code&gt;, commit on it, &lt;code&gt;merge&lt;/code&gt; it back in, etc. For example, enter this sequence of commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;commit
checkout c0
branch
checkout b1
commit
checkout b0
merge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and you'll get this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FdsVV63n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FdsVV63n.png" alt="done"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to reset, well, there's no git command for that, but we've repurposed &lt;code&gt;init&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FF56RC9v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FF56RC9v.png" alt="initted"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Why?
&lt;/h1&gt;

&lt;p&gt;If you look at the commit history for Git Gud, you'll notice a massive spike in development over the course of a weekend. That weekend was &lt;a href="https://brickhack.io/" rel="noopener noreferrer"&gt;BrickHack&lt;/a&gt;, RIT's annual hackathon. It was an interesting experience, and a great way to get a prototype up and running.&lt;/p&gt;

&lt;p&gt;It did introduce some issues, though. The code isn't too great, since we didn't have a chance to really think through issues in just 24 hours. We wrote it in WebAssembly rather than the pure JavaScript that would have been less effort to develop and debug, because one of the team members only knew C++ and wasn't sure he could learn JavaScript in the few days well enough in the few days before the hackathon&lt;sup&gt;1&lt;/sup&gt;.&lt;/p&gt;

&lt;p&gt;&lt;small&gt;1: As it turns out, he was able to learn it in an hour or so during the hackathon, at least well enough to edit some drawing code. Oops. Probably could have done that better, then.&lt;/small&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Next steps
&lt;/h1&gt;

&lt;p&gt;Right now, Git Gud pretty barebones, as you'll &lt;strong&gt;definitely&lt;/strong&gt; notice if you try it. There are quite a few features we want to implement, most of which boil down to working more like the real git. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you type &lt;code&gt;git&lt;/code&gt; at the beginning of the line (say, out of habit from using real git), delete it from the input rather than breaking&lt;/li&gt;
&lt;li&gt;Informative (aka &lt;em&gt;any&lt;/em&gt;, in some cases) error messages when you do something wrong&lt;/li&gt;
&lt;li&gt;Rebasing&lt;/li&gt;
&lt;li&gt;Commit messages&lt;/li&gt;
&lt;li&gt;Branches with names&lt;/li&gt;
&lt;li&gt;Parsing flags like &lt;code&gt;-b&lt;/code&gt; on &lt;code&gt;checkout&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;File changes, rather than just abstract 'commits'&lt;/li&gt;
&lt;li&gt;More themes. Amber on black is pretty, but it'd be nice (and not too hard, really) to offer multiple colors.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Got any other ideas? Anything you want me to know as I develop it more? Either &lt;a href="https://github.com/nic-hartley/git-gud/issues" rel="noopener noreferrer"&gt;raise an issue&lt;/a&gt;, or comment on this post.&lt;/p&gt;

</description>
      <category>git</category>
      <category>beginners</category>
      <category>showdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>The Best Thing about C++</title>
      <dc:creator>Nic Hartley</dc:creator>
      <pubDate>Tue, 12 Feb 2019 22:48:18 +0000</pubDate>
      <link>https://dev.to/nichartley/the-best-thing-about-c-42ib</link>
      <guid>https://dev.to/nichartley/the-best-thing-about-c-42ib</guid>
      <description>

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: For this post, you'll need a pretty decent understanding of programming. I'll explain most of the words I use in the article, but I still expect you to know what an "object" is, and not just in the OOP sense.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Destructors are great. When I first learned C++ they seemed like magic, and now I'm mildly annoyed by languages that don't have them. The thing is, &lt;em&gt;most&lt;/em&gt; languages don't have them. If you've only ever coded in Java or C#, you're probably wondering why I like such terrible, useless things, because you've never actually experienced destructors. Java has the &lt;code&gt;finalize&lt;/code&gt; overrideable method, and C# has something that it &lt;em&gt;calls&lt;/em&gt; destructors (which even apes the C++ syntax), but neither one is a real destructor.&lt;/p&gt;

&lt;h1&gt;
  
  
  Object lifetimes
&lt;/h1&gt;

&lt;p&gt;Before we can talk about what a destructor is and why it's great, we need to talk about something related: Object lifetimes. An object's lifetime is just how long it sticks around as usable, allocated memory. If you have some handle to that object, be it a pointer, a reference, a variable, whatever, then until the object's lifetime is over, you can continue using it.&lt;/p&gt;

&lt;p&gt;In most languages, it's outright impossible to guarantee &lt;em&gt;exactly&lt;/em&gt; when &lt;em&gt;every&lt;/em&gt; object's lifetime ends. In some, though, they get closer than others. For example, in Java, the object lasts at least until it's no longer referenced, and then until the garbage collector gets around to collecting the garbage. You have no guarantees when, or even &lt;em&gt;if&lt;/em&gt;, that happens.&lt;/p&gt;

&lt;p&gt;On the other hand, languages like C++, Rust, and Swift have much more strictly defined object lifetimes. I won't go into the exact rules, but the rule of thumb is that once every variable referring to the object is out of scope, that object's lifetime ends immediately, rather than ending at some indeterminate point afterwards. I'll call these "strict" lifetimes, since they have a precise end time.&lt;/p&gt;

&lt;p&gt;There is, of course, an exception with pointers in C++; in that case, an object's lifetime ends when it's &lt;code&gt;delete&lt;/code&gt;d.&lt;/p&gt;

&lt;p&gt;One important corollary to note is that when an object's lifetime ends, so do the lifetimes of its fields.&lt;/p&gt;

&lt;h1&gt;
  
  
  Destructors
&lt;/h1&gt;

&lt;p&gt;A destructor is a function that runs at the end of a &lt;em&gt;strict&lt;/em&gt; lifetime. It's basically the inverse of a constructor, hence the name. You can absolutely guarantee that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A destructor will run, barring something very strange happening.&lt;/li&gt;
&lt;li&gt;It will run only after the object is no longer being used&lt;sup&gt;1&lt;/sup&gt;.&lt;/li&gt;
&lt;li&gt;It will run soon after the object is no longer being used (mostly)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Number 3 is somewhat fuzzy, but if your language has strict lifetimes and you restrict things to the smallest scope you reasonably can, then the destructor will run quickly after the object's last usage.&lt;/p&gt;

&lt;p&gt;Because a field's lifetime ends with its containing object, you don't need to explicitly call the destructors for your fields. They're called after the destructor for the containing object.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why are they good?
&lt;/h1&gt;

&lt;p&gt;There are two related things that destructors allow you to do: Simpler cleanup, and RAII.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simpler cleanup
&lt;/h2&gt;

&lt;p&gt;Have you ever coded anything complicated in C? You've probably got more than a few blocks of code like this:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;foo&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;my_foo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;construct_foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;use_a_foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_foo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;use_it_again&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_foo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;destruct_foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_foo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That's all well and good, until you remember that &lt;code&gt;use_a_foo&lt;/code&gt; might fail, and if it does, we shouldn't run &lt;code&gt;use_it_again&lt;/code&gt;. If &lt;code&gt;use_a_foo&lt;/code&gt; does fail, it'll return &lt;code&gt;false&lt;/code&gt;, so let's check that:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;foo&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;my_foo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;make_a_foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;use_a_foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_foo&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;use_it_again&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_foo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;destruct_foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_foo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The issue here is that now, sometimes, you're not properly destructing &lt;code&gt;my_foo&lt;/code&gt;. Sure, in this example it's trivial to fix, but it quickly gets out of hand, trying to keep the code legible while also correctly destructing every object.&lt;/p&gt;

&lt;p&gt;In contrast, this is the equivalent C++:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;foo&lt;/span&gt; &lt;span class="n"&gt;my_foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;use_a_foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_foo&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;use_it_again&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_foo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;foo&lt;/code&gt; destructor is called implicitly as soon as &lt;code&gt;my_foo&lt;/code&gt; goes out of scope, so you don't need to manage it. That means that whatever cleanup needs to be done -- closing file handles, deallocating memory, whatever. In C++ you also have exceptions, and if you throw an exception, the destructors will &lt;em&gt;still&lt;/em&gt; be called when you get to a scope above the one the object is in.&lt;/p&gt;

&lt;h2&gt;
  
  
  RAII
&lt;/h2&gt;

&lt;p&gt;RAII, short for "resource acquisition is initialization" is a fairly small leap, once you've realized that "cleanup" can be generalized a little. The name means that anything which takes control a resource -- be it a thread handle, a file handle, whatever -- does it when it's constructed, and then makes sure that it's cleaned up when it's destructed.&lt;/p&gt;

&lt;p&gt;For example, this is a fairly common pattern for acquiring &lt;a href="https://en.wikipedia.org/wiki/Mutual_exclusion"&gt;mutex&lt;/a&gt;es in C++:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;lock_guard&lt;/span&gt; &lt;span class="n"&gt;_l&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;the_mutex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// ... do your processing ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When it's constructed, a &lt;code&gt;std::lock_guard&lt;/code&gt; takes control of, by locking, a mutex. That way, no matter what happens in &lt;code&gt;// ... do your processing ...&lt;/code&gt;, unless you forcibly exit the entire thread somehow, you still unlock the mutex once that block is done, and it happens automatically.&lt;/p&gt;

&lt;p&gt;But the concept has been expanded somewhat. Some types do error-checking on destruction, like &lt;code&gt;std::thread&lt;/code&gt;, which makes sure that the thread is either done executing and joined back to the parent thread, or detached so it can keep executing on its own.&lt;/p&gt;

&lt;h1&gt;
  
  
  So what's a finalizer?
&lt;/h1&gt;

&lt;p&gt;A finalizer is like a destructor in that both run at the end of a lifetime, but the word "finalizer" is used when the lifetime isn't strict. Because the lifetime isn't strict, and because the lifetime might not even end until the program stops, you have no guarantee that the finalizer will run, or that it'll run "soon" after the object stops being used to any useful degree.&lt;/p&gt;

&lt;p&gt;Now, to be clear, there's nothing &lt;em&gt;inherently&lt;/em&gt; wrong with a language not having destructors. Most language provide some way around the lack. In C#, you can do this:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;lock&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// ... do your processing on object ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That's arguably even better design than C++'s lock guards, since it makes it explicitly clear &lt;em&gt;what&lt;/em&gt; is having its access controlled, rather than just that &lt;em&gt;something&lt;/em&gt; is controlled. The lock statement will also release in a timely manner no matter what.&lt;/p&gt;

&lt;p&gt;More generally, anything that implements &lt;code&gt;IDisposable&lt;/code&gt; can be basically given a destructor:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Foo&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Foo&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// use f&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;There are only two minor issues with that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It's yet another piece of syntax to learn and remember when coding.&lt;/li&gt;
&lt;li&gt;You need to actually implement &lt;code&gt;IDisposable&lt;/code&gt;, which might not be done in bad code&lt;sup&gt;2&lt;/sup&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Both of those can be worked around if necessary, but compared to the inherent simplicity and elegance of RAII, it's frustrating. Again, it's not necessarily a &lt;em&gt;bad&lt;/em&gt; design, just an uncomfortable one.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why finalizers?
&lt;/h1&gt;

&lt;p&gt;To put it simply, they're easier on both language designers and users. Just sort of handwaving away object destruction and saying "it'll go away eventually once you're done with it" is &lt;em&gt;much&lt;/em&gt; easier than writing or learning, say, Rust's complex object lifetime semantics. Personally, I prefer Rust, because it &lt;em&gt;does&lt;/em&gt; give me that information and avoids the overhead of garbage collection in most cases, but when you're just getting into coding, it's just another thing on the already large pile of things to learn.&lt;/p&gt;

&lt;p&gt;Plus, destructors really aren't necessary for most languages. Java and C#, for example, already introduce the overhead of a virtualization layer; tossing a garbage collector into the mix isn't that much more. Add something like &lt;code&gt;using&lt;/code&gt; or try-with-resources and you have a workable alternative, albeit with a little more mental overhead.&lt;/p&gt;

&lt;h1&gt;
  
  
  Questions?
&lt;/h1&gt;

&lt;p&gt;If you're still confused about this, feel free to leave comments! This can be a tough concept to wrap your head around, especially if you've never had any exposure to destructors before. If you're reading this with only a background in JavaScript... well, you have my condolences. It was probably tough. Thanks for sticking it out!&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Footnotes&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;C++ &lt;em&gt;does&lt;/em&gt; allow you to call destructors manually (the syntax is &lt;code&gt;foo-&amp;gt;~type_of_foo()&lt;/code&gt;) but this is very much &lt;em&gt;not&lt;/em&gt; recommended. It causes all sorts of issues because destructors typically depend on all three assumptions holding, and even if you do everything right you can still break things.&lt;/li&gt;
&lt;li&gt;Interestingly, Java seems to have an epidemic of not using &lt;code&gt;AutoCloseable&lt;/code&gt;. For a while I wondered why, but then I realized that &lt;code&gt;AutoCloseable&lt;/code&gt; was only added in Java 7! Certainly frustrating if you're dealing with code so old it predates generics. Thankfully, it can be worked around fairly simply in most cases.&lt;/li&gt;
&lt;/ol&gt;


</description>
      <category>cpp</category>
      <category>destructors</category>
    </item>
    <item>
      <title>% Is Not Modulo</title>
      <dc:creator>Nic Hartley</dc:creator>
      <pubDate>Wed, 06 Feb 2019 03:19:37 +0000</pubDate>
      <link>https://dev.to/nichartley/-is-not-modulo-lbd</link>
      <guid>https://dev.to/nichartley/-is-not-modulo-lbd</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: This post doesn't actually apply to all languages. Only many of them. To see if it applies to your chosen language, check if &lt;code&gt;-4 % 3&lt;/code&gt; equals &lt;code&gt;-1&lt;/code&gt;. If it's &lt;code&gt;2&lt;/code&gt;, your &lt;code&gt;%&lt;/code&gt; is actually modulo. If you get something else, let me know, because I'm curious!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You may have seen &lt;code&gt;%&lt;/code&gt; used in a few places. Maybe someone was generating a random number in a range:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;or cycling through an array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You've probably heard this referred to as "modulo", too. If you know anything about modular arithmetic, at first glance it seems to be accurate, too. But it's... not quite. The difference might seem insignificant, but if you find yourself implementing any math that uses real modular arithmetic, it's important.&lt;/p&gt;

&lt;h1&gt;
  
  
  Vocab
&lt;/h1&gt;

&lt;p&gt;First, quick vocab lesson:&lt;/p&gt;

&lt;p&gt;A / B = C means "A divided by B is equal to C". A is the divisor, B is the dividend, and C is the quotient. If I refer to "division" without specifying, in this article I mean integer or floored division. That's when you do a division without keeping track of the decimal component (so, for example, 14 / 5 is 2, not 2.8).&lt;/p&gt;

&lt;p&gt;Right, with that out of the way...&lt;/p&gt;

&lt;h1&gt;
  
  
  What's &lt;code&gt;%&lt;/code&gt;?
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;%&lt;/code&gt; gets the remainder of an integer division. If you think of integer division as splitting a lot of objects evenly into a number of groups, the remainder is how many objects are left over. For example, 14 / 5 is 2, because each of the 5 groups can have 2 objects in it, and there are 4 objects left over which can't be evenly split into the groups.&lt;/p&gt;

&lt;p&gt;Or, more mathematically, the remainder is the difference of the divisor and the product of the dividend and quotient. For example, 14 / 5 is 2, so the remainder is 14 - (2 * 5) = 4.&lt;/p&gt;

&lt;p&gt;For the sake of clarity, I'll be using "rem" as an operator to specify that I want to get the remainder of a division. So, for example, &lt;code&gt;14 rem 5&lt;/code&gt; is 4.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Getting the remainder is rarely implemented like that on actual hardware. The effect is the same, though, so I'll leave that for another day.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  What's modulo?
&lt;/h1&gt;

&lt;p&gt;Modulo, or modular arithmetic, is a little different. First of all, it's not an operation. It's more of a system of doing math. It's just like normal arithmetic, but whenever you perform an operation, it wraps in a. That range is from zero to what's called the "modulus".&lt;/p&gt;

&lt;p&gt;That might be a little technical and abstract, so think about telling time. Whether you use a 12-hour or &lt;del&gt;correct&lt;/del&gt; 24-hour clock, think about 1:00, just after midnight. Now think about what time is two hours before that. It's not -1:00, it's either 11:00 or 23:00. Or, going the other way, you don't go from 11:00 to 13:00 in 12-hour time or 23:00 to 25:00 in 24-hour time. Instead, you &lt;em&gt;wrap around&lt;/em&gt;, going back to the start of the range -- from 0 to 12 or 24 -- when you pass the end, or ahead to the end when you go back behind the start.&lt;/p&gt;

&lt;p&gt;In math, because it's an arithmetic system, modulo is usually used as a sort of modifier for the entire equation. In programming, though, it's not exactly easy to redefine how arithmetic works for a single expression (at least, not in most programming languages), so it's used as an operator. To use the time example from before with a 24-hour clock, &lt;code&gt;25 mod 24 = 1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You might be wondering what happens if you're still outside the range when you wrap around. For example, what's &lt;code&gt;14 mod 5&lt;/code&gt;? If you just wrap once, then you get 9, which is still outside of the range. You just keep wrapping in that case, down to 4, which &lt;em&gt;is&lt;/em&gt; in the range. &lt;/p&gt;

&lt;h1&gt;
  
  
  So... what's the difference?
&lt;/h1&gt;

&lt;p&gt;Up until now, I've only used positive integers for both divisors and dividends. Under those conditions, remainder and modulo perform the same. I won't be getting into all reals in this post, if ever, because remainder and modulo are almost always used with integer arithmetic in programming.&lt;/p&gt;

&lt;p&gt;But there's still a massive area that I just... haven't covered yet: Negative numbers. So how do things differ there?&lt;/p&gt;

&lt;p&gt;Well, let's start with the simplest case. To go back to the clock example, what's -1 rem 24 and -1 mod 24?&lt;/p&gt;

&lt;p&gt;The remainder is pretty easy to calculate. -1 / 24 is 0, so the difference is -1.&lt;/p&gt;

&lt;p&gt;The modulo is also simple. -1 is under 0, so it wraps back around to 23.&lt;/p&gt;

&lt;p&gt;The same problem happens, but backwards, if we use a negative modulo. 12 / -5 is -2, so 12 rem -5 is the difference between 12 and 10, or 2. Wrapping 12 around to fit in the range from 0 to -5 can't give us a positive number, though, and in fact it gives us -3.&lt;/p&gt;

&lt;p&gt;With two negative numbers, things go right back to working normally. -12 rem -5 and -12 mod -5 are both -2.&lt;/p&gt;

&lt;h1&gt;
  
  
  How do I fix it?
&lt;/h1&gt;

&lt;p&gt;You may have already noticed a pattern about the difference between remainder and modulo. Specifically, the difference, when there is one, is always exactly the divisor. Also, as mentioned before, the divisor and dividend are different signs. Both of those are provably true, but I'm not going to get into the actual math here -- just take my word for it.&lt;/p&gt;

&lt;p&gt;That makes the fix pretty easy. First, check whether &lt;code&gt;%&lt;/code&gt; means remainder or modulo in your language. It's very likely to be remainder, but there are some large ones, like Python, where it's modulo. You can do that pretty easily by using any of the examples I've used in the previous section and seeing which answer you get.&lt;/p&gt;

&lt;p&gt;If your language's &lt;code&gt;%&lt;/code&gt; is a remainder, then chances are there's a standard library function to do modulo. If not, though, here's a C function to do "real" modulo based on the remainder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;mod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;dividend&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;divisor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dividend&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;dividend&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;divisor&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// if they're the same sign&lt;/span&gt;
    &lt;span class="c1"&gt;// then remainder is the same as modulo&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;dividend&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;divisor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="c1"&gt;// otherwise, if they're different signs&lt;/span&gt;
    &lt;span class="c1"&gt;// account for the difference&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dividend&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;divisor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;divisor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Zero has to be special-cased because whichever way you check the sign (both positive or both negative) it always ends up with zero being wrong on one of the branches. If you have any ideas for how to make the code cleaner, let me know!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That should be fairly simple to port to just about any language, though the check to see if they're the same sign may need to be written differently if binary XOR isn't available in yours.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why did things work?
&lt;/h1&gt;

&lt;p&gt;At this point, you might be wondering about how things have worked, given this discrepancy. In most cases, it boils down to things always being positive. For example, the &lt;code&gt;rand()&lt;/code&gt; example I gave at the beginning:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In C, and therefore most C-derived languages, the builtin &lt;code&gt;rand&lt;/code&gt;-like function returns numbers from 0 to some maximum value, and the &lt;code&gt;max&lt;/code&gt; value is always positive. Of course, more modern languages typically offer another, more clear way to get random numbers anyway, and you should use those instead.&lt;/p&gt;

&lt;p&gt;The array-index example is similar:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This gets the next index in the array, wrapping back around to the beginning once the end is reached. Because the index starts out positive and, aside from when it wraps to zero, only increases, the negatives are never reached. Though if you were trying to do it backwards, it'd break:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In this case, when &lt;code&gt;index&lt;/code&gt; is 0, &lt;code&gt;(0 - 1) % array.length&lt;/code&gt; will give you -1, which is an out of bounds access. You'd have to do a proper modulo add to account for this.&lt;/p&gt;




&lt;p&gt;So, have you ever encountered any issues with the difference between modulo and remainder? I have; fixing one such bug is what inspired this post, actually.&lt;/p&gt;

</description>
      <category>math</category>
    </item>
    <item>
      <title>How do you use IRC?</title>
      <dc:creator>Nic Hartley</dc:creator>
      <pubDate>Wed, 30 Jan 2019 00:42:47 +0000</pubDate>
      <link>https://dev.to/nichartley/how-do-you-use-irc-311f</link>
      <guid>https://dev.to/nichartley/how-do-you-use-irc-311f</guid>
      <description>&lt;p&gt;IRC is pretty neat. It's from the late 1980s, but it's still around, and still fairly widely used. As of this writing, the IRC network I'm on the most has 86,546 users, and according to &lt;a href="http://irc.netsplit.de/networks/top100.php"&gt;netsplit.de&lt;/a&gt;, the top 100 most popular IRC networks have 234,581 users combined. It's also pretty common in open-source projects, as a way to get support.&lt;/p&gt;

&lt;p&gt;But... how do you use it? You've been told that your favorite project is on #aproject on Freenode, but how do you get on that channel, too? Well, in big, abstract steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download an IRC client&lt;/li&gt;
&lt;li&gt;Pick a nick&lt;/li&gt;
&lt;li&gt;Find the server you want&lt;/li&gt;
&lt;li&gt;Connect to it&lt;/li&gt;
&lt;li&gt;Connect to your channels&lt;/li&gt;
&lt;li&gt;Register your nick&lt;/li&gt;
&lt;li&gt;Additional info&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  1. Download an IRC client
&lt;/h1&gt;

&lt;p&gt;This step, as you might guess, depends on your operating system. There are a wide variety of IRC clients, from command-line software like &lt;a href="https://github.com/irssi/irssi"&gt;irssi&lt;/a&gt; to the GUI-oriented generic chat software &lt;a href="https://pidgin.im/"&gt;Pidgin&lt;/a&gt;. Because I personally use it and it's cross-platform, this tutorial uses &lt;a href="https://hexchat.github.io/"&gt;HexChat&lt;/a&gt;, but all of them work similarly.&lt;/p&gt;

&lt;h1&gt;
  
  
  2. Pick a nick
&lt;/h1&gt;

&lt;p&gt;This is a more important step than you might think. A "nick", or nickname, is how you're identified in IRC. It's your name on IRC. &lt;/p&gt;

&lt;p&gt;It can be at most nine-characters long&lt;sup&gt;1&lt;/sup&gt;, and can contain letters (uppercase or lowercase), numbers, hyphens (&lt;code&gt;-&lt;/code&gt;), underscores (&lt;code&gt;_&lt;/code&gt;), square brackets (&lt;code&gt;[]&lt;/code&gt;), curly braces (&lt;code&gt;{}&lt;/code&gt;), backslash (&lt;code&gt;\&lt;/code&gt;), backticks (&lt;code&gt;`&lt;/code&gt;), or pipes (&lt;code&gt;|&lt;/code&gt;). If you have a consistent handle across the internet, I highly recommend using that, or some minor variation on it, so people recognize you elsewhere, too.&lt;/p&gt;

&lt;p&gt;Fill your nick in in the topmost box, and add a username. The username doesn't have to be anything specific, but it's recommended that you make it close to the username of your local user. If you don't know that, just put in &lt;code&gt;unknown&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;small&gt;1: Some servers -- e.g. Freenode -- allow longer nicks, but the IRC protocol specifies a maximum of 9. Therefore, it's generally a good idea to use a 9-character nick, so you can take it with you to different servers.&lt;/small&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  3. Find the server you want
&lt;/h1&gt;

&lt;p&gt;You need to find two things to connect to an IRC server network: The domain or IP address, and the port. In HexChat, quite a lot of servers are presupplied. Fill in your nick at the top, find the server's name on the list and click Connect, and it'll all happen automatically.&lt;/p&gt;

&lt;p&gt;If you've been given a name but no more information and can't find it on the list, try Googling it. Many IRC servers have an associated website which will give you all the details you need. That is, the domain name or IP address, and port.&lt;/p&gt;

&lt;p&gt;If you're given a domain or IP and port and want to connect directly, you can add your own server to the list. Click Add -- it's the topmost of the five buttons -- give it a name you'll remember, click Edit, and add the domain name and port to the list at the top, separating them with a slash. For example, if the domain is &lt;code&gt;irc.server&lt;/code&gt; and the port is &lt;code&gt;1234&lt;/code&gt;, you'd put &lt;code&gt;irc.server/1234&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you're not given a port, try 6667. It's the de facto default for IRC.&lt;/p&gt;

&lt;h1&gt;
  
  
  4. Connect to it
&lt;/h1&gt;

&lt;p&gt;In HexChat, this is as simple as clicking the server in the list, then clicking "Connect" in the bottom right.&lt;/p&gt;

&lt;p&gt;You may see a message about your nick -- something like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;your_nick :Nickname is already in use&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This nickname is registered. Please choose a different nickname, or identify via &lt;strong&gt;/msg NickServ identify &lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
You have 30 seconds to identify to your nickname before it is changed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Try connecting again with another nickname. The former means someone is currently logged in with that nickname, and the latter means someone else has staked a claim on that nick. I'll walk you through doing it for yourself in step 6.&lt;/p&gt;

&lt;h1&gt;
  
  
  5. Connect to your channels
&lt;/h1&gt;

&lt;p&gt;Once you connect to the server, wait for a moment. It takes some time to establish an IRC connection. Once you see the text stop scrolling, you can join a channel with &lt;code&gt;/join #channelname&lt;/code&gt;. You &lt;em&gt;must&lt;/em&gt; include the first &lt;code&gt;#&lt;/code&gt;; it's part of the channel name. Some channels start with &lt;code&gt;&amp;amp;&lt;/code&gt; instead -- rather than being global across the entire network, these are exclusive to the server you're currently on.&lt;/p&gt;

&lt;h1&gt;
  
  
  6. Register your nick
&lt;/h1&gt;

&lt;p&gt;While trying to connect to your desire channel, you might have seen a message like "Please register and identify to speak". There are several ways to do that, depending on the server, but most of them involve NickServ.&lt;/p&gt;

&lt;p&gt;NickServ is a special bot available on most servers. You message it to register your nickname, and it ensures that no one else takes your nickname, as well as tying nicks to emails so troublemakers can be effectively moderated. To register your nick with NickServ, send it a private message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/msg NickServ REGISTER [your-password-here] your@email.here
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Of course, replace &lt;code&gt;[your-password-here]&lt;/code&gt; with your actual, unique password, and &lt;code&gt;your@email.here&lt;/code&gt; with your actual email. You'll get an email sent to that address with a special code, which just confirms that you actually have that email. Confirm that's really your email with &lt;code&gt;/msg NickServ CONFIRM [code]&lt;/code&gt;, and the nick is yours!&lt;/p&gt;

&lt;p&gt;Now whenever you join, you'll see this message:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This nickname is registered. Please choose a different nickname, or identify via &lt;strong&gt;/msg NickServ identify &lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
You have 30 seconds to identify to your nickname before it is changed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You now have the password -- you just created it -- so just type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/msg NickServ IDENTIFY [your-password-here]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And just like that, NickServ knows you're who you say you are. You can also do some more configuration, which is largely out of the scope of this tutorial. If you have any other questions, &lt;code&gt;/msg NickServ HELP&lt;/code&gt;. (The all caps isn't actually required, but I find it amusing to shout 'help' at a robot)&lt;/p&gt;

&lt;h1&gt;
  
  
  7. Additional info
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Multiple nicks?
&lt;/h2&gt;

&lt;p&gt;If you have multiple nicks, you need to group them. Change your nick to the other nick you want to use, then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/msg NickServ IDENTIFY old-nick [your-password-here]
/msg NickServ GROUP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now your two nicks are grouped together, and any NickServ management you do to one applies to the other.&lt;/p&gt;

&lt;h2&gt;
  
  
  AFK?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;/away&lt;/code&gt; you go! Use that command to tell the server, and other people, that you're away. You can also add a message, like &lt;code&gt;/away to get food&lt;/code&gt;, if you want to be a little more specific.&lt;/p&gt;

&lt;h2&gt;
  
  
  Curious how IRC works?
&lt;/h2&gt;

&lt;p&gt;I'm going to be writing up more articles on how IRC works internally later, but those are by no means the only resources. The &lt;a href="https://tools.ietf.org/html/rfc1459"&gt;RFC&lt;/a&gt; is surprisingly easy to follow if you get some experience using IRC before reading it, and, given that it's the standard every IRC server meets or exceeds, it gives most of the necessary information. Extra features like SASL aren't in the original RFC, but they're also standardized and open.&lt;/p&gt;

&lt;h2&gt;
  
  
  Want to say you're doing something?
&lt;/h2&gt;

&lt;p&gt;Use &lt;code&gt;/me&lt;/code&gt;. It's not a standard IRC command, but it's supported by basically every server I've been a regular on. This command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/me does a thing
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;produces this message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* nic-hartley does a thing
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;in contrast to the normal IRC message format, which might be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nic-hartley: does a thing
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Got more questions?
&lt;/h2&gt;

&lt;p&gt;Ask in the comments! I'm happy to answer more questions, if I know the answer.&lt;/p&gt;

</description>
      <category>irc</category>
    </item>
    <item>
      <title>Why I'll Love Flutter Next Year</title>
      <dc:creator>Nic Hartley</dc:creator>
      <pubDate>Thu, 17 Jan 2019 16:48:11 +0000</pubDate>
      <link>https://dev.to/nichartley/why-ill-love-flutter-next-year-3fg2</link>
      <guid>https://dev.to/nichartley/why-ill-love-flutter-next-year-3fg2</guid>
      <description>

&lt;p&gt;If you've used &lt;a href="https://flutter.io/"&gt;Flutter&lt;/a&gt; a little, you're probably overjoyed with it. A cross-platform mobile development suite? Which actually &lt;em&gt;works&lt;/em&gt; cross-platform, with no platform-specific configuration? Hot restart and stateful hot reload, so you can test changes in seconds? No need to mess with platform-specific configuration files? All of your layout is done in the language itself?!&lt;/p&gt;

&lt;p&gt;All in all, it seems like a perfect thing. The hot-reload and hot-restart especially make Flutter hard not to love. I really can't put in words how useful it is to wait &lt;em&gt;seconds&lt;/em&gt;, not minutes, to see your changes on your device.&lt;/p&gt;

&lt;p&gt;The more you use Flutter, though, the more that initial warmth seeps away, replaced by the cold realization that it has its limitations, like anything else. &lt;/p&gt;

&lt;p&gt;Among those is sending notifications. If you're building an entirely offline app -- in my case, a mobile game -- then it's not easy to get notifications working. Sure, you could go through &lt;a href="https://firebase.google.com/docs/cloud-messaging/"&gt;FCM&lt;/a&gt; (since GCM is &lt;a href="https://developers.google.com/cloud-messaging/"&gt;phasing out in April this year&lt;/a&gt; in favor of it), but that would require me to do a round-trip between a server just to send a notification from an app on the device to the device, or at least bundle that capability in when I don't need or want it.&lt;/p&gt;

&lt;p&gt;So how do you do offline notifications in Flutter?&lt;/p&gt;

&lt;p&gt;The short answer is that you can't. You can, of course, call out to native code, but the point of Flutter is to &lt;em&gt;avoid&lt;/em&gt; writing native code yourself, and let Flutter handle it automagically. Instead, you have to look for third-party libraries which &lt;a href="https://pub.dartlang.org/packages/flutter_local_notifications"&gt;sort of work&lt;/a&gt;, except that you can't schedule or group notifications. (Maybe you can, but I couldn't get it to work.)&lt;/p&gt;

&lt;p&gt;That kind of little thing is all over Flutter. For example, when it comes time to make a release for your app -- or even give it a pretty icon -- you need to do &lt;a href="https://flutter.io/docs/deployment/android"&gt;platform&lt;/a&gt; specific &lt;a href="https://flutter.io/docs/deployment/ios"&gt;things&lt;/a&gt; (which, let's be fair, can be &lt;a href="https://flutter.io/docs/deployment/fastlane-cd"&gt;automated&lt;/a&gt;) to get that done. It'd be easy to make a lot of that platform-independent -- static icons could be generated from a single high-res file, like what &lt;a href="https://pub.dartlang.org/packages/flutter_launcher_icons"&gt;&lt;code&gt;flutter_launcher_icons&lt;/code&gt;&lt;/a&gt; does; permissions could come from a list in &lt;code&gt;pubspec.yaml&lt;/code&gt; or even code analysis.&lt;/p&gt;

&lt;p&gt;None of this is to say Flutter is bad. It's new. It's barely two years old, and when you're building something as complex as an entirely new way to develop cross-platform mobile apps, some early stumbling is to be expected. It has a ton of promise, and I think they're quickly getting to where they should be, but they're not there yet.&lt;/p&gt;

&lt;p&gt;In short, I'll love Flutter a lot more next year.&lt;/p&gt;


</description>
      <category>flutter</category>
      <category>rithfoss</category>
    </item>
  </channel>
</rss>
