<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alec Magnet on Medium]]></title>
        <description><![CDATA[Stories by Alec Magnet on Medium]]></description>
        <link>https://medium.com/@alecmagnet?source=rss-42a8a2b664f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Ku2-D6wIIe9PyN9u.jpg</url>
            <title>Stories by Alec Magnet on Medium</title>
            <link>https://medium.com/@alecmagnet?source=rss-42a8a2b664f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 14:04:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alecmagnet/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Check Out Marginalia, My Final Project for Coding Bootcamp]]></title>
            <link>https://medium.com/@alecmagnet/check-out-marginalia-my-final-project-for-coding-bootcamp-796893c29a11?source=rss-42a8a2b664f------2</link>
            <guid isPermaLink="false">https://medium.com/p/796893c29a11</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[final-project]]></category>
            <category><![CDATA[codingbootcamp]]></category>
            <dc:creator><![CDATA[Alec Magnet]]></dc:creator>
            <pubDate>Sun, 07 Nov 2021 00:08:43 GMT</pubDate>
            <atom:updated>2021-11-09T20:01:57.377Z</atom:updated>
            <content:encoded><![CDATA[<p>A few weeks ago, I graduated from Flatiron’s software engineering bootcamp. Since then, I’ve been adding features and polishing up the code for my final project, <a href="https://magnets-marginalia.herokuapp.com/"><strong>Marginalia</strong></a>. It’s still a work in progress, but it’s live, so click the link to take a look! You can also check out the <a href="https://github.com/alecmagnet/marginalia">repo on GitHub</a> or watch a demo video below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fg2aug6ulkn4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dg2aug6ulkn4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fg2aug6ulkn4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fabb8150924fa829ffc943103736d83f/href">https://medium.com/media/fabb8150924fa829ffc943103736d83f/href</a></iframe><h3>What Is Marginalia</h3><p>Marginalia is a social reading and annotation site where people can have conversations with one another about literary works they share and read.</p><p>The word <em>marginalia</em> refers to the notes and markings that readers make in the margins of page. These notes leave traces of a reader’s progress through a text. They also provide a way for readers to communicate with one another, sometimes from across centuries. The first poem in our database — appropriately, “<a href="https://magnets-marginalia.herokuapp.com/texts/1">Marginalia</a>” by Billy Collins — conveys how moving these moments of unexpected contact with another reader can be.</p><p>This app, Marginalia, seeks to restore the social dimension of reading by providing a venue for readers to speak with one another through the comments they leave on literary texts.</p><h3>How Was It Made?</h3><p>I coded Marginalia using JS, React, Redux, Ruby, and Rails, along with several other dependencies, including <a href="https://mui.com/">MUI</a>, <a href="https://quilljs.com/">Quill</a>, <a href="https://github.com/zenoamaro/react-quill">React-Quill</a>, <a href="https://github.com/remarkablemark/html-react-parser#readme">html-react-parser</a>, <a href="https://github.com/rails/rails-html-sanitizer">Rails Html Sanitizers</a>, and <a href="https://github.com/bcrypt-ruby/bcrypt-ruby">bcrypt</a>.</p><p>Through trial and a <em>lot</em> of error, I learned a crucial lesson about coding, which I plan to apply from here on out: <strong>Plan for modularity by making your code as straightforward and standardized as possible!</strong></p><p>Since you can’t anticipate all the ways you might reuse a component, each one needs to be flexible.</p><p>The main thing that tripped me up here was style. I taught myself to use MUI as I went, so the components I wrote early on use a lot of unnecessary styling that only really works in the instance where I first call them. As I update this project, I hope to simplify my style and make those components more reusable.</p><p>Another thing you’ll notice as you look through my repo is that I learned how to make my code drier along the way. That, too, requires simple, standardized code. It’s harder to map through an array of menu items if you need to put different sx props on the first and last ones. I got much better at this as I went. Next time, I won’t give myself so many tangles to smooth out and refactor.</p><h3>What Can You Do on Marginalia?</h3><p>A user of Marginalia can:</p><ul><li>Securely sign up, log in, log out, and remain authorized on refresh</li><li>Upload poems, stories, and other literary texts</li><li>Edit texts they uploaded</li><li>Or, if the user is a “librarian” user-type, edit any uploaded text</li><li>Browse, search, filter, and read those texts</li><li>Post comments on texts and replies to other comments</li><li>Edit and delete their own comments</li><li>If a comment has replies or is a reply, deleting it will leave a ghost that says “comment was deleted” rather than simply vanishing</li><li>Assign their comments multiple comment types, such “question” or “critique”</li><li>Add and remove comment types from their comments</li><li>Browse, search, and filter all comments on a particular text</li><li>Browse, search, and filter other users’ profiles</li><li>Edit their own profile</li><li>Delete their account</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZOn3BQloCA4Xg_iJncvqmQ.png" /><figcaption>Marginalia’s homepage</figcaption></figure><h3>What Features Remain to be Added</h3><p>This app was an ambitious project for me. I taught myself Redux and MUI from scratch to build it, and I learned a ton along the way. Even after the weeks I’ve worked on it since graduating, there are still a number of features I’d like to add.</p><p>The most important is that I would like users to be able to comment not just on a whole text, but also on one specific line of a poem or one sentence of a story. I’m not sure how I’ll make that work yet, but here’s my plan so far:</p><p>I’ll add a new table to my database called passages and update my models so that each litText has_many passages and each passage has_many comments. When a user uploads a text, I’ll break the content up and create a new passage for each unit. Poems will be more straightforward, since each line can be a unit, but I still need to figure out exactly how to do it with prose texts. Then I’ll refactor how I’m rendering them on the front-end so that, when a user hovers over a passage, it highlights in yellow, and when a user clicks on one, all the comments that belong to it appear, along with a form to post a new comment.</p><p>I’d also like to create a model for hashtags that a user could add to both comments and texts. That way, I could learn how to use <a href="https://www.itsolutionstuff.com/post/laravel-many-to-many-polymorphic-relationship-tutorialexample.html">polymorphic many-to-many relationships</a> — each hashtag would have_many taggables, which could be either comments or texts.</p><p>In fact, there are many more features I’d like to add, but the last one I’ll mention here is a search field within the Navbar. After a user types in three or four characters, I’d have a popper appear underneath. The popper would call a component that filters through all the texts, comments, and user profiles and displays previews of any that contain the phrase typed into the search field. I might reuse the container components for Members and Library — after all, modularity is the name of the game! But I’d like the previews to be narrower, so that I can include several columns of them.</p><h3>Who Made It?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/0*LWDto_jHOLR3k_XV" /></figure><p>I did. Hello! My name is Alec Magnet. I graduate from coding bootcamp in October 2021 after thirteen years teaching literature and writing at the City College of New York, Marymount Manhattan College, and elsewhere. Now I’m looking for a full-stack software engineering position where I can put the talents and enthusiasm I developed as an educator to use building tools people can use to learn, grow, and flourish.</p><p>Check me out on <a href="https://www.linkedin.com/in/alec-magnet/">LinkedIn</a> or <a href="https://github.com/alecmagnet">GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=796893c29a11" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Functions, Not Conditionals, While Awaiting Data in a React Component]]></title>
            <link>https://medium.com/codex/use-functions-not-conditionals-while-awaiting-data-in-a-react-component-20dcdced8120?source=rss-42a8a2b664f------2</link>
            <guid isPermaLink="false">https://medium.com/p/20dcdced8120</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[fetch]]></category>
            <dc:creator><![CDATA[Alec Magnet]]></dc:creator>
            <pubDate>Sun, 17 Oct 2021 23:58:59 GMT</pubDate>
            <atom:updated>2021-10-18T16:41:13.553Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="A robot floating in space with a question mark above its head contemplates putting a coin, labeled “input,” into a gumball machine, labeled “functional machine”" src="https://cdn-images-1.medium.com/max/1024/1*Q9iKYn-x3Fsu0ohQat5Scw.png" /><figcaption>“<a href="https://medium.com/madhash/what-exactly-is-functional-programming-ea02c86753fd">Robot Wants Gumball from Functional Machine</a>” by Aphinya Dechalert</figcaption></figure><p>If you’ve found your way to this post, then you may be struggling with how to keep everything from breaking in a React component that’s waiting for the response to a fetch request.</p><p>Let’s say you’re making a simple blogging app. You set up a component called PostsContainer with a useEffect that fetches the posts from your backend. In the milliseconds it takes for the fetch to run, PostsContainer will start to render, as will any child components that it calls. How to keep it from breaking?</p><p>Well, if your a bootcamp student or recent graduate like me, your instructors may have taught you to set a conditional in your return. Like this:</p><pre>export default function PostsContainer() {<br>  const [posts, setPosts] = useState([])<br>  useEffect(() =&gt; {<br>   <em> // fetch posts and set state</em><br>  }<br>  <em>// other stuff</em><br>  return (<br>    {posts.length === 0 ? &lt;h1&gt;Loading...&lt;/h1&gt; :<br>      <em>// what you actually want on the DOM</em></pre><p>That’s great. That’ll work. But what about <em>// other stuff</em>? What if you need to iterate through those posts and do anything with them before you render? You <em>do </em>need to do that!</p><figure><img alt="A smiling man looks at a complicated cartoon computer with old-fashioned components labeled “map( ),” “filter( ),” and “reduce( )”" src="https://cdn-images-1.medium.com/max/1024/1*G4NnKLgO3uioVlNBSa9cag.jpeg" /><figcaption>We’re talking about JavaScript, not Python, but the concepts remain the same (<a href="https://realpython.com/python-functional-programming/">credit</a>)</figcaption></figure><p>Well, extrapolating what what you’ve learned, you might just set the same kind of conditional for each thing you need to do:</p><pre>let filteredPosts = []<br>if (posts.length &gt; 0) {<br>  filteredPosts = posts.filter(post =&gt; {<br>    <em>// whatever you want to filter by</em></pre><p>It may the job done, but it’s messy and prone to unexpected errors. It’s also not very <em>dry</em>. You’ll be writing versions of if (thing) or let thing = {}on line after line. Worst of all, it may still break your code. What if you’re testing the length of a deeply nested array that simply doesn’t exist until your fetch returns a response and your state updates? How elaborately will you have to design your empty variable to keep everything from crashing down in those few milliseconds of waiting?</p><p><strong>So here’s a better way. Don’t write these as conditionals. Write them as functions:</strong></p><pre>const filteredPosts = () =&gt; posts.filter(post =&gt; <em>// etc.</em></pre><p>Then, call these functions inside your return.</p><p>Where you would have written &lt;div&gt;{filteredPosts}&lt;/div&gt; in the first example, now write &lt;div&gt;{filteredPosts()}&lt;/div&gt; with the magic bananas to invoke it. That way, the logic inside that function only runs once you hit that line in the return statement, which you’ll only do if posts.length &gt; 0.</p><figure><img alt="Two bananas facing each other so that they look like parentheses" src="https://cdn-images-1.medium.com/max/1024/1*311R5bwmvjL2umIvYynjaQ.jpeg" /><figcaption>(<a href="http://texturetaddka.com/ripe-yellow-banana-textures">source</a>)</figcaption></figure><p>Hooray!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20dcdced8120" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/use-functions-not-conditionals-while-awaiting-data-in-a-react-component-20dcdced8120">Use Functions, Not Conditionals, While Awaiting Data in a React Component</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On Graduating Bootcamp and Being a Coder]]></title>
            <link>https://medium.com/codex/on-graduating-bootcamp-and-being-a-coder-ffe574f18439?source=rss-42a8a2b664f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffe574f18439</guid>
            <category><![CDATA[graduation]]></category>
            <category><![CDATA[codingbootcamp]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Alec Magnet]]></dc:creator>
            <pubDate>Sat, 09 Oct 2021 20:00:55 GMT</pubDate>
            <atom:updated>2021-10-12T16:09:08.527Z</atom:updated>
            <content:encoded><![CDATA[<p>Well, I graduated from software engineering bootcamp yesterday. Now I am several things: I’m exhausted. I’m inordinately proud of myself. And I am, I guess, a software engineer.</p><p>This graduation was not like others I’ve experienced. None is, really, in this time of the pandemic. Seeing a slide with a photo of your face when your name is called feels much less momentous than standing, walking, and being handed a physical copy of your diploma.</p><p>But this graduation was different in a more fundamental way, too — a way that says something important about coding.</p><p>After other graduations, you are officially a <em>thing: </em>a bachelor, a master, a doctor. You’re credentialed. If you want, you can even add some letters after your name. What am I after graduating from coding bootcamp?</p><p>Well, I’m a coder. I’m a software engineer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*EwDssofydzRDZzwyht3v_A.jpeg" /></figure><p>In a way, though, I already was. For the last month or so, the teachers at Flatiron have been telling my classmates and I to list ourselves on LinkedIn as software engineers, not software engineering students.</p><p>As a teacher myself for thirteen years — and a student of some sort or another for most of my life — I have an almost superstitious reverence for academic formality, so I haven’t yet.</p><p>But I see their point. Being a coder is about coding.You don’t have to have letters after your name to be a software engineer. You have to know how to code.</p><p>Nothing says that more than the fact that there were recent computer science grads with me in the program.</p><p>Well, no, actually. There are things that say that more: It’s the day after graduation, and already the Slack workspace that my first bootcamp friends and I made for our cohort is alive with messages about algo problems on Codewars and LeetCode.</p><p>It’s the day after graduation, and I’ve already started doing practice problems for my first technical assessment.</p><p>We’re coders because we code. Not because we’re credentialed, but because we put the work in, we keep on learning, and we code.</p><p>I’m going to go update the headline on <a href="https://www.linkedin.com/in/alec-magnet/">my LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffe574f18439" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/on-graduating-bootcamp-and-being-a-coder-ffe574f18439">On Graduating Bootcamp and Being a Coder</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Coding as Sorcery: Redux and the Shadesmar]]></title>
            <link>https://medium.com/geekculture/coding-as-sorcery-redux-and-the-shadesmar-33c4006efd47?source=rss-42a8a2b664f------2</link>
            <guid isPermaLink="false">https://medium.com/p/33c4006efd47</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[magic]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[fantasy]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Alec Magnet]]></dc:creator>
            <pubDate>Thu, 07 Oct 2021 07:57:29 GMT</pubDate>
            <atom:updated>2021-10-07T22:17:34.022Z</atom:updated>
            <content:encoded><![CDATA[<p>If coding is sorcery (and it is), then how do different concept in coding compare to the facets of various magic systems from fantasy fiction, mythology, and the history of the dark arts? That’s the question this series explores. (Here are parts <a href="https://medium.com/codex/oop-magic-systems-and-the-allegory-of-the-cave-bf891c4cdf0e">one</a> and <a href="https://medium.com/geekculture/coding-is-sorcery-potions-object-composition-in-javascript-245310cfb405">two</a>.)</p><p>This time around, we’ll be delving into one of the most widely used front-end libraries, <a href="https://redux.js.org/">Redux</a>, and the latest offering from one of the most precise and thoughtful crafters of magic systems in fantasy fiction, Brandon Sanderson’s <a href="https://en.wikipedia.org/wiki/The_Stormlight_Archive"><em>The Stormlight Archive</em></a><em>.</em> (Mild spoilers ahead. Be forewarned!)</p><figure><img alt="Szeth and Shallan from “The Words of Radiance”" src="https://cdn-images-1.medium.com/max/1024/1*VQFZUAr3xWNcaQCEtLb6Lg.jpeg" /><figcaption>Szeth and Shallan from “<em>Stormlight,” a composite of </em><a href="https://bluehighwind.blogspot.com/2014/04/the-stormlight-archive-words-of-radiance.html"><em>two artworks</em></a><em> by </em><a href="https://www.michaelwhelan.com/"><em>Michael Whelan</em></a><em> (</em><a href="https://wallpaperaccess.com/stormlight-archive"><em>via</em></a><em>)</em></figcaption></figure><h3>What Is Redux?</h3><p>Redux is a predictable state-management tool for Javascript applications — essentially, an architecture for controlling an app’s data-flow and accessing the most current data from one part of an app to another. In software engineering, “state” refers the remembered information of previous events and user interactions. When you type a comment into an input field, for example, each keystroke changes the state of that component of the application, updating it so that the latest state reflects everything up to the last thing you typed. While you’re typing your comment, only the form you’re typing in needs to record your draft in state. But once you post it, other parts of the app need to know that you did so. That’s where state management comes in.</p><p>Redux especially popular to use with <a href="https://reactjs.org/">React.js</a> — so much so that the Redux team put out an official <a href="https://react-redux.js.org/">React-Redux</a> library. I began to teach myself how to use Redux while working on my final project for coding bootcamp, a social annotation app called Marginalia. (<a href="https://github.com/alecmagnet/marginalia">Check it out</a> on Github.) Here’s an example of why I needed something to manage my state:</p><p>Let’s say you post a comment interpreting some phrase from a poem or short story. The component rendering that poem sends your comment off to the backend to be stored in the database and updates the page to include your comment. Sick! But then you look at your comment and think, “Jeez, I really need to update my profile pic. I took that in the middle of lockdown, and I’m looking much more well-kempt these days.” So you navigate over to the profile edit page. You don’t want the whole app to reload and fetch all of the data for every component again. That would slow things down like crazy. But how is your profile page supposed to know that you posted that comment and add it, say, to list of previews and links? Well, that’s what Redux is for. Redux saves whatever state you need to be available throughout your app in an object that any component can access.</p><p>So, aside from their strikingly similar logos, what does Redux have to do with <em>The Stormlight Archive </em>and its supernatural realm, Shadesmar?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8XBeSHRIPWDIpUyFbSuTcA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*wLwWZDApELWz8jgI78SIAA.jpeg" /><figcaption><a href="https://regroove.ca/blog/react-redux/">React, Redux</a>, &amp; <a href="https://www.brandonsanderson.com/alternate-stormlight-symbol-reveal/">Stormlight</a></figcaption></figure><h3>What Is the Shadesmar?</h3><p>Brandon Sanderson crafts his magic systems with precise attention and care. (He’d better — nothing less would befit the writer who first proposed distinguishing “hard” and “soft” fantasy based on how rigorous and well-defined their magic systems are. It may sound like a kinda obnoxious distinction, but in fact it’s pretty brilliant, since both, according to Sanderson, can equally support good storytelling in different ways. That, however, is a blog post for another time.)</p><p>Only the first four <em>Stormlight </em>novels in a planned series of ten have been published. But — between them and a couple of smaller novellas — the series runs somewhere between three and four thousand pages so far. There’s no way even to summarize Sanderson’s intricate worldbuilding and magic system in this post, so I’m going to focus on just a couple of aspect. That said, <strong>SPOILER ALERT! </strong>Some of what I’m about to describe takes thousands of pages to be revealed. Proceed at your own peril.</p><p>The world of <em>Stormlight</em> is divided up into three realms, the physical, spiritual, and cognitive. This last one, also known as the Shadesmar, bridges the other two.</p><figure><img alt="a map of the Shadesmar or cognitive realm" src="https://cdn-images-1.medium.com/max/750/1*pBK0zZYy5-WY7SS3MlCk5A.jpeg" /><figcaption>Shadesmar Map by <a href="https://coppermind.net/wiki/Isaac_Stewart">Isaac Stewart</a> (via <a href="https://stormlightarchive.fandom.com/wiki/Shadesmar">Fandom</a>)</figcaption></figure><p>Certain people (and, I guess, entities) are able to travel between these realms, or at least between the physical realm and Shadesmar, especially <a href="https://stormlightarchive.fandom.com/wiki/Surgebinding">surgebinders</a>, or people who can harness the power of the natural and magical world. Within the cognitive realm is a reflection of each thing that exists in the physical realm — a cognitive model, perhaps, or something like a mental soul. Some <a href="https://stormlightarchive.fandom.com/wiki/Soulcasting">surgebinders</a> can access these models and even change them — a power known as soulcasting — which changes their corresponding duplicate in the physical realm.</p><h3>What Is the Analogy Between Them?</h3><p>If all of this sounds complicated, that’s because it is. Then again, so is Redux. In fact, Redux can be so notoriously tricky to implement that the first thing that came up when I searched “redux react” on Giphy was this (which tells you a lot about — both about how frustrating Redux can be and about how useful it is when you get it working):</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FfVUvmalt2zAOzJUhKn%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fdemocraticmemefactory-nohatespeech-nohate-counterspeech-fVUvmalt2zAOzJUhKn&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2FfVUvmalt2zAOzJUhKn%2Fgiphy.gif%3Fcid%3D790b76110e03373eba221b18e349ff44cdb5362c5849c021%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e0c662e6f0793dafe2c836c74162e71/href">https://medium.com/media/5e0c662e6f0793dafe2c836c74162e71/href</a></iframe><p>That said, Redux is not terribly hard to understand conceptually, and it provides some handy parallels to help explain the magic of <em>Stormlight</em>. One of thinking of Shadesmar, in fact, is by way of analogy with Redux’s universal state object. Behind the user interface of your website — the physical world — is a cognitive realm storing all the shared state of every component everywhere in the application. It’s behind your UI, but it’s still the frontend. (I suppose in this analogy your backend would be the spiritual realm. Sanderson hasn’t gotten that far in what he’s written, but I suspect that metaphor will begin to crumble at this point when he does.)</p><p>Using Redux, you can access this cognitive realm behind the front-line interface. You can call on hooks — React’s and Redux’s version of surges — to find information in that realm (useSelector) and to change it (useDispatch), thereby changing what’s displayed on the DOM, a web-app’s equivalent for the physical realm.</p><h3>Reflections and Metamorphoses</h3><p>This post actually marks an important turning point for me. For the first time in this series, my knowledge of coding is more useful to help explain the magic system in question, rather than the other way around.</p><p>To some degree, that’s a product of just how complex and intricate Sanderson’s magic systems tend to be. But I’d like to pause here and reflect on the other reality this change reflects — the fact that, in these fifteen weeks of bootcamp, I’ve learned enough about coding that my brain reflexively jumps to code libraries for analogies to help explain tricky concepts. Tomorrow, I graduate, and this experience has truly wrought a metamorphosis in my own cognitive realm, soulcasting and rewiring my brain into that of a coder.</p><p>I’m going to keep this series going, though. As ever, please let me know what you think about the topic of this post. I love to hear your thoughts!</p><figure><img alt="Pattern and Shallan, two characters from the Stormlight Archive, in a mystical-looking landscape." src="https://cdn-images-1.medium.com/max/700/1*p6DpFnIcKvpavYAyJDdbMw.jpeg" /><figcaption>Fanart of Pattern and Shallan in Shadesmar by <a href="https://www.deviantart.com/gondalier/art/Shadesmar-494029111">Gondalier</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33c4006efd47" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/coding-as-sorcery-redux-and-the-shadesmar-33c4006efd47">Coding as Sorcery: Redux and the Shadesmar</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Coding as Sorcery: Potions & Object Composition in JavaScript]]></title>
            <link>https://medium.com/geekculture/coding-is-sorcery-potions-object-composition-in-javascript-245310cfb405?source=rss-42a8a2b664f------2</link>
            <guid isPermaLink="false">https://medium.com/p/245310cfb405</guid>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[magic]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Alec Magnet]]></dc:creator>
            <pubDate>Mon, 13 Sep 2021 19:51:19 GMT</pubDate>
            <atom:updated>2021-10-07T05:37:21.985Z</atom:updated>
            <content:encoded><![CDATA[<p>If coding is sorcery (and it is), then how do different concept in coding compare to the facets of various magic systems from fantasy fiction, mythology, and the history of the dark arts?</p><p>This time around, I’ll be looking at object-oriented Javascript, and specifically the way <strong>object composition</strong> resembles brewing up potions.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FQaBBC9KOUw5tP31DeS%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fcartoonnetwork-sci-new-animation-julia-pott-QaBBC9KOUw5tP31DeS&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2FQaBBC9KOUw5tP31DeS%2Fgiphy.gif%3Fcid%3D790b76110f9563bd6264af6c71b555a12d98070b54e7ee81%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc6e848d710188fc7aeae07876c71fb3/href">https://medium.com/media/cc6e848d710188fc7aeae07876c71fb3/href</a></iframe><p>In <a href="https://medium.com/codex/oop-magic-systems-and-the-allegory-of-the-cave-bf891c4cdf0e">my last post</a>, I compared class inheritance in Ruby to the magic of the true name, a magical feature that shows up throughout the history of magic and myth, from <a href="https://www.ucl.ac.uk/museums-static/digitalegypt/literature/isisandra.html">ancient</a> <a href="https://web.archive.org/web/20110211013949/http://www.reshafim.org.il/ad/egypt/texts/shabaka_stone.htm">Egypt</a> to Ursula Le Guin’s <em>Earthsea </em>series or Patrick Rothfuss’s <em>The Name of the Wind.</em> In Ruby, if we know, for example, that Ged’s boat lookfar in <em>A Wizard of Earthsea </em>is an instance of the class Boat, then we also know a bunch of information about lookfar and a bunch of methods we can call on it:</p><pre>$ lookfar.sails <br># =&gt; mainsail</pre><figure><img alt="A drawing of two people in a sailing boat with one sail on a dark sea with a dark, ominous sky behind them" src="https://cdn-images-1.medium.com/max/1024/1*I9QVTt1fONyAag5v9ITVKg.jpeg" /><figcaption>Fanart by <a href="https://www.deviantart.com/ffaunax/art/Lookfar-at-the-world-s-end-880089346">Ffaunax</a> of Ged and Vetch in the boat Lookfar from Le Guin’s “A Wizard of Earthsea”</figcaption></figure><p>Moreover, if we know that Boat as a class inherits from WaterCraft, then we know even more about it, since Boat inherits the methods from WaterCraft.</p><h3>Prototype Inheritance vs. Class Inheritance</h3><p>JavaScript, however, does not use class inheritance in exactly the way Ruby does. In Ruby, an object is an instance of a class, which inherits methods and data from other classes. Starting with ES6, JavaScript includes the keyword class, but it is a bit of syntactical sugar standing in for a constructor function that links two objects together through <em>prototypal inheritance.</em></p><pre>class MyClass {}<br>typeof MyClass<br><em>#=&gt; function</em></pre><p>What is the difference? Just about everything in JavaScript is an object, and each object has a private property that links it to another object, its <em>prototype, </em>all the way back to the global object, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects">Object</a> (not to be confused with the more general term <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects"><em>global objects</em></a><em>,</em> meaning standard built-in objects or objects in the global scope).</p><p>There’s a lot of debate about which system works better.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fv40uv76TcIzaZ3KoBa%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fstar-wars-senate-v40uv76TcIzaZ3KoBa&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv40uv76TcIzaZ3KoBa%2Fgiphy.gif%3Fcid%3D790b76113e16f3a230b069569444b5ea55998d07a69e1cd2%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d1f9c5cef8c5287aa4578ead88d2e94/href">https://medium.com/media/0d1f9c5cef8c5287aa4578ead88d2e94/href</a></iframe><p>I’m not going to get into it. Instead, let’s talk about one of the techniques that prototypal inheritance allows us to use — defining objects by brewing them up like potions using <strong>object composition</strong>.</p><h3>What Is Object Composition?</h3><p>Instead of defining classes that inherit all the info &amp; methods of a their parent class, JavaScript’s prototypal inheritance allows us to define objects that inherit just the stuff you really need. Here’s how it works:</p><pre>const snakeFang = { snakeFang: 6 }<br>const pocupineQuill = { porcupineQuill: 2 }<br>const wolfsbaneSprig = { wolfsbaneSprig: 1 }<br>const valerianRoot = { valerianRoot: 1 }</pre><pre>const WideyePotion = (options) =&gt; {<br>  return Object.assign({}, snakeFang, wolfsbaneSprig, options)<br>}</pre><pre>const CureForBoilsPotion = (options) =&gt; {<br>  return Object.assign({}, snakeFang, pocupineQuill, options)<br>}</pre><pre>const DraughtOfPeace = (options) =&gt; {<br>  return Object.assign({}, pocupineQuill, valerianRoot, options)<br>}</pre><p>(I’ve simplified these recipes, but you get the idea. Still, don’t try them at home.)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FU5Dg7awkAwBDmNbWzp%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fharrypotter-U5Dg7awkAwBDmNbWzp&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2FU5Dg7awkAwBDmNbWzp%2Fgiphy.gif%3Fcid%3D790b76116e1c8ed1d669abed411a8ae02ba365144d456b95%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="293" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdec727f2150c0a6c5c6f9dfa79770b6/href">https://medium.com/media/cdec727f2150c0a6c5c6f9dfa79770b6/href</a></iframe><p>In this example, our ingredients are what is known as <strong>mixins.</strong> What is a mixin? The name says it all — you mix it in. According to <a href="https://javascript.info/mixins"><em>JavaScript.info</em></a><em>,</em></p><blockquote>a <a href="https://en.wikipedia.org/wiki/Mixin">mixin</a> is a class containing methods that can be used by other classes without a need to inherit from it.</blockquote><p>Composing an object with mixins lets us include only the ingredients we want to include in our potion. Why is that such a big deal?</p><h3>Favor Composition over Inheritance</h3><blockquote>“Favor object composition over class inheritance.” ~The Gang of Four, “<a href="https://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;camp=213733&amp;creative=393185&amp;creativeASIN=0201633612&amp;linkCode=shr&amp;tag=eejs-20&amp;linkId=WMUILDJNIUXY4NSH">Design Patterns: Elements of Reusable Object Oriented Software</a>”</blockquote><p>Picking and choosing the ingredients of our objects helps us avoid some of the major pitfalls of class inheritance. It makes your code flexible, whereas inheritance hierarchies necessarily become <em>in</em>flexible, requiring you to duplicate code in order to shoehorn in new features that your existing code cannot be adapted to accommodate.</p><p>Further, saves us from what is called the gorilla/banana problem of class inheritance: even if you only need to use one method from the parent class, the child class still inherits the whole megillah. As <a href="https://en.wikipedia.org/wiki/Joe_Armstrong_(programmer)">Joe Armstrong</a>, the creator of the programming language <a href="https://en.wikipedia.org/wiki/Erlang_(programming_language)">Erlang</a> explained,</p><blockquote>[T]he problem with object-oriented languages is they’ve got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.</blockquote><figure><img alt="a gorilla staring closely at a banana" src="https://cdn-images-1.medium.com/max/500/1*PboCTr_gzuCZ8voG7Qg5qA.jpeg" /><figcaption>There’s a flaw in this metaphor. Gorillas in the wild don’t generally eat bananas because wild bananas are often barely edible and sometimes even toxic. They do love human-engineered bananas if they can get their hands on them, but then you’d be inheriting agriculture, not the entire jungle.</figcaption></figure><p>In our potions analogy, class inheritance would require us to put everything in the world into our cauldron, then somehow tell our potion only to be made out of the things we actually wanted.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3o7buaSlNzz1PlkivC%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fcooking-witch-looney-tunes-3o7buaSlNzz1PlkivC&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2F3o7buaSlNzz1PlkivC%2Fgiphy.gif%3Fcid%3D790b76115ef280db667b9213c8835604f3515b64dda608cf%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="290" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae7ec1073fa235dd1060b149039f3976/href">https://medium.com/media/ae7ec1073fa235dd1060b149039f3976/href</a></iframe><h3>Let Me Know What You Think!</h3><p>As always, I’d love to know your thoughts on the analogies and overlaps between coding and magic. Please write me a response here on <em>Medium</em> or drop me a line on <a href="https://www.linkedin.com/in/alec-magnet/">LinkedIn</a> to keep this conversation rolling!</p><figure><img alt="A wizard with a long white beard and a pointy hat stirs a bubbling cauldron in the woods at night while several small vials of red liquid levitate around him." src="https://cdn-images-1.medium.com/max/853/1*AG3eYG1UVVdM1VC714mAQw.jpeg" /></figure><h3>Sources</h3><p>Eric Elliot, “<a href="https://medium.com/javascript-scene/master-the-javascript-interview-what-s-the-difference-between-class-prototypal-inheritance-e4cd0a7562e9#.h96dymht1">Master the JavaScript Interview: What’s the Difference Between Class &amp; Prototypal Inheritance?</a>”</p><p>— — — , “<a href="https://medium.com/javascript-scene/3-different-kinds-of-prototypal-inheritance-es6-edition-32d777fa16c9">3 Different Kinds of Prototypal Inheritance: ES6+ Edition</a>”</p><p>Alex Jover Morales, “<a href="https://alligator.io/js/class-composition/#:~:text=A%20common%20composition%20pattern%20in,have%20an%20Animal%20and%20FlyingAnimal%20.">Class Composition in JavaScript</a>”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=245310cfb405" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/coding-is-sorcery-potions-object-composition-in-javascript-245310cfb405">Coding as Sorcery: Potions &amp; Object Composition in JavaScript</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Coding as Sorcery, Part 1: OOP and the Magic of the True Name]]></title>
            <link>https://medium.com/codex/oop-magic-systems-and-the-allegory-of-the-cave-bf891c4cdf0e?source=rss-42a8a2b664f------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf891c4cdf0e</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[magic]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Alec Magnet]]></dc:creator>
            <pubDate>Tue, 24 Aug 2021 06:09:52 GMT</pubDate>
            <atom:updated>2021-10-07T15:29:32.184Z</atom:updated>
            <content:encoded><![CDATA[<h3>Coding as Sorcery: OOP and the Magic of the True Name</h3><p>Software coding is a lot like sorcery. You string together arcane and powerful words and symbols, and then the world — or at least your webapp — changes. New elements appear or disappear on the page. Forms and inputs change both what’s displayed and what’s in your in your database.</p><p>When you first start learning, your code feels a lot like <em>Harry Potter </em>magic — just some abracadabra-sounding gobbledygook that makes things happen for unspecified reasons (probably because it looks like Latin).</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FpI2paNxecnUNW%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fharry-potter-hermione-granger-ronald-weasley-pI2paNxecnUNW&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2FpI2paNxecnUNW%2F200.gif%3Fcid%3D790b7611d1158444f652d62877a056e111b7cccb89fef5de%26rid%3D200.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="257" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6c8f1383f59079017d1ce02aaa5f40c/href">https://medium.com/media/f6c8f1383f59079017d1ce02aaa5f40c/href</a></iframe><p>As you get deeper into coding, though, you start to understand — little by little — a bit more about how and why the magic works the way it does.</p><p>Someday, I’d like to do a deeper dive into how various programming languages compare to the magic systems of different fantasy properties. I’ve just been learning Ruby in my bootcamp, though, so today I’m going to home in on one particular comparison — <a href="https://en.wikipedia.org/wiki/Object-oriented_programming">object-oriented programming</a> and the concept of the <a href="https://en.wikipedia.org/wiki/True_name">true name</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FUX05RPLaVhdIs%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fbeyonce-destinys-child-kelly-rowland-UX05RPLaVhdIs&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2FUX05RPLaVhdIs%2Fgiphy.gif%3Fcid%3D790b761191da4b405226f4b34f0071b9607eb41dc82adb2a%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="174" frameborder="0" scrolling="no"><a href="https://medium.com/media/d09e95347dd6dde0dc9e788d9971dc1c/href">https://medium.com/media/d09e95347dd6dde0dc9e788d9971dc1c/href</a></iframe><h3><strong>What Is OOP?</strong></h3><p>Object-orientation is a way of abstracting your data so that each example groups together not only the content of the data, but also a list of things you can do it — the operations you can perform with it, the other data it is associated with, and so on.</p><p>In Ruby, each object is an instance of a <strong>Class</strong>, and each class defines a set of methods you can call on each instance, as well as a set of relationships each method may have.</p><p>For example, you might define a class of Broom and create a method called fly:</p><pre>class Broom <br>  def fly<br>     puts &quot;Up! This broom is flying!&quot;<br>  end<br>end</pre><pre>$ nimbus_2000 = Broom.new<br>$ nimbus_2000<br><em>#=&gt; #&lt;Broom:0x007fc52c2cc588&gt;</em></pre><pre>$ nimbus_2000.fly<br><em>#=&gt; &quot;Up! This broom is flying!&quot;</em></pre><p>Calling <strong>.new</strong> on the class <strong>Broom</strong> instantiates a new object, <strong>nimbus_2000</strong>, a new instance of the class of Broom. This new instance has data about it — we know, at least, where it is being stored in memory (which is what that string of letters and numbers our terminal returns tells us). We also have something we can do with our broom — call <strong>#fly</strong> on it.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FsOoX5jiJhVb0I%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Ffunny-film-harry-potter-sOoX5jiJhVb0I&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2FsOoX5jiJhVb0I%2F200.gif%3Fcid%3D790b76116a8fa49b74f7d4dab0071ca7c1f3c9c208faf8df%26rid%3D200.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="175" frameborder="0" scrolling="no"><a href="https://medium.com/media/51e02654815f1321f52ea117955b2f80/href">https://medium.com/media/51e02654815f1321f52ea117955b2f80/href</a></iframe><h3>The Name of Every Thing</h3><p>In this way, OOP is less like Harry Potter magic, with its magic words, than it is like at least one of the types of magic in <em>The Earthsea Cycle</em> by Ursula K. Le Guin or in <em>The Kingkiller Chronicle </em>by Patrick Rothfuss. In these stories, if a character knows the true name of the wind, they can summon, transform, and control it, just as knowing that <strong>nimbus_2000 </strong>is an instance of <strong>Broom </strong>lets us know that we can call <strong>.fly</strong> on it.</p><figure><img alt="Cover of The Books of Earthsea: The Complete Illustrated Edition by Charles Vess showing a man and woman walking through water they control by magic while a massive red dragon flies past them." src="https://cdn-images-1.medium.com/max/637/1*2Sk4auZ-NlwkdcEOxDCLZw.jpeg" /><figcaption>Ged and Tenar from <em>Earthsea</em> illustrated <a href="https://www.muddycolors.com/2017/10/earthsea-cover-process/">by Charles Vess</a></figcaption></figure><p>True-name magic has a <a href="https://en.wikipedia.org/wiki/True_name">long history</a> not only in fiction, but also in mythology and religion. Think, for example, of the power granted over Rumpelstiltskin in <em>Grimm’s Tales </em>by knowing his name. Think, too, of the Jewish prohibition on erasing or defacing the written name of God.</p><p>In fact, it goes back much further. There’s an <a href="https://www.ucl.ac.uk/museums-static/digitalegypt/literature/isisandra.html">ancient Egyptian narrative</a> from the time of the Middle Kingdom in which Isis tricks Ra into revealing his secret name to her — nothing else is powerful enough to neutralize the venom with which she has poisoned him. Ra is so concerned about the power that Isis will have over him once she knows his true name that he only agrees to be saved this way if she will promise to tell no one but her son Horus — and only if Horus vows secrecy himself.</p><figure><img alt="Ptah receiving homage from the 19th-dynasty tomb of Irynefer" src="https://cdn-images-1.medium.com/max/1024/1*LoUawixx6i4jU4DBNlub8Q.jpeg" /><figcaption>Ptah receiving homage, from the 19th-dynasty <a href="https://egypte-eternelle.org/index.php?option=com_content&amp;view=article&amp;id=184&amp;Itemid=685&amp;lang=en">tomb of Irynefer</a></figcaption></figure><p>In fact, in the <a href="https://en.wikipedia.org/wiki/Ancient_Egyptian_creation_myths#Memphis">Memphite version</a> of the Egyption creation story, the god Ptah brought the world into existence when he, according to the <a href="https://web.archive.org/web/20110211013949/http://www.reshafim.org.il/ad/egypt/texts/shabaka_stone.htm">Shabaka Stone</a>, “pronounced the name of every thing”—including the other gods, their shrines, the cities of Egypt, food, and “all good things.”</p><h3>A Class Is an Instance of a Class</h3><p>I hope no one will think I’m being glib about an ancient culture’s mythology when I say that this story provides an excellent analogy to help understand the OOP concept of class inheritance.</p><p>Let’s imagine Ptah creating a new, delicious food — let’s say this piece of fruit or bread:</p><figure><img alt="Ancient Egyptian wall-painting of a lady offering another lady a lemon" src="https://cdn-images-1.medium.com/max/768/1*Jnk8iOx30XkRUCXJZwJ8-Q.jpeg" /><figcaption>Detail of a wall-painting in the tomb of Nakht (16th-14th BCE), in the cemetery of Sheikh Abd al-Qurnah</figcaption></figure><p>Let’s say it’s a fruit. (UPDATE: it’s <a href="https://www.history.com/news/eat-like-an-egyptian">bread</a>.) The analogy for this creation in Ruby is <a href="https://medium.com/@lainakarosic/instantiating-and-initializing-an-object-in-ruby-8b22f55f67d2">instantiation</a>. In OOP terms, this particular piece of fruit may be thought of as an instance of whatever type of fruit it is (a very faded pomegranate? a fig??):</p><pre>$ this_particular_fruit = Pomegranate.new<br>$ this_particular_fruit<br><em>#=&gt; #&lt;Pomegranate</em><em>:0x007fc52c2d7d20&gt;</em></pre><p><strong>Pomegranate</strong> is the class, while<strong> this_particular_fruit</strong> is the object — an instance of this class. However, <strong>Pomegranate</strong> is itself an instance of larger class, <strong>Fruit </strong>in general, and it <em>inherits</em> some of its parent class’s properties. It’s organic, has seeds, and is part of the reproductive cycle of the tree or plant it grew on.</p><p>In Ruby, we might represent this relationship as follows:</p><pre>class Fruit<br>  def seeds<br>    &quot;I have seeds!&quot;<br>  end<br>end</pre><pre>class Pomegranate &lt; Fruit<br>  def seeds<br>    super<br>    &quot;My seeds are edible and delicious!&quot;<br>  end<br>end</pre><pre>$ that_fruit_in_the_picture = Pomegranate.new<br>$ that_fruit_in_the_picture.seeds<br><em>#=&gt; &quot;I have seeds!&quot;<br>&quot;My seeds are edible and delicious!&quot;</em></pre><p>The <strong>&lt;</strong> syntax establishes that <strong>Pomegranate </strong>is a type of <strong>Fruit</strong> and thus inherits its methods. The keyword <strong>super </strong>allows us to build on a method by including everything that method does in the superclass, then adding new functionality in the subclass — hence why <strong>that_fruit_in_the_picture.seeds</strong> returns both “I have seeds!” and “My seeds are edible and delicious!”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*4_kFGuVN0swSBCo10Uw8Tw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*EZzpGp2P7-AFXZY1nupGcA.png" /><figcaption><a href="https://en.wikipedia.org/wiki/File:Lemon_-_whole_and_split.jpg">Lemon</a> from Wikimedia. <a href="https://www.theverge.com/tldr/2020/3/30/21199544/seamus-blackley-xbox-creator-ancient-egyptian-bread-4000-year-old-yeast-culture">Bread</a> from X-Box co-creator Seamus Blackley, who baked it with traditional tools and leavening cultures sampled from ancient Egyptian baking vessels.</figcaption></figure><p><strong>UPDATE:</strong> I don’t know why I saw a pomegranate. If it is a fruit, it’s obviously a lemon. But it’s not. It’s <a href="https://www.theverge.com/tldr/2020/3/30/21199544/seamus-blackley-xbox-creator-ancient-egyptian-bread-4000-year-old-yeast-culture">bread</a>. If it were a lemon, though, you would expect to see a different return if you called <strong>.seeds</strong> on it:</p><pre>class Lemon &lt; Fruit<br>  def seeds<br>    super<br>    &quot;My seeds are not the part of me that&#39;s good to eat!&quot;<br>  end<br>end</pre><pre>$ actually_a_lemon = Lemon.new<br>$ actually_a_lemon.seeds<br><em>#=&gt; &quot;I have seeds!&quot;<br>&quot;My seeds are not the part of me that&#39;s good to eat!&quot;</em></pre><p><strong>Fruit</strong> itself might be an instance of <strong>Food </strong>or <strong>Plant</strong>, which in turn may be an instance of <strong>LivingThing</strong>, and so on all the way up to <strong>Everything</strong>.</p><p>The same is true in Ruby. Just as, in another religious tradition, it’s <a href="https://en.wikipedia.org/wiki/Turtles_all_the_way_down">turtles all the way down</a>, in Ruby, it’s objects all the way up to the <a href="https://codequizzes.wordpress.com/2014/04/23/rubys-main-object-top-level-context/">main object</a>. This is the top-level scope of a Ruby program. Methods defined outside of another Class or Module belong to this object, which Ruby calls “main.”</p><figure><img alt="The cover of The Earthsea Trilogy depicting the characters Ged and Tenar and a dragon" src="https://cdn-images-1.medium.com/max/288/1*hDDKKDBQr6PFoc_kCDLE6g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/216/1*mUxI31q-huo9ypBGRnfb3w.jpeg" /></figure><h3>Messing with the Fabric of Reality</h3><p>Because in Ruby it’s objects all the way up, you can mess with the fabric of reality within your Ruby app. You can define new methods — and even hijack existing methods — that belong to the core classes built into Ruby itself. This form of hubris is called <em>monkey patching</em>, and it can completely break your code — or, apparently, come in quite handy.</p><p>All you need to do to hijack a method that belongs to a core class is redefine that method within the class:</p><pre>class String<br>  def upcase<br>    self.reverse<br>  end<br>end</pre><p>Now, when you call #upcase on an instance of string, instead of capitalizing all the letters, your program will return them in reverse order:</p><pre>$ &#39;hello world&#39;.upcase<br><em># =&gt; &quot;dlrow olleh&quot;</em></pre><p>In this way, Ruby may be closer to the magic of true names in Le Guin’s <em>Earthsea</em> books than in Rothfuss’s <em>Kingkiller.</em> (It’s hard to know for sure, since Rothfuss seems to be pulling a George R. R. Martin, and who knows if we’ll <a href="https://winteriscoming.net/2021/07/07/patrick-rothfuss-talks-the-doors-of-stone-10th-anniversary-edition-wise-mans-fear/">ever see</a> the last volume of his trilogy.) But Rothfuss’s Kvoth seems like he can only call down the wind with its true name. Le Guin’s characters, by contrast, must be thoughtful and sparing in how they use the true words for things to manipulate their world, since every use of magic changes and reorders things at their root. Just as monkey patching can <a href="https://en.wikipedia.org/wiki/Monkey_patch#Pitfalls">break</a> <a href="https://www.beyondjava.net/what-about-monkey-patching-is-it-as-dangerous-as-they-say">everything</a>, so too can the wizards of Earthsea.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*4xlzvraAD9SGStew4UxHDA.png" /><figcaption>Art from <a href="https://company.wizards.com/en/news/wizards-celebrates-pride-2021">Wizards</a> of the Coast</figcaption></figure><h3><strong>A Conference of the Mages</strong></h3><p>Please tell me what you think! I’d love to hear more ideas on the overlaps and analogies between programming and various magic systems or mythological beliefs. Write me a response on Medium or reach out through <a href="https://www.linkedin.com/in/alec-magnet/">LinkedIn</a> to keep this conversation rolling.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf891c4cdf0e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/oop-magic-systems-and-the-allegory-of-the-cave-bf891c4cdf0e">Coding as Sorcery, Part 1: OOP and the Magic of the True Name</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adventures in Coding with Anxiety (Part 1?)]]></title>
            <link>https://medium.com/@alecmagnet/adventures-in-coding-with-anxiety-part-1-a589ba1ecf23?source=rss-42a8a2b664f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a589ba1ecf23</guid>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[anxiety]]></category>
            <category><![CDATA[perfectionism]]></category>
            <category><![CDATA[codingbootcamp]]></category>
            <dc:creator><![CDATA[Alec Magnet]]></dc:creator>
            <pubDate>Mon, 02 Aug 2021 18:09:27 GMT</pubDate>
            <atom:updated>2021-10-17T21:04:45.026Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Coding Against Perfectionism</strong></h3><p>A friend sent a <a href="https://twitter.com/JenAshleyWright/status/1141896207666688000?s=20">tweet</a> the other day to remind me of one of my favorite nature facts — that caterpillars <a href="https://www.scientificamerican.com/article/caterpillar-butterfly-metamorphosis-explainer/">become butterflies</a> by dissolving into goo and remaking themselves. They don’t take each limb and elegantly refine it. They essentially digest themselves into a bag of gross soup with breathing tubes and then go from there. Change is messy. It’s hard. It’s not meant to be effortless.</p><h3>Jennifer Wright on Twitter: &quot;People talk about caterpillars becoming a butterflies as though they just go into a cocoon, slap on wings, and are good to go.Caterpillars have to dissolve into a disgusting pile of goo to become butterflies.So if you&#39;re a mess wrapped up in blankets right now, keep going. / Twitter&quot;</h3><p>People talk about caterpillars becoming a butterflies as though they just go into a cocoon, slap on wings, and are good to go.Caterpillars have to dissolve into a disgusting pile of goo to become butterflies.So if you&#39;re a mess wrapped up in blankets right now, keep going.</p><p>I needed the reminder because I’m going through something of a metamorphosis myself these days. Having already ditched academia, I’ve now left education entirely to become a software engineer. I’m writing this post in my third week of coding bootcamp at <a href="https://flatironschool.com/">Flatiron</a>.</p><p>Lots of folks have blogged about how bootcamp is bananas — difficult, stressful, scary, particularly for those of us with anxiety. By the end of each day, my brain truly does feel like it’s dissolved into jelly. But, in this chrysalis state, one thing that does seem to be growing back out of the goo differently is my relationship to anxiety itself. In fact, coding feels like it could have been designed as behaviorist therapy to overcome perfectionism.</p><figure><img alt="Stages of a butterfly emerging from its crysalis" src="https://cdn-images-1.medium.com/max/550/1*WEd-nV0cznGgw28rDbp4gg.jpeg" /><figcaption><a href="https://www.zmescience.com/ecology/animals-ecology/how-caterpillar-turn-butterfly-0534534/">ZME Science</a></figcaption></figure><p><strong>One Thing at a Time</strong></p><p>Flatiron throws you in the emotional deep end of coding right away by assigning labs that implement a version of <a href="https://www.guru99.com/test-driven-development.html">test-driven development</a>. They’ve written a script that checks your code, and part of how you learn the requirements to complete the lab is by running it right away and failing all the tests.</p><figure><img alt="Troy from Community walking into the darkest timeline" src="https://cdn-images-1.medium.com/max/480/1*K82a7OCqVVMaOXEwHIOQCQ.gif" /><figcaption><a href="https://giphy.com/gifs/fire-community-troy-dXmS4hlzZEuyB79bGI">Giphy</a></figcaption></figure><p>Yes, it’s like walking in on the darkest timeline, but only at first. When faced with a challenge like this, you can’t think about doing everything perfectly. There’s no way to be flawless from start to finish. Everything is already broken and on fire, and you need to write the code to mend it and put it out. Perfectionists have trouble not getting bogged down in the fear of failure, but when failure’s where you’re starting from, what can you do but get to work fixing things?</p><p>Which is easier to do because the tests break things down into steps. Instead of facing one monolithic catastrophe, you’ve got a series of discrete smaller problems to tackle one by one. And every time you run the tests, every time you see the failing number fall and the passing rise, that little jolt of dopamine is delightful.</p><figure><img alt="Screenshot of Terminal showing 2 failed tests and 23 passed tests" src="https://cdn-images-1.medium.com/max/574/1*Zd853bOTBZryGc3XvVdlsQ.png" /></figure><p>If you’re not doing test-driven development — or a bootcamp lab — you won’t have a set of tests to structure your coding, but I’m learning to keep that feeling going by checking every few lines I write. I’m learning JavaScript right now (remember, y’all, third week of bootcamp), so my main tools are <strong><em>console.log( )</em></strong>, <strong><em>debugger</em></strong>, and a live preview of the page I’m building.</p><p>Let’s say you wanted to use some data from an external source. After a little song and dance using terms like fetch and JSON, you’ll have that data in an <em>object</em> — essentially a collection of key/value pairs, like:</p><figure><img alt="Table showing some of the members of the Spiders from Mars arranged by instrument" src="https://cdn-images-1.medium.com/max/288/1*PBs8IuPxcZGzxNyXaAa8wQ.png" /></figure><p>In most cases, however, our object’s values won’t just be names. They’ll be collections of data themselves, with more collections nested inside <em>their</em> values, and more nested inside theirs. If you mapped it all out, it might look something like this:</p><figure><img alt="Table listing some of David Bowie’s bands, their members, albums they released, additional personnel on those albums, etc." src="https://cdn-images-1.medium.com/max/930/1*TZWPFr_sOw6A7jHxMV1AFw.png" /></figure><p>The data you want may be several layers deep, but you’re still learning how to write the code to access it. In that case, you might burrow down one layer deep, then add a line using the <strong><em>console.log( )</em></strong> command on what you’ve uncovered. If you refresh your page in Chrome with the developer tools open, then you’ll see that collection, which was nested one level deep, logged — appropriately enough — in the console. Are you on the right track? Rad! Go a level deeper and console log that.</p><p>Now let’s say you’ve dug down four levels deep, and you want to pass that collection into a function. Without all this console logging, your function may throw an error or do something wacky, and you’d have to go back through your code <a href="https://www.reddit.com/r/ProgrammerHumor/comments/ojkbyv/our_favorite_runtime_error/">searching</a> for what the mistake might have been. That said, the function still<em> </em>might throw an error even <em>with </em>all the logging, but at least you’d know that those parts of your code are not the problem. Knowing that as you write and test each line makes it much easier to go on to the next one.</p><p>Often, with this kind of data, your code will involve at least one function that loops through a collection, performing some action on each of its elements or values — <strong><em>.forEach</em></strong>, <strong><em>for … while</em></strong>, etc. Then, you check your work with JavaScript’s best-named debugging tool, <strong><em>debugger</em></strong>.</p><figure><img alt="Frustrated Australian Survivor contestant with caption that changes from “BUGGER” to “DEBUGGER”" src="https://cdn-images-1.medium.com/max/450/1*ZU5BaltwJbeSmVK8nvnqCw.gif" /></figure><p>Debugger allows you to run through loop, pausing on each iteration at the line where you added the <strong><em>debugger</em></strong> statement to your code. (This is called a <em>breakpoint.</em>) In your terminal or in the console tab of browser’s developer tools, you can observe the value of each expression at this point in the script, the value and scope of each variable, and the stack of functions being called. As soon as you write a loop, you can run through it with debugger. That way, if any of these don’t line up with what you expect them too, you can fix them pronto before you move on to writing other code.</p><p>Finally, you can have your page running on a local server. Each time you write a line, check what it does. Did everything break? Did it do something other than what you expected? Well, then you know where the problem is, and you can set about fixing it.</p><p>You can see how this is good coding practice. You waste less time checking each step than searching back through 50 lines of code to find the missing parenthesis that broke your entire web app. But it’s also good anxiety practice. Perfectionism tricks you into seeing whatever you’re trying to make as a monolith that must emerge perfect and complete, like Venus from a seashell.</p><figure><img alt="Sandro Botticelli’s “The Birth of Venus” with meme text reading, “I woke up like this”" src="https://cdn-images-1.medium.com/max/1024/1*LqOzJn6OLwkJ-ZP5tQ8Arw.jpeg" /></figure><p>Coding, however, encourages you to break things down into the smallest steps. When one of those steps doesn’t work, it’s not a catastrophe. It’s a small, concrete problem. If you’ve been checking each line as you go, you already know where that problem is. Now, you just have to fix it.</p><p>Even better, it’s either broken, or it’s fixed. Each line of code either works, or it doesn’t, which is incredibly soothing. Contrast this clarity to the uncertainty of writing prose. As soon as I wrote the previous sentence, I read it over again and worried that the near-rhyme of <em>clarity</em> and <em>uncertainty </em>might come across as inelegant and sloppy — or, worse, as a failed attempt to be precious. I replaced each word with a few synonyms, but each new version sounded worse to me. Either the rhythm didn’t flow, or else the new words didn’t actually convey the precise meaning I’m trying to articulate. Now I don’t know how to fix this problem. I’m not even sure it was a problem to begin with. As Oscar Wilde <a href="https://quoteinvestigator.com/2015/10/25/comma/">once (maybe) said</a> of a hard day’s writing work: “I spent all morning putting in a comma and all afternoon taking it out.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*GrDBOsFUJk2hZT4_7FPGwg.jpeg" /><figcaption><a href="https://commons.wikimedia.org/wiki/File:Leonid_Pasternak_-_The_Passion_of_creation.jpg">Leonid Pasternak</a></figcaption></figure><p>When you’re writing code, there may be many different ways to achieve them same result, but each one either works or it doesn’t. Either way, you know. The proof is in the console and on the page.</p><p><strong>Beginner’s Mind</strong></p><p>After three weeks of bootcamp, I already feel like a grizzled veteran. I’m exhausted, for one thing, but I also have a pretty good grasp of how to do a number of different things in JavaScript. Part of that grasp is internalizing logic and syntax, but part of it is simply learning how to learn. And here is what might be the most crucial way that coding combats perfectionism — you don’t need to know everything already in order to do a good job. Instead, you need to know how to figure a problem out — what to Google, how to understand the results, find the most helpful, and apply it to the problem at hand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*X21vDD5n_gRhV4IbjsTq-Q.png" /></figure><p>Over the last two weeks, I’ve heard the <a href="https://www.reddit.com/r/ProgrammerHumor/comments/lwpwb7/we_get_paid_to_google/">same</a> <a href="https://melreams.com/2015/11/i-google-things-professionally/">joke</a> <a href="https://www.semicolonworld.com/humor/programming-memes/175/day-1-vs-10-years-of-experience">over</a> <a href="https://www.reddit.com/r/ProgrammerHumor/comments/lspz2e/my_wife_is_on_to_us/">and</a> <a href="https://s3.amazonaws.com/rails-camp-tutorials/blog/programming+memes/programming-or-googling.jpg">over</a>: “Programmers get paid to Google things.” This may sound flippant, but it’s <a href="https://qr.ae/pGMtVE">actually</a> <a href="https://qr.ae/pGbKPE">quite</a> <a href="https://melreams.com/2015/11/i-google-things-professionally/">profound</a>. It keeps you in what the Zen master Shunryu Suzuki calls “beginner’s mind” — an acceptance of not already knowing everything that opens the possibility of curiosity, wonder, and perpetual learning.</p><figure><img alt="Bill Murray from “What About Bob” with text: “The journey of a thousand miles begins with baby steps.”" src="https://cdn-images-1.medium.com/max/422/1*68gHN4yg1Ywth_Bto-xInQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a589ba1ecf23" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>