<?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: Victoria Lima De Carvalho</title>
    <description>The latest articles on DEV Community by Victoria Lima De Carvalho (@victoria_limadecarvalho).</description>
    <link>https://dev.to/victoria_limadecarvalho</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%2F2798755%2F3a5df2d0-3d36-4125-a891-ff5c4398179c.jpg</url>
      <title>DEV Community: Victoria Lima De Carvalho</title>
      <link>https://dev.to/victoria_limadecarvalho</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/victoria_limadecarvalho"/>
    <language>en</language>
    <item>
      <title>MUI Material Styling: How to Implement it in Your React App</title>
      <dc:creator>Victoria Lima De Carvalho</dc:creator>
      <pubDate>Thu, 08 May 2025 19:23:54 +0000</pubDate>
      <link>https://dev.to/victoria_limadecarvalho/mui-material-styling-how-to-implement-it-in-your-react-app-3i40</link>
      <guid>https://dev.to/victoria_limadecarvalho/mui-material-styling-how-to-implement-it-in-your-react-app-3i40</guid>
      <description>&lt;p&gt;Let’s face it—building sleek, responsive user interfaces can be a tedious. But Material UI (MUI) can make it easier. If you're working with React, MUI is one of the best libraries out there for whipping up beautiful UIs. With its ready-made components and powerful styling tools (based on Google’s Material Design), your app won’t just work well—it’ll look good too.&lt;/p&gt;

&lt;p&gt;In this guide, we'll dive into how to use MUI's styling solution and implement it in your React project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why MUI Styling?&lt;/strong&gt;&lt;br&gt;
MUI’s styling solution is one of the standout features of the library. It allows developers to style components using JavaScript, enabling better maintainability, dynamic theming, and a more seamless integration with the React ecosystem. The primary benefits include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Customizability:&lt;br&gt;
Easily tweak components to suit your brand.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Theming: Create a consistent design language using a global theme.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Responsiveness: MUI makes it easy to build responsive layouts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Simplicity: The syntax and concepts are easy to grasp, especially for those already familiar with CSS-in-JS.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Getting Started with MUI Styling&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Step 1: Install MUI in Your React Project&lt;/strong&gt;&lt;br&gt;
Before diving into styling, make sure that MUI is installed in your project. You can add MUI and its required dependencies by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @mui/material @emotion/react @emotion/styled

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

&lt;/div&gt;



&lt;p&gt;This will install the core Material UI components and the Emotion library for styling (Emotion is the default styling engine for MUI).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Basic Usage with sx Prop&lt;/strong&gt;&lt;br&gt;
MUI comes with the sx prop, a powerful and flexible way to style components directly. The sx prop is a shorthand for adding custom styles to components and is a key feature of MUI 5.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For example, to style a button:&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;import { Button } from '@mui/material';

function MyButton() {
  return (
    &amp;lt;Button sx={{ backgroundColor: 'blue', color: 'white', padding: '10px 20px' }}&amp;gt;
      Click Me
    &amp;lt;/Button&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;The sx prop accepts an object with CSS properties, making it simple to apply inline styles. You can also leverage theme values directly in this object, such as theme.palette.primary.main.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Theming with ThemeProvider&lt;/strong&gt;&lt;br&gt;
One of MUI’s greatest strengths is its theming capabilities. You can create a global theme that applies consistent styles across your application.&lt;/p&gt;

&lt;p&gt;To create a theme, use MUI's createTheme function and wrap your application with the ThemeProvider component. Here's an example of setting up a custom theme:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createTheme, ThemeProvider } from '@mui/material/styles';
import { Button } from '@mui/material';

const theme = createTheme({
  palette: {
    primary: {
      main: '#1976d2', // Custom primary color
    },
    secondary: {
      main: '#dc004e', // Custom secondary color
    },
  },
});

function App() {
  return (
    &amp;lt;ThemeProvider theme={theme}&amp;gt;
      &amp;lt;Button color="primary"&amp;gt;Primary Button&amp;lt;/Button&amp;gt;
      &amp;lt;Button color="secondary"&amp;gt;Secondary Button&amp;lt;/Button&amp;gt;
    &amp;lt;/ThemeProvider&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;In this example:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We created a theme with custom primary and secondary colors.&lt;/p&gt;

&lt;p&gt;The ThemeProvider component makes the theme available to all child components, allowing them to access theme values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Using styled API for Custom Components&lt;/strong&gt;&lt;br&gt;
MUI also provides the styled utility, which enables you to define custom styled components with JavaScript. This works similarly to CSS-in-JS libraries but with the full power of the MUI theme.&lt;/p&gt;

&lt;p&gt;For instance, let’s create a custom-styled Card component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { styled } from '@mui/system';
import { Card, CardContent, Typography } from '@mui/material';

const CustomCard = styled(Card)(({ theme }) =&amp;gt; ({
  backgroundColor: theme.palette.primary.light,
  padding: theme.spacing(3),
  boxShadow: theme.shadows[3],
}));

function App() {
  return (
    &amp;lt;CustomCard&amp;gt;
      &amp;lt;CardContent&amp;gt;
        &amp;lt;Typography variant="h5"&amp;gt;Custom Card&amp;lt;/Typography&amp;gt;
        &amp;lt;Typography variant="body2"&amp;gt;This is a custom-styled card using MUI's styled API.&amp;lt;/Typography&amp;gt;
      &amp;lt;/CardContent&amp;gt;
    &amp;lt;/CustomCard&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;In this example:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We used the styled function to create a custom Card component.&lt;/p&gt;

&lt;p&gt;The styles are dynamically generated using the MUI theme.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Responsive Design with MUI’s Grid System&lt;/strong&gt;&lt;br&gt;
MUI also includes a powerful grid system, which allows you to create responsive layouts easily.&lt;/p&gt;

&lt;p&gt;Here’s an example of a responsive layout using MUI's Grid components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Grid, Paper } from '@mui/material';

function ResponsiveLayout() {
  return (
    &amp;lt;Grid container spacing={2}&amp;gt;
      &amp;lt;Grid item xs={12} sm={6} md={4}&amp;gt;
        &amp;lt;Paper&amp;gt;Item 1&amp;lt;/Paper&amp;gt;
      &amp;lt;/Grid&amp;gt;
      &amp;lt;Grid item xs={12} sm={6} md={4}&amp;gt;
        &amp;lt;Paper&amp;gt;Item 2&amp;lt;/Paper&amp;gt;
      &amp;lt;/Grid&amp;gt;
      &amp;lt;Grid item xs={12} sm={6} md={4}&amp;gt;
        &amp;lt;Paper&amp;gt;Item 3&amp;lt;/Paper&amp;gt;
      &amp;lt;/Grid&amp;gt;
    &amp;lt;/Grid&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;In this layout:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The Grid component is used to create a flexible and responsive grid system.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The xs, sm, and md props define how the items behave on different screen sizes (e.g., full width on small screens and one-third width on medium screens).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Best Practices&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Use the sx prop for simple customizations: If you're making minor tweaks to an MUI component, the sx prop is the way to go.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Leverage the theme: Use the theme to define global design standards (e.g., color palette, typography) and ensure consistency throughout your app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modular styling: For complex components, consider using the styled API to create reusable, custom-styled components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stay responsive: MUI's grid and responsive utilities help you build layouts that adapt well to various screen sizes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Core Takeaways&lt;/strong&gt;&lt;br&gt;
MUI’s styling system brings the best of both worlds: design consistency and development flexibility. Whether you’re fine-tuning a button or creating a full design system, MUI gives you the tools to do it fast—and do it right.&lt;/p&gt;

&lt;p&gt;Sources:&lt;br&gt;
&lt;a href="https://mui.com/material-ui/getting-started/" rel="noopener noreferrer"&gt;Material UI&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>styling</category>
      <category>mui</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Using Formik- Beginner’s Guide to Connecting a React Formik Form to a Flask Backend</title>
      <dc:creator>Victoria Lima De Carvalho</dc:creator>
      <pubDate>Tue, 15 Apr 2025 16:45:56 +0000</pubDate>
      <link>https://dev.to/victoria_limadecarvalho/using-formik-beginners-guide-to-connecting-a-react-formik-form-to-a-flask-backend-2abo</link>
      <guid>https://dev.to/victoria_limadecarvalho/using-formik-beginners-guide-to-connecting-a-react-formik-form-to-a-flask-backend-2abo</guid>
      <description>&lt;p&gt;If you're just getting started with building full-stack web apps using Flask (Python) for your backend and React for your frontend, you might be wondering how to handle forms smoothly. Don't worry, that’s where Formik comes in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Formik?&lt;/strong&gt; &lt;br&gt;
It's a very useful library for managing forms in React.&lt;/p&gt;

&lt;p&gt;What We’re Building...&lt;br&gt;
A basic registration form where a user enters their email and password. &lt;/p&gt;

&lt;p&gt;The form will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Validate input using &lt;em&gt;&lt;strong&gt;Formik and Yup&lt;/strong&gt;&lt;/em&gt; &lt;/li&gt;
&lt;li&gt;Send the data to a Flask backend using fetch( ).&lt;/li&gt;
&lt;li&gt;Handle the response from Flask and show a success or error message.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 1:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Flask Backend Setup&lt;br&gt;
Here’s a simple Flask backend that accepts form data from the frontend.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# app.py
from flask import Flask, request, jsonify
from flask_cors import CORS

app = Flask(__name__)
CORS(app)  # Allows requests from your React app (very important!)

@app.route('/api/register', methods=['POST'])
def register():
    data = request.get_json()

    # Simple validation
    if not data.get('email') or not data.get('password'):
        return jsonify({'error': 'Email and password are required.'}), 400

    # In a real app, you'd save the data to a database here
    print("Received data:", data)

    return jsonify({'message': 'Registration successful!'}), 200

if __name__ == '__main__':
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run this with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 2:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
React Frontend with Formik (Using fetch)&lt;br&gt;
Now we will build the form in React using &lt;strong&gt;Formik&lt;/strong&gt; for dynamically rendering inputs, and &lt;strong&gt;Yup&lt;/strong&gt; for validation schema.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;First&lt;/em&gt;&lt;/strong&gt;, install the necessary libraries in your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#in your React frontend
npm install formik yup

#in your Flask backend
pip install Flask flask-cors
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Then&lt;/em&gt;&lt;/strong&gt;, create the form:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// RegisterForm.jsx
import React from 'react';
import { Formik, Form, Field, ErrorMessage } from 'formik';
import * as Yup from 'yup';

const RegisterForm = () =&amp;gt; {
  const initialValues = {
    email: '',
    password: ''
  };

  const validationSchema = Yup.object({
    email: Yup.string().email('Invalid email format').required('Required'),
    password: Yup.string().min(6, 'Password must be at least 6 characters').required('Required')
  });

  const handleSubmit = async (values, { setSubmitting, resetForm }) =&amp;gt; {
    try {
      const response = await fetch('http://localhost:5000/api/register', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify(values)
      });

      const data = await response.json();

      if (!response.ok) {
        alert(`Error: ${data.error}`);
      } else {
        alert(data.message);
        resetForm();
      }
    } catch (error) {
      alert('Something went wrong. Please try again.');
    } finally {
      setSubmitting(false);
    }
  };

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h2&amp;gt;Register&amp;lt;/h2&amp;gt;
      &amp;lt;Formik
        initialValues={initialValues}
        validationSchema={validationSchema}
        onSubmit={handleSubmit}
      &amp;gt;
        &amp;lt;Form&amp;gt;
          &amp;lt;div&amp;gt;
            &amp;lt;label&amp;gt;Email:&amp;lt;/label&amp;gt;
            &amp;lt;Field type="email" name="email" /&amp;gt;
            &amp;lt;ErrorMessage name="email" component="div" /&amp;gt;
          &amp;lt;/div&amp;gt;

          &amp;lt;div&amp;gt;
            &amp;lt;label&amp;gt;Password:&amp;lt;/label&amp;gt;
            &amp;lt;Field type="password" name="password" /&amp;gt;
            &amp;lt;ErrorMessage name="password" component="div" /&amp;gt;
          &amp;lt;/div&amp;gt;

          &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
        &amp;lt;/Form&amp;gt;
      &amp;lt;/Formik&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default RegisterForm;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What’s Happening Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Formik manages the form’s state and handles submission for you.&lt;/li&gt;
&lt;li&gt;Yup checks that the email is valid and the password isn’t too short.&lt;/li&gt;
&lt;li&gt;We use fetch() to send the form data as JSON to our Flask server.&lt;/li&gt;
&lt;li&gt;Flask checks the data and sends back a JSON response.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If everything goes well, we show a success message . If not, we show an error.&lt;/p&gt;

&lt;p&gt;Core Takeaways:&lt;br&gt;
Formik makes working with forms in React &lt;em&gt;&lt;strong&gt;much easier&lt;/strong&gt;&lt;/em&gt;, and it works really well with a Flask backend. With just a few lines of code (or 100 lines, depending on the form you're trying to build...), you can build a working form that validates user input and connects to your backend.&lt;/p&gt;

&lt;p&gt;Sources:&lt;br&gt;
&lt;a href="https://formik.org/docs/tutorial" rel="noopener noreferrer"&gt;Formik Docs&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>formik</category>
      <category>flask</category>
      <category>yup</category>
    </item>
    <item>
      <title>Understanding Private and Semi-Private Attributes in Python Classes</title>
      <dc:creator>Victoria Lima De Carvalho</dc:creator>
      <pubDate>Thu, 27 Mar 2025 14:31:04 +0000</pubDate>
      <link>https://dev.to/victoria_limadecarvalho/understanding-private-and-semi-private-attributes-in-python-classes-2n7f</link>
      <guid>https://dev.to/victoria_limadecarvalho/understanding-private-and-semi-private-attributes-in-python-classes-2n7f</guid>
      <description>&lt;p&gt;If you're learning Python and working with classes, you’ve probably heard the terms private and semi-private attributes. These are concepts that help you control how data inside a class can be accessed or modified. But, what do these terms really mean, and how do they work in Python?&lt;/p&gt;

&lt;p&gt;In this blog post, I’ll explain what private and semi-private attributes are, how they are used, when to use them, and why they are important.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Are Private and Semi-Private Attributes?&lt;/strong&gt;&lt;br&gt;
In Python, attributes (or variables) inside a class can be categorized as public, private, or semi-private.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Public attributes can be accessed and modified freely from outside the class.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Private attributes are intended to be hidden from the outside world.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Semi-private attributes are a bit of a soft rule, Python doesn’t enforce them, but they signal that the attribute should be treated as internal.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How to Define Private Attributes in Python&lt;/strong&gt;&lt;br&gt;
Private attributes are defined with two leading underscores (__) before the attribute name. This tells Python that the attribute is meant to be hidden from external access, although it's not a foolproof method. Python uses this to &lt;strong&gt;mangle&lt;/strong&gt; the attribute name and make it a little more difficult to access directly (though not impossible).&lt;/p&gt;

&lt;p&gt;(Note: Private attributes should not be confused with Dunder attributes, which have two leading and two trailing underscores, such as __ init __.)&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Dog:
    def __init__(self, name, age):  # The __init__ is a Dunder Attribute
        self.__name = name  # Private attribute
        self.__age = age    # Private attribute

    def get_name(self):  # Public method to access private attribute
        return self.__name

    def get_age(self):   # Public method to access private attribute
        return self.__age

    def set_age(self, age):  # Public method to modify private attribute
        if age &amp;gt; 0:
            self.__age = age
        else:
            print("Age must be positive.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, __name and __age are private attributes. We use getter and setter methods (get_name, get_age, and set_age) to allow controlled access and modification of these attributes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Use Private Attributes?&lt;/strong&gt;&lt;br&gt;
So, why go through the trouble of making attributes private in the first place? Here’s why:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Encapsulation: Private attributes help you hide the internal details of your class, keeping your data safe from accidental or malicious changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Control: By using private attributes, you can control how and when your data gets accessed or updated. For example, the set_age method ensures the age attribute can’t be set to an invalid value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Security: By restricting access to an attribute, you reduce the risk of its value being changed in unexpected ways.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Trying to Access Private Attributes&lt;/strong&gt;&lt;br&gt;
If you try to directly access a private attribute, Python will raise an error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dog = Dog("Max", 5)

# Trying to access the private attribute directly will raise an error
print(dog.__name)  # AttributeError: 'Dog' object has no attribute '__name'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead, you should use the public methods (get_name(), get_age()) to access private attributes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Name Mangling&lt;/strong&gt;&lt;br&gt;
Python uses a feature called name mangling to make private attributes harder to access directly. When you define an attribute with two leading underscores &lt;em&gt;(e.g., __name), Python internally changes its name by adding the class name prefix (e.g., _Dog __name)&lt;/em&gt;. This is done to prevent accidental access or modification from outside the class.&lt;/p&gt;

&lt;p&gt;While you can &lt;em&gt;technically&lt;/em&gt; access the mangled attribute using its new name (e.g., dog._ Dog__name), it’s strongly discouraged (just don't). This breaks the encapsulation principle and defeats the purpose of making the attribute private in the first place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Semi-Private Attributes&lt;/strong&gt;&lt;br&gt;
Semi-private attributes are defined with a single underscore (_) before the attribute name. This is a convention in Python indicating that the attribute is intended for internal use within the class. However, unlike private attributes, semi-private attributes can still be accessed from outside the class, and Python doesn’t enforce any restriction. That being said, the goal of defining the attribute as semi-private is to alert other developers not to modify the attribute directly from outside the class.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Car:
    def __init__(self, make, model):
        self._make = make  # Semi-private attribute
        self._model = model  # Semi-private attribute
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even though you can access _make and _model directly, it’s best to think of them as internal details of the class and avoid modifying them from the outside.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to Use Private and Semi-Private Attributes&lt;/strong&gt;&lt;br&gt;
Here’s when you should use private and semi-private attributes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Private Attributes: These are useful when you need to protect certain data from being accessed or changed directly. For example, if you have an attribute like age, you might want to make it private to ensure no one messes with it directly. You can then create a method like set_age() to validate the input before updating the attribute.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Semi-Private Attributes: These are more like a suggestion that the attribute is for internal use. While you can technically access or modify them, it’s generally better to leave them alone. The single underscore is a "soft" rule, so don’t take it too literally, but it’s a good practice to &lt;strong&gt;&lt;em&gt;respect the convention&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Private Methods vs. Private Attributes&lt;/strong&gt;&lt;br&gt;
Private methods and private attributes are similar in that they both follow the same naming convention with two leading underscores to signal they’re meant for internal use only. However, there’s an important distinction:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Private methods are functions that perform actions or calculations within the class.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Private attributes are variables that store data related to the class.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even though they serve different purposes (actions vs. data), they both follow the same visibility rules.&lt;/p&gt;

&lt;p&gt;But, remember, Python doesn't strictly enforce access control. You could still access private methods or attributes using name mangling (e.g., _ ClassName __ method or _ ClassName __ attribute). It’s better to rely on the conventions, though.&lt;/p&gt;

&lt;p&gt;Core Takeaways:&lt;br&gt;
In Python, private and semi-private attributes are useful tools to manage how data is accessed and modified within your classes.&lt;/p&gt;

&lt;p&gt;Private attributes (with two leading underscores) are meant to be hidden from external access, and you should interact with them using public methods.&lt;/p&gt;

&lt;p&gt;Semi-private attributes (with one leading underscore) are intended for internal use but are not strictly off-limits.&lt;/p&gt;

&lt;p&gt;By using these conventions, you can create cleaner, safer, and more maintainable code!&lt;/p&gt;

&lt;p&gt;Sources:&lt;br&gt;
&lt;a href="https://www.w3resource.com/python-interview/how-do-you-create-private-attributes-in-a-class.php" rel="noopener noreferrer"&gt;w3resources&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.python.org/3/tutorial/classes.html#private-variables" rel="noopener noreferrer"&gt;python.docs:private variables&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.python.org/3/reference/expressions.html#private-name-mangling" rel="noopener noreferrer"&gt;python.docs:private name mangling&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/private-attributes-in-a-python-class/" rel="noopener noreferrer"&gt;geeksforgeeks&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Destructuring of Props in React.js</title>
      <dc:creator>Victoria Lima De Carvalho</dc:creator>
      <pubDate>Thu, 06 Mar 2025 17:51:36 +0000</pubDate>
      <link>https://dev.to/victoria_limadecarvalho/destructuring-of-props-in-reactjs-2a72</link>
      <guid>https://dev.to/victoria_limadecarvalho/destructuring-of-props-in-reactjs-2a72</guid>
      <description>&lt;p&gt;In React, props (short for "properties") are a way to pass data from a parent component to a child component. Think of props as the way we send information down to components so they can use it.&lt;/p&gt;

&lt;p&gt;Destructuring is a JavaScript feature that allows us to extract values from an object and assign them to variables.&lt;/p&gt;

&lt;p&gt;Props contain different values that you pass to a component, like text, numbers, or even functions! Normally, you would have to refer to each prop by its name, like props.age, props.location, etc. But destructuring is a shortcut that allows you to grab only the props you want, in a simpler way, directly.&lt;/p&gt;

&lt;p&gt;As i've learned to code, I try to implement ways to write a cleaner and more concise code. I've found that destructuring of props is an important practice for having a cleaner and more readable code.&lt;/p&gt;

&lt;p&gt;Here's how you would usually access props without destructuring in a functional component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Welcome(props) {
  return &amp;lt;h1&amp;gt;Hello, {props.name}!&amp;lt;/h1&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, props is an object, and we access name using props.name.&lt;/p&gt;

&lt;p&gt;Now, let’s make the code cleaner using destructuring. Instead of accessing props.name, we can directly extract the name property from props object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Welcome({ name }) {
  return &amp;lt;h1&amp;gt;Hello, {name}!&amp;lt;/h1&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s what happens:&lt;/p&gt;

&lt;p&gt;When you wrap the prop value in curly brackets {} like this: { name } you are destructuring! It takes the name property from the props object and creates a variable name that we can use directly in our function.&lt;br&gt;
This is a shorter and cleaner way to write the code, especially when you have &lt;em&gt;many&lt;/em&gt; props.&lt;/p&gt;

&lt;p&gt;Why is this useful?&lt;br&gt;
Provides for a cleaner code: Instead of writing props.name, you can just write { name }.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Less repetition&lt;/strong&gt;&lt;/em&gt;: If you have several props, you don’t need to repeat props. &lt;em&gt;every time&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Improves readability: Destructuring makes it clear which props are being used in the component.&lt;/p&gt;

&lt;p&gt;Example with multiple props:&lt;br&gt;
Let's say you have a component that takes multiple props:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function UserProfile({ name, age, location }) {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h2&amp;gt;Name: {name}&amp;lt;/h2&amp;gt;
      &amp;lt;h3&amp;gt;Age: {age}&amp;lt;/h3&amp;gt;
      &amp;lt;p&amp;gt;Location: {location}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, name, age, and location are being &lt;em&gt;&lt;strong&gt;destructured&lt;/strong&gt;&lt;/em&gt; from the props object. Instead of writing props.name, props.age, and props.location, you just directly access these values.&lt;/p&gt;

&lt;p&gt;Core Takeaway:&lt;br&gt;
Destructuring props makes your code cleaner, easier to read, and more concise.&lt;br&gt;
You don’t need to use the props keyword every time you want to access a prop if you destructure them in the function parameters.&lt;/p&gt;

&lt;p&gt;Sources: &lt;br&gt;
(&lt;a href="https://react.dev/learn/passing-props-to-a-component" rel="noopener noreferrer"&gt;https://react.dev/learn/passing-props-to-a-component&lt;/a&gt;)&lt;br&gt;
(&lt;a href="https://www.w3schools.com/react/react_es6_destructuring.asp" rel="noopener noreferrer"&gt;https://www.w3schools.com/react/react_es6_destructuring.asp&lt;/a&gt;)&lt;br&gt;
(&lt;a href="https://www.dhiwise.com/post/component-development-with-react-destructuring-props" rel="noopener noreferrer"&gt;https://www.dhiwise.com/post/component-development-with-react-destructuring-props&lt;/a&gt;)&lt;/p&gt;

</description>
      <category>react</category>
      <category>destructuring</category>
      <category>props</category>
    </item>
    <item>
      <title>Using the forEach() method in JS</title>
      <dc:creator>Victoria Lima De Carvalho</dc:creator>
      <pubDate>Sun, 09 Feb 2025 18:25:36 +0000</pubDate>
      <link>https://dev.to/victoria_limadecarvalho/using-the-foreach-method-in-js-d1</link>
      <guid>https://dev.to/victoria_limadecarvalho/using-the-foreach-method-in-js-d1</guid>
      <description>&lt;p&gt;The forEach() method is one of the most effective ways to go through all the elements in an array. With this method, you can perform specific actions on each element in the array.&lt;/p&gt;

&lt;p&gt;A key benefit of using forEach() is that it allows you to work with each element without needing to create a new array. This method is useful when you need to update a variable, print something to the console, or modify the DOM.&lt;br&gt;
One of the most important things to remember, is that forEach() doesn’t return a new array.&lt;/p&gt;

&lt;p&gt;Another advantage of using the forEach() method, is that it doesn’t require the index of each item. It’s a simpler and faster way to loop through an array. So when you're writing you code, you can know that the forEach() method will iterate through the arrays without needing to have a starting index.&lt;/p&gt;

&lt;p&gt;In arrays with empty slots, forEach() will ignore them. A regular for loop will still process those empty slots, even if they don’t contain any values in them. This is another way that using forEach() can be beneficial. &lt;/p&gt;

&lt;p&gt;One thing to keep in mind is that you cannot stop a forEach() loop once it starts. So, if you need to break out of the loop early, or stop the loop from continuing at a certain determined point, forEach() won’t work for you.&lt;/p&gt;

&lt;p&gt;Another important fact to remember about this method, is that forEach() only works with functions that run synchronously. This means that it won’t wait for promises or asynchronous functions to finish before it starts the method of iterating through the elements in the array. So remember to be mindful of that when combining forEach() with asynchronous code.&lt;/p&gt;

&lt;p&gt;Here’s an example of how forEach() is typically written:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;thisArg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sources: &lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/difference-between-foreach-and-for-loop-in-javascript/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/difference-between-foreach-and-for-loop-in-javascript/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/jsref/jsref_foreach.asp" rel="noopener noreferrer"&gt;https://www.w3schools.com/jsref/jsref_foreach.asp&lt;/a&gt;&lt;/p&gt;

</description>
      <category>foreach</category>
      <category>javascript</category>
      <category>arraymethods</category>
    </item>
  </channel>
</rss>
