<?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>Forem: Ryan Faulhaber</title>
    <description>The latest articles on Forem by Ryan Faulhaber (@rfaulhaber).</description>
    <link>https://forem.com/rfaulhaber</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%2F144696%2F77132247-c611-4ef5-ad47-0affee9feaf1.jpeg</url>
      <title>Forem: Ryan Faulhaber</title>
      <link>https://forem.com/rfaulhaber</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rfaulhaber"/>
    <language>en</language>
    <item>
      <title>Cool Emacs Things: Evil</title>
      <dc:creator>Ryan Faulhaber</dc:creator>
      <pubDate>Sun, 19 Sep 2021 16:00:11 +0000</pubDate>
      <link>https://forem.com/rfaulhaber/cool-emacs-things-evil-3l2e</link>
      <guid>https://forem.com/rfaulhaber/cool-emacs-things-evil-3l2e</guid>
      <description>&lt;p&gt;I like Vim a lot. I've been a Vim user for almost my entire professional career at this point. I learned Vim because the idea of editing text without touching the mouse appealed to me (also because I was tired of not knowing how to use Vim in environments without graphical editors. Pro tip, if you're in this situation and don't want to learn Vim: use &lt;a href="https://www.nano-editor.org/"&gt;Nano&lt;/a&gt;). Now I can't edit text without it. For a while I used Vim proper, and then I used other editors with their Vim emulators.&lt;/p&gt;

&lt;p&gt;Once I learned Vim, Vim proper was my editor for a while. I learned all about plugins and &lt;a href="https://github.com/rfaulhaber/dotfiles/blob/f895c6c8536a149bd536cfba942e811000bcd47d/config/nvim/init.vim"&gt;had a small configuration file&lt;/a&gt; (now a &lt;a href="https://github.com/rfaulhaber/dotfiles/blob/master/nix/modules/programs/neovim/default.nix"&gt;Nix configuration&lt;/a&gt;). After a while though I found Vim itself cumbersome, and realized every other editor had a Vim plugin. So for a while I used IdeaVim, Atom's Vim plugin, and then finally VSCode's Vim plugin.&lt;/p&gt;

&lt;p&gt;In my own experience, I've noticed that even Vim users underestimate Vim. Many Vim users I've known only learn the motions and stop there. Vim has some powerful functionality that a good number of people aren't aware of or don't use. Many Vim users seem satisfied to know the motions and leave it at that. And that's fine! I was that way for a very long time. But sometimes, I found myself wanting more advanced functionality that plugins couldn't offer.&lt;/p&gt;

&lt;p&gt;Finally, I started using Emacs through Spacemacs, and then changed to Doom Emacs. Each configuration comes with Vim emulation through a package called Evil, the very cleverly named Extensible VI Layer for Emacs.&lt;/p&gt;

&lt;p&gt;As a baseline, Evil does, at the very least, everything every other Vim plugin does. If you're familiar with Vim keybindings, motions, macros, marks, and the like, Evil supports those. But I wouldn't be writing about Evil if that was all it did! In fact I think it's safe to say that Evil is the most complete Vim emulator out there outside of Vim itself.&lt;/p&gt;

&lt;p&gt;To me, one of the most noteworthy differences from other Vim emulators is that Evil has extensive Ex support. Ex commands are not very well supported in the other Vim plugins I've tried. Evil supports many of the basic Ex commands, such as &lt;code&gt;:r&lt;/code&gt;, &lt;code&gt;:w&lt;/code&gt;, &lt;code&gt;:!&lt;/code&gt;, and so on, but also &lt;code&gt;:normal&lt;/code&gt;, &lt;code&gt;:global&lt;/code&gt;, and ranges. Evil doesn't implement every Ex command, though, since a good deal of Ex commands would be redundant in Emacs, such as ones like &lt;code&gt;:set&lt;/code&gt;. It's also easy to define your own Ex commands. Evil provides &lt;code&gt;evil-ex-define-cmd&lt;/code&gt;, allowing you to implement your own Ex commands. Doom &lt;a href="https://github.com/hlissner/doom-emacs/blob/develop/modules/editor/evil/%2Bcommands.el"&gt;provides some useful extras&lt;/a&gt; on top of Evil.&lt;/p&gt;

&lt;p&gt;But the biggest difference between Evil and other Vim emulators is that Evil is an Emacs extension. When you configure Evil, you write Emacs Lisp, the same as any other configuration for Emacs. So Evil does not provide commands like &lt;code&gt;:nnoremap&lt;/code&gt;. This is not so with, for example, IdeaVim or VSCode's Vim plugins. That said, you could think of Emacs Lisp as a stand in for Vimscript. This means that any Evil customization will use all Emacs's ability for customization and text-editing. The things Evil does not implement, as far as I can tell, would be redundant in Emacs.&lt;/p&gt;

&lt;p&gt;This, to me, is the biggest advantage of Evil: it's as extensible as Emacs itself is. While Evil may not offer complete feature parity with Vim (I can't imagine having or even wanting a Vimscript interpreter, for example), it contains all the important parts, and a lot more than any other emulator I've used.&lt;/p&gt;

&lt;p&gt;Were it not for Evil, I would not have continued using Emacs. For me, it's a crucial package.&lt;/p&gt;

</description>
      <category>emacs</category>
    </item>
    <item>
      <title>Cool Emacs Things: Dired</title>
      <dc:creator>Ryan Faulhaber</dc:creator>
      <pubDate>Fri, 28 May 2021 19:31:12 +0000</pubDate>
      <link>https://forem.com/rfaulhaber/cool-emacs-things-dired-240a</link>
      <guid>https://forem.com/rfaulhaber/cool-emacs-things-dired-240a</guid>
      <description>&lt;p&gt;Today we continue &lt;a href="https://ryanfaulhaber.com/series/cool-emacs-things/"&gt;my ongoing series on Emacs&lt;/a&gt; with a feature of Emacs that feels genuinely magical: Dired.&lt;/p&gt;

&lt;p&gt;One of the first things I did when I became a Linux user was to learn how to use the terminal. The terminal is an indispensable tool in the Unix world broadly because of its versatility. I got to a point where I used the terminal so heavily that eventually on Linux I stopped installing file explorers, and on macOS I had entire directories that never had those annoying &lt;code&gt;.DS_Store&lt;/code&gt; files. Personally, managing files in the terminal is often much simpler and more direct than a graphical file explorer.&lt;/p&gt;

&lt;p&gt;Navigating your file system without a graphical file explorer requires you to know two standard Unix programs: &lt;code&gt;cd&lt;/code&gt; (change directory) and &lt;code&gt;ls&lt;/code&gt; (list directory contents). &lt;code&gt;ls&lt;/code&gt; in particular can print out very detailed information about the files in your system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# navigate to a project directory&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; ~/Projects/dial
&lt;span class="c"&gt;# print contents&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-lh&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;total&lt;/th&gt;
&lt;th&gt;32K&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;drwxr-xr-x&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;ryan&lt;/td&gt;
&lt;td&gt;users&lt;/td&gt;
&lt;td&gt;4.0K&lt;/td&gt;
&lt;td&gt;May&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;15:48&lt;/td&gt;
&lt;td&gt;bin&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-rw-r--r--&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;ryan&lt;/td&gt;
&lt;td&gt;users&lt;/td&gt;
&lt;td&gt;7.2K&lt;/td&gt;
&lt;td&gt;May&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;12:39&lt;/td&gt;
&lt;td&gt;Cargo.lock&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-rw-r--r--&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;ryan&lt;/td&gt;
&lt;td&gt;users&lt;/td&gt;
&lt;td&gt;78&lt;/td&gt;
&lt;td&gt;May&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;15:53&lt;/td&gt;
&lt;td&gt;Cargo.toml&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;drwxr-xr-x&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;ryan&lt;/td&gt;
&lt;td&gt;users&lt;/td&gt;
&lt;td&gt;4.0K&lt;/td&gt;
&lt;td&gt;May&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;15:49&lt;/td&gt;
&lt;td&gt;dial-core&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;drwxr-xr-x&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;ryan&lt;/td&gt;
&lt;td&gt;users&lt;/td&gt;
&lt;td&gt;4.0K&lt;/td&gt;
&lt;td&gt;May&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;15:53&lt;/td&gt;
&lt;td&gt;parse&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-rw-r--r--&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;ryan&lt;/td&gt;
&lt;td&gt;users&lt;/td&gt;
&lt;td&gt;186&lt;/td&gt;
&lt;td&gt;May&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;15:36&lt;/td&gt;
&lt;td&gt;README.org&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;drwxr-xr-x&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;ryan&lt;/td&gt;
&lt;td&gt;users&lt;/td&gt;
&lt;td&gt;4.0K&lt;/td&gt;
&lt;td&gt;May&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;15:49&lt;/td&gt;
&lt;td&gt;target&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;From left-to-right, these columns represent: file permissions (modifiable by &lt;code&gt;chmod&lt;/code&gt;), links to this file, file owner (modifiable by &lt;code&gt;chown&lt;/code&gt;), group owner (modifiable by &lt;code&gt;chgrp&lt;/code&gt;), file size, last modified timestamp, and file name.&lt;/p&gt;

&lt;p&gt;Dired defies explanation for those who haven't used it, and while writing this I struggled with how to explain it exactly. I'm tempted to describe it as "interactive &lt;code&gt;ls&lt;/code&gt;".&lt;/p&gt;

&lt;p&gt;Imagine if, when you typed &lt;code&gt;ls&lt;/code&gt; and got a list of files, you could click on those names. If the name is a directory, your terminal would automatically &lt;code&gt;cd&lt;/code&gt; to that directory and invoke &lt;code&gt;ls&lt;/code&gt; again. If that name is a file, your terminal opens that file in your favorite text editor. If your favorite text editor is Emacs, I have good news for you: this is what Dired is.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OeHVJ1lb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9igelo97ni4cyips1443.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OeHVJ1lb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9igelo97ni4cyips1443.png" alt="Screenshot of Dired mode, displaying a the output of the ls command"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But Dired does a little more than just navigation: Dired is a file explorer in its own right. From Dired you can move, copy, rename, and delete files, make links, &lt;a href="https://github.com/stsquad/dired-rsync"&gt;run rsync&lt;/a&gt; (with an extra package), &lt;code&gt;diff&lt;/code&gt; files, and more.&lt;/p&gt;

&lt;p&gt;But that's not all! Dired has a sibling called &lt;a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Wdired.html"&gt;wdired-mode&lt;/a&gt;, or "writable Dired." wdired lets you edit a Dired buffer, thereby allowing you to rename files with all the editing powers of Emacs. So, for example, replacing all of your &lt;code&gt;.js&lt;/code&gt; to &lt;code&gt;.ts&lt;/code&gt; files is just a matter of finding and replacing &lt;code&gt;js&lt;/code&gt; with &lt;code&gt;ts&lt;/code&gt;. wdired will also let you change file permissions, so you could change &lt;code&gt;rw-r--r--&lt;/code&gt; to, say, &lt;code&gt;rw-rw-rw-&lt;/code&gt; by simply changing the text without having to break out &lt;code&gt;chmod&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is why I navigate my file explorer in Emacs rather than my terminal now.&lt;/p&gt;

</description>
      <category>emacs</category>
      <category>tooling</category>
    </item>
    <item>
      <title>Quest for a Better Scripting Language</title>
      <dc:creator>Ryan Faulhaber</dc:creator>
      <pubDate>Tue, 27 Apr 2021 21:33:39 +0000</pubDate>
      <link>https://forem.com/rfaulhaber/quest-for-a-better-scripting-language-3ppj</link>
      <guid>https://forem.com/rfaulhaber/quest-for-a-better-scripting-language-3ppj</guid>
      <description>&lt;p&gt;I’ve been a Linux user for quite a few years now, and writing shell scripts is a pretty common thing for me. I have written many little scripts to do repetitive tasks in various languages. In this post I want to think out loud about what makes a worthwhile scripting language.&lt;/p&gt;

&lt;p&gt;Also please note that these are purely my opinions based on subjective experience, I’m not really interested in making any objective claims in this post. Your mileage may very with any of these languages.&lt;/p&gt;

&lt;p&gt;&lt;a id="orgbb1f8e4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  The Goal
&lt;/h1&gt;

&lt;p&gt;Before we set out on our tour of languages, I want to make clear what I’m looking for: I’m not looking for the perfect programming language, I’m looking for a language that makes automating tasks easier. Such tasks may include anything like renaming every file in a directory, parsing Git CLI output, automating AWS tasks, and so on. These are things I do on a daily basis that are repetitive and could be automated, and I’m looking for a tool that makes doing these things easiest. These tasks also tend to be &lt;em&gt;ad hoc&lt;/em&gt; as well and not something that could be solved by simply using GitKraken or something.&lt;/p&gt;

&lt;p&gt;So in my experience, this is the kind of thing where you’d reach for a language like Bash over, say, Java. Although you could write a full-blown tool to solve some problem in Java, more often than not it’s a little overkill (I don’t fault anyone who does this! To each their own, but I’m looking for something more lightweight).&lt;/p&gt;

&lt;p&gt;What I want is something that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Writes to stdout and reads stdin easily&lt;/li&gt;
&lt;li&gt;  Runs commands trivially&lt;/li&gt;
&lt;li&gt;  Is easy to write on the fly, such as in a REPL&lt;/li&gt;
&lt;li&gt;  Is portable and doesn’t expect much from its user (i.e. should either use software that one can reasonably expect to be installed on a system or requires minimal installation such as running &lt;code&gt;brew install&lt;/code&gt; or similar)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With that, let’s review the languages I’ve used.&lt;/p&gt;

&lt;p&gt;&lt;a id="orgd72ad44"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Bash
&lt;/h1&gt;

&lt;p&gt;Bash is a natural candidate: it comes on every Unix-like system, it’s trivial to run commands with, it uses stdin and stdout trivially, and it has a long history behind it, with lots of resources online for how to accomplish tasks. I have written many Bash scripts myself and for many years used it as my shell (I now use Zsh though).&lt;/p&gt;

&lt;p&gt;Bash would be much less useful without many of the programs that also come standard on a Unix system though, such as &lt;code&gt;sed&lt;/code&gt; and &lt;code&gt;tail&lt;/code&gt;. Programs like these let you write very modular and robust commands, such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git tag | &lt;span class="nb"&gt;tail&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; 1 | xargs &lt;span class="nt"&gt;-I&lt;/span&gt; &lt;span class="o"&gt;{}&lt;/span&gt; jq &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="nt"&gt;--arg&lt;/span&gt; tag &lt;span class="o"&gt;{}&lt;/span&gt; &lt;span class="s1"&gt;'{tag: $tag}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These programs don’t have to know anything about the other, but through the magic of stdin and stdout, they can communicate with one another.&lt;/p&gt;

&lt;p&gt;The biggest downside to Bash though is that it’s a weird language, and that its simplicity sometimes makes it obtuse. Bash has functions for example, but they can only return status codes and not values. Bash is also difficult to test: you can’t just do a dry-run of your script without changing your environment somehow (sure you could run your script in a Docker container or something, but that’s not exactly trivial). I almost consider writing more than about 10 lines of Bash to be a red flag.&lt;/p&gt;

&lt;p&gt;To summarize, Bash is good at what it does and almost gets me where I need, but it’s idiosyncrasies cause easy mistakes, and surely we can do better.&lt;/p&gt;

&lt;p&gt;&lt;a id="orgba3bb2e"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Python
&lt;/h1&gt;

&lt;p&gt;It’s hard not to mention Python, one of the most popularly used languages. I’ve never been paid to write Python but I have written quite a bit of it (and overall I have very mixed feelings about Python as a language). When I was in college, and for a bit of time after, I wrote lots of Python to do tasks around my computer. Python seems to be a modern Perl in that regard.&lt;/p&gt;

&lt;p&gt;Python isn’t a shell language. You can’t just open it up and type &lt;code&gt;ls&lt;/code&gt; and expect it to do something. But otherwise, coming with all the bells and whistles of a full-blown programming language, it’s easy to write. And to its credit, Python is a very expressive language.&lt;/p&gt;

&lt;p&gt;For me, Python is what I’d reach for when I want to do something more complicated that would be a pain to do in Bash.&lt;/p&gt;

&lt;p&gt;&lt;a id="org32f595c"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Ruby
&lt;/h1&gt;

&lt;p&gt;With the decline in popularity of Rails it seems that Ruby isn’t as popular as it once was. That said, when it was more popular, I wrote a ton of Ruby scripts to do various tasks.&lt;/p&gt;

&lt;p&gt;Ruby to me has always been just “Python but better.” Python seems to suffer from years of incoherent design while Ruby does less so. Ruby also just has a lot of interesting language features.&lt;/p&gt;

&lt;p&gt;Like Python, Ruby is not a shell language. That said, Ruby is at least as good as Python and comes with a lot of neat little utilities to make writing code easier.&lt;/p&gt;

&lt;p&gt;I have a soft spot for Ruby but don’t write much of it anymore.&lt;/p&gt;

&lt;p&gt;&lt;a id="orgb650c95"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  JavaScript
&lt;/h1&gt;

&lt;p&gt;JavaScript is not a perfect language but despite that fact I will die on a hill defending it. Although I believe that JavaScript is often unfairly maligned and is a better language than most people think, this is one regard where I cannot stand by it.&lt;/p&gt;

&lt;p&gt;Writing any JavaScript code that interacts with the file system is a chore at best, though this is perhaps the fault of Node than it is JavaScript in particular. JavaScript is, while not the most verbose language out there, still requires a lot of code to do simple things around the system. I personally find JavaScript unsuitable for such tasks. It’s better for writing applications.&lt;sup&gt;1&lt;/sup&gt;&lt;/p&gt;

&lt;p&gt;&lt;a id="org09e51a9"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Emacs Lisp
&lt;/h1&gt;

&lt;p&gt;This is something of a wild card in this list.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ryanfaulhaber.com/posts/try-emacs/"&gt;I use Emacs&lt;/a&gt;, and once you really get into the Emacs world, you tend to want to just do everything in Emacs, and Emacs is more than happy to let you do that. You can customize Emacs with Emacs Lisp, a cousin of Common Lisp.&lt;/p&gt;

&lt;p&gt;I don’t think that Lisps are necessarily hard to write, but they can be hard to read if you’re not used to mentally parsing a million parentheses. Emacs Lisp isn’t the best Lisp in the world but it does make customizing Emacs pretty easy.&lt;/p&gt;

&lt;p&gt;Emacs Lisp is pretty good at interacting with files and running commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight common_lisp"&gt;&lt;code&gt;&lt;span class="c1"&gt;;; emacs lisp has built-in functions that can do similar things,&lt;/span&gt;
&lt;span class="c1"&gt;;; but for the sake of an example...&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nv"&gt;output&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;shell-command-to-string&lt;/span&gt; &lt;span class="s"&gt;"ls *.org"&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;length&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;split-string&lt;/span&gt; &lt;span class="nv"&gt;output&lt;/span&gt; &lt;span class="s"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Emacs also came to mind because Emacs comes with a built-in Emacs Lisp shell, called Eshell. Eshell is like any other shell, except that instead of, say, using the Bash language, it uses Emacs Lisp. Eshell is an okay shell and is good for doing things here and there, but the idea of a Lisp shell is pretty interesting to me. I’ve never seen any other Lisp shells, however.&lt;/p&gt;

&lt;p&gt;Although personally I feel that Emacs Lisp is an acceptable solution for personal use, it does depend on Emacs. Emacs runs on all my systems so for my own personal use it’s also acceptable in that regard. You may be out of luck though if your coworker, who does not use Emacs, needs a solution to a problem you’ve already solved with Emacs Lisp.&lt;/p&gt;

&lt;p&gt;&lt;a id="orgb844f24"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusions
&lt;/h1&gt;

&lt;p&gt;By writing this post I feel like I’ve hit a limit with the tools that I have. I feel like in the above languages I’ve only found partial solutions. The problem with existing shells is that the languages tend to be obtuse and fall apart for more complicated tasks, and the programming languages have the inverse problem. I feel that there must be a solution out there that resolves this apparent contradiction between shell scripting and full-blown programming languages. I can’t help but feel that maybe it’s time for a new tool to this end.&lt;/p&gt;

&lt;p&gt;What would a new language look like? Much like the goals above, I think it would:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Be interactive, e.g. typing &lt;code&gt;ls&lt;/code&gt; and hitting enter runs &lt;code&gt;ls&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  Support commands as first class (see Bash)&lt;/li&gt;
&lt;li&gt;  Have enough language support that it would be relatively easy to write longer scripts&lt;/li&gt;
&lt;li&gt;  Use modern language conventions to make writing longer scripts easier while also not bogging down the expressiveness of the language&lt;/li&gt;
&lt;li&gt;  Support redirection and piping as syntax (perhaps Bash’s biggest strength)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a id="org9612ada"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Honorable mentions
&lt;/h1&gt;

&lt;p&gt;Here is a brief discussion on possible candidates that I don’t know enough about but look interesting.&lt;/p&gt;

&lt;p&gt;&lt;a id="org2335f22"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Perl
&lt;/h2&gt;

&lt;p&gt;I don’t know any Perl and there’s a chance I probably never well, I can’t help but feel that I missed the boat on this one. Recent developments in the Perl world make it seem interesting, and it seems that the Perl community has done a lot of work to improve the language in recent years.&lt;/p&gt;

&lt;p&gt;&lt;a id="org81c78d0"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  AWK
&lt;/h2&gt;

&lt;p&gt;It’s a shame I don’t know AWK and I’ve been meaning to fix this for years. The very little AWK I know is interesting, and my impression of AWK is that it seems like a way to write &lt;em&gt;ad hoc&lt;/em&gt; programs in the middle of a Bash script. Maybe you want something &lt;code&gt;sed&lt;/code&gt; can do but it’s just kind of a pain to write in &lt;code&gt;sed&lt;/code&gt;? AWK can probably do it.&lt;/p&gt;

&lt;p&gt;&lt;a id="org5cc9fe2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Lua
&lt;/h2&gt;

&lt;p&gt;I just started writing Lua as I recently discovered &lt;a href="https://www.hammerspoon.org"&gt;Hammerspoon&lt;/a&gt;. Lua reminds me a lot of JavaScript and seems like it’d be a good Python / Ruby replacement. I don’t know much about it otherwise.&lt;/p&gt;

&lt;p&gt;&lt;a id="org9b388d4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tcl
&lt;/h2&gt;

&lt;p&gt;I stumbled across Tcl recently and I’m pretty intrigued by it. It seems like a deliberate attempt to improve a language like Bash, and it has a shell called Tclsh. Tcl has more “proper” language features that I think would eliminate a number of pain points with Bash, but I’m not sure how it would fare for large, complicated tasks. It might be worth investigating.&lt;/p&gt;

&lt;p&gt;&lt;a id="org3d18b37"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Koi
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://koi-lang.dev/"&gt;Koi&lt;/a&gt; is a little language I stumbled across on GitHub. It seems like it hits the sweet spot of being both interactive and easy to write. I haven’t had much of a chance to mess around with it but it seems really cool and is exactly what I’d want out of a language like this.&lt;/p&gt;

&lt;h1&gt;
  
  
  Footnotes
&lt;/h1&gt;

&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt; To be clear, I should mention that I’m not just singling out JavaScript in this regard. Other languages such as Java, C#, Go, Rust, etc. likely fit this bill to for similar reasons, but I mention JavaScript in particular only because I’ve tried to write scripts with it.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Cool Emacs Things: Magit</title>
      <dc:creator>Ryan Faulhaber</dc:creator>
      <pubDate>Sat, 21 Nov 2020 21:13:34 +0000</pubDate>
      <link>https://forem.com/rfaulhaber/cool-emacs-things-magit-4c6a</link>
      <guid>https://forem.com/rfaulhaber/cool-emacs-things-magit-4c6a</guid>
      <description>&lt;p&gt;This is part of an &lt;a href="https://ryanfaulhaber.com/series/cool-emacs-things" rel="noopener noreferrer"&gt;ongoing series&lt;/a&gt; where I talk about the little things that make Emacs a nice editor. Today's entry: &lt;a href="https://magit.vc/" rel="noopener noreferrer"&gt;Magit&lt;/a&gt;, a Git interface for Emacs.&lt;/p&gt;

&lt;p&gt;I'm not much of a Git client person myself. I don't use or particularly like Sourcetree or GitKraken. VS Code and JetBrains IDEs have some nice features, especially when it comes to merging and rebasing, but they're still not quite like Magit.&lt;/p&gt;

&lt;p&gt;Until I used Magit I interacted with Git through the command line, because Git in the command line supported all of Git's features. I didn't have to worry about whether GitKraken supported viewing the reflog or file history, I could run &lt;code&gt;git reflog&lt;/code&gt; and &lt;code&gt;git log file&lt;/code&gt; and not have to worry about it.&lt;/p&gt;

&lt;p&gt;Magit on its surface isn't all that different from the VS Code Git integration: you can pull and push code, see diffs, read the Git log, and so on. But what makes Magit special is that its integration with Emacs makes it very ergonomic to use.&lt;/p&gt;

&lt;p&gt;I'll illustrate with an example of committing some changes. After making some changes, I'll go to the Magit buffer and see 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcaypyh84dtzl3y90x2z7.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcaypyh84dtzl3y90x2z7.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is roughly the same as running &lt;code&gt;git status&lt;/code&gt;: I see a list of files I've modified and whether they're staged. If I move my cursor down and hit Enter on the file name, it'll take me to the file in question.&lt;/p&gt;

&lt;p&gt;If I hover over the filename and type &lt;code&gt;d&lt;/code&gt; I'm presented with some choices regarding seeing the differences. After hitting &lt;code&gt;d&lt;/code&gt; again I'm presented with a window that shows the diffs:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fm5k7wbzvjo1rv7d0ncmc.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fm5k7wbzvjo1rv7d0ncmc.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I can stage individual files by typing &lt;code&gt;s&lt;/code&gt; over the filenames, or staging groups of files by highlighting several and hitting &lt;code&gt;s&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Finally, if I want to make a commit, I type &lt;code&gt;c&lt;/code&gt; from the Magit buffer and presented with a number of useful options, not unfamiliar to us Git command-line users:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmsg7sse8d3wyler0jn3s.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmsg7sse8d3wyler0jn3s.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each one of these arguments are actual Git arguments that will be applied to your Git commit.&lt;/p&gt;

&lt;p&gt;Finally, the commit window.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3a97r7hod0u8rvcm8x7z.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3a97r7hod0u8rvcm8x7z.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Magit provides a normal text buffer for writing a commit message (with all of the conveniences of Emacs of course). The first line is only supposed to be 50 characters long so Magit will mark any extra text in red. Below is the diff for the commit you're making.&lt;/p&gt;

&lt;p&gt;Once I'm ready to commit, I type &lt;code&gt;C-c C-c&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Magit supports not only what appears to be most Git functionality, but you can modify this behavior using actual options that Git gives you. In terms of the interface, Magit makes it very easy to understand what Git commands it'll be running, and in turn passes along greater control to you. If, for example, I wanted to force push this code for some reason, I'd run &lt;code&gt;M-x magit-push&lt;/code&gt; (or simply &lt;code&gt;p&lt;/code&gt; from a Magit buffer), I'll see 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpix6y1852gwqwd9zkb3m.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpix6y1852gwqwd9zkb3m.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This looks similar to the commit window we saw earlier.&lt;/p&gt;

&lt;p&gt;After typing &lt;code&gt;-F&lt;/code&gt; I've turned on the &lt;code&gt;--force&lt;/code&gt; flag, and Magit will run &lt;code&gt;git push --force&lt;/code&gt; instead.&lt;/p&gt;

&lt;p&gt;I like Magit because, unlike Sourcetree or even the terminal you don't have to leave the editor to do Git things, and unlike VS Code or IntelliJ, I can perform all these Git actions without ever having to touch the mouse.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://emacsair.me/2017/09/01/magit-walk-through/" rel="noopener noreferrer"&gt;Magit can do a lot more than this&lt;/a&gt;, of course, but even if this was all it could do it would probably still be my favorite Git client. To me it's yet another reason to use Emacs.&lt;/p&gt;

</description>
      <category>emacs</category>
      <category>devtools</category>
    </item>
    <item>
      <title>Critique of the Magic of Modern IDEs</title>
      <dc:creator>Ryan Faulhaber</dc:creator>
      <pubDate>Sun, 15 Nov 2020 18:26:11 +0000</pubDate>
      <link>https://forem.com/rfaulhaber/critique-of-the-magic-of-modern-ides-3pkn</link>
      <guid>https://forem.com/rfaulhaber/critique-of-the-magic-of-modern-ides-3pkn</guid>
      <description>&lt;p&gt;The StackOverflow blog recently posted &lt;a href="https://stackoverflow.blog/2020/11/09/modern-ide-vs-vim-emacs/?cb=1"&gt;this article&lt;/a&gt; asking why so many people continue to use Vim and Emacs when modern editors like Atom exist. This is a question I have &lt;a href="https://ryanfaulhaber.com/posts/try-emacs"&gt;personally addressed before&lt;/a&gt; with regards to Emacs, but I want to address this post specifically because I think it gets at a commonly held misunderstanding about these editors.&lt;/p&gt;

&lt;p&gt;The basic point of the post explores why people would want to use an antiquated editor like Vim or Emacs, and that those who continue to use either are missing out on the so-called magic of a newer IDE.&lt;/p&gt;

&lt;p&gt;I think that this post doesn't understand why someone would want to use Vim or Emacs in the first place, and is happy to throw them into the dustbin of history simply because they're old. In fact Vim and Emacs still have a lot to offer, and each are able to offer things that newer editors simply aren't interested in providing.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an IDE?
&lt;/h2&gt;

&lt;p&gt;As anyone will tell you, an IDE is an integrated development environment. This is a catchall term for a special kind of text editor that provides special functionality for writing code. What separates Notepad on Windows from, say, IntelliJ IDEA is that the latter has features that enable you to compile and run programs, code completion, version control integration, and a whole host of other things.&lt;/p&gt;

&lt;p&gt;Increasingly the line between IDE and text editor is blurring, however. Something like VS Code or Atom can be considered either depending on who you ask. Typically, I would consider Atom a text editor while I'd consider IntelliJ IDEA an IDE, because the latter is specifically suited for providing a Java development environment (and about a dozen other languages as well): it comes with Java-specific code completion, compiling and running commands, and so forth, while Atom inherently does not, though it &lt;em&gt;can&lt;/em&gt; be made to do so. Visual Studio can do the same for C#. Vim, Atom, VS Code, and Emacs inherently do not.&lt;/p&gt;

&lt;h2&gt;
  
  
  The So-Called Magic of IDEs
&lt;/h2&gt;

&lt;p&gt;In my first software class in college we wrote Java using Eclipse. The course mandated that you use Eclipse to compile your code, and the first class involved setting up our environment in such a way that we wouldn't have to worry about configuring our IDE for the rest of the course. This was the first time I wrote Java and for a long time didn't know that you could run Java code any other way.&lt;/p&gt;

&lt;p&gt;I was in for a shock when I took my first C class a semester later. The professor forbade us from using an IDE, instead we had to use &lt;code&gt;gcc&lt;/code&gt; with the &lt;code&gt;-ansi&lt;/code&gt; flag. Per the requirements of the course I wrote all my code in gedit and compiled it manually in the terminal. Compiling code in this manner was frustrating: I didn't notice issues with my code until I ran &lt;code&gt;gcc&lt;/code&gt;, and I wouldn't know if I had resolved my issue until I reran the command. Doing this with an IDE wouldn't be so frustrating, I thought!&lt;/p&gt;

&lt;p&gt;This experience taught me three things, and it's a lesson I feel everyone who writes code sooner or later learns:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; You don't need an IDE to compile and run code. It seems obvious in retrospect but learning how to code in this way presents how code works in a mystified way.&lt;/li&gt;
&lt;li&gt; Your tools are only as good as you utilize them. While gedit didn't provide me with much useful feedback on my C code as I wrote it, &lt;code&gt;gcc&lt;/code&gt; sure did. Learning to listen to the warnings saved me a bit of grief as I went through the course. Learning other tools like &lt;code&gt;make&lt;/code&gt; also made my life easier at the time. This holds true for any editor as well: IntelliJ provides an astronomical amount of features, but if all I do is use this huge editor to just compile and run Java, what difference does it make if I wrote my code in gedit and compile my code from the command line?&lt;/li&gt;
&lt;li&gt; Usually you don't need a specific editor to write code. Code written in Vim is the same as code written in Visual Studio, but these are tools meant to assist &lt;em&gt;you&lt;/em&gt;. Code running on a server somewhere doesn't care whether or not it was written in Emacs or Sublime.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All of this is to say that an IDE is a tool of mystification: it deliberately makes writing code easier, and does so by automating the more tedious aspects of the process. As a software developer I feel that it's important to know how to do these things yourself, as doing so will result in a deeper understanding of the code you write.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Cold Vim/Emacs War
&lt;/h2&gt;

&lt;p&gt;I want to address the so-called war between Vim and Emacs, and I want to start by asking: what war is there?&lt;/p&gt;

&lt;p&gt;If you had never heard of Vim or Emacs before this article you would think that there are deeply embedded communities who spend all day in flame wars over which editor they prefer, and their refusal to move on was holding back the whole of software engineering.&lt;/p&gt;

&lt;p&gt;But where is this? The article points to a Medium article that talks about how a developer turned Atom into Vim, and says that this attitude is retrograde: the author is so entrenched in the past that they used Atom's customizability to turn it into something that more closely resembles Vim.&lt;/p&gt;

&lt;p&gt;I have been using Vim for four years and Emacs for almost one (and in fact I use &lt;a href="https://github.com/emacs-evil/evil"&gt;Vim keybindings within Emacs&lt;/a&gt;!), and I've never seen any serious hostility between Vim and Emacs users. The original antagonism between the two editors came from Richard Stallman's objection to Vi being closed source. This is no longer relevant, however, as both Vim and Emacs are both free and open source software. I think there are people who prefer to use one over the other, in the same way some people would prefer chocolate or vanilla ice cream, but I think any serious animosity between Vim and Emacs users dried up decades ago.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use Vim or Emacs?
&lt;/h2&gt;

&lt;p&gt;It's at this point I wonder if either of the authors of this piece have ever used Vim or Emacs! They certainly don't understand what the appeal of either would be, or why you'd want to import features from Vim into Atom, and if there's a desire to import features from Vim or Emacs into a modern editor like Atom, then modern editors clearly lack something.&lt;/p&gt;

&lt;p&gt;To sum up what each editor offers, Vim offers ergonomics and Emacs offers customizability, and each of these are things you truly cannot appreciate until you have used either.&lt;/p&gt;

&lt;p&gt;Vim's keybindings are meant to maximize keyboard use and cut down on repetitive editing actions. If you want to change what's between a set of parentheses, Vim lets you do this by typing &lt;code&gt;ci(&lt;/code&gt;. Rather than reach for the mouse and highlight the contents, Vim saves you from having to move your hands. It takes some getting used to but is well worth the effort to learn.&lt;/p&gt;

&lt;p&gt;Emacs offers something more subtle and profound, I think: an editor that can do exactly what you want it to do, and as a software developer, this is an invaluable feature to me. As "hackable" as Atom is, Emacs takes it to a greater extreme, allowing you to change even the most fundamental behavior of your editor. Frequently I write small functions in Emacs Lisp to tweak the behavior of the editor. I'm an avid &lt;a href="https://orgmode.org/"&gt;Org mode&lt;/a&gt; user, and I have a small handful of functions to automate otherwise tedious actions, such as converting numbers to links to tickets in JIRA.&lt;/p&gt;

&lt;p&gt;To say that Vim and Emacs themselves or their users somehow hold back modern editors, or that newer developers shouldn't bother with these tools is absurd. I have only been a professional developer for about four years and I've spent three of them using either Vim or Vim plugins. I feel that I'm a much more productive developer now that I know Vim, and using Vim and Emacs in turn has taught me new ways to utilize the tools I use on a day-to-day basis. This isn't to say you should avoid more modern editors, but to assert that either is completely worthless misses why people would continue to use either in the first place.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Some First Impressions of Nix</title>
      <dc:creator>Ryan Faulhaber</dc:creator>
      <pubDate>Sat, 29 Aug 2020 02:50:35 +0000</pubDate>
      <link>https://forem.com/rfaulhaber/some-first-impressions-of-nix-2c1c</link>
      <guid>https://forem.com/rfaulhaber/some-first-impressions-of-nix-2c1c</guid>
      <description>&lt;p&gt;In my relatively few years of software development I've seen first hand how hard it can be to set up a consistent environment, development or otherwise, across a team, and I think Nix might be a solution.&lt;/p&gt;

&lt;p&gt;Docker is notably a solution for this: rather than bring everyone's environments up to speed, Docker brings the environment to you in the form of containers. Since Docker containers are deterministic, you also know that if your application works on your computer in a container, it'll work on a server in a container. Very handy.&lt;/p&gt;

&lt;p&gt;I recently learned about &lt;a href="https://nixos.org/"&gt;NixOS&lt;/a&gt; and the Nix package manager, and it's very appealing to me as a developer and a Linux user for a few reasons. The goal of NixOS and its related software seems to be the ability to create systems and environments declaratively. This may sound like Docker, but unlike Docker, the end goal is your system, not a system apart from your environment.&lt;/p&gt;

&lt;p&gt;I've been working with it all for a few weeks now, and here are some thoughts I have.&lt;/p&gt;

&lt;h1&gt;
  
  
  Nix, the operating system (NixOS)
&lt;/h1&gt;

&lt;p&gt;NixOS is the Linux distro that uses the Nix package manager first class. This is maybe the part of the Nix ecosystem I have the least experience with, as I've only been running it in a VM so far. My goal is to take my current setup in Arch and reproduce it in a configuration.nix file, get that out of the VM, and use it to set up a new NixOS installation. The fact that this is even possible is pretty cool, and with relatively little work I've already gotten a decent amount of my system reproduced (though along the way I've also decided to make a few adjustments, like switch from &lt;a href="https://github.com/baskerville/bspwm"&gt;bspwm&lt;/a&gt; to &lt;a href="https://swaywm.org/"&gt;SwayWM&lt;/a&gt;).&lt;/p&gt;

&lt;h1&gt;
  
  
  Nix, the package manager (&lt;code&gt;nix&lt;/code&gt;, &lt;code&gt;nix-*&lt;/code&gt;)
&lt;/h1&gt;

&lt;p&gt;Calling Nix a package manager is underselling it, I think, because Nix is unlike any other package manager I've ever used.&lt;/p&gt;

&lt;p&gt;For one thing, its usage isn't limited to NixOS, or even Linux: you can install and run packages using Nix on Mac as well. This, it turns out, is very handy on Mac.&lt;/p&gt;

&lt;p&gt;On Ubuntu, you might install a package like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apt install nodejs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;On Nix, the equivalent would be:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nix-env -i nodejs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is not the preferred way to install something, though, because when you regenerate your system's configuration, &lt;code&gt;node&lt;/code&gt; won't be there. The only "permanent" packages are those that are specified in your system's configuration. That way, you always know exactly what's installed. The upside to this is that Nix proivdes a way of "trying" packages without letting you commit to keeping them on your system. The downside is that you have to reload your whole system just to permanently install something. A small price to pay, I suppose!&lt;/p&gt;

&lt;p&gt;These aspects of Nix also have another upside: rollbacks to a specific state. If you mess up your configuration, as is easy to do in Linux, you can roll back your entire system to a time where it wasn't messed up.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;code&gt;nix-shell&lt;/code&gt;, the portable environment builder
&lt;/h1&gt;

&lt;p&gt;A brief aside.&lt;/p&gt;

&lt;p&gt;The Nix package manager comes with a fascinating tool called &lt;code&gt;nix-shell&lt;/code&gt;. Its purpose is also similar to that of Docker: provide a declarative build envronment.&lt;/p&gt;

&lt;p&gt;What it does is, according to a &lt;code&gt;shell.nix&lt;/code&gt; file or a specific command, it will generate a shell environment suited to that configuration, keeping it separate from the "main" environment.&lt;/p&gt;

&lt;p&gt;For example, let's say I want to work on a Node project. I could run the following:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nix-shell -p nodejs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After some output to the terminal, I'm dropped into a new shell environment where &lt;code&gt;node&lt;/code&gt; is now an executable. This way, you can specify the tools you need for a particular project without installing them in your main environment. I find this useful for Python, which, for some reason, has always given me a lot of trouble on my Mac.[1]&lt;/p&gt;

&lt;h1&gt;
  
  
  Nix, the programming language
&lt;/h1&gt;

&lt;p&gt;Finally, Nix is also a programming language. I mean, it &lt;em&gt;is&lt;/em&gt; a full blown functional programming language, but it's also kind of a configuration language, or at least had configuration languages in mind while it was designed. Imagine of JSON, YAML, or TOML also had functions and could be evaluated, and that's kind of what Nix is (or at least, how it reads to me!).&lt;/p&gt;

&lt;p&gt;A sample piece of Nix configuration, taken from the NixOS manual, looks like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;users.users.alice = {
  isNormalUser = true;
  home = "/home/alice";
  description = "Alice Foobar";
  extraGroups = [ "wheel" "networkmanager" ];
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is part of a larger configuration, and if you're familiar with JSON you can probably imagine what this is setting. What's interesting though is that obviously this configuration actually corresponds to something on your system and would produce an actual user named "alice" with that home directory and those groups, etc.&lt;/p&gt;

&lt;p&gt;The language itself isn't terribly complicated conceptually if you're familiar with other functional programming languages, but I have found it hard to get used to. I find it very hard to know what's possible, and I also find it difficult to know what is set where. While writing my configuration.nix file for what'll hopefully be my new NixOS install, I've frequently found myself asking things like "How do I enable such and such setting?" or "When would I need to use &lt;code&gt;mkOption&lt;/code&gt;?" I'm sure I'll pick it up in time, though.&lt;/p&gt;

&lt;h1&gt;
  
  
  Final thoughts
&lt;/h1&gt;

&lt;p&gt;The Nix ecosystem is very fascinating. For as long as I've been writing code I've long wondered how to consistenly reproduce developer environments, and I think if Nix isn't a full blown solution to this problem, it seems on track to being one. I'm very eager to learn more Nix!&lt;/p&gt;

</description>
      <category>linux</category>
      <category>devtools</category>
    </item>
    <item>
      <title>Cool Emacs Things: Editing Files over SSH</title>
      <dc:creator>Ryan Faulhaber</dc:creator>
      <pubDate>Sat, 22 Aug 2020 18:59:41 +0000</pubDate>
      <link>https://forem.com/rfaulhaber/cool-emacs-things-editing-files-over-ssh-2hpm</link>
      <guid>https://forem.com/rfaulhaber/cool-emacs-things-editing-files-over-ssh-2hpm</guid>
      <description>&lt;p&gt;This is the first installment of an indefinite series calling (in lieu of a better name) “Cool Emacs Things,” little things about Emacs that makes it a very handy editor.&lt;/p&gt;

&lt;p&gt;Today’s entry: Editing files over SSH.&lt;/p&gt;

&lt;p&gt;This was something I discovered recently by accident. I run a private email server and the IMAP portion of the server is handled by &lt;a href="https://www.dovecot.org/"&gt;Dovecot&lt;/a&gt;. Dovecot is great but by default the configuration is spread across dozens of files, and, while trying to tediously edit multiple files over SSH in Vim, I thought, “Wouldn’t it be nice if I could do this with Emacs?” Well guess what!&lt;/p&gt;

&lt;p&gt;&lt;code&gt;C-x C-f&lt;/code&gt; (or &lt;code&gt;SPC f f&lt;/code&gt; in Doom, which is what I use) will open a “find file” dialog, obviously letting you open files and peruse your file system. However you don’t have to just browse for files. I use Ivy, so your experience may vary, but when I type &lt;code&gt;/ssh: TAB&lt;/code&gt; I’m shown a list of my SSH connections. &lt;code&gt;/ssh:ryan@email-server:/&lt;/code&gt; then will cause Emacs to presumably run some commands using SSH (or a related program) and treat it as a directory on your own computer. You can then used Dired (like an interactive &lt;code&gt;ls&lt;/code&gt;, if you aren’t an Emacs user!) to explore your remote files and folders and even open files and edit them.&lt;/p&gt;

&lt;p&gt;The Emacs package that handles this is called &lt;a href="https://www.gnu.org/software/tramp/"&gt;TRAMP&lt;/a&gt;, and allows you to do a lot more than just what I’m talking about in this post.&lt;/p&gt;

&lt;p&gt;There is one issue with this, however: my Dovecot configuration requires root permissions to edit them. TRAMP can handle this too with something called &lt;a href="https://www.gnu.org/software/tramp/#Multi_002dhops"&gt;multiple hops&lt;/a&gt;. The idea is that I’ll first connect to the host via SSH and then run any further commands using &lt;code&gt;doas&lt;/code&gt; (the OpenBSD equivalent of &lt;code&gt;sudo&lt;/code&gt; more or less, as my email server is hosted on OpenBSD).&lt;/p&gt;

&lt;p&gt;The final command to do all this looks like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/ssh:ryan@email-server|doas:ryan@email-server:/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now I can browse and edit my email server with elevated permissions. Cool!&lt;/p&gt;

</description>
      <category>emacs</category>
      <category>devtools</category>
    </item>
    <item>
      <title>Writing an Emacs module in Rust</title>
      <dc:creator>Ryan Faulhaber</dc:creator>
      <pubDate>Sat, 15 Aug 2020 02:31:19 +0000</pubDate>
      <link>https://forem.com/rfaulhaber/writing-an-emacs-module-in-rust-3pg5</link>
      <guid>https://forem.com/rfaulhaber/writing-an-emacs-module-in-rust-3pg5</guid>
      <description>&lt;p&gt;I'm a new Emacs user. I made the jump to Emacs from VSCode / IntelliJ / Vim back in March, and it's been a mind-blowing experience. I cannot sing Emacs's praise enough, it's a truly incredible piece of software.&lt;/p&gt;

&lt;p&gt;I'm also a new Rust developer. I don't write Rust professionally but I made my way through the wonderful and informative &lt;a href="https://doc.rust-lang.org/book/"&gt;Rust book&lt;/a&gt; and I fell head-over-heels for this language. I never thought of myself as having any interest in systems programming until I learned Rust, and Rust has allowed me to very easily bridge that gap.&lt;/p&gt;

&lt;p&gt;So recently I learned that Emacs allows you to write dynamically-loaded modules written in C. In case you don't know, if you want to customize Emacs, you must write Emacs Lisp code. This is no different than if you want to customize VS Code and writing JavaScript or TypeScript, although Emacs Lisp is far more robust in terms of what it will allow you to customize. Not all Emacs Lisp code is written in Emacs Lisp, though. Some functions that have to interact with the system on a lower-level &lt;a href="https://www.gnu.org/software/emacs/manual/html_node/eintr/Primitive-Functions.html#Primitive-Functions"&gt;are written in C&lt;/a&gt; but can be called like Emacs Lisp functions. Emacs also lets you write such functions yourself.&lt;/p&gt;

&lt;p&gt;I would hardly consider myself an expert in the fields of C or systems programming, but I've always wanted a good excuse to mess around with rust-bindgen. I also realize there's already &lt;a href="https://github.com/ubolonton/emacs-module-rs"&gt;Emacs bindings for Rust&lt;/a&gt;, but for the sake of learning we'll ignore that for now.&lt;/p&gt;

&lt;p&gt;Here's how I tried to write a module for Emacs in Rust.&lt;/p&gt;

&lt;h1&gt;
  
  
  How it works
&lt;/h1&gt;

&lt;p&gt;According to the &lt;a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Module-Initialization.html#Module-Initialization"&gt;Emacs documentation&lt;/a&gt; on the matter, if we were writing C, writing an Emacs module requires the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Include the &lt;code&gt;emacs-module.h&lt;/code&gt; header file&lt;/li&gt;
&lt;li&gt; Specify &lt;code&gt;int plugin_is_GPL_compatible;&lt;/code&gt; in your code&lt;/li&gt;
&lt;li&gt; Implement the &lt;code&gt;emacs_module_init&lt;/code&gt; function, which Emacs will call upon loading our module&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And that's pretty much it. But obviously we're dealing with Rust, so our plan of attack will instead be to generate bindings using &lt;a href="https://github.com/rust-lang/rust-bindgen"&gt;&lt;code&gt;rust-bindgen&lt;/code&gt;&lt;/a&gt; and implement our init function in Rust.&lt;/p&gt;

&lt;h1&gt;
  
  
  Setup
&lt;/h1&gt;

&lt;p&gt;I started this like I begin all new Rust projects: by calling &lt;code&gt;cargo new --lib emacs-module-test&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;My Cargo.toml file was edited to contain the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="nn"&gt;[package]&lt;/span&gt;
&lt;span class="py"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"emacs-module-test"&lt;/span&gt;
&lt;span class="py"&gt;version&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.1.0"&lt;/span&gt;
&lt;span class="py"&gt;authors&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Ryan Faulhaber &amp;lt;faulhaberryan@gmail.com&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="py"&gt;edition&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"2018"&lt;/span&gt;
&lt;span class="c"&gt;# let's make our code GPL-compatible!&lt;/span&gt;
&lt;span class="py"&gt;license&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"GPL-3.0-or-later"&lt;/span&gt;

&lt;span class="nn"&gt;[lib]&lt;/span&gt;
&lt;span class="py"&gt;path&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"src/lib.rs"&lt;/span&gt;

&lt;span class="c"&gt;# we need to specify "cdylib" because our project has to output a shared object&lt;/span&gt;
&lt;span class="c"&gt;# file&lt;/span&gt;
&lt;span class="py"&gt;crate-type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;["cdylib"]&lt;/span&gt;

&lt;span class="nn"&gt;[dependencies]&lt;/span&gt;
&lt;span class="c"&gt;# we'll need some help from libc to interact with C's types&lt;/span&gt;
&lt;span class="py"&gt;libc&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.2"&lt;/span&gt;

&lt;span class="nn"&gt;[build-dependencies]&lt;/span&gt;
&lt;span class="c"&gt;# and of course we'll need bindgen&lt;/span&gt;
&lt;span class="py"&gt;bindgen&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.54.1"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we'll a build step, as per bindgen's instructions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c"&gt;// build.rs&lt;/span&gt;
&lt;span class="k"&gt;extern&lt;/span&gt; &lt;span class="n"&gt;crate&lt;/span&gt; &lt;span class="n"&gt;bindgen&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;path&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;PathBuf&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;bindings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;bindgen&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;Builder&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;default&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="c"&gt;// I just imported it straight from where it was on my computer.&lt;/span&gt;
        &lt;span class="c"&gt;// If we were building a real module we might not want to do this!&lt;/span&gt;
        &lt;span class="c"&gt;// Also if you're trying this on macOS this header file may not be&lt;/span&gt;
        &lt;span class="c"&gt;// in this particular location&lt;/span&gt;
        &lt;span class="nf"&gt;.header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/usr/include/emacs-module.h"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c"&gt;// We want to specify our own emacs_module_init function, so we won't&lt;/span&gt;
        &lt;span class="c"&gt;// generate one in Rust automatically&lt;/span&gt;
        &lt;span class="nf"&gt;.blacklist_function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"emacs_module_init"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c"&gt;// Generate the bindings&lt;/span&gt;
        &lt;span class="nf"&gt;.generate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="c"&gt;// Explode if something goes wrong&lt;/span&gt;
        &lt;span class="nf"&gt;.expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Unable to generate bindings"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;out_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;PathBuf&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;env&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"OUT_DIR"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="n"&gt;bindings&lt;/span&gt;
        &lt;span class="nf"&gt;.write_to_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out_path&lt;/span&gt;&lt;span class="nf"&gt;.join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"bindings.rs"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="nf"&gt;.expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Couldn't write bindings!"&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;p&gt;This is mostly lifted straight from &lt;code&gt;rust-bindgen&lt;/code&gt;'s documentation.&lt;/p&gt;

&lt;p&gt;Finally, we'll start the lib.rs file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c"&gt;// this is also borrowed from rust-bindgen. C code obviously has different&lt;/span&gt;
&lt;span class="c"&gt;// stylistic conventions. For the sake of simplicity we'll write stylistically&lt;/span&gt;
&lt;span class="c"&gt;// unconventional code&lt;/span&gt;
&lt;span class="nd"&gt;#![allow(non_upper_case_globals)]&lt;/span&gt;
&lt;span class="nd"&gt;#![allow(non_camel_case_types)]&lt;/span&gt;
&lt;span class="nd"&gt;#![allow(non_snake_case)]&lt;/span&gt;

&lt;span class="c"&gt;// this dumps the contents of bindings.rs into this file upon compilation&lt;/span&gt;
&lt;span class="nd"&gt;include!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;concat!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;env!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"OUT_DIR"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s"&gt;"/bindings.rs"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So far so good. The project should compile (&lt;code&gt;cargo build&lt;/code&gt;) without issues. This would also be the time to drop &lt;a href="https://www.gnu.org/licenses/gpl-3.0.en.html"&gt;a copy of the GPL-3.0 license&lt;/a&gt; into a file called LICENSE.&lt;/p&gt;

&lt;h1&gt;
  
  
  Looking through &lt;code&gt;bindings.rs&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;Before we get started we should take a look at the bindings that &lt;code&gt;rust-bindgen&lt;/code&gt; generated. The path will be something different for you, but to give you a sense of where to look, the path on my machine was: &lt;code&gt;target/debug/build/emacs-module-84a415ae9d763afd/out/bindings.rs&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There's a few types that we should make note of.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;emacs_runtime&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;In the code we'll be writing Emacs provides us with an instance of this struct that represents the Emacs runtime, so we don't have to worry about creating it (I would be interested in mocking it though…). The most important part of this struct is the &lt;code&gt;get_environment&lt;/code&gt; member, which is a function pointer. As the signature implies it returns an instance of &lt;code&gt;emacs_env&lt;/code&gt;, so let's check that out.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;emacs_env&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Since I'm running Emacs 26 there are two version of this struct. I'm only concerned with &lt;code&gt;emacs_env_26&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is the more important struct, as a number of its members are function pointers to crucial functions we'll need to interact with Emacs. I won't go over them all now, but the ones that we'll be using are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;make_function&lt;/code&gt;, which creates the body of a function&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;make_string&lt;/code&gt;, which converts a string from C (Rust) into an &lt;code&gt;emacs_value&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;intern&lt;/code&gt;, which allows us to create symbols in Emacs&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;funcall&lt;/code&gt;, which allows us to call Emacs functions and receive their return value&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;emacs_value&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This is a representation of a value in Emacs Lisp in C (Rust). It's not entirely clear to me how it works internally, but fortunately it doesn't really matter for what we're doing.&lt;/p&gt;

&lt;h1&gt;
  
  
  Writing the module
&lt;/h1&gt;

&lt;p&gt;For the sake of simplicity, we'll write a dead simple module, one that's so simple we could write it in Emacs Lisp:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight common_lisp"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;defun&lt;/span&gt; &lt;span class="nv"&gt;my-message-from-rust&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="s"&gt;"Returns a message from Rust"&lt;/span&gt;
  &lt;span class="s"&gt;"Hello Emacs, I'm from Rust"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;defun&lt;/span&gt; &lt;span class="nv"&gt;my-sum&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;&amp;amp;rest&lt;/span&gt; &lt;span class="nv"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="s"&gt;"Returns the sum of ARGS"&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;apply&lt;/span&gt; &lt;span class="ss"&gt;'+&lt;/span&gt; &lt;span class="nv"&gt;args&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;provide&lt;/span&gt; &lt;span class="ss"&gt;'my-rust-mod&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our module will provide two functions, &lt;code&gt;my-message-from-rust&lt;/code&gt; and &lt;code&gt;my-sum&lt;/code&gt;. The former simply returns a string literal, while the latter sums up all the values passed to it. That should be easy enough.&lt;/p&gt;

&lt;p&gt;As I mentioned earlier, the documentation says that we'll have to implement a function called &lt;code&gt;emacs_module_init&lt;/code&gt;. This is where our Rust code will define its functions.&lt;/p&gt;

&lt;p&gt;In Emacs, it's conventional to register your module with the list of features available to Emacs. The &lt;code&gt;provide&lt;/code&gt; call tells Emacs that &lt;code&gt;'my-rust-mod&lt;/code&gt; is now a feature within Emacs.&lt;/p&gt;

&lt;p&gt;Let's at least set up the function first. Our &lt;code&gt;lib.rs&lt;/code&gt; file should look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#![allow(non_upper_case_globals)]&lt;/span&gt;
&lt;span class="nd"&gt;#![allow(non_camel_case_types)]&lt;/span&gt;
&lt;span class="nd"&gt;#![allow(non_snake_case)]&lt;/span&gt;

&lt;span class="c"&gt;// you shouldn't have to put this at the top of your file, but I noticed that&lt;/span&gt;
&lt;span class="c"&gt;// rust-analyer got a little confused on my computer when I put it after my code&lt;/span&gt;
&lt;span class="nd"&gt;include!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;concat!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;env!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"OUT_DIR"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s"&gt;"/bindings.rs"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c"&gt;// we'll be using these later&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;ffi&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;CString&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;os&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;#[no_mangle]&lt;/span&gt;
&lt;span class="nd"&gt;#[allow(non_upper_case_globals)]&lt;/span&gt;
&lt;span class="c"&gt;// Rust doesn't allow uninitialized static values, and Emacs doesn't care what&lt;/span&gt;
&lt;span class="c"&gt;// the value of this variable is, as long as it's there&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;plugin_is_GPL_compatible&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nn"&gt;libc&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nb"&gt;c_int&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="c"&gt;// ordinarily the Rust compiler will mangle funciton names. we don't want to do&lt;/span&gt;
&lt;span class="c"&gt;// that, since the C code won't know what code to call.&lt;/span&gt;
&lt;span class="c"&gt;// we'll also want to use `unsafe` because we need access to raw pointers&lt;/span&gt;
&lt;span class="nd"&gt;#[no_mangle]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;unsafe&lt;/span&gt; &lt;span class="k"&gt;extern&lt;/span&gt; &lt;span class="s"&gt;"C"&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;emacs_module_init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ert&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;emacs_runtime&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;libc&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nb"&gt;c_int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ert&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="py"&gt;.get_environment&lt;/span&gt;
        &lt;span class="c"&gt;// for simplicity's sake we'll be getting a lot of milage out of&lt;/span&gt;
        &lt;span class="c"&gt;// .expect()!&lt;/span&gt;
        &lt;span class="nf"&gt;.expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"cannot get environment from Emacs"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c"&gt;// remember, these are function pointers we're dealing with!&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ert&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c"&gt;// to be used later&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;make_function&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="py"&gt;.make_function&lt;/span&gt;&lt;span class="nf"&gt;.except&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"cannot get make_function!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nd"&gt;todo!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Finish writing this function!"&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;p&gt;Now let's write some functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;my-message-from-rust&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;First, the actual Rust code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c"&gt;// no need to no-mangle it since it'll never be called by name&lt;/span&gt;
&lt;span class="k"&gt;unsafe&lt;/span&gt; &lt;span class="k"&gt;extern&lt;/span&gt; &lt;span class="s"&gt;"C"&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;message_from_rust&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;emacs_env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;nargs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;isize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;emacs_value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="nn"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nb"&gt;c_void&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;emacs_value&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// our actual message&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello Emacs! I'm from Rust!"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c"&gt;// function pointer to make_string, provided by Emacs&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;make_string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="py"&gt;.make_string&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="c"&gt;// converted to a CString&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;c_string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;CString&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="c"&gt;// grab the size in bytes, as needed by Emacs&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;c_string&lt;/span&gt;&lt;span class="nf"&gt;.as_bytes&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.len&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;isize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c"&gt;// return the emacs_value returned by make_string&lt;/span&gt;
    &lt;span class="nf"&gt;make_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c_string&lt;/span&gt;&lt;span class="nf"&gt;.as_ptr&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;len&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;p&gt;Now, let's return to our init function and add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_message_func&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;make_function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c"&gt;// a reference to our Emacs environment, of course&lt;/span&gt;
    &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c"&gt;// min_arity argument&lt;/span&gt;
    &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c"&gt;// max_arity argument&lt;/span&gt;
    &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c"&gt;// our actual function&lt;/span&gt;
    &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message_from_rust&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="c"&gt;// docstring, so users can check the documentation for this funciton in&lt;/span&gt;
    &lt;span class="c"&gt;// Emacs&lt;/span&gt;
    &lt;span class="nn"&gt;CString&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"This will print a nice message from Rust code!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nf"&gt;.as_ptr&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="c"&gt;// data argument. we are not passing this function any additional data, so&lt;/span&gt;
    &lt;span class="c"&gt;// we give it `null`&lt;/span&gt;
    &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;null_mut&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;p&gt;What's important to note about what we're doing here is that we're creating a new function &lt;em&gt;value&lt;/em&gt;. Functions in Emacs Lisp (and indeed any functional programming language I've ever heard of) are just values, like integers or strings. Much like our call to &lt;code&gt;make_string&lt;/code&gt; earlier, we're just creating a new value on Emacs's terms. In fact it's probably more like creating an anonymous function. If this was the only code we wrote, our users would have no way of calling our code from within Emacs. We'll get to that later, though.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;my-sum&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This one is a bit more interesting because we want our function to accept an indefinite amount of arguments. The actual function code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c"&gt;// again, no need to no-mangle&lt;/span&gt;
&lt;span class="k"&gt;unsafe&lt;/span&gt; &lt;span class="k"&gt;extern&lt;/span&gt; &lt;span class="s"&gt;"C"&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;my_sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;emacs_env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;nargs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;isize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;emacs_value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="nn"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nb"&gt;c_void&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;emacs_value&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// Emacs provides us with a way of grabbing an integer value out of an&lt;/span&gt;
    &lt;span class="c"&gt;// emacs_value object&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;extract_integer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="py"&gt;.extract_integer&lt;/span&gt;
        &lt;span class="nf"&gt;.expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"could not get extract_integer"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Vec&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c"&gt;// Emacs is kind enough to tell us how many values were passed to our&lt;/span&gt;
    &lt;span class="c"&gt;// function, so we don't really have to worry about whether or not the size&lt;/span&gt;
    &lt;span class="c"&gt;// of `args` is the same as `nargs`&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="n"&gt;nargs&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c"&gt;// pointer arithmetic! how unsafe!&lt;/span&gt;
        &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="nf"&gt;.push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;extract_integer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="nf"&gt;.offset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// some good old Rust iterators&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="nf"&gt;.iter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.fold&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c"&gt;// again, we have to rely on Emacs to convert to the proper type&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;make_integer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="py"&gt;.make_integer&lt;/span&gt;&lt;span class="nf"&gt;.expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"could not get make_integer"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;make_integer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sum&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;p&gt;And again, we have to register it with the system in a similar way to our other function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_sum_func&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;make_function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c"&gt;// this is a special value provided to us by Emacs letting it know that we&lt;/span&gt;
    &lt;span class="c"&gt;// want our fuction to accept an indefinite amount of arguments&lt;/span&gt;
    &lt;span class="n"&gt;emacs_variadic_function&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;isize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_sum&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nn"&gt;CString&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Sums a series of integers"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nf"&gt;.as_ptr&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;null_mut&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;h2&gt;
  
  
  Finishing up module init
&lt;/h2&gt;

&lt;p&gt;As I mentioned earlier, we have to associate our new function values to names in order to call them. At the moment they're sort of floating out in the ether with only memory addresses to reference them, and that's not particularly useful.&lt;/p&gt;

&lt;p&gt;First, we need some symbols to associate to these functions. A symbol in Lisp is more or less just an identifier, but in order to create them they must first be &lt;em&gt;interned&lt;/em&gt;. This is where we can use the &lt;code&gt;intern&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Let's add the following to our init function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;intern&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="py"&gt;.intern&lt;/span&gt;&lt;span class="nf"&gt;.expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"could not get intern"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c"&gt;// creates "my-message-from-rust symbol"&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_message_sym&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;intern&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;CString&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"my-message-from-rust"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.as_ptr&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="c"&gt;// creates "my-sum"&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_sum_sym&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;intern&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;CString&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"my-sum"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.as_ptr&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we'll need to associate our functions with said symbols:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c"&gt;// intern will return a symbol if it's already defined.&lt;/span&gt;
&lt;span class="c"&gt;// we're going to use `fset` to associate our functions to symbols&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;fset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;intern&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;CString&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"fset"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.as_ptr&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="c"&gt;// we also want to actually call fset, so we'll need funcall&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;funcall&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="py"&gt;.funcall&lt;/span&gt;&lt;span class="nf"&gt;.expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"could not get funcall"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c"&gt;// in Emacs Lisp this is like:&lt;/span&gt;
&lt;span class="c"&gt;// (fset 'my-message-from-rust (lambda () ...))&lt;/span&gt;
&lt;span class="nf"&gt;funcall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;my_message_sym&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;my_message_func&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="nf"&gt;.as_mut_ptr&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="nf"&gt;funcall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;my_sum_sym&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;my_sum_func&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="nf"&gt;.as_mut_ptr&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, we'll want to provide our new feature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;provide&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;intern&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;CString&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"provide"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.as_ptr&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;feat_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;intern&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;CString&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"my-rust-mod"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.as_ptr&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;provide_args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;feat_name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="nf"&gt;.as_mut_ptr&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c"&gt;// equivalent of (provide 'my-rust-mod)&lt;/span&gt;
&lt;span class="nf"&gt;funcall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;provide&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;provide_args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c"&gt;// and finally, we can return from this function!&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Does it work?
&lt;/h1&gt;

&lt;p&gt;Let's run a &lt;code&gt;cargo build&lt;/code&gt; to make sure everything at least compiles.&lt;/p&gt;

&lt;p&gt;Rust should give us a file called &lt;code&gt;libemacs_module.so&lt;/code&gt; in &lt;code&gt;target/debug&lt;/code&gt; (or &lt;code&gt;libemacs_module.dylib&lt;/code&gt; if you're on macOS) assuming your project name is called &lt;code&gt;emacs_module&lt;/code&gt;. There are a few ways of trying to run our code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open Emacs, run &lt;code&gt;(module-load "path/to/your/libemacs_module.so")&lt;/code&gt;, and running the functions yourself&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;From the terminal, running:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;emacs &lt;span class="nt"&gt;-Q&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; path/to/your/libemacs_module.so &lt;span class="nt"&gt;--batch&lt;/span&gt; &lt;span class="nt"&gt;--eval&lt;/span&gt; &lt;span class="s1"&gt;'(message "%s" (my-message-from-rust))'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Either way, the functions you defined in Rust should now be runnable from Emacs.&lt;/p&gt;

&lt;h1&gt;
  
  
  Things I couldn't figure out
&lt;/h1&gt;

&lt;p&gt;This article was written based on my own experience and process of writing the example code I've walked you through. There's a few things, though, I don't understand about what I've done:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; If I compile this with &lt;code&gt;cargo build --release&lt;/code&gt;, I suddenly get type errors from Emacs. I suspect it's a configuration error but as of the time of writing this I'm not sure what the issue is.&lt;/li&gt;
&lt;li&gt; I'm not sure how you'd write an interactive function, if at all.&lt;/li&gt;
&lt;li&gt; I'm not sure how you'd deal with more complex data types, like alists. How would you create them or manipulate them?&lt;/li&gt;
&lt;li&gt; There's quite a bit of verbose &lt;code&gt;CString&lt;/code&gt; construction happening. I found that if I put that behind a function I suddenly get segfaults. I'm not sure why.&lt;/li&gt;
&lt;li&gt; Similarly, refactoring this code to make &lt;code&gt;intern&lt;/code&gt; its own Rust function leads to segfaults.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  What's the point of all this?
&lt;/h1&gt;

&lt;p&gt;If you've never used Emacs before and you've read this whole thing, you might realize that Emacs isn't exactly a &lt;em&gt;normal&lt;/em&gt; editor. It's not every day we're compiling and linking code to our editor. But why would we want to do this? Here are two reasons I can think of:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Performance. Emacs Lisp is often good enough (at least, in my experience) but for more significant computation it might not be a bad idea to offload that to Rust code.&lt;/li&gt;
&lt;li&gt; Further extensibility. Emacs is already very extensible, and Emacs has decades of history behind it. Emacs Lisp can do a lot language-wise, but it has its limits. Code written in Rust (or even C, of course) wouldn't have such limits.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In any event, I just think it's a pretty handy feature to have. Maybe in the future I'll be writing a more extensive dynamic module for Emacs (though I think I'll stick to using &lt;a href="https://github.com/ubolonton/emacs-module-rs"&gt;emacs-module-rs&lt;/a&gt;)!&lt;/p&gt;

&lt;p&gt;If you want to see the full code, you can check it out &lt;a href="https://github.com/rfaulhaber/emacs-module-test"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>emacs</category>
      <category>rust</category>
      <category>showdev</category>
    </item>
    <item>
      <title>You Should Try Linux</title>
      <dc:creator>Ryan Faulhaber</dc:creator>
      <pubDate>Thu, 06 Aug 2020 01:55:24 +0000</pubDate>
      <link>https://forem.com/rfaulhaber/you-should-try-linux-59ge</link>
      <guid>https://forem.com/rfaulhaber/you-should-try-linux-59ge</guid>
      <description>&lt;p&gt;I’ve been using Linux since about 2013 and it’s been a consistently rewarding experience. Not only am I far more productive on Linux than I am on macOS or Windows, I have the satisfaction of using a system that’s uniquely mine.&lt;/p&gt;

&lt;p&gt;When I first started using Linux I was beginning my computer science education. I had a consistent problem with the tools the classes I was taking called for. It always seemed like there were normal install instructions, and install instructions for Windows (I had a big clunky Windows laptop at the time). The computer lab had all the software I’d need but it was a pain to always be going to the computer lab to get my work done. It just so happened that my dad, who works in IT, had a customer give him an old Dell laptop and he told me I could have it if I wanted it. It didn’t come with a Windows license so I had to make do. I installed Ubuntu onto it and started down the Linux journey I’m on now.&lt;/p&gt;

&lt;p&gt;If your daily driver is macOS or Windows, I want to try and convince you to at least try Linux.&lt;/p&gt;

&lt;p&gt;&lt;a id="org9032162"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Linux is easier to use than you think
&lt;/h1&gt;

&lt;p&gt;A lot of people I’ve talked to avoid Linux because they hear it’s hard to use. It doesn’t support x piece of software or y isn’t compatible with it. Sometimes those are fair points, and sometimes Linux does require you to adjust how you do things. For example, if you’re locked into Office 365 and don’t want to switch, Linux indeed will probably not be much help in this case.&lt;/p&gt;

&lt;p&gt;However, if you’re flexible in the software you use, Linux can provide alternatives to a lot of software that isn’t supported on it (instead of Microsoft Office you could use LibreOffice. I know it’s not the same but for being free and open source it’s &lt;em&gt;very&lt;/em&gt; fully featured).&lt;/p&gt;

&lt;p&gt;Installing Linux can also be pretty simple. The more well-supported distros have graphical installers that don’t require a ton of technical knowledge (a distro is “flavor” of Linux: each distro comes with the Linux kernel but might provide a different user experience. Ubuntu, Debian, Mint, and Arch are all distros). Of course, if you wanted to get into the nitty-gritty of Linux installation, &lt;a href="https://wiki.archlinux.org/index.php/installation_guide"&gt;there are ways&lt;/a&gt; &lt;a href="http://www.linuxfromscratch.org/"&gt;of going about that&lt;/a&gt; too.&lt;/p&gt;

&lt;p&gt;&lt;a id="orgd6270be"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Linux is everywhere
&lt;/h1&gt;

&lt;p&gt;Linux is the world’s most used operating system in every domain except for desktops (that honor belongs to Windows). If you choose to use a Linux desktop, the skills you learn by using and customizing your desktop are things you can take with you into other domains. When I first started learning how to use AWS, I wasn’t intimidated at all by EC2 because I knew it was just a Linux server of some kind. When AWS told me how to set up my SSH keys, provision and update my server, and so on, this was all stuff I already had a sense of how to do, just because I was already doing a lot of that stuff on my desktop!&lt;/p&gt;

&lt;p&gt;&lt;a id="org4726b0d"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Linux comes from the Unix tradition (kind of)
&lt;/h1&gt;

&lt;p&gt;If you’re a Windows user, you honestly have no idea on what you’re missing out on in this regard.&lt;/p&gt;

&lt;p&gt;Linux is not a Unix, but it was designed to be a clone of Unix. This means that there’s a lot of crossover (at a certain level) between how things work on Linux and how things work on Unix systems (Unix systems include any of the BSDs and macOS). The terminal experience, for example, will for all intents and purposes be nearly the same. It’s not until you get into the lower level details that things start to make a difference (fun fact: the &lt;code&gt;ls&lt;/code&gt; program has different implementations between Linux and Unix, though they behave similarly).&lt;/p&gt;

&lt;p&gt;I had never used macOS until I got my first job, where they asked me if I’d rather have a Windows laptop or a Macbook. I chose a Macbook, opened the terminal, and felt mostly at home.&lt;/p&gt;

&lt;p&gt;&lt;a id="org330ea12"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Linux is yours
&lt;/h1&gt;

&lt;p&gt;This, to me, has become the main selling point. I have a Macbook, I have a Windows partition on my computer, but the reason why I keep using Linux most of the time is because my Linux desktop is &lt;em&gt;uniquely&lt;/em&gt; mine.&lt;/p&gt;

&lt;p&gt;I mean this both in terms of the customization and maintenance of my system. I’m an Arch Linux user (maybe soon-to-be NixOS user?) and one of the things I’ve come to value about Arch is that, if I’m willing to put in the work, I can make my system look and feel pretty much however I want. I’ve become enamored with &lt;a href="https://github.com/baskerville/bspwm"&gt;tiling window managers&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With Windows and macOS, although they may have their merits, the way you interact with them is largely at the whims of Microsoft and Apple respectively. If you don’t like what Apple decided to do this year with macOS, too bad! With Linux, you are not stuck to such a fate.&lt;/p&gt;

&lt;p&gt;If you’re willing to put in the work and learn how to do it, customizing your system exactly how you want can be very rewarding. It’s a trade-off though: you must put in the time and learn the skills to do it. You’ll likely learn a lot doing it along the way, though. If you feel so inclined you can look for inspiration from &lt;a href="https://www.reddit.com/r/unixporn/"&gt;r/unixporn&lt;/a&gt;, where users show off their system customizations.&lt;/p&gt;

&lt;p&gt;&lt;a id="org37cb289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  How can I try Linux?
&lt;/h1&gt;

&lt;p&gt;If you’re just starting out with Linux, I’d recommend one of the more well supported distros, like Ubuntu or Linux Mint. I’ve also heard good things about Elementary, Pop!OS and Fedora, although I’ve never used any of those. If you rely on graphical software especially these distros will make the transition easier.&lt;/p&gt;

&lt;p&gt;To get a good sense of what’s out there, &lt;a href="https://distrowatch.com"&gt;Distrowatch&lt;/a&gt; has information on nearly every distro out there that you could think of, and has links to where to find more information about particular distros. If you don’t want to commit a partition of your hard drive to it, you can also always try it &lt;a href="https://www.virtualbox.org/"&gt;in a VM.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a id="org9214e9a"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  How can I learn Linux?
&lt;/h1&gt;

&lt;p&gt;I think I’ll be putting out a series of posts with the intention of teaching people how to use Linux from an absolute beginner’s perspective, so watch my feed!&lt;/p&gt;

&lt;p&gt;Back when I was getting started with Linux I read &lt;a href="https://archive.is/Akjau"&gt;Learn Linux The Hard Way&lt;/a&gt;, which served as a wonderful introduction to Linux overall (the site seems to have since been taken down, but it can be accessed through that archive.org page). In the meantime, this should serve as a good crash course.&lt;/p&gt;

&lt;p&gt;Aside form the book above, I learned Linux two ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Starting with the question “How can I do this more efficiently?”, doing some Googling, and learning about all kinds of things I didn’t know before.&lt;/li&gt;
&lt;li&gt; Doing as much as possible in the terminal&lt;/li&gt;
&lt;li&gt; Seeing other people’s dotfiles&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With Linux comes a tradition of nearly 30 years of computing, and over the course of that 30 or so probably every problem you can think of as an individual has been solved. If you think there’s an easier way to do something in Linux, there probably is, but might involve writing a script.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Lessons Learned from Functional Programming</title>
      <dc:creator>Ryan Faulhaber</dc:creator>
      <pubDate>Sun, 02 Aug 2020 20:53:10 +0000</pubDate>
      <link>https://forem.com/rfaulhaber/lessons-learned-from-functional-programming-3mno</link>
      <guid>https://forem.com/rfaulhaber/lessons-learned-from-functional-programming-3mno</guid>
      <description>&lt;p&gt;When I went to college the majority of my programming classes were taught with Java. As a result I learned what I like to call "classical" object-oriented programming. As I started writing more JavaScript I realized I had a lot of issues importing the OO lessons I learned. At some point I read Kyle Simpson's &lt;a href="https://github.com/getify/Functional-Light-JS"&gt;Functional-Light JS&lt;/a&gt; and my whole world turned upside down. From there I dove into the world of functional programming and internalized many of the lessons I learned. I write JavaScript completely differently now, and I feel as though I'm a better programmer for it overall in any language I write. Here are some of the lessons I learned.&lt;/p&gt;

&lt;h1&gt;
  
  
  Data should be externally immutable
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;Mutable&lt;/em&gt; data generally means data that can be changed. Consider the following JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are &lt;em&gt;mutating&lt;/em&gt; the &lt;code&gt;x&lt;/code&gt; array by changing the item at &lt;code&gt;1&lt;/code&gt;. Many proper functional programming languages do not have a means for letting you do this. Instead, new data is &lt;em&gt;derived&lt;/em&gt;. In functional programming, the equivalent code would basically do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is, it copies every element except the one we want to change, and return a new array.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is it important?
&lt;/h2&gt;

&lt;p&gt;In languages that have implicit referencing (e.g. Java, JavaScript), having functions that mutate objects can lead to confusing and hard to trace code. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;changeFirst&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;first&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;changeFirst&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you were working in a large codebase, and you didn't happen to know what &lt;code&gt;changeFirst&lt;/code&gt; did, this could lead to potentially confusing code. If &lt;code&gt;changeFirst&lt;/code&gt; treated &lt;code&gt;x&lt;/code&gt; as immutable, you'd know that after &lt;code&gt;x&lt;/code&gt; was passed to it you wouldn't have to worry what the value is. This, I think, would be clearer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;changeFirst&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;first&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="c1"&gt;// --- don't have to worry about x after this point ---&lt;/span&gt;
&lt;span class="c1"&gt;// (unless we need to derive more data from it of course)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;changeFirst&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And of course by &lt;em&gt;externally&lt;/em&gt; mutable I mean that a function should be free to mutate data within itself, but should not mutate a function's arguments or anything in the outside world.&lt;/p&gt;

&lt;h1&gt;
  
  
  Functions should reduce side effects
&lt;/h1&gt;

&lt;p&gt;A &lt;strong&gt;side effect&lt;/strong&gt; is when a function modifies some value outside of its current scope. Contrary to popular belief, though, side effects are not in themselves &lt;em&gt;bad&lt;/em&gt;, nor are they necessarily &lt;em&gt;hidden&lt;/em&gt;. Side effects do tend to create code that's harder to reason about, though.&lt;/p&gt;

&lt;p&gt;Kyle Simpson's &lt;a href="https://github.com/getify/Functional-Light-JS/blob/master/manuscript/ch5.md/#chapter-5-reducing-side-effects"&gt;chapter on side effects in JavaScript&lt;/a&gt; is wonderful, but I'll try to do it justice here.&lt;/p&gt;

&lt;p&gt;Unfortunately, object-oriented languages have side effects baked into their design, and I think that's part of the reason why there's so much literature written around "clean code" and things like that.&lt;/p&gt;

&lt;p&gt;For example, consider the following Java code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Foo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;inc&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="o"&gt;++;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, a call to &lt;code&gt;Foo&lt;/code&gt;'s &lt;code&gt;inc&lt;/code&gt; method produces a side effect of modifying an instance of &lt;code&gt;Foo&lt;/code&gt;'s state. See what I mean when I say they're baked in?&lt;/p&gt;

&lt;p&gt;Again, though, this isn't to say that they're bad. The problem with this code though is that it's not immediately obvious what's happening to the outside.&lt;/p&gt;

&lt;p&gt;An example in JavaScript would be the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;++&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;p&gt;&lt;code&gt;doSomething&lt;/code&gt; here modifies &lt;code&gt;x&lt;/code&gt;, which is definitely outside of the scope of its function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is it important?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Side_effect_(computer_science)"&gt;The Wikipedia article on side effects&lt;/a&gt; mentions some interesting concepts: referential transparency and idempotence.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Referential transparency&lt;/strong&gt; is simply when an expression is written in such a way that you could replace the expression itself with its resulting value. Consider the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;add&lt;/code&gt; is referentially transparent because we could replace its call with the number &lt;code&gt;5&lt;/code&gt; and it would make no difference to the behavior of our program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Idempotence&lt;/strong&gt; is similar. It can be thought of as having a similar definition to "deterministic." An idempotent function basically means that you can call the same function more than once with the same arguments and achieve the same results. The best example is REST endpoints, where a lot of REST API callouts are expected to do the same thing. An API call like &lt;code&gt;GET /user?id=123&lt;/code&gt; would be expected to return a specific user. You could call that endpoint a hundred times and it would do the same thing.&lt;/p&gt;

&lt;p&gt;I think these two concepts, above all else, help with making code readable and reasonable. If we know our functions have little side effects and always do the same things, we can spend less time worrying how they effect the system.&lt;/p&gt;

&lt;p&gt;In general, reducing side effects requires some discipline, especially in OO languages. I try to stick to writing functions that operate only on their function parameters as much as possible and return a value somehow derived from the arguments. This way I hope to write more predictable and deterministic code.&lt;/p&gt;

&lt;h1&gt;
  
  
  Classes aren't always necessary
&lt;/h1&gt;

&lt;p&gt;This was a hard thing for me to (un-)learn while learning JavaScript (and subsequently newer languages that aren't strictly OO, like Go and Rust).&lt;/p&gt;

&lt;p&gt;One of the problems with learning Java or C# as your first language (Java was mine), I tend to find, is that it forces you to think of problems in terms of object interactions. Java and C# don't give you much option in this regard: your entire application has to be expressed in terms of classes, so you have to use them. This, to me, is the fatal flaw of both languages. Not all problems necessitate classes.&lt;/p&gt;

&lt;p&gt;In languages such as JavaScript where you don't have to express everything in terms of classes, where is the line drawn? For me, it's a question of statefulness. Does the part of my application I'm currently working on need to keep track of anything directly? In writing JavaScript, I find that a majority of the time it usually does not.&lt;/p&gt;

&lt;p&gt;In JavaScript, there are mainly two types of classes I create:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Component classes. If I'm writing React, for example, and I find that I need a stateful component, I will declare it as a class. Otherwise it's a function.&lt;/li&gt;
&lt;li&gt; Useful types. I don't create these often but sometimes you find yourself needing to collect data in a way that standard objects don't allow for. If I were writing a parser for example, the parser itself would probably be a class.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The rest of my code lives in functions.&lt;/p&gt;

&lt;p&gt;In statically typed languages, there's a third type of class I'd create: what the programming language Kotlin calls "data classes." A data class is just a class that wraps data and has no internal logic to it. It's a class with all public fields that is meant to take advantage of a language's static typing. Such classes tend to be things like REST API requests or responses.&lt;/p&gt;

&lt;h1&gt;
  
  
  In conclusion
&lt;/h1&gt;

&lt;p&gt;The above are all lessons I've learned from not only reading about functional programming but trying to learn functional languages. Functional programming languages are different than what most people are used to, I think, but they also offer a different way of thinking about programs, even if most of the time we can't write programs functionally.&lt;/p&gt;

&lt;p&gt;I don't write purely functional JavaScript, but I've tried to import the lessons I've learned from functional programming where possible to make my JavaScript clearer. JavaScript can be confusing as it is and it doesn't need any help in that regard, but I feel that trying to write more functional code as made my JavaScript clearer.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Ways Emacs Has Changed What I Do</title>
      <dc:creator>Ryan Faulhaber</dc:creator>
      <pubDate>Fri, 24 Jul 2020 03:09:16 +0000</pubDate>
      <link>https://forem.com/rfaulhaber/ways-emacs-has-changed-what-i-do-3e1c</link>
      <guid>https://forem.com/rfaulhaber/ways-emacs-has-changed-what-i-do-3e1c</guid>
      <description>&lt;p&gt;&lt;a href="https://ryanfaulhaber.com/posts/try-emacs/" rel="noopener noreferrer"&gt;Previously&lt;/a&gt; I had written about trying Emacs, but looking back on that post I felt like I was bit vague about the ways in which it’s changed the things I do, so I wanted to provide some examples. Emacs has replaced a number of programs in my life, and not all of them are developer related.&lt;/p&gt;

&lt;p&gt;&lt;a id="org74ef3cd"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Programming
&lt;/h1&gt;

&lt;p&gt;If you can believe it, this is maybe the most underwhelming part. Don’t get me wrong, though! Emacs is a great editor obviously, and it has all the conveniences of a more modern editor and much more. I did want to talk about what it’s like to write code in Emacs though, briefly.&lt;/p&gt;

&lt;p&gt;Being a web developer I write a lot of JavaScript, and as you’d imagine there’s a bunch of extensions in Emacs for writing JavaScript. Emacs has a package called &lt;a href="https://github.com/emacsorphanage/quickrun" rel="noopener noreferrer"&gt;quickrun&lt;/a&gt; that can evaluate code in buffers on the fly.&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%2Fryanfaulhaber.com%2Fimages%2Fquickrun.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%2Fryanfaulhaber.com%2Fimages%2Fquickrun.png" alt="img"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As someone who sometimes needs a reminder on the particularities of how certain JavaScript methods work, this is very useful!&lt;/p&gt;

&lt;p&gt;&lt;a id="org4787855"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Journaling
&lt;/h1&gt;

&lt;p&gt;I’ve always wanted to get into the habit of journaling. For the last few years of my life I’ve been through a couple of journaling apps, some of which I’ve paid for! Bur for whatever reason I could never get into the habit. I’d start out strong and then stop a week or two in, only to sporadically update.&lt;/p&gt;

&lt;p&gt;With Emacs, I’ve been journaling almost every day for the last two months or so, and it’s all thanks to &lt;a href="https://github.com/bastibe/org-journal" rel="noopener noreferrer"&gt;org-journal&lt;/a&gt; (I also think it has something to do with the fact that my journal and all my other Org documents live in the same place, and that Emacs provides a very convenient way of creating new journal entries).&lt;/p&gt;

&lt;p&gt;&lt;a id="orgbdc87e3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Blogging
&lt;/h1&gt;

&lt;p&gt;The biggest benefit of Org mode, like Markdown, is that it’s a format that can be easily translated into another format. &lt;a href="https://ox-hugo.scripter.co/" rel="noopener noreferrer"&gt;ox-hugo&lt;/a&gt;, an Org exporter geared towards converting Org documents into Hugo-compatible Markdown files, is now what I use to manage my blog. Blogging is new to me and I only have a few posts under my belt, but almost all of them have been written as Org documents and exported via ox-hugo (or just as GitHub-flavored Markdown when I post the same thing on dev.to).&lt;/p&gt;

&lt;p&gt;&lt;a id="org19c2ba9"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Note-taking
&lt;/h1&gt;

&lt;p&gt;This is the biggest change.&lt;/p&gt;

&lt;p&gt;A lot of what I read could be called academic. Before Emacs I had used Evernote, Notion, Trello, physical notebooks, and other apps that I’m probably forgetting to take notes. For some reason it had never occurred to me to take notes as plaintext (I never took notes as Markdown files), but when I learned about Org mode, it seemed natural that I’d use it to take notes.&lt;/p&gt;

&lt;p&gt;But Emacs let me take it one step further.&lt;/p&gt;

&lt;p&gt;I had been reading about &lt;a href="https://zettelkasten.de/" rel="noopener noreferrer"&gt;Zettelkasten&lt;/a&gt; and learned about &lt;a href="https://roamresearch.com/" rel="noopener noreferrer"&gt;Roam Research&lt;/a&gt;. The idea of having a flat note hierarchy with links between all your notes (structurally similar to but functionally different than a Wiki) was immediately appealing to me. Of course, because the Emacs ecosystem is so fully featured, there’s a package for that: &lt;a href="https://github.com/org-roam/org-roam" rel="noopener noreferrer"&gt;org-roam&lt;/a&gt;, which is truly a marvel of an Emacs package.&lt;/p&gt;

&lt;p&gt;Although I’m still in the process of figuring out how the Zettelkasten method can work with a Roam-like system, I’ve already taken extensive notes using org-roam: my org-roam directory currently sits at 323 files, though not all of those files have content.&lt;/p&gt;

&lt;p&gt;&lt;a id="org4a68e0f"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Email
&lt;/h1&gt;

&lt;p&gt;I never thought I’d be this person. When you hear about people “living” in Emacs, this is just part of what they mean.&lt;/p&gt;

&lt;p&gt;I host my own private email server (for a guide on how to do this yourself, I strongly recommend &lt;a href="https://www.c0ffee.net/blog/mail-server-guide/" rel="noopener noreferrer"&gt;this one&lt;/a&gt;. It’s the one I used), and I’ve never found a great or consistent email client for the desktop. The closest I came was Mailspring, which, although it is nice, it’s a bit slow for what it is.&lt;/p&gt;

&lt;p&gt;When I first started learning Emacs, I knew you could check your email with it. &lt;a href="https://www.djcbsoftware.nl/code/mu/mu4e.html" rel="noopener noreferrer"&gt;mu4e&lt;/a&gt; will let you do this. You can read, manage, and send email all from Emacs. You can even write emails as Org documents! It’s surprisingly easy and consistent to use. It’s best used when your emails are plaintext, but &lt;a href="https://useplaintext.email/" rel="noopener noreferrer"&gt;that’s generally true too&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a id="orgeaaccec"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  And plenty more…
&lt;/h1&gt;

&lt;p&gt;Emacs has changed a lot of what I do in a lot of small ways that I can’t really count. It’s really a wonderful program, and I can’t believe how much I’ve come to really love using it. Every day I feel like I’m learning something new about it, and it’s all such a joy to use! As I said in my last post, you really should give it a try.&lt;/p&gt;

</description>
      <category>emacs</category>
      <category>developer</category>
      <category>productivity</category>
    </item>
    <item>
      <title>You Should Try Emacs</title>
      <dc:creator>Ryan Faulhaber</dc:creator>
      <pubDate>Mon, 13 Jul 2020 19:59:38 +0000</pubDate>
      <link>https://forem.com/rfaulhaber/you-should-try-emacs-3lhk</link>
      <guid>https://forem.com/rfaulhaber/you-should-try-emacs-3lhk</guid>
      <description>&lt;p&gt;No, really, you should try Emacs. I gave it a shot a few months ago and now I’m hooked.&lt;/p&gt;

&lt;p&gt;I know Emacs isn’t the most trendy thing these days, in fact it seems that VS Code is the new hotness. But Emacs deserves your attention.&lt;/p&gt;

&lt;p&gt;Let me start by telling you how I arrived at Emacs: some time ago I used IntelliJ for work, almost exclusively. IntelliJ is great, honestly. You can do &lt;em&gt;a lot&lt;/em&gt; without having to leave the editor, which I came to realize was something I wanted from an editor.&lt;/p&gt;

&lt;p&gt;Some time later I switched to VS Code, and I switched for a lot of little reasons: there were a lot of plugins, the editor looked nice, the editor was more lightweight than IntelliJ, some languages I used were better supported. VS Code is also great.&lt;/p&gt;

&lt;p&gt;Then I learned Vim, and that’s where I think the real journey to Emacs began. At first I just learned Vim keybindings (press &lt;code&gt;i&lt;/code&gt; to enter “insert mode”, press &lt;code&gt;viw&lt;/code&gt; to highlight a word, etc.), and fortunately the Vim plugins for VS Code and IntelliJ supported most of what I needed to do. But whenever I’d use Vim proper in the terminal, I always realized it could do &lt;em&gt;a lot&lt;/em&gt; more, and the thing I started to realize was that I wanted all those features. The Vim plugins for VS Code and IntelliJ are, for all intents and purposes though, black boxes. Sure you could open a PR and implement some feature yourself, but why bother when Vim itself has those features? Or so was my reasoning.&lt;/p&gt;

&lt;p&gt;So for some time I switched between three editors to get various tasks done, but I still felt it wasn’t enough. I felt all three missed &lt;em&gt;something&lt;/em&gt;, but I couldn’t quite articulate what.&lt;/p&gt;

&lt;p&gt;Then I learned about &lt;a href="https://www.youtube.com/watch?v=dP1xVpMPn8M"&gt;Acme&lt;/a&gt;, the editor from the &lt;a href="https://9p.io/plan9/about.html"&gt;Plan 9 operating system&lt;/a&gt;, and my mind was blown. Acme wasn’t without its own issues, sure, but the idea that the editor itself should require almost no additional work from the user in order to gain extra features was incredible to me. In Acme, you don’t need a built-in editor command to sort a bunch of lines. Instead, you can pipe your lines through Unix’s &lt;code&gt;sort&lt;/code&gt; command and pipe the output back into the editor. Acme was as extensible as your own system was.&lt;/p&gt;

&lt;p&gt;Unfortunately, using Acme was somewhat unfeasible. I really needed syntax highlighting and Vim keybindings (once you learn them they’re very difficult to forget, and you tend to want to use them everywhere!), and that was a showstopper for me.&lt;/p&gt;

&lt;p&gt;Enter Emacs. Someone I know who was a Vim user made the switch to Emacs and was telling me how incredible it was, and at first I was skeptical. I thought Emacs was some old dusty program from the 70s that was as arcane as something like Prolog. Plus I had tried the tutorial years ago, and I thought the keybindings were weird. I was assured, though, that Emacs had a plugin called &lt;a href="https://github.com/emacs-evil/evil"&gt;Evil&lt;/a&gt; that could emulate Vim keybindings, and maybe even better than VS Code or IntelliJ (spoiler alert, it does). “Very well,” I thought, “It wouldn’t hurt to try.” I was not prepared for what Emacs had to offer.&lt;/p&gt;

&lt;p&gt;Four months in and Emacs is now the &lt;em&gt;only&lt;/em&gt; editor I use. I will say though, in the beginning, Emacs was extremely daunting. It was maybe the second hardest editor to learn after Vim (Vim took me a good month before I was productive with it). What is most daunting about Emacs though is why it’s taken over my life: it’s infinitely extensible.&lt;/p&gt;

&lt;p&gt;You may be skeptical. You might think “Well VS Code is extensible!” Indeed, it is. But Emacs is extensible to a degree that’s easy to underestimate. For all intents and purposes, Emacs is a &lt;a href="https://en.wikipedia.org/wiki/Lisp_machine"&gt;Lisp machine&lt;/a&gt;. Emacs, much like your browser, provides an entire platform upon which functionality can be built. In your browser’s case, that functionality is written in JavaScript. In Emacs, it’s Lisp (specifically Emacs Lisp). Moving the cursor in any direction, for example, is a binding between a key press and a Lisp function.&lt;/p&gt;

&lt;p&gt;I’d argue that extensibility and customizability are crucial for productivity. Everyone is different and as such I imagine we all use our computers a bit differently. Emacs is extremely accommodating to whatever your workflow is, provided you’re willing to put in a bit of effort to customize Emacs.&lt;/p&gt;

&lt;p&gt;In some ways, Emacs is the equal but opposite of Acme. Emacs provides &lt;em&gt;a lot&lt;/em&gt; of tools. But unlike an editor like VS Code, editing Emacs is as easy as opening a new buffer (a collection of text that may or may not correspond to a file), writing some Emacs Lisp, evaluating it on the fly, and with just a few lines of Lisp you have a new plugin.&lt;/p&gt;

&lt;p&gt;I’ve emphasized Emacs’s extensibility thus far, and I think that should be its main selling point. Emacs is so extensible that there are pre-configurations of Emacs to &lt;a href="https://github.com/hlissner/doom-emacs"&gt;make it look something like VS Code&lt;/a&gt; (Doom Emacs is wonderful. It’s what I use and what got me into Emacs). It’s so extensible that it can be used &lt;a href="https://www.djcbsoftware.nl/code/mu/mu4e.html"&gt;as an email client&lt;/a&gt; and &lt;a href="https://github.com/hayamiz/twittering-mode"&gt;Twitter browser&lt;/a&gt;. And what’s incredible about all these extensions is that Emacs will carry all your configuration and keybindings around to all these different contexts. If you’re a Vim user, being able to do things like check your email or use &lt;a href="https://magit.vc/"&gt;Emacs’s Git client&lt;/a&gt; with Vim keybindings is wonderful.&lt;/p&gt;

&lt;p&gt;(Side note: I never actually used a Git client before using Emacs. Magit is maybe the only one I could ever see myself using.)&lt;/p&gt;

&lt;p&gt;And lest I forget, Emacs also has something called &lt;a href="https://orgmode.org/"&gt;Org mode&lt;/a&gt;. For a more comprehensive introduction, I recommend &lt;a href="https://youtu.be/SzA2YODtgK4"&gt;this video&lt;/a&gt;. Org mode on its surface can be thought of a more feature-complete Markdown: it’s a plaintext syntax that is designed with the intention of rendering as something else, including but not limited to HTML. However Org mode in its own right is very powerful because it’s backed up by Emacs. Org mode documents can be used as interactive todo lists and agendas. Like Markdown, Org mode supports source code blocks. Unlike Markdown (at least inherently), Emacs can actually evaluate Org source code blocks for some supported languages. You can use this to write documentation to, for example, illustrate what some block of code prints to the console. Or, since Org mode can evaluate Emacs Lisp, you could &lt;a href="https://github.com/hrs/dotfiles/blob/main/emacs/dot-emacs.d/configuration.org"&gt;write your entire Emacs confugration as an Org document&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So, if you’re in the business of text editing, and you’re used to having to fine-tune configuration to get the exact outcome you want, I strongly suggest at least giving Emacs a try. I feel like Emacs is an often forgotten about editor, and I think it deserves a shot.&lt;/p&gt;

&lt;p&gt;Do you use Emacs, or have you ever used it in the past? What do you think about it?&lt;/p&gt;




&lt;p&gt;I'm a software developer working in full-stack web development. I'm also interested in systems programming, programming languages, and computer science in general. Follow me on &lt;a href="https://dev.to/rfaulhaber"&gt;dev.to&lt;/a&gt; and &lt;a href="https://twitter.com/ryan_faulhaber"&gt;Twitter&lt;/a&gt;, and check out &lt;a href="https://ryanfaulhaber.com"&gt;my site&lt;/a&gt; and &lt;a href="https://github.com/rfaulhaber"&gt;GitHub&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>emacs</category>
      <category>technology</category>
      <category>developer</category>
      <category>ide</category>
    </item>
  </channel>
</rss>
