<?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: Michael Phan</title>
    <description>The latest articles on DEV Community by Michael Phan (@michaelalexanderphan).</description>
    <link>https://dev.to/michaelalexanderphan</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%2F1172959%2F2d93293c-ae48-4695-8225-d9c188919777.png</url>
      <title>DEV Community: Michael Phan</title>
      <link>https://dev.to/michaelalexanderphan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/michaelalexanderphan"/>
    <language>en</language>
    <item>
      <title>Testing in React.js and Flask</title>
      <dc:creator>Michael Phan</dc:creator>
      <pubDate>Mon, 18 Dec 2023 07:02:01 +0000</pubDate>
      <link>https://dev.to/michaelalexanderphan/a-beginners-guide-to-testing-in-reactjs-and-flask-5bmn</link>
      <guid>https://dev.to/michaelalexanderphan/a-beginners-guide-to-testing-in-reactjs-and-flask-5bmn</guid>
      <description>&lt;h2&gt;
  
  
  A Practical Dive into System Testing for Junior Developers
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As I approach the end of my software engineering bootcamp, I've realized that testing is a crucial aspect of building reliable applications. I used to be a bit intimidated by the idea of testing, especially since we had a lot of tests written for us during our coding challenges. Looking at those test files was overwhelming at first, but as I've learned more about it, I can't stress enough how important it can be the larger our projects scale up. As we are getting ready to present our final projects, a full stack application, I thought it'd be super helpful to talk about something that's really important but not always highlighted enough: System Testing. We've heard a bit about Unit Testing, and it will probably be the most relevant to us as junior developers, however for bigger projects such as ours, we are going to be focusing on System Testing!&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Testing Matters
&lt;/h2&gt;

&lt;p&gt;Before we jump into testing, let's understand why it's essential. Think of testing as a safety net for your code. It helps you catch bugs early in the development process, ensuring that your application behaves as expected. Here are a few key reasons why testing is so important:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Preventing Bugs&lt;/strong&gt;&lt;br&gt;
Testing allows you to identify and fix issues before they reach users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Confidence in Code Changes&lt;/strong&gt;&lt;br&gt;
When you make changes or add new features, tests provide reassurance that existing functionality still works.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Collaboration and Maintenance&lt;/strong&gt;&lt;br&gt;
Tests serve as documentation for your code. They help you and your team understand how different parts of the application should work. Plus, they make it easier to maintain and improve your code over time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding Different Types of Testing&lt;/strong&gt;&lt;br&gt;
Before we discuss System Testing, let's break down the different types of testing we've come across:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;Unit Testing&lt;/em&gt;: Testing individual units or components.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Integration Testing&lt;/em&gt;: Ensuring different modules work together.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;System Testing&lt;/em&gt;: A comprehensive testing of the complete and fully integrated software application.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Acceptance Testing&lt;/em&gt;: Verifying the application meets business requirements. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Why System Testing Is Great For Our Projects&lt;/strong&gt;&lt;br&gt;
System Testing is a holistic approach that examines the entire application in a scenario that mimics real-world use. It's not just about checking individual parts but ensuring that everything works together seamlessly--an aspect crucial for the success of our capstone projects.&lt;/p&gt;

&lt;p&gt;Why Focus on System Testing?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Comprehensive Coverage&lt;/strong&gt;: It evaluates the application's overall functioning and performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User Perspective&lt;/strong&gt;: System tests simulate real user experiences, covering functional and non-functional requirements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Risk-Mitigation&lt;/strong&gt;: Helps identify issues that might not be evident in unit or integration tests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;System Testing in Practice: A Full Stack Application Example&lt;br&gt;
Let's consider an example relevant to our full stack project, a front-end built with React, and a back-end using Flask, and a database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;System Test Scenario: User Registration and Login Flow&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Test Objective&lt;/strong&gt;: Verify that a new user can register and log in to the application.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Steps:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Access the application's registration page.&lt;/li&gt;
&lt;li&gt;Fill in the registration form with user details and submit.&lt;/li&gt;
&lt;li&gt;Check if the user is directed to a confirmation page or receives a confirmation email.
-Log out and then navigate to the login page&lt;/li&gt;
&lt;li&gt;Log in with the newly created credentials
-Verify that the user accesses the dashboard after login.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3.&lt;strong&gt;Tools:&lt;/strong&gt; Tools like Selenium or Cypress can automate these steps, simulating a user's actions in a browser.&lt;/p&gt;

&lt;p&gt;Writing a System Test (Pseudocode):&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="c1"&gt;# Example of a system test script in pseudocode
# using a tool like Selenium or Cypress
&lt;/span&gt;
&lt;span class="nf"&gt;navigate_to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;registration_page&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;fill_form&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;username&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;newuser&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;password&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;password123&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="nf"&gt;submit_form&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;assert_on_page&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;confirmation_page&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;logout&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;navigate_to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;login_page&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;username&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;newuser&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;password&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;password123&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="nf"&gt;assert_on_page&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;dashboard&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Selenium and Cypress are among the most common and widely used tools in the development space for browser automation and system testing. They are popular for reasons such as&lt;/p&gt;

&lt;h4&gt;
  
  
  Selenium
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Versatility&lt;/strong&gt;: Selenium supports multiple programming languages like Java, C#, Python, Ruby, and JavaScript, making it a versatile choice for various development teams.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Browser Compatibility&lt;/strong&gt;: It works across different browsers like Chrome, Firefox, Internet Explorer, and Safari.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Community and Support&lt;/strong&gt;: Being one of the oldest tools in the market, it has a large community and extensive support resources.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integration with Other Tools&lt;/strong&gt;: Selenium integrates well with other testing frameworks and Continuous Integration (CI) tools.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Cypress
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Modern Framework&lt;/strong&gt;: Cypress is built for modern web applications and offers a more developer-friendly experience.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real-time Testing&lt;/strong&gt;: It allows developers to see tests running in real time, which can be beneficial for debugging.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automatic Waiting&lt;/strong&gt;: Cypress automatically waits for commands and assertions, reducing the flakiness of tests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rich Set of Features&lt;/strong&gt;: It provides features like time travel, snapshots, and network traffic control, making testing more efficient.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition to Selenium and Cypress, there are other tools like Puppeteer, WebDriverIO, and Playwright that are also gaining traction in the development community for similar purposes. The choice of tool often depends on the specific needs of the project and the familiarity of the development team with the tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices in System Testing
&lt;/h2&gt;

&lt;p&gt;When conducting system testing, there are several best practices to follow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Start Early and Test often:&lt;/strong&gt; Incorporate system testing early in the development cycle. This helps in identifying and fixing issues sooner.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Create Realistic Test Scenarios:&lt;/strong&gt; Simulate real-world scenarios that closely mimic user behavior and environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prioritize Tests:&lt;/strong&gt; Focus on critical paths in your application. Not all tests are equally important.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automate Where Possible:&lt;/strong&gt; Automate repetitive and time-consuming tests to improve efficiency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep Tests Maintainable:&lt;/strong&gt; Write clear, concise, and well-documented tests. This makes maintenance easier as your application evolves.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Review and Refine:&lt;/strong&gt; Regularly review your test cases and update them as the application changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Integrating System Testing into Your Workflow
&lt;/h2&gt;

&lt;p&gt;As junior developers stepping out into the field, especially with a freshly completed project that we may continue to work on and improve, understanding and implementing System Testing provides us with a more broad perspective on our applications' functionality.  While Unit Testing remains a fundamental skill for us, System Testing elevates our testing approach to encompass the entire application, ensuring we deliver a product that not only works in parts but excels as a whole.&lt;/p&gt;

&lt;p&gt;Learning System Testing now is a great way to get ready for the real world of software development. It's a skill that'll help us not just as coders but as developers who can create cool, user-friendly applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Extra Resources&lt;/strong&gt;&lt;br&gt;
1.&lt;em&gt;integration testing documentation&lt;/em&gt; &lt;a href="https://www.guru99.com/testing-documentation.html"&gt;https://www.guru99.com/testing-documentation.html&lt;/a&gt;&lt;br&gt;
2.&lt;em&gt;What is System Testing - an ultimate beginners guide&lt;/em&gt;&lt;br&gt;
&lt;a href="https://www.softwaretestinghelp.com/system-testing/"&gt;https://www.softwaretestinghelp.com/system-testing/&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;Selenium Tutorial: A Complete Guide on Selenium Testing&lt;/em&gt;
&lt;a href="https://www.lambdatest.com/selenium"&gt;https://www.lambdatest.com/selenium&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Relationships in SQLAlchemy</title>
      <dc:creator>Michael Phan</dc:creator>
      <pubDate>Fri, 01 Dec 2023 08:12:21 +0000</pubDate>
      <link>https://dev.to/michaelalexanderphan/relationships-in-sqlalchemy-cp1</link>
      <guid>https://dev.to/michaelalexanderphan/relationships-in-sqlalchemy-cp1</guid>
      <description>&lt;h2&gt;
  
  
  Beginning the Relationship Mapping
&lt;/h2&gt;

&lt;p&gt;As a student first diving into SQLAlchemy for our full-stack Twitter clone project, I was met with a complex web of tables and relationships. Here's the path of my understanding, supplemented by our actual code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;OneToMany/ManyToOne Relationships:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
These relationships form the backbone of user-generated content platforms. A user can create many posts, but each post is tied to one creator.&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;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# ... other columns ...
&lt;/span&gt;    &lt;span class="c1"&gt;# OneToMany: User to Posts
&lt;/span&gt;    &lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;relationship&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Post&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;back_populates&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cascade&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;all, delete-orphan&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;This code represents the concept of 'users' and their 'posts' in a straightforward manner: one user, many posts.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;ManyToMany Relationships:&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
A user's social connections are more complex. They can follow many users and be followed by many, creating a ManyToMany relationship.&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;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# ... other columns ...
&lt;/span&gt;    &lt;span class="c1"&gt;# ManyToMany: User to Followers and Following
&lt;/span&gt;    &lt;span class="n"&gt;followers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;relationship&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Follower&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;back_populates&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;following&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;foreign_keys&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Follower.following_id&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;following&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;relationship&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Follower&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;back_populates&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;follower&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;foreign_keys&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Follower.follower_id&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The Follower table serves as the associative table, creating a network of user connections.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Self-referential Relationships:&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
The Follower table's nature of referencing the same User table for both 'follower_id' and 'following_id' makes it self-referential.&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;Follower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# ... other columns ...
&lt;/span&gt;    &lt;span class="c1"&gt;# Self-referential: Users following Users
&lt;/span&gt;    &lt;span class="n"&gt;follower&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;relationship&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;User&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;back_populates&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;followers&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;foreign_keys&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;follower_id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="n"&gt;following&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;relationship&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;User&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;back_populates&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;following&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;foreign_keys&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;following_id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;This snippet is the key to creating a social graph within our application.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Circular Relationships&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
Circular relationships occur when two or more entities are mutually dependent on each other, creating a cycle. This can be challenging to represent and manage but is essential for certain features like threaded comments, where a post can be a comment to another post.&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;Post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# ... other columns ...
&lt;/span&gt;    &lt;span class="c1"&gt;# Circular relationship: Posts to Comments
&lt;/span&gt;    &lt;span class="n"&gt;comments&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;relationship&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Post&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;back_populates&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;parent&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cascade&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;all, delete-orphan&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;parent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;relationship&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Post&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;back_populates&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;comments&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;remote_side&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Here, a Post can be a parent to other Post records, allowing for a hierarchy of posts and comments that reference each other.&lt;/p&gt;

&lt;p&gt;Delving Deeper&lt;br&gt;
I've realized that relationships in databases, like in real life, are not one-dimensional. They're intricate and interwoven.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Backref and Back Populates:&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
These SQLAlchemy features allow us to define the nature of our relationships bidirectionally. They ensure that both sides of the relationship are synchronized.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Cascade Options:&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
The cascade parameters were a lesson in responsibility. Like ensuring you clean up after a pet, cascading helps clean up related records to prevent database clutter.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Understanding Hybrid Properties&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
Hybrid properties in SQLAlchemy act like computed columns and provide a way to define custom, calculated fields.&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;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# ... other columns ...
&lt;/span&gt;    &lt;span class="nd"&gt;@hybrid_property&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;password&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="c1"&gt;# Password is not directly accessible
&lt;/span&gt;        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;AttributeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Password access is not allowed&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nd"&gt;@password.setter&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;password&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;password&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;# Password is hashed for security
&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;_password_hash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bcrypt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hashpw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;bcrypt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gensalt&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;This example shows the encapsulation and security considerations for user passwords.&lt;/p&gt;

&lt;p&gt;Performance Considerations&lt;br&gt;
I learned the importance of choosing the right loading strategy—lazy, eager, or selective—to optimize database access patterns.&lt;/p&gt;

&lt;p&gt;You know when you finally get that eureka moment? That happened to me with database relationships. They're not just lines connecting dots in a diagram; they're like the digital version of how we all interact with each other on social media. It's pretty cool to think about how those tables and columns in our database are actually laying down the tracks for friendships, conversations, and all the drama in between – right in the code!&lt;/p&gt;

&lt;p&gt;SQLAlchemy doesn't just help us map out our database; it allows us to craft a narrative of interactions, shaping our application's story through data.&lt;/p&gt;

&lt;p&gt;This journey taught me that each line of code echoes a relationship, a connection. It's about the macro—the application as a whole—and the micro—the individual relationships and their nuances.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Understanding SQLAlchemy relationships took me from confusion to clarity, from being a student to thinking like a developer. I'm not just proud of the application we built but also of the deeper understanding of how each part interconnects.&lt;/p&gt;

&lt;p&gt;This deep dive into SQLAlchemy really felt like a journey into the heart of tech development. It's fascinating to see how these database relationships aren't just technical stuff – they're the building blocks of the online world. Kind of like getting a behind-the-scenes look at how all our digital interactions are wired together.&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://docs.sqlalchemy.org/en/14/orm/basic_relationships.html"&gt;https://docs.sqlalchemy.org/en/14/orm/basic_relationships.html&lt;/a&gt; / SQLAlchemy Documentation&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Unlocking Python's Power With List Comprehensions and Advanced Data Structures</title>
      <dc:creator>Michael Phan</dc:creator>
      <pubDate>Wed, 15 Nov 2023 14:04:05 +0000</pubDate>
      <link>https://dev.to/michaelalexanderphan/unlocking-pythons-power-with-list-comprehensions-and-advanced-data-structures-4895</link>
      <guid>https://dev.to/michaelalexanderphan/unlocking-pythons-power-with-list-comprehensions-and-advanced-data-structures-4895</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;Python, renowned for its simplicity and efficiency, offers powerful tools that can optimize and simplify code. Among these are list comprehensions and advanced data structures. This blog will explore these concepts, shedding light on their utility and elegance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Section 1:&lt;/em&gt;&lt;/strong&gt; Demystifying List Comprehensions&lt;br&gt;
List comprehensions provide a concise way to create lists. They are more compact and faster than traditional for-loops, making your code more Pythonic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding the Basics:&lt;/strong&gt;&lt;br&gt;
A list comprehension consists of brackets containing an expression followed by a for clause, then zero or more for or if clauses. The expression can be anything, meaning you can put in all kinds of objects in lists.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic List Comprehension&lt;/strong&gt;&lt;br&gt;
Here’s a simple 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="n"&gt;squares&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;squares&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This snippet generates a list of square numbers from 0 to 9. It’s equivalent to writing a for-loop but is more succinct and readable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Section 2:&lt;/em&gt;&lt;/strong&gt; Advanced Usage of List Comprehensions&lt;br&gt;
List comprehensions can be more complex. They can include multiple for clauses, which behave like nested loops.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nested Loops in List Comprehensions&lt;/strong&gt;&lt;br&gt;
Consider generating a list of tuples:&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="n"&gt;pairs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pairs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This snippet generates a list of tuples, representing all combinations of the two lists, excluding pairs with the same elements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Section 3: Exploring Advanced Data Structures&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Python offers several advanced data structures like tuples, sets, and dictionaries, which are crucial for various complex tasks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tuples:&lt;/strong&gt;&lt;br&gt;
Tuples are immutable sequences, typically used to store heterogeneous data.&lt;/p&gt;

&lt;p&gt;Tuples&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="n"&gt;my_tuple&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;3.4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_tuple&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Sets:&lt;/strong&gt;&lt;br&gt;
Sets are unordered collections of unique elements. They are ideal for membership testing and eliminating duplicate entries.&lt;/p&gt;

&lt;p&gt;Sets&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="n"&gt;my_set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_set&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Output: {1, 2, 3}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dictionaries:&lt;br&gt;
Dictionaries store key-value pairs and are optimized for retrieving data. They are mutable and dynamic, allowing keys to be added or removed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dictionaries&lt;/strong&gt;&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="n"&gt;my_dict&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'John'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'age'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;26&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;  &lt;span class="c1"&gt;# Output: John
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dictionaries are incredibly versatile, ideal for scenarios where data needs to be easily accessible by a key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Section 4: Advanced Data Structures in Action&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
In practice, these advanced data structures can significantly simplify complex data manipulations. They shine especially when combined with list comprehensions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Combining Data Structures&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Consider this example where we filter a list of dictionaries:&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="n"&gt;employees&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="s"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'John'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'dept'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'Engineering'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
             &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'Jane'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'dept'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'Sales'&lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;

&lt;span class="n"&gt;engineering&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;emp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;emp&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;emp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'dept'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;'Engineering'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;engineering&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This snippet demonstrates using a list comprehension with a dictionary to filter data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Section 5: Practical Applications and Best Practices&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Understanding when and how to use these tools is crucial. List comprehensions are best for simple transformations, while advanced data structures are essential for complex data manipulation and storage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;br&gt;
Mastering list comprehensions and advanced data structures is a stepping stone to more advanced Python programming. These concepts are not just limited to small-scale problems but are extensively used in real-world applications, including data analysis, machine learning, web development, and automation. As you continue to explore Python, these tools will prove invaluable, helping you to write code that is not only effective but also clean and aligned with Python's core philosophy.&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
Python's Official Documentation&lt;/p&gt;

</description>
    </item>
    <item>
      <title>useEffect Hooks in React</title>
      <dc:creator>Michael Phan</dc:creator>
      <pubDate>Fri, 20 Oct 2023 07:38:52 +0000</pubDate>
      <link>https://dev.to/michaelalexanderphan/useeffect-hooks-in-react-58i5</link>
      <guid>https://dev.to/michaelalexanderphan/useeffect-hooks-in-react-58i5</guid>
      <description>&lt;p&gt;&lt;em&gt;*&lt;em&gt;Unlocking the Secrets of useEffect in React: *&lt;/em&gt;&lt;/em&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;My attempt at simplifying useEffect:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Imagine you have a smart house, or a bunch of smart appliances. Various activities happen automatically—lights turn off and on, the temperature adjusts, and the doors lock or unlock based on different factors like time or whether someone is home. In React, a tool used to build websites, useEffect is like the system that manages these automated activities, known as "side effects."&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;What is useEffect?&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
useEffect is a tool that helps us manage various activities in our website automatically. Just like a smart home system that manages lights or temperature, useEffect takes care of different tasks such as loading data or reacting to user interactions.&lt;br&gt;
useEffect performs side effects in a function component. Side effects could be data-fetching, subscriptions, manually changing the DOM, etc.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;When Do We Use useEffect?&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
In a smart house, you might want the lights to turn on automatically at 6 PM. Similarly, in a website, you might want to load some data as soon as a visitor arrives.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wRs35KNe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qrgfi2tvdi7p4h8gyur8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wRs35KNe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qrgfi2tvdi7p4h8gyur8.png" alt="Image description" width="697" height="120"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Cleaning Up With useEffect&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
After hosting a party, you’d clean up and reset your home. Similarly, useEffect lets us clean up after activities, ensuring that everything runs smoothly and nothing is left hanging.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F-orqnOo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ntcop67djcznxs8szmja.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F-orqnOo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ntcop67djcznxs8szmja.png" alt="Image description" width="665" height="151"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Custom Rules with useEffect&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
Sometimes, you might have specific rules, like turning off lights in unoccupied rooms. You can customize useEffect to handle such special cases, making it adaptable to various needs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jD4IWBsB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/75y0d7yt50jzhp3y36i8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jD4IWBsB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/75y0d7yt50jzhp3y36i8.png" alt="Image description" width="591" height="92"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Guidelines for Using useEffect&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Avoid Endless Loops: Make sure your commands don’t keep repeating endlessly, like a light that keeps turning off and on.&lt;/p&gt;

&lt;p&gt;Specify Dependencies: Ensure you clearly state what factors or conditions your activities depend on, so they run at the right times.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;*&lt;em&gt;Advanced Automation with useEffect: *&lt;/em&gt;&lt;/em&gt;&lt;br&gt;
Tailoring Your Smart House&lt;br&gt;
Continuing with our smart house analogy, let’s delve deeper into the customization and advanced features that useEffect offers in enhancing our React homes (websites).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Multiple useEffect for Different Activities&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
Imagine you want to control the lights in one room and the air conditioning in another separately. In React, you can use multiple useEffect hooks to manage different activities independently.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OvrjPWUc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m3gm0vkehkyh242jrtkm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OvrjPWUc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m3gm0vkehkyh242jrtkm.png" alt="Image description" width="492" height="151"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, each useEffect is like a separate control system managing a different part of the house, allowing for more specialized and organized configurations.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Crafting Custom Controls with useEffect&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
Custom hooks in React are like creating your personalized smart home routines or modes, like a "Cinema Mode" that dims the lights and sets the room temperature to a comfortable level.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m8p6Qurz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xgay2oz4gqev75mpbj9d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m8p6Qurz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xgay2oz4gqev75mpbj9d.png" alt="Image description" width="642" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This way, you can create reusable sets of commands (routines) that can be easily applied whenever needed, making the system more versatile and user-friendly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Conclusion&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Understanding useEffect is like mastering the control system of a smart house in the world of website development. It allows your website to perform various tasks automatically, making the user’s experience smooth and dynamic. With useEffect, you can manage, customize, and optimize these tasks to create effective and user-friendly websites.&lt;/p&gt;

&lt;p&gt;more info &lt;a href="https://legacy.reactjs.org/docs/hooks-effect.html"&gt;https://legacy.reactjs.org/docs/hooks-effect.html&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>My Journey into JavaScript: Balancing Late Nights and Learning</title>
      <dc:creator>Michael Phan</dc:creator>
      <pubDate>Fri, 29 Sep 2023 09:30:29 +0000</pubDate>
      <link>https://dev.to/michaelalexanderphan/my-journey-into-javascript-balancing-late-nights-and-learning-57e2</link>
      <guid>https://dev.to/michaelalexanderphan/my-journey-into-javascript-balancing-late-nights-and-learning-57e2</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction to Flatiron School SWE Bootcamp&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When I first joined my coding bootcamp, I had no idea what to expect. I anticipated a solitary journey, assuming I would be on my own in my quest to learn JavaScript. However, I was pleasantly surprised to discover that the experience was far more social and enriching than I had imagined. This newfound camaraderie, combined with the challenges of late-night coding and the battle with imposter syndrome, transformed my journey into a truly rewarding and fulfilling adventure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Appeal of DOM Manipulation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first phase of my bootcamp focused on JavaScript, with its ability to manipulate the Document Object Model (DOM), fascinated me from the start. It held the promise of creating dynamic and interactive web applications, but I soon realized that it wasn't just about memorizing code snippets – it was about deeply understanding the concepts behind them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Late Nights and Struggles&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As I delved into the world of JavaScript, I found myself burning out more often than not. I was determined to master the language and ensure that my understanding was solid. However, my relentless pursuit of knowledge began to take a toll on my health. It was a wakeup call that made me realize the need for balance in my learning journey.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Reward of Understanding&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Amidst the late-night coding sessions and moments of frustration, there came a breakthrough. That moment when everything clicked, and I truly understood a concept, was euphoric. It was the reward for all the effort I had invested. This feeling of mastery fueled my determination to keep going, but I knew I needed to find a healthier approach.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learning Efficiency and Balance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I realized that efficiency in learning is not about how many hours you spend coding but about how effectively you utilize your time. Late nights and all-nighters were not sustainable in the long run. I started to adopt strategies to maximize my learning without sacrificing my well-being.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Structured Learning:&lt;/em&gt;&lt;/strong&gt; I organized my learning into focused sessions with breaks in between to prevent burnout.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Code Analogies:&lt;/em&gt;&lt;/strong&gt; I discovered that code analogies were incredibly helpful in grasping complex concepts. They served as mental bridges, connecting new knowledge to familiar concepts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hands-on Learning:&lt;/em&gt;&lt;/strong&gt; Practical exercises and projects allowed me to apply what I learned immediately, reinforcing my understanding.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Power of Asking for Help&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the most significant lessons I learned was the importance of seeking help. There's no shame in asking questions or reaching out to peers, instructors, or online communities. When I encountered roadblocks, I realized that a simple explanation or code snippet from someone else could provide the clarity I needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;From Comparing to Empowering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Early on, I found that I was comparing myself often to the rest of the group. Instead of viewing my peers as competitors, I realized that we all shared the same goal. We were on a collective journey against the curriculum, not against each other. This shift in perspective transformed my experience. Rather than comparing myself in a detrimental way, I began to see my cohort as a source of support and encouragement. We were a team, each with unique strengths, working together to conquer the challenges of coding.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Looking Ahead&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As I reflect on this first phase of my coding bootcamp, I find myself excited for what lies ahead. The next phase will focus on React, and I'm eager to delve into new ways of efficiently coding and building dynamic web applications. My journey continues, and I'm ready to embrace the challenges and rewards that come with it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Pledge to Active Learning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I've come to recognize that I learn best through hands-on experience. Lectures alone can leave me feeling adrift. So, as I step into the next phase of my bootcamp, I'm committed to a new approach. I'll engage in prior practice and practical exercises to ensure that I come to lectures armed with questions and a readiness to be actively involved. This, I believe, will enhance my learning process and bring me closer to my goals.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;My journey through phase 1 of my coding bootcamp has been a transformative experience. It exceeded my initial expectations of a solitary pursuit and introduced me to an amazing community of fellow learners. I faced the formidable imposter syndrome head-on, turning it from a hindrance into a driving force.&lt;/p&gt;

&lt;p&gt;As I continue down this coding path, I am not only learning the intricacies of JavaScript, React, Python, and Flask, but also the importance of collaboration, support, balance, and shared goals. The late-night struggles and the imposter syndrome challenges have all been instrumental in shaping my perspective, making me realize that it's not about being the best coder in the room but about being the best learner I can be.&lt;/p&gt;

&lt;p&gt;I will always wish nothing but success for everyone on a similar journey, for we are not in competition with each other; we are allies in the pursuit of the never ending knowledge and skill that this industry requires.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
