<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Charlotte Bush</title>
    <description>The latest articles on DEV Community by Charlotte Bush (@varlotte).</description>
    <link>https://dev.to/varlotte</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%2F1130424%2Fa2ab8b9c-0c67-4062-8b18-f690882b122f.jpeg</url>
      <title>DEV Community: Charlotte Bush</title>
      <link>https://dev.to/varlotte</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/varlotte"/>
    <language>en</language>
    <item>
      <title>Telling (User) Stories</title>
      <dc:creator>Charlotte Bush</dc:creator>
      <pubDate>Sun, 28 Apr 2024 20:04:54 +0000</pubDate>
      <link>https://dev.to/varlotte/telling-user-stories-1mo6</link>
      <guid>https://dev.to/varlotte/telling-user-stories-1mo6</guid>
      <description>&lt;p&gt;One of my favorite things to ask my community of more established devs in networking conversations is &lt;em&gt;“what do you wish new devs knew?”&lt;/em&gt; Answers have led to great conversations around building relationships with a team, managing workflows and expectations, and many have been around writing and developing user stories. The first time a dev friend told me that they were putting their user stories in Jira, I was gobsmacked, since in boot camp, we were taught that user stories were just something you could toss off into a readme. &lt;/p&gt;

&lt;p&gt;According to my teachers, user stories were useful, but not central to design, and they could just go into the docs of an MVP (minimum viable product.) I get why we were told this (the &lt;em&gt;what&lt;/em&gt; of development is often seen as more important than the &lt;em&gt;how&lt;/em&gt; or the &lt;em&gt;why&lt;/em&gt;, especially for new devs, and while I don’t necessarily agree with this approach, it does make sense) but as I’ve learned different (arguably better) practices, I thought I’d start to codify some of them here, so anyone else in a bootcamp can see what’s up and be a more user-focused developer from the jump. &lt;/p&gt;

&lt;h2&gt;
  
  
  What (and why) is a user story?
&lt;/h2&gt;

&lt;p&gt;Note: In my research, it looks like many PM frameworks and styles (Agile, Scrum, Kanban, etc) list different technical components of user stories, which I want to acknowledge, but am still researching and won’t go into much here until I know more. &lt;/p&gt;

&lt;p&gt;At its most basic level, &lt;em&gt;a good user story says what the feature will do for the user&lt;/em&gt;, but not necessarily how, since that’s more prescriptive. You’d want to say “a user can create an account” but not “a user will create an account by submitting to the form which will then POST to the API.” That way, if you, the developer, build the account creation flow in a different way, you’re not totally boxed into a corner by your own user story. &lt;/p&gt;

&lt;p&gt;From my conversations, I’ve gathered that a mindful developer who’s focused on the user will have as many user stories as there are features on the application, so every part serves a purpose and can be iterated on with clarity and intention. (I also suspect designing with user stories in mind is helpful to maintain a healthy scope for a project, but what I’ve been learning about managing scope creep is going to be a different blog post!) This all ties back to something called user-centered design.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is user-centered design?
&lt;/h2&gt;

&lt;p&gt;In my research, it looks like user-centered design is exactly what it says on the tin: &lt;em&gt;design that considers the user through each iterative step of the process&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;This makes a ton of sense to me, a developer with a background in theater, writing, and education, fields whose success depend on the experience of a “user.”  Playwrights write for an audience even if that audience is just a single reader (fun fact: this type of play is called a &lt;em&gt;closet drama&lt;/em&gt;) and we think about not just the &lt;em&gt;what&lt;/em&gt; but also the &lt;em&gt;how&lt;/em&gt; and &lt;em&gt;why&lt;/em&gt; of each beat of a user’s experience of a play, making user stories integral. Teachers write each lesson plan to be a useful tool, and considering each student’s personal user story of a lesson is a process of inclusive learning design called &lt;em&gt;differentiation&lt;/em&gt;. Even this blog has what some writers call a &lt;em&gt;speech act&lt;/em&gt;, or a user story to justify its existence. I’m writing this post so that hopefully some dev even newer than me will see it and put their user stories into Jira or Linear and not clog up a readme with them, even if bootcamp teachers say so. If the blog doesn’t convince a reader, then I’ve failed to provide this user story. This is all to say that user-centered design seems like a really reasonable and helpful framework, one that developers who’ve worked in a non-tech field should be able to apply pretty easily to development. That said, if there are better frameworks for app design, I’d be happy to hear about them. &lt;/p&gt;

&lt;h2&gt;
  
  
  Ok, cool, so where do user stories live?
&lt;/h2&gt;

&lt;p&gt;All the experienced devs I’ve spoken to have mentioned putting user stories into productivity tracking software like Jira, rather than in the docs of the application, like we were taught in bootcamp. I understand this as being largely for modularity (so you can be working one user story/task and a member of your team can be working on a different one simultaneously) and scalability (if your app blows up in popularity, you’ll need a lot more space for user stories than a readme can reasonably provide.) I know I’ll be moving user stories for my application, &lt;a href="https://rxgnosis.com"&gt;RXGnosis&lt;/a&gt;, into Linear and using them more as a checklist for future development and less as a demo or narrative for the users themselves. This will also help me make my GitHub documentation easier to read- a perk!&lt;/p&gt;

&lt;h2&gt;
  
  
  What should the actual users see?
&lt;/h2&gt;

&lt;p&gt;Actual users don’t need to see user stories. Just because it’s about them doesn’t mean that it’ll help them to see it, just like seeing a recipe for a cake doesn’t affect your experience of eating it. What you, the person eating the cake, benefit from is a totally different set of information than a recipe would give you. You'd want to know the flavor profile, the potential allergens, and the price, for example. That information for web developers is more like a User Guide, and can live in the app’s user-facing docs. &lt;/p&gt;

&lt;p&gt;I really hope this helps other new devs think about User-Centered Design, what user stories can do, and where they can live, so our new-dev documentation can be cleaner and more intentional. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>pm</category>
      <category>userstories</category>
      <category>learning</category>
    </item>
    <item>
      <title>Telling (User) Stories</title>
      <dc:creator>Charlotte Bush</dc:creator>
      <pubDate>Sun, 28 Apr 2024 20:04:54 +0000</pubDate>
      <link>https://dev.to/varlotte/telling-user-stories-25c9</link>
      <guid>https://dev.to/varlotte/telling-user-stories-25c9</guid>
      <description>&lt;p&gt;One of my favorite things to ask my community of more established devs in networking conversations is &lt;em&gt;“what do you wish new devs knew?”&lt;/em&gt; Answers have led to great conversations around building relationships with a team, managing workflows and expectations, and many have been around writing and developing user stories. The first time a dev friend told me that they were putting their user stories in Jira, I was gobsmacked, since in boot camp, we were taught that user stories were just something you could toss off into a readme. &lt;/p&gt;

&lt;p&gt;According to my teachers, user stories were useful, but not central to design, and they could just go into the docs of an MVP (minimum viable product.) I get why we were told this (the &lt;em&gt;what&lt;/em&gt; of development is often seen as more important than the &lt;em&gt;how&lt;/em&gt; or the &lt;em&gt;why&lt;/em&gt;, especially for new devs, and while I don’t necessarily agree with this approach, it does make sense) but as I’ve learned different (arguably better) practices, I thought I’d start to codify some of them here, so anyone else in a bootcamp can see what’s up and be a more user-focused developer from the jump. &lt;/p&gt;

&lt;h2&gt;
  
  
  What (and why) is a user story?
&lt;/h2&gt;

&lt;p&gt;Note: In my research, it looks like many PM frameworks and styles (Agile, Scrum, Kanban, etc) list different technical components of user stories, which I want to acknowledge, but am still researching and won’t go into much here until I know more. &lt;/p&gt;

&lt;p&gt;At its most basic level, &lt;em&gt;a good user story says what the feature will do for the user&lt;/em&gt;, but not necessarily how, since that’s more prescriptive. You’d want to say “a user can create an account” but not “a user will create an account by submitting to the form which will then POST to the API.” That way, if you, the developer, build the account creation flow in a different way, you’re not totally boxed into a corner by your own user story. &lt;/p&gt;

&lt;p&gt;From my conversations, I’ve gathered that a mindful developer who’s focused on the user will have as many user stories as there are features on the application, so every part serves a purpose and can be iterated on with clarity and intention. (I also suspect designing with user stories in mind is helpful to maintain a healthy scope for a project, but what I’ve been learning about managing scope creep is going to be a different blog post!) This all ties back to something called user-centered design.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is user-centered design?
&lt;/h2&gt;

&lt;p&gt;In my research, it looks like user-centered design is exactly what it says on the tin: &lt;em&gt;design that considers the user through each iterative step of the process&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;This makes a ton of sense to me, a developer with a background in theater, writing, and education, fields whose success depend on the experience of a “user.”  Playwrights write for an audience even if that audience is just a single reader (fun fact: this type of play is called a &lt;em&gt;closet drama&lt;/em&gt;) and we think about not just the &lt;em&gt;what&lt;/em&gt; but also the &lt;em&gt;how&lt;/em&gt; and &lt;em&gt;why&lt;/em&gt; of each beat of a user’s experience of a play, making user stories integral. Teachers write each lesson plan to be a useful tool, and considering each student’s personal user story of a lesson is a process of inclusive learning design called &lt;em&gt;differentiation&lt;/em&gt;. Even this blog has what some writers call a &lt;em&gt;speech act&lt;/em&gt;, or a user story to justify its existence. I’m writing this post so that hopefully some dev even newer than me will see it and put their user stories into Jira or Linear and not clog up a readme with them, even if bootcamp teachers say so. If the blog doesn’t convince a reader, then I’ve failed to provide this user story. This is all to say that user-centered design seems like a really reasonable and helpful framework, one that developers who’ve worked in a non-tech field should be able to apply pretty easily to development. That said, if there are better frameworks for app design, I’d be happy to hear about them. &lt;/p&gt;

&lt;h2&gt;
  
  
  Ok, cool, so where do user stories live?
&lt;/h2&gt;

&lt;p&gt;All the experienced devs I’ve spoken to have mentioned putting user stories into productivity tracking software like Jira, rather than in the docs of the application, like we were taught in bootcamp. I understand this as being largely for modularity (so you can be working one user story/task and a member of your team can be working on a different one simultaneously) and scalability (if your app blows up in popularity, you’ll need a lot more space for user stories than a readme can reasonably provide.) I know I’ll be moving user stories for my application, &lt;a href="https://rxgnosis.com"&gt;RXGnosis&lt;/a&gt;, into Linear and using them more as a checklist for future development and less as a demo or narrative for the users themselves. This will also help me make my GitHub documentation easier to read- a perk!&lt;/p&gt;

&lt;h2&gt;
  
  
  What should the actual users see?
&lt;/h2&gt;

&lt;p&gt;Actual users don’t need to see user stories. Just because it’s about them doesn’t mean that it’ll help them to see it, just like seeing a recipe for a cake doesn’t affect your experience of eating it. What you, the person eating the cake, benefit from is a totally different set of information than a recipe would give you. You'd want to know the flavor profile, the potential allergens, and the price, for example. That information for web developers is more like a User Guide, and can live in the app’s user-facing docs. &lt;/p&gt;

&lt;p&gt;I really hope this helps other new devs think about User-Centered Design, what user stories can do, and where they can live, so our new-dev documentation can be cleaner and more intentional. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>pm</category>
      <category>userstories</category>
      <category>learning</category>
    </item>
    <item>
      <title>Snapshots through the Prisma</title>
      <dc:creator>Charlotte Bush</dc:creator>
      <pubDate>Wed, 10 Jan 2024 22:26:23 +0000</pubDate>
      <link>https://dev.to/varlotte/snapshots-through-the-prisma-249e</link>
      <guid>https://dev.to/varlotte/snapshots-through-the-prisma-249e</guid>
      <description>&lt;p&gt;Well, the cliche "new year, new me" may not apply to me personally, but it definitely applies to my Flatiron final project. I spent my last month in bootcamp making a patient advocacy tool for mental health prescriptions, and I'm really excited to deploy it and give it to its eager beta testers (and hopefully show it to some prospective employers!) That said, it's in dire need of some new years' TLC if I want to get it to that point. On the agenda: &lt;/p&gt;

&lt;p&gt;&lt;del&gt;1. Finding a good ORM library&lt;/del&gt;&lt;br&gt;
&lt;del&gt;2. Installing it, with node and express&lt;/del&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Converting the ORM models, seed logic, relationships, auth, and backend routes from Python, Flask, and SQLite into something more easily compatible with Postgres&lt;/li&gt;
&lt;li&gt;Setting up the Postgres docker image&lt;/li&gt;
&lt;li&gt;Updating the readme to reflect all the changes (I love good docs!)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So far, I'm about halfway through my list, converting my backend from my beloved Python into my uneasy new frenemies Typescript and Express. I found a cool new ORM to help manage everything, which is adding another mean girl to the Plastics' cafeteria table: &lt;a href="https://prisma.io/docs/getting-started"&gt;Prisma&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Things I've loved about Prisma: writing models and relationships is so much more concise. A models.py file that took a hundred or so lines in Python (it was the association proxy stuff, I'm sure of it!) became a 50-line schema.prisma file. &lt;/p&gt;

&lt;p&gt;Things I've hated about Prisma: the syntax feels like a hybrid of Python's more intuitive grammar and Javascript's finicky logic, and it definitely has a learning curve.&lt;/p&gt;

&lt;p&gt;Today's adventure was wrapping up the search routing for my capstone app, which once I got the hang of, Prisma had a variety of tools to help me use to make it a little easier to offer users even more functionality than I'd originally planned. Let's get into it! &lt;/p&gt;

&lt;p&gt;The first thing I noticed was that all the concision of writing models in Prisma totally vanished while I was writing routes. In Python, the GET request for my search functionality was about ten lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MedicationsByName(Resource):
    def get(self):
        query= request.args.get("q")
        medications = Medication.query.filter(
            Medication.name_brand.ilike(f"%{query}%")
            | Medication.name_generic.ilike(f"%{query}%")
        ).all()
        return make_response([medication.to_dict(rules=("-faves","-treatments", "-conditions")) for medication in medications], 200)  

api.add_resource(MedicationsByName, '/medications')  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Prisma, if I pasted the whole of my GET request in here, it'd make this blog unreadably long. It's something like 80 lines, mostly of opening and closing curly brackets, which makes it feel more verbose than it actually is. &lt;/p&gt;

&lt;p&gt;Once I got over that initial annoyance, though, I found out something cool. Prisma's &lt;a href="https://www.prisma.io/docs/orm/reference/prisma-client-reference#model-queries"&gt;model queries&lt;/a&gt; and &lt;a href="https://www.prisma.io/docs/orm/reference/prisma-client-reference#filter-conditions-and-operators"&gt;filter conditions&lt;/a&gt;let you essentially wire up a search GET to look for more than one model property at once. While you can also do this in Python, Prisma made it surprisingly elegant today!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  where: {
        OR: [
          {
            nameBrand: {
              contains: query,
              mode: "insensitive",
            },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I used Prisma's "where" and "or" to essentially tell my search GET "hey, go back to the seed data, and look for the following fields in each object." Where in Python I was pretty much just letting users search for medications by name (brand or generic) I can now let users search for all types of attributes of their medications with a few quick keystrokes including side effects and other conditions that the medications can treat. &lt;/p&gt;

&lt;p&gt;On top of that, adding:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mode: "insensitive"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to the search objects allows the GET request to query my yaml database accurately regardless of the casing of the search terms. I also added &lt;a href="https://www.prisma.io/docs/orm/prisma-client/queries/full-text-search"&gt;Full-Text Search&lt;/a&gt; to my "side effects" search routing so that my GET request can more easily go through the big wall of text that is side effects data in my database. &lt;/p&gt;

&lt;p&gt;I know I have a long way to go learning this new framework, but I picked up something really cool today, and was able to use it to make my search functionality more useful for my app's eventual users! Thanks, Prisma!&lt;/p&gt;

</description>
      <category>prisma</category>
      <category>backend</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to Be Your Own PM, Make Friends (With Deadlines) and Influence People (Mostly Yourself)</title>
      <dc:creator>Charlotte Bush</dc:creator>
      <pubDate>Thu, 09 Nov 2023 00:28:15 +0000</pubDate>
      <link>https://dev.to/varlotte/how-to-be-your-own-pm-make-friends-with-deadlines-and-influence-people-mostly-yourself-7f2</link>
      <guid>https://dev.to/varlotte/how-to-be-your-own-pm-make-friends-with-deadlines-and-influence-people-mostly-yourself-7f2</guid>
      <description>&lt;p&gt;With bootcamp winding down, I found myself at a loss for what to write about here. Do I want to go into detail about my capstone project, and all the new technologies I learned to execute my vision? Do I want to take time to break down a key feature of Flask-SQLAlchemy that I had to learn on the fly to make my backend seamless? Or do I want to zoom out and get a little more reflective?&lt;/p&gt;

&lt;p&gt;To answer my own (mostly rhetorical) questions, I think I'd prefer to zoom out a little for now, and think about the &lt;em&gt;how&lt;/em&gt; of executing both my capstone project and that cool Flask-SQLAlchemy feature (both of which I'll probably go into greater detail about here soon.) &lt;/p&gt;

&lt;p&gt;A part of my development process over the past month that I'm particularly proud of is the way I worked as my own Project Manager to create a full-stack, multi-page, cool-looking (if I do say so myself) and bug-free (mostly) application on time and with minimal stress. &lt;/p&gt;

&lt;p&gt;I get the sense as a new dev that Project Management isn't a skillset that's seen as "technical" in the industry, an erroneous perception that I think is filled with all the inherent gender biases around "hard" and "soft" skills. As someone who's been on un-PM-ed projects with other new devs, software development without Project Management can sometimes be a clown show. With these things in mind, I'd love to talk you through some tools I used to manage my project successfully.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scoping The Project
&lt;/h2&gt;

&lt;p&gt;The first thing I did to set myself up for success was to outline a few different "ideal" versions of the project: one with all the stops pulled out that went above and beyond, a "scaled back" option with a handful fewer bells and whistles, and a utilitarian option that did the bare minimum. While the final product I demonstrated to the class had elements of all three plans, the process of outlining the options was very helpful for deciding what MVP (minimum viable product) should be. (I also included the "scaled back" option in my readme to show anyone who looks at it that I was mindful of scope and time constraints.) &lt;/p&gt;

&lt;h2&gt;
  
  
  Sprint Planning
&lt;/h2&gt;

&lt;p&gt;We were given about two and a half weeks to pitch, plan, execute, and present our projects. I knew that without an outline of tasks and a clear sense of allotment of time, I would easily get distracted. And as cool as a Trello board would be, it might not be enough this time. After some research, I was recommended Linear.app, and I've never looked back. I love the clean and intuitive UI, and how easy it is to assign tasks different "cycles" (their word for sprints.) Using Linear and my own notes about scope, I was able to assign different tasks to their own weeklong "cycles" and stay mostly on top of my goals. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpxb4ncjded169qeeo0zo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpxb4ncjded169qeeo0zo.png" alt="A screenshot of the cycles section of my Linear page" width="800" height="371"&gt;&lt;/a&gt;&lt;br&gt;
Another cool thing about Linear is that it can graph out your productivity by cycle and show you how many of your goals you've met in each sprint. This was really helpful for the next step. &lt;/p&gt;

&lt;h2&gt;
  
  
  Estimating Time (...and re-estimating)
&lt;/h2&gt;

&lt;p&gt;I had frequent check-ins with myself (basically a one-woman retro meeting) using the graph feature on Linear and my list of still-open to-dos. In these checkins, I'd look at how long I'd spent on certain tasks and re-evaluate if my initial estimations of time were still accurate. I was proud to see as the project progressed how much more accurate my estimations of task length became.&lt;/p&gt;

&lt;h2&gt;
  
  
  Forgiving Yourself
&lt;/h2&gt;

&lt;p&gt;While my estimation skills definitely improved over the course of the project, they weren't perfect. There were a handful of times I wanted to deliver on a task and found myself running out of time. While holding myself accountable, I became better equipped to forgive myself and (when possible) grant myself more elbow room. Additionally, by starting scaled-back but keeping my blue-sky vision in mind, I was able to pull many of my stretch goals in after completing my MVP. &lt;/p&gt;

&lt;h2&gt;
  
  
  Other Miscellaneous Helpful Things
&lt;/h2&gt;

&lt;p&gt;Making sure all my commit messages were clear and descriptive and that new code sections had brief comments describing intent (aka the "Memento" school of software engineering) was really helpful for staying on top of goals and remembering what had already been done. &lt;/p&gt;

&lt;p&gt;These are a few of my most helpful project management tips  from this project; I'd love to hear more about yours in the comments! I'll probably blog here more about my project soon.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>pm</category>
      <category>productivity</category>
      <category>softskills</category>
    </item>
    <item>
      <title>Serializing America’s Next Top Model (Class)</title>
      <dc:creator>Charlotte Bush</dc:creator>
      <pubDate>Sun, 15 Oct 2023 20:27:01 +0000</pubDate>
      <link>https://dev.to/varlotte/serializing-americas-next-top-model-class-1fjm</link>
      <guid>https://dev.to/varlotte/serializing-americas-next-top-model-class-1fjm</guid>
      <description>&lt;p&gt;Delving into backend dev has been fascinating. I love thinking about how data is organized and displayed, and how it “talks” to other data and servers, so this was a fun time for me. As I began to learn more, though, I realized I had a ton of questions about serialization, so I wanted to create an explainer based on some of my own questions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ezmeqgnodm0xdam7bto.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ezmeqgnodm0xdam7bto.jpg" alt='Tyra Banks holding photos, text says: "I have two model classes in my hands ("-loser_contestant",)"' width="577" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is serialization?
&lt;/h2&gt;

&lt;p&gt;Serialization is just the process of converting a data object into a format suitable for transmission and storage. From a practical standpoint, this means it takes in an object and turns it into a giant string that you can send over the internet or store in a database or file. So far, so good. In Python, we serialize with functions like jsonify() whereas in JavaScript we use JSON.serialize. &lt;/p&gt;

&lt;h2&gt;
  
  
  So wait, if there’s a serialization, does this mean there’s a deserialization?
&lt;/h2&gt;

&lt;p&gt;Deserializing is the opposite and equal reaction of serialization (that makes sense so far) done with things like JSON.parse(), and transforms data back into real objects. Any time you deal with data sent over the internet or stored in a database, you’re doing serialization AND deserialization.&lt;/p&gt;

&lt;h2&gt;
  
  
  What do we use serialization for in Flask?
&lt;/h2&gt;

&lt;p&gt;When you integrate SerializerMixin into your Flask-SQLalchemy model classes, you can make your models serializable, which in turn makes the data within them (as a blog I found says) “compact, platform-independent, and easy for platforms and humans to read!” &lt;/p&gt;

&lt;p&gt;Note: In the example below, SerializerMixin is the first argument in the model class, and has been imported “offscreen” at the top of the file like so:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;from sqlalchemy_serializer import SerializerMixin&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How do we do serialization?
&lt;/h2&gt;

&lt;p&gt;If you have an instance of a model class, you can use a method like to_json() or add rules into a to_dict (by saying instance.to_dict(rules=(“-excluded_thing”,))) to serialize on a more individual basis, but you can also serialize on a broader level first inside the class itself. When you define a model class, you can use a property like serialize_rules  to specify which fields to exclude from the default serialized representation of the model. In this example, we’re defining a class and showing its one-to-many relationship with another, while also indicating via serialize_rules that we don’t want to see certain things returned in API calls. In this case, we’ll see the orders affiliated with each deli but not the other delis’ orders affiliated with those orders (which would be, in technical terms, a recursion hellscape.)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Deli(db.Model, SerializerMixin):
            __tablename__ = 'delis'

            id = db.Column(db.Integer, primary_key=True)
            name = db.Column(db.String)
            signature_sandwich = db.Column(db.String)

            # Add relationship (deli has many customers through orders)
            orders = db.relationship(
                "Order", backref="deli", cascade="all, delete-orphan")

            # Add serialization rules
            serialize_rules = ("-orders.deli",)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What’s that weird comma doing?
&lt;/h2&gt;

&lt;p&gt;Serialization rules are tuples (aka a sequence of immutable objects separated by a comma and enclosed in parentheses) and tuples always have commas, even if there’s only one value in there. If you don’t include the comma, Flask-SQLAlchemy will raise a TypeError exception indicating that currently, serialize_rules isn’t a tuple, but it has to be. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fldizsxgznck0j9uscrl1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fldizsxgznck0j9uscrl1.jpg" alt="Tyra Banks looking enraged, text says &amp;quot;You didn't put a comma in your serializer tuple!&amp;quot;" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why write serializer rules?
&lt;/h2&gt;

&lt;p&gt;If you want to see customized parts of a data set, or avoid seeing recursive or redundant (or just unhelpful) portions of a data set, you’re gonna want to change how the data gets serialized. Check out the following example of models:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask_sqlalchemy import SQLAlchemy
        from sqlalchemy_serializer import SerializerMixin


        db = SQLAlchemy()

        class User(db.Model, SerializerMixin):
            __tablename__ = 'users'

            id = db.Column(db.Integer, primary_key=True)
            name = db.Column(db.String)
            email = db.Column(db.String, unique=True)

            # Add relationship (has many posts)
            posts = db.relationship("Post", backref="author")

            # Add serialization rules (don't show people's passwords!)
            serialize_rules = ("-password",)

        class Post(db.Model, SerializerMixin):
            __tablename__ = 'posts'

            id = db.Column(db.Integer, primary_key=True)
            title = db.Column(db.String)
            content = db.Column(db.Text)

            # Add relationship (belongs to one user)
            author_id = db.Column(db.Integer, db.ForeignKey('users.id'))

            # Add serialization rules (don't show comments by default)
            serialize_rules = ("-comments",)

        class Comment(db.Model, SerializerMixin):
            __tablename__ = 'comments'

            id = db.Column(db.Integer, primary_key=True)
            content = db.Column(db.Text)

            # Add relationship (belongs to one post)
            post_id = db.Column(db.Integer, db.ForeignKey('posts.id'))

            # Add serialization rules (no rules)
            serialize_rules = ()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we’re serializing specifics that are integral to privacy, like not seeing a password or comments affiliated with a post. You can also get a little more interesting with serialization to prevent users from seeing a recursive data spiral, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask_sqlalchemy import SQLAlchemy
    from sqlalchemy_serializer import SerializerMixin


       db = SQLAlchemy()

    class Deli(db.Model, SerializerMixin):
         __tablename__ = 'delis'

         id = db.Column(db.Integer, primary_key=True)
         name = db.Column(db.String)
         signature_sandwich = db.Column(db.String)

         # Add relationship (deli has many customers through orders)
         orders = db.relationship(
         "Order", backref="deli", cascade="all, delete-orphan")

         # Add serialization rules (-orders.deli,)
         serialize_rules = ("-orders.deli",)

         # Add validation for name
         @validates('name')
         def validate_name(self, key, name):
             if name and len(name) &amp;gt;= 1:
                 return name
             else:
                 raise ValueError("Must have valid name attribute")


    class Customer(db.Model, SerializerMixin):
        __tablename__ = 'customers'

        id = db.Column(db.Integer, primary_key=True)
        name = db.Column(db.String)
        allergies = db.Column(db.String)

        # Add relationship (visits many delis through orders)
        orders = db.relationship(
        "Order", backref="customer", cascade="all, delete-orphan")

        # Add serialization rules (-orders.customer,)
        serialize_rules = ("-orders.customer",)

    class Order(db.Model, SerializerMixin):
        __tablename__ = 'orders'

        id = db.Column(db.Integer, primary_key=True)
        name = db.Column(db.String)

        # Add relationships (foreign keys for customer and deli)
        customer_id = db.Column(db.Integer, db.ForeignKey("customers.id"))
        deli_id = db.Column(db.Integer, db.ForeignKey("delis.id"))

        # Add serialization rules (deli.orders, customer.orders)
        serialize_rules = ("-deli.orders", "-customer.orders")

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How do we know what to put in the serialize_rules tuple?
&lt;/h2&gt;

&lt;p&gt;So this is really cool and all, but how do we know what to put into the tuples? Is there a rule for the dot notation? What am I actually saying when I type ("-orders.customer",) or ("-deli.orders", "-customer.orders”)?&lt;/p&gt;

&lt;p&gt;In the model class Customer that I defined above, the relationship is defined as being between Customer and Orders (the intermediate table.) So when you serialize to avoid the recursion spiral of doom, you only want to see the orders affiliated with a specific instance of a customer, and no other customers, even if they have the same order. That’s why the serializer rules for this class is ("-orders.customer”,). Without that dot notation, you could see that Customer A ordered a bacon-egg-and-cheese, but also a bunch of other customers who also ordered it, like Customer B, Customer C, and Customer D, which a) isn’t relevant to our data interests and b) makes Flask-SQLalchemy unhappy. So we code efficiently and throw a serialize rule in there to make sure we only see relevant information for that model. &lt;/p&gt;

&lt;p&gt;On the intermediate table in the earlier example, Orders, the tuple has two excluded fields, ("-deli.orders", "-customer.orders”). This means that when we look for orders affiliated with a specific deli or customer, we won’t see the other orders that deli or customer has. This keeps our data specific, relevant, and  non-recursive, and our code functional and free of the dreaded “Recursion Limit Exceeded” errors. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F50zsd2kzv9gffm1x03f9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F50zsd2kzv9gffm1x03f9.jpg" alt='Tyra Banks wearing pearls, text says: "recursiononrecursiononrecursion"' width="581" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;￼&lt;/p&gt;

&lt;h2&gt;
  
  
  Will serializer rules affect how data is stored in the database?
&lt;/h2&gt;

&lt;p&gt;Nope! These rules don’t affect the database, just how the data is presented in your APIs. You’ll still be able to retrieve and sort through it in all its big messy glory, even if you use serialization rules to make it more organized on the backend.   &lt;/p&gt;

&lt;h2&gt;
  
  
  What happens if we don’t serialize data in a RESTful API?
&lt;/h2&gt;

&lt;p&gt;The short answer is: nothing good. Here are some examples of what can happen:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The client might not be able to parse the raw data. (This can cause crashes.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The client might be exposed to sensitive information that should be protected. (This can lead to users getting sensitive information leaked or exposed)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The data might be too big to be transferred efficiently and take a while to load in the client&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the raw data isn’t formatted in a way the client can “understand” it might not be displayable at all.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn0d7gjxr5i1121voed2g.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn0d7gjxr5i1121voed2g.jpg" alt='image of J Alexander looking confused with text saying: "The client when your data should have been serialized"' width="577" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;￼&lt;br&gt;
Don’t want to see these things happen? Serialize, serialize, serialize.&lt;/p&gt;

&lt;h2&gt;
  
  
  Works cited:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;S. Stevens, “Flask+SQLAlchemy Serializer: A Comprehensive Guide to Serialization,” Medium, Aug. 08, 2023. &lt;a href="https://medium.com/@seanstevens729/flask-sqlalchemy-serializer-a-comprehensive-guide-to-serialization-aec8eeb8b456#:%7E:text=Serialization%2C%20the%20process%20of%20converting"&gt;https://medium.com/@seanstevens729/flask-sqlalchemy-serializer-a-comprehensive-guide-to-serialization-aec8eeb8b456#:~:text=Serialization%2C%20the%20process%20of%20converting&lt;/a&gt;  (accessed Oct. 15, 2023).&lt;/li&gt;
&lt;li&gt;“Python Recursion Errors &amp;amp; Serializer,” DEV Community, Jun. 05, 2023. &lt;a href="https://dev.to/jvaughn619/python-recursion-errors-serializer-2kh8"&gt;https://dev.to/jvaughn619/python-recursion-errors-serializer-2kh8&lt;/a&gt;  (accessed Oct. 15, 2023).&lt;/li&gt;
&lt;li&gt;S. radha krishnan, “Python Serialization and Deserialization in Flask SQLAlchemy,” Medium, Oct. 11, 2023. &lt;a href="https://medium.com/@srimathiradhakrishna/python-serialization-and-deserialization-in-flask-sqlalchemy-c2ff09d69677"&gt;https://medium.com/@srimathiradhakrishna/python-serialization-and-deserialization-in-flask-sqlalchemy-c2ff09d69677&lt;/a&gt; (accessed Oct. 15, 2023).&lt;/li&gt;
&lt;li&gt;“API — Flask Documentation (3.0.x),” flask.palletsprojects.com. &lt;a href="https://flask.palletsprojects.com/en/3.0.x/api/"&gt;https://flask.palletsprojects.com/en/3.0.x/api/&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Top Model Memes:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;“Americas next top model,” Imgflip. &lt;a href="https://imgflip.com/i/82ntne"&gt;https://imgflip.com/i/82ntne&lt;/a&gt;  (accessed Oct. 15, 2023).&lt;/li&gt;
&lt;li&gt;“Tyra Banks,” Imgflip. &lt;a href="https://imgflip.com/i/82nu69"&gt;https://imgflip.com/i/82nu69&lt;/a&gt;  (accessed Oct. 15, 2023).&lt;/li&gt;
&lt;li&gt;“Tyra Banks,” Imgflip. &lt;a href="https://imgflip.com/i/82nuhn"&gt;https://imgflip.com/i/82nuhn&lt;/a&gt;  (accessed Oct. 15, 2023).&lt;/li&gt;
&lt;li&gt;“Miss J Alexander,” Imgflip. &lt;a href="https://imgflip.com/i/82nyz5"&gt;https://imgflip.com/i/82nyz5&lt;/a&gt;  (accessed Oct. 15, 2023).&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>No One Expects the self._spanish_inquisition (Because it’s protected)</title>
      <dc:creator>Charlotte Bush</dc:creator>
      <pubDate>Fri, 22 Sep 2023 20:58:23 +0000</pubDate>
      <link>https://dev.to/varlotte/no-one-expects-the-selfspanishinquisition-because-its-protected-4p2m</link>
      <guid>https://dev.to/varlotte/no-one-expects-the-selfspanishinquisition-because-its-protected-4p2m</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5mmc190ls8xgyk29kjzd.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5mmc190ls8xgyk29kjzd.jpg" alt="A member of Monty Python sits at a newscasters' desk outdoors. Text says: &amp;quot;And now for something completely _different.&amp;quot;" width="666" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Phase three of bootcamp has been an intro to Python. I’ve appreciated so much about it, from its relatively humane syntax to its modularity, to the way list comprehensions let me make this joke:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa8r7l3qdv5215f5aa4ss.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa8r7l3qdv5215f5aa4ss.jpg" alt='A wild-eyed man with a bushy beard. Text says "There are some who call me [Tim for Tim in self.Tim]"' width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As I delved into learning about Object Oriented Programming, I started noticing a pattern in the error messages I was getting, and I got curious. Whenever I created a property with a setter, a getter, or attributes, it would throw an error and return an infinite loop. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqszcf6riuvdmk7a5n2f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqszcf6riuvdmk7a5n2f.png" alt='A sample of "recursion limit exceeded" pytest error messages.' width="800" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(A sample photo of the errors I got on a mock code challenge last week)&lt;/p&gt;

&lt;p&gt;In this sample, the code I was writing that threw the error was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@property&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;price&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Eventually, after a very frustrated 20 minutes of trial and error, I added a protected attribute indicator, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="nd"&gt;@property&lt;/span&gt;
      &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;price&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_price&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and the recursion errors stopped, but I was left with the lingering question of why. Why did all attributes in setters and getters in Python OOP want to be private or protected? I’d heard that in languages like Java, the private keyword does what __ does in Python (private is two underscores, and protected is one) and if the folklore says that Python was created to solve Java’s problems, what problem does the __ and _ solve?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxlojlqreb1yphh1mi7pj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxlojlqreb1yphh1mi7pj.jpg" alt='An image of Monty Python doing the Spanish Inquisition sketch. Text says "Nobody expects _protected attributes."' width="612" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, __private and _protected attributes do a few things, some more obvious than others. Their chief weapons (other than fear and surprise, of course) are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Preventing direct access to an attribute without additional logic being performed. This could be really useful if you need users to do additional validation or logic before setting a value, like a password.&lt;/li&gt;
&lt;li&gt;Ensuring the attribute is always used in a consistent way, or returned in a specific format. &lt;/li&gt;
&lt;li&gt;Making it easier to change the internal implementation of a class without breaking something external, like a database record or an API. (I suspect this wasn’t the problem I ran into in my mock code challenge, though.)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I also bumped into a principle of OOP called &lt;em&gt;Encapsulation&lt;/em&gt;, which aside from sounding like a molecular gastronomy technique, boils down to the idea that keeping data and their methods in one place makes them harder to access (and therefore modify and otherwise futz with) unintentionally. It forces modularity and intention, both of which are hallmarks of OOP. It also reminded me of all my adventures with functional and local scope in JavaScript, which was a fun blast of nostalgia.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftuxrc45fijvzoqj6ugla.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftuxrc45fijvzoqj6ugla.jpg" alt='A member of Monty Python dressed as a Viking. Text says "And I OOP."' width="666" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A Digression: &lt;/p&gt;

&lt;p&gt;For the curious at home, I followed the rabbit hole to find the other principles of OOP in Python. Other than &lt;em&gt;Encapsulation&lt;/em&gt;, we have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Inheritance&lt;/em&gt;: the idea that an object can inherit methods and properties from another, as in the case of parent and child classes. An example of this:&lt;br&gt;
&lt;br&gt;
                 &lt;/p&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# parent class         
&lt;/span&gt;    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
      &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;

      &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# child class
&lt;/span&gt;    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
      &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sAge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Polymorphism&lt;/em&gt;: the idea that a function or object can be used in multiple ways. A simple example of this is that you can use the + operator on both integers and strings in Python. When you see polymorphism in OOP, it’s generally paired with inheritance, allowing child class methods to override methods inherited from the parent when called with the child class object (aka method overriding.) In doing this, you can still access the methods of the parent, but you’ve effectively modified it to better meet the needs of the child. And finally:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Abstraction&lt;/em&gt;: the core of this principle is streamlining processes by only showing users details necessary to their experience. This usually gets achieved in OOP by having a base class and subclasses.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I know now why Python wouldn’t want me to use a public attribute with a getter or a setter, and why it’d throw errors, but why was my code throwing those infinite recursion errors and not just regular syntax errors?&lt;/p&gt;

&lt;p&gt;Turns out, the recursion happens when you try to access a public attribute from within the getter or setter method of a property. This is because Python will try to call the getter or setter method again, which will lead to infinite recursion. The reason for this? The names of both method and attribute are the same, so the infinite recursion is from Python thinking it needs to call itself over and over and over.&lt;/p&gt;

&lt;p&gt;Check out this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;           &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
                &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Charlotte&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

            &lt;span class="nd"&gt;@property&lt;/span&gt;
            &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;
             &lt;span class="nd"&gt;@name.setter&lt;/span&gt;
                    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
                        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;

        &lt;span class="n"&gt;my_class&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_class&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This throws the “recursion limit exceeded” error from earlier, because name is the name of the method AND the attribute. Python gets confused (much like me) when names are messy like this. So throwing in a private or protected marker differentiates the attribute from the method, and prevents the infinite, test-breaking recursion. You’d fix the code in the above example like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;          &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
                &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Charlotte&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

            &lt;span class="nd"&gt;@property&lt;/span&gt;
            &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__name&lt;/span&gt;

            &lt;span class="nd"&gt;@name.setter&lt;/span&gt;
            &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
                &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;

        &lt;span class="n"&gt;my_class&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_class&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By making it private in this case, my_class.name becomes non-recursive! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F13cuz7nvxheox3cewtth.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F13cuz7nvxheox3cewtth.jpg" alt="Monty Python members dressed as peasants. Text says &amp;quot;Public attributes in a setter or getter: help! help! I'm being repressed!" width="684" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And my final attribute privacy question: Is it better to use a private or a protected attribute? &lt;/p&gt;

&lt;p&gt;This led me to exploring the difference between private and protected attributes. After the recursion error merry-go-round, I was expecting something weird as an answer, but it turns out the key difference is one of inheritability. &lt;/p&gt;

&lt;p&gt;As Justin Ellis defines on his blog: “private (_&lt;em&gt;)means that the attribute/method can only be used inside the class where it is defined. Protected (&lt;/em&gt;) means that the attribute/method can only be used in the class where it is defined or its subclasses.” That subclass access makes all the difference, and I can see the appeal of protected attributes in the appropriate context.&lt;/p&gt;

&lt;p&gt;Whew! If you’ve made it this far, thanks for reading this long, strange trip of a blog. Tldr;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What does making attributes and classes private (or protected) actually do?&lt;/li&gt;
&lt;li&gt;What are the 4 principles of OOP in Python?&lt;/li&gt;
&lt;li&gt;Why do public attributes in setters and getters throw recursion errors (and regular not syntax errors)?&lt;/li&gt;
&lt;li&gt;Are private or protected attributes better to use?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I hope this helps!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn40d7zj0apo8alncu2ag.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn40d7zj0apo8alncu2ag.jpg" alt='A member of Monty Python doing a silly walk. Text says "this walk is def silly, __init__."' width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Works Used:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;“Image tagged in what is your name,” Imgflip. &lt;a href="https://imgflip.com/i/7zztzs"&gt;https://imgflip.com/i/7zztzs&lt;/a&gt;  (accessed Sep. 22, 2023).&lt;/li&gt;
&lt;li&gt;“Nobody Expects the Spanish Inquisition Monty Python,” Imgflip. &lt;a href="https://imgflip.com/i/803cpn"&gt;https://imgflip.com/i/803cpn&lt;/a&gt;  (accessed Sep. 22, 2023).&lt;/li&gt;
&lt;li&gt;“Encapsulation in Python - GeeksforGeeks,” GeeksforGeeks, Oct. 15, 2019. &lt;a href="https://www.geeksforgeeks.org/encapsulation-in-python"&gt;https://www.geeksforgeeks.org/encapsulation-in-python&lt;/a&gt; /&lt;/li&gt;
&lt;li&gt;“Python: The four pillars of Object-Oriented Programming,” www.linkedin.com. &lt;a href="https://www.linkedin.com/pulse/python-four-pillars-object-oriented-programming-benjamin-b-phiri/"&gt;https://www.linkedin.com/pulse/python-four-pillars-object-oriented-programming-benjamin-b-phiri/&lt;/a&gt;  (accessed Sep. 22, 2023).&lt;/li&gt;
&lt;li&gt;“Access Modifiers in Python,” Justin A. Ellis, Jan. 15, 2022. &lt;a href="https://jellis18.github.io/post/2022-01-15-access-modifiers-python/#:%7E:text=Private%20vs%20Protected&amp;amp;text=It%20will%20actually%20raise%20an"&gt;https://jellis18.github.io/post/2022-01-15-access-modifiers-python/#:~:text=Private%20vs%20Protected&amp;amp;text=It%20will%20actually%20raise%20an&lt;/a&gt; (accessed Sep. 22, 2023).&lt;/li&gt;
&lt;li&gt;“Image tagged in and now for something completely different,” Imgflip. &lt;a href="https://imgflip.com/i/803c57"&gt;https://imgflip.com/i/803c57&lt;/a&gt;  (accessed Sep. 22, 2023).&lt;/li&gt;
&lt;li&gt;“Help! Help! I’m being repressed!,” Imgflip. &lt;a href="https://imgflip.com/i/803ci0"&gt;https://imgflip.com/i/803ci0&lt;/a&gt;  (accessed Sep. 22, 2023).&lt;/li&gt;
&lt;li&gt;“Ministry of Silly Walks,” Imgflip. &lt;a href="https://imgflip.com/i/803d5k"&gt;https://imgflip.com/i/803d5k&lt;/a&gt; (accessed Sep. 22, 2023).&lt;/li&gt;
&lt;li&gt;“Image tagged in monty python viking,” Imgflip. &lt;a href="https://imgflip.com/i/803gu1"&gt;https://imgflip.com/i/803gu1&lt;/a&gt;  (accessed Sep. 22, 2023).&lt;/li&gt;
&lt;li&gt;“BBC Radio 4 - Front Row, Terry Gilliam and Edward Gardner, Joshua Ferris, Clean Bandit, Terry Gilliam Animations for Monty Python’s Flying Circus - Artwork by Terry Gilliam of a woman looking in a mirror.,” BBC. &lt;a href="https://www.bbc.co.uk/programmes/p02067rh/p02067gc"&gt;https://www.bbc.co.uk/programmes/p02067rh/p02067gc&lt;/a&gt;  (accessed Sep. 22, 2023).&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>beginners</category>
      <category>python</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Side Effects: React, uh, Finds a Way</title>
      <dc:creator>Charlotte Bush</dc:creator>
      <pubDate>Thu, 31 Aug 2023 21:48:12 +0000</pubDate>
      <link>https://dev.to/varlotte/side-effects-react-uh-finds-a-way-2lg4</link>
      <guid>https://dev.to/varlotte/side-effects-react-uh-finds-a-way-2lg4</guid>
      <description>&lt;p&gt;Learning React after vanilla Javascript has been mind-bending. Working in React after weeks of trying to wrangle the DOM by hand is like realizing you can get a laugh with a clever movie reference, not having to do a whole long setup and punchline.&lt;br&gt;
￼&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fedpw49kbuflpmxiin7wj.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fedpw49kbuflpmxiin7wj.jpeg" alt="Image description" width="800" height="419"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;[1] “Welcome to Jurassic Park,” Imgflip, &lt;a href="https://imgflip.com/i/7xmixa"&gt;https://imgflip.com/i/7xmixa&lt;/a&gt; (accessed Aug. 31, 2023).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I was particularly fascinated during this phase of boot camp with the idea of functional components, or (to explain it to my two-weeks-younger self) what if functions, but on a scale that’s somehow smaller (one function per component makes things a ton more modular, and scope becomes easier to define) but also a whole lot more expansive. &lt;/p&gt;

&lt;p&gt;￼&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8toy54vb6onb2emqnak8.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8toy54vb6onb2emqnak8.jpeg" alt="Image description" width="686" height="499"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;[2] “That’s a big,” Imgflip, &lt;a href="https://imgflip.com/i/7xm2h7"&gt;https://imgflip.com/i/7xm2h7&lt;/a&gt; (accessed Aug. 31, 2023).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So, my adorable two-weeks-younger self wonders, what happens if you need to do something out of scope of the component? In vanilla JavaScript, you have a handy tool called a “closure” that lets you access an outer function’s scope from an inner function, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function secretPassword() {
          const password = 'velociraptor93';
          return {
            guessPassword: function(guess) {
              if (guess === password) {
                return true;
              } else {
                return false;
              }
            }
          }
        }

        const passwordGame = secretPassword();
        passwordGame.guessPassword('clevergirl'); // false
        passwordGame.guessPassword('velociraptor93'); // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apart from terrible password design, what this example shows is the closure function &lt;code&gt;guessPassword&lt;/code&gt; getting exclusive access to the secret password. So what happens if you need to do something like this, outside of function scope, in a react component?&lt;/p&gt;

&lt;p&gt;The short answer? Side effects. Whether you know it or not, you’ve been using these bad boys in React to ensure that anything you want done outside of the scope of the functional component gets done, from making an API call, to setting up a subscription, to manually changing the DOM. The “side” part often gets omitted, making their reach in our code easier to notice (I see you there, useEffect.) &lt;/p&gt;

&lt;p&gt;I started wondering why these actions, which in vanilla Javascript were something of the main event, are now relegated to being classified as side effects. To understand why this linguistic snub of naming happens, we have to start thinking more about functions. &lt;/p&gt;

&lt;p&gt;In our earlier Jurassic Park meme, we did think about react components as big functions, taking in inputs (usually props) and returning JSX (that piquant mix of HTML and JavaScript we’ve come to savor.) These functions can be thought of as pure if, given the same inputs, they deterministically produce the same result. So far, so testable, right? Here’s where sideEffects come in.&lt;/p&gt;

&lt;p&gt;Side effects are thought of as “unpredictable” because they interact with the outside world, like an API, the DOM, or really anything outside a specific render of the functional component. That said, because we don’t necessarily control what’s outside of the component, the results are regarded as potentially:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fte2omvqm3vo01iiq6s65.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fte2omvqm3vo01iiq6s65.png" alt="Image description" width="800" height="456"&gt;&lt;/a&gt;￼&lt;br&gt;
&lt;em&gt;[3]Ytimg.com, 2023. &lt;a href="https://i.ytimg.com/vi/TRQp5x1iQEk/maxresdefault.jpg"&gt;https://i.ytimg.com/vi/TRQp5x1iQEk/maxresdefault.jpg&lt;/a&gt;  (accessed Aug. 31, 2023).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Enter, &lt;code&gt;useEffect&lt;/code&gt;, which handles side effects in what would otherwise be pure React components. Much like a pack of raptors, performing a side effect (like a fetch get request) by itself would get in the way of our component’s rendering. To horribly paraphrase the OG Jurassic Park, you &lt;em&gt;can&lt;/em&gt; do it, but you &lt;em&gt;shouldn’t&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxe8ox9qawv7aia8dd4ti.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxe8ox9qawv7aia8dd4ti.jpeg" alt="Image description" width="800" height="400"&gt;&lt;/a&gt;￼&lt;br&gt;
&lt;em&gt;[4] “Jurassic Park Raptor,” Imgflip, &lt;a href="https://imgflip.com/i/7xmhzy"&gt;https://imgflip.com/i/7xmhzy&lt;/a&gt; (accessed Aug. 31, 2023).&lt;a href="https://imgflip.com/i/7xmhzy"&gt;https://imgflip.com/i/7xmhzy&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
                fetch(raptorURL)
                  .then((r) =&amp;gt; r.json())
                  .then((data) =&amp;gt; setRaptorData(data));
              }, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using &lt;code&gt;useEffect&lt;/code&gt; on a fetch request like this one allows us to get the benefits of the side effect (hello, API data!) while still preserving the purity of the component’s render. In this example, the component will render a second time once the data has returned. Both of these renders are still being mediated by the &lt;code&gt;useEffect&lt;/code&gt;. Sounds like a clever girl to me!  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Works Used:&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;“The React useEffect Hook for Absolute Beginners,” freeCodeCamp.org, Mar. 01, 2022. &lt;a href="https://www.freecodecamp.org/news/react-useeffect-absolute-beginners/"&gt;https://www.freecodecamp.org/news/react-useeffect-absolute-beginners/&lt;/a&gt; (accessed Aug. 31, 2023).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“Using the Effect Hook – React,” legacy.reactjs.org. &lt;a href="https://legacy.reactjs.org/docs/hooks-effect.html#:%7E:text=Data%20fetching%2C%20setting%20up%20a"&gt;https://legacy.reactjs.org/docs/hooks-effect.html#:~:text=Data%20fetching%2C%20setting%20up%20a&lt;/a&gt; (accessed Aug. 31, 2023).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Cover Image:&lt;/em&gt;&lt;br&gt;
‌&lt;br&gt;
[1]People.com, 2023. &lt;a href="https://people.com/thmb/ZaDCClsPoc1buDSzf6biAdXhLJo=/1500x0/filters:no_upscale():max_bytes(150000):strip_icc():focal(999x0:1001x2)/jurassic-park-watn-tout-2000-26d6d3b1e08f458889f9497772ab477c.jpg"&gt;https://people.com/thmb/ZaDCClsPoc1buDSzf6biAdXhLJo=/1500x0/filters:no_upscale():max_bytes(150000):strip_icc():focal(999x0:1001x2)/jurassic-park-watn-tout-2000-26d6d3b1e08f458889f9497772ab477c.jpg&lt;/a&gt;  (accessed Aug. 31, 2023).&lt;/p&gt;

</description>
    </item>
    <item>
      <title>.then((playDominion)=&gt;</title>
      <dc:creator>Charlotte Bush</dc:creator>
      <pubDate>Fri, 11 Aug 2023 20:55:53 +0000</pubDate>
      <link>https://dev.to/varlotte/thenplaydominion-4cj</link>
      <guid>https://dev.to/varlotte/thenplaydominion-4cj</guid>
      <description>&lt;p&gt;As a hatchling dev early in my bootcamp career, I’m constantly on the lookout for new metaphors to help rewire my brain and make it all make sense. One that’s been a helpful scaffold for me as I get deeper into JavaScript is thinking about it in terms of my favorite classic deckbuilder, Dominion. &lt;/p&gt;

&lt;p&gt;A little &lt;a href="https://www.riograndegames.com/games/dominion/"&gt;about Dominion&lt;/a&gt;: it’s a very rad, much-expanded game from 2008. You play by building a deck and drafting a hand out of a bunch of different types of cards. On paper, at least, you win by getting the most victory points, but how you get there can be (much like a certain programming language) a little more…dynamic. &lt;/p&gt;

&lt;p&gt;Starting to learn JavaScript, with its multiple ways of saying, doing, or making the same things, really reminded me of Dominion, initially from the parallels between chaining functions, and action cards, but once I started thinking about it, the similarities just kept coming. Let’s talk about a few in an internet-friendly numbered list:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Setup:&lt;/strong&gt; On the most basic level, drawing and prepping your hand before play (especially if that round of play is a bunch of chained action cards) is the tabletop equivalent of declaring variables before outlining some functions with them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Functions and Actions&lt;/strong&gt; can both be chained, even with other (code/card) blocks: When I first started trying to write in JavaScript, the idea of calling a function as the logic of an event listener that is itself nested inside yet another function was a little brain breaking until I thought about it like Dominion, where as long as you have actions, you can “chain” action cards. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxu8a9hjadojxb0kmnu2i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxu8a9hjadojxb0kmnu2i.png" alt="Image description" width="688" height="508"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Futjotddn8iua83db84ub.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Futjotddn8iua83db84ub.png" alt="Image description" width="742" height="616"&gt;&lt;/a&gt;&lt;br&gt;
￼&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;append() and the vassal&lt;/strong&gt; If in this metaphor, the DOM is like the current field of play, any card like the vassal (which lets you draw the top card from your deck and play it if it’s an action) append to it outside of regular actions (functions) feel pretty similar to append(). &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Closures and Harbingers&lt;/strong&gt; Is something out of scope? Maybe if you use a closure (in this case one of the cards that lets you go back into your discard pile, like the harbinger) you can get access to cards/variables that you otherwise wouldn’t!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reactions and .thens&lt;/strong&gt; reactions (like moat) often are immediate responses to other cards, like attacks, and can be chained with other actions, the same way a .then at the end of a fetch request can have a rendering function nested inside. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7hyipzmp6n4vzf5vco1q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7hyipzmp6n4vzf5vco1q.png" alt="Image description" width="490" height="414"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sequence of Execution&lt;/strong&gt; JavaScript, like Dominion cards, needs to get resolved in the order it’s written/played (unless you have sneaky workarounds, like the “defer” script attribute, moving your script tag to the bottom of  or the harbinger or the spy, both of which “disrupt” the expected sequence of draw, play, and discard.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsr3rn7sz1rh6b590ezzd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsr3rn7sz1rh6b590ezzd.png" alt="Image description" width="800" height="66"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Function and Variable Delete&lt;/strong&gt; The same way functions and variables are deleted on page close, dominion hands are lost after they’re played. (This one’s kind of an easy comparison, I suspect)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope these analogy explainers were as helpful for you as they are for me, and if there are any that I missed or could've explained better, leave them in the comments- I'm excited to keep learning!&lt;/p&gt;

&lt;p&gt;Works Used:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;“List of cards,” List of cards - DominionStrategy Wiki, &lt;a href="https://wiki.dominionstrategy.com/index.php/List_of_cards"&gt;https://wiki.dominionstrategy.com/index.php/List_of_cards&lt;/a&gt; (accessed Aug. 10, 2023).&lt;/li&gt;
&lt;li&gt;D. X. Vaccarino, “Dominion.” 2008. Rio Grande Games, Placitas, NM. (Accessed August 10, 2023).&lt;/li&gt;
&lt;li&gt;N. Knutsen, “Complete Rules for Dominion and All Its Expansions,” Shuffles Public Rulebooks- Dominion, &lt;a href="https://www.shufflestulsa.com/public/rulebooks/Dominion.pdf"&gt;https://www.shufflestulsa.com/public/rulebooks/Dominion.pdf&lt;/a&gt; (accessed Aug. 10, 2023).&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>boardgames</category>
    </item>
  </channel>
</rss>
