<?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: tahsinsoyak</title>
    <description>The latest articles on DEV Community by tahsinsoyak (@tahsinsoyak).</description>
    <link>https://dev.to/tahsinsoyak</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%2F740045%2Fa3e930f8-bc25-439c-9e97-d73eab44c39e.jpg</url>
      <title>DEV Community: tahsinsoyak</title>
      <link>https://dev.to/tahsinsoyak</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tahsinsoyak"/>
    <language>en</language>
    <item>
      <title>JSON: What is it and How to Use It?</title>
      <dc:creator>tahsinsoyak</dc:creator>
      <pubDate>Sun, 05 May 2024 08:00:00 +0000</pubDate>
      <link>https://dev.to/tahsinsoyak/json-what-is-it-and-how-to-use-it-3cj5</link>
      <guid>https://dev.to/tahsinsoyak/json-what-is-it-and-how-to-use-it-3cj5</guid>
      <description>&lt;p&gt;JSON, a data format created for JavaScript applications, stands for JavaScript Object Notation. The primary purpose of JSON is to facilitate data exchange with smaller data payloads.&lt;/p&gt;

&lt;p&gt;JSON encompasses five data types:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Number&lt;/li&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;li&gt;Array&lt;/li&gt;
&lt;li&gt;Boolean&lt;/li&gt;
&lt;li&gt;Object&lt;/li&gt;
&lt;li&gt;Null&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Data in JSON consists of two parts: key and value. The key defines which property of the object it is (akin to a variable name in code), while the value defines the actual value of that property (similar to the variable's value in code).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compact Data Exchange: JSON excels at minimizing data size during data exchange, enhancing efficiency.&lt;/li&gt;
&lt;li&gt;Language-Agnostic: Being independent of programming languages, JSON is versatile and widely compatible.&lt;/li&gt;
&lt;li&gt;Human-Readable: JSON's structure is easy to read and understand, fostering clarity in data representation.&lt;/li&gt;
&lt;li&gt;Easy to Parse: JSON data can be easily parsed and converted into native data structures in various programming languages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Professional Example: Consider a scenario where a web application needs to exchange user data between the frontend and backend. JSON can be employed to structure this data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "user": {
    "id": 147,
    "username": "tahsinsoyak",
    "email": "tahsinsoyak@gmail.com",
    "preferences": {
      "theme": "dark",
      "notifications": true
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, keys like "id," "username," and "preferences" represent different properties of the user object, while values provide corresponding data. JSON's simplicity and clarity make it an ideal choice for such data exchange scenarios.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One more example:&lt;/strong&gt; E-Commerce -  Product Information&lt;br&gt;
Consider an e-commerce platform that needs to exchange product information between the server and the user interface. JSON can be utilized to represent a product's details:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "product": {
    "id": "ABC123",
    "name": "Smartphone",
    "brand": "Suntheo",
    "price": 499.99,
    "specifications": ["4GB RAM", "128GB Storage", "Dual Camera"]
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below is a simple example of a Flask application that handles a GET request and returns the provided JSON response:&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 import Flask, jsonify

app = Flask(__name__)

# Sample product data
products = {
    "ABC123": {
        "name": "Smartphone",
        "brand": "Suntheo",
        "price": 499.99,
        "specifications": ["4GB RAM", "128GB Storage", "Dual Camera"]
    },
    # Add more products as needed
}

@app.route('/product/&amp;lt;string:product_id&amp;gt;', methods=['GET'])
def get_product(product_id):
    # Check if the product ID exists
    if product_id in products:
        return jsonify({"product": {product_id: products[product_id]}})
    else:
        return jsonify({"error": "Product not found"}), 404

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The /product/&lt;a&gt;string:product_id&lt;/a&gt; endpoint is defined to handle GET requests with a dynamic product_id parameter.&lt;/li&gt;
&lt;li&gt;The get_product function checks if the provided product_id exists in the products dictionary and returns the corresponding product data if found. Otherwise, it returns an error response with a 404 status code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, you can test different product IDs by visiting URLs like:&lt;br&gt;
&lt;a href="http://127.0.0.1:5000/product/ABC123"&gt;http://127.0.0.1:5000/product/ABC123&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you need further information or have specific questions, feel free to ask! Tahsin Soyak &lt;a href="mailto:tahsinsoyakk@gmail.com"&gt;tahsinsoyakk@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
    <item>
      <title>Clean Code: Definition and Principles - Part 3 (Last Part)</title>
      <dc:creator>tahsinsoyak</dc:creator>
      <pubDate>Sun, 28 Apr 2024 16:21:00 +0000</pubDate>
      <link>https://dev.to/tahsinsoyak/clean-code-definition-and-principles-part-3-last-part-107n</link>
      <guid>https://dev.to/tahsinsoyak/clean-code-definition-and-principles-part-3-last-part-107n</guid>
      <description>&lt;p&gt;Clean code refers to well-organized, easily understandable, and maintainable code. Now, let's delve into last part of specific principles that guide clean code writing:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Source Code Structure (G)&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Separate concepts vertically.&lt;/li&gt;
&lt;li&gt;Vertically dense displays for related code.&lt;/li&gt;
&lt;li&gt;Define variables close to their usage.&lt;/li&gt;
&lt;li&gt;Define closely related functions near each other.&lt;/li&gt;
&lt;li&gt;Functions performing similar tasks should be in close proximity.&lt;/li&gt;
&lt;li&gt;Arrange functions in a downward flow.&lt;/li&gt;
&lt;li&gt;Keep code lines short.&lt;/li&gt;
&lt;li&gt;Avoid horizontal alignment (alignment with the line above or below).&lt;/li&gt;
&lt;li&gt;Use spaces to keep related things close and unrelated things distant.&lt;/li&gt;
&lt;li&gt;Do not disrupt the indents created by the code.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Separate concepts vertically
class User:
    def __init__(self, name, email):
        self.name = name
        self.email = email

# Display closely related code vertically
class UserManager:
    def __init__(self):
        self.users = []

    def add_user(self, user):
        self.users.append(user)

# Define variables close to their usage
total_price = calculate_total_price(product_price, quantity)  # Good
# Avoid defining variables far from their usage
total_price = 0  # Bad

# Place related functions close to each other
def process_data(data):
    preprocess(data)
    analyze(data)

# Similar functions should be close to each other
def calculate_area_circle(radius):
    pass

def calculate_area_square(side_length):
    pass

# Functions should flow downwards
def step_one():
    pass

def step_two():
    pass

# Keep code lines short
result = perform_complex_calculation(data)  # Good
result = perform_a_very_complex_calculation_that_does_a_lot_of_things(data)  # Bad

# Avoid horizontal alignment (aligning with the line above or below)
first_name = "John"  # Good
last_name  = "Doe"   # Bad

# Use spacing to keep related things close, unrelated things distant
class User:
    def __init__(self, name, email):
        self.name = name
        self.email = email
    def print_details(self):
        print(f"Name: {self.name}, Email: {self.email}")

# Do not disrupt the indentation created by the code structure
if condition:
    do_something()
    do_another_thing()

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Objects and Data Structures (H)&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Hide the internal structure of the code.&lt;/li&gt;
&lt;li&gt;Prefer ready-made collection structures provided by programming languages.&lt;/li&gt;
&lt;li&gt;Avoid hybrid structures.&lt;/li&gt;
&lt;li&gt;Be as small as possible.&lt;/li&gt;
&lt;li&gt;Do one thing.&lt;/li&gt;
&lt;li&gt;Work with a small number of variables.&lt;/li&gt;
&lt;li&gt;The base class should know nothing about its derivatives.&lt;/li&gt;
&lt;li&gt;Having several simple functions is better than shaping them based on desired behavior by passing parameters to a single function.&lt;/li&gt;
&lt;li&gt;Avoid static methods.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Hide the internal structure of the code
class Rectangle:
    def __init__(self, width, height):
        self.width = width
        self.height = height

# Prefer language-provided collection structures for data
user_list = []  # Good
user_dict = {}  # Good

# Avoid hybrid structures
# Use a clear and small structure
class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

# Work with a small number of variables
x, y, z = 1, 2, 3  # Good
coordinate1, coordinate2, coordinate3 = 1, 2, 3  # Bad

# Basic class should not know about its derived classes
class Animal:
    def make_sound(self):
        pass

# Favor having many simple functions over passing parameters to shape behavior
def calculate_area_circle(radius):
    pass

def calculate_area_square(side_length):
    pass

# Avoid static methods
class MathOperations:
    @staticmethod
    def add(a, b):
        return a + b  # Bad
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Tests (K)&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Have one assert per test.&lt;/li&gt;
&lt;li&gt;Tests should be readable.&lt;/li&gt;
&lt;li&gt;Tests should run quickly.&lt;/li&gt;
&lt;li&gt;Tests should be independent.&lt;/li&gt;
&lt;li&gt;Tests should be repeatable.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Use one assert per test
def test_calculate_total_price():
    assert calculate_total_price(10, 2) == 20

# Make tests readable
def test_user_manager_add_user():
    user_manager = UserManager()
    user_manager.add_user(User("John", "john@example.com"))
    assert len(user_manager.users) == 1

# Ensure tests run quickly
# Ensure tests are independent
# Ensure tests are repeatable

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

&lt;/div&gt;



&lt;p&gt;These examples showcase how a professional programmer might adhere to the Clean Code principles related to source code structure, objects and data structures, and testing in Python. The focus is on creating code that is readable, maintainable, and follows best practices.&lt;/p&gt;

&lt;p&gt;If you need further information or have specific questions, feel free to ask! Tahsin Soyak &lt;a href="mailto:tahsinsoyakk@gmail.com"&gt;tahsinsoyakk@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Clean Code: Definition and Principles - Part 2</title>
      <dc:creator>tahsinsoyak</dc:creator>
      <pubDate>Sun, 21 Apr 2024 12:29:00 +0000</pubDate>
      <link>https://dev.to/tahsinsoyak/clean-code-definition-and-principles-part-2-1lh5</link>
      <guid>https://dev.to/tahsinsoyak/clean-code-definition-and-principles-part-2-1lh5</guid>
      <description>&lt;p&gt;Clean code refers to well-organized, easily understandable, and maintainable code. Now, let's delve into part 2 of specific principles that guide clean code writing:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Naming Conventions (D)&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use clear and non-confusing naming conventions.&lt;/li&gt;
&lt;li&gt;Create meaningful distinctions with naming conventions. (Crucial for abstraction)&lt;/li&gt;
&lt;li&gt;Find easily pronounceable naming conventions.&lt;/li&gt;
&lt;li&gt;Choose names that can be easily found and accessed when needed.&lt;/li&gt;
&lt;li&gt;Avoid hidden numbers and constants within the code.&lt;/li&gt;
&lt;li&gt;Avoid adding a set of starting tags to encoding and variables.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Clear and non-confusing naming conventions
customer_list = []  # Good
data = []          # Bad - unclear

# Meaningful distinctions with naming conventions
class Shape:
    def calculate_area(self):
        pass

class Circle(Shape):  # Good - clear distinction
    def calculate_area(self):
        pass

class Rectangle(Shape):  # Good - clear distinction
    def calculate_area(self):
        pass

# Easily pronounceable naming conventions
user_preferences = {}  # Good
usr_prefs = {}         # Bad - not easily pronounceable

# Easily found and accessed names
PI = 3.14  # Bad - not easily found, lacks context
PI_VALUE = 3.14  # Good - easily found and accessed

# Avoid hidden numbers and constants
discount_multiplier = 0.9  # Good - clear purpose
total_price = product_price * discount_multiplier  # Good

# Avoid starting tags to encoding and variables
encoded_data = encode(data)  # Good
d_encoded = encode(data)     # Bad - unclear
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Function Guidelines (E)&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Keep it small.&lt;/li&gt;
&lt;li&gt;Should do one thing and do it well.&lt;/li&gt;
&lt;li&gt;Have a clear and descriptive name.&lt;/li&gt;
&lt;li&gt;Take as few arguments as possible.&lt;/li&gt;
&lt;li&gt;Should not contain side effects.&lt;/li&gt;
&lt;li&gt;Do not pass flag (true/false) arguments into the parameters and make different method calls within this method.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Keep it small
def calculate_total_price(product_price, quantity):
    # Small function that calculates the total price
    return product_price * quantity

# Do one thing and do it well
def send_email(to, subject, body):
    # Sends an email
    pass

# Have a clear and descriptive name
def get_user_data(user_id):
    # Retrieves user data
    pass

# Take as few arguments as possible
def calculate_area(radius):
    # Calculates the area of a circle
    pass

# Should not contain side effects
def update_user_profile(user_id, new_data):
    # Updates user profile - side effect as it modifies external state
    pass

# Do not pass flag arguments into parameters and make different method calls
def process_data(data, normalize=False):
    if normalize:
        normalize_data(data)
    else:
        process_raw_data(data)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Commenting Rules (F)&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Strive to express yourself within the code.&lt;/li&gt;
&lt;li&gt;Avoid unnecessary comments.&lt;/li&gt;
&lt;li&gt;Do not add comment lines to separate the start and end of the code.&lt;/li&gt;
&lt;li&gt;Do not turn the code into a comment. &lt;/li&gt;
&lt;li&gt;Delete unnecessary code.&lt;/li&gt;
&lt;li&gt;Explain the reason for writing a comment.&lt;/li&gt;
&lt;li&gt;Use comments as code explanations.&lt;/li&gt;
&lt;li&gt;Use comments as warnings for outcomes.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Strive to express yourself within the code
result = calculate_area(radius)  # Good - self-explanatory

# Avoid unnecessary comments
# This is a loop that iterates over each element
for element in elements:  # Bad - unnecessary comment
    process_element(element)

# Do not add comment lines to separate the start and end of the code
# ===============================
# Function to calculate area
# ===============================
def calculate_area(radius):
    return 3.14 * radius ** 2

# Bad - unnecessary comments for separation

# Do not turn the code into a comment. Delete unnecessary code
# unused_variable = 42
# Commented out because it's not needed anymore
# Better to remove the code entirely

# Explain the reason for writing a comment
# Using a specific algorithm due to performance requirements
# This comment explains the reason for choosing a particular approach

# Use comments as code explanations
# This loop calculates the sum of all elements
for element in elements:
    total += element

# Use comments as warnings for outcomes
# Warning: Changing this code may affect the entire system.
# This comment alerts developers about potential consequences.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These examples demonstrate how a professional programmer might apply each Clean Code principle in Python. The emphasis is on clarity, readability, and maintaining a codebase that is easy to understand and work with.&lt;/p&gt;

&lt;p&gt;If you need further information or have specific questions, feel free to ask! Tahsin Soyak &lt;a href="mailto:tahsinsoyakk@gmail.com"&gt;tahsinsoyakk@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
    <item>
      <title>Clean Code: Definition and Principles - Part 1</title>
      <dc:creator>tahsinsoyak</dc:creator>
      <pubDate>Sun, 14 Apr 2024 10:20:00 +0000</pubDate>
      <link>https://dev.to/tahsinsoyak/clean-code-definition-and-principles-part-1-4ak3</link>
      <guid>https://dev.to/tahsinsoyak/clean-code-definition-and-principles-part-1-4ak3</guid>
      <description>&lt;p&gt;Clean code refers to well-organized, easily understandable, and maintainable code that allows developers, beyond the original coder, to comprehend and contribute efficiently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Principles:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Readability: Code should be straightforward and easily comprehensible.&lt;/li&gt;
&lt;li&gt;Changeability: Code should be easily modifiable without affecting its overall structure.&lt;/li&gt;
&lt;li&gt;Extensibility: Code should be designed to allow easy additions or extensions.&lt;/li&gt;
&lt;li&gt;Maintainability: Code should be structured for straightforward maintenance.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;General Rules (A):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Implement universally accepted coding approaches.&lt;/li&gt;
&lt;li&gt;Strive for simplicity, avoiding complex structures.&lt;/li&gt;
&lt;li&gt;Leave the code cleaner than you found it; avoid unnecessary complexity&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Scenario: Consider a function that calculates the area of a rectangle.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Bad Code
def area(r_length, r_width):
    res = r_length * r_width
    return res

# Good Code
def calculate_rectangle_area(length, width):
    area_result = length * width
    return area_result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Universally Accepted Approaches: Follow Python conventions and naming standards.&lt;/li&gt;
&lt;li&gt;Strive for Simplicity: Use clear function names and avoid unnecessary abbreviations.&lt;/li&gt;
&lt;li&gt;Leave Code Cleaner: Provide meaningful names and use spaces for readability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Design Rules (B):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Store configured data in easily accessible and modifiable sections.&lt;/li&gt;
&lt;li&gt;Prefer polymorphism over if/else or switch/case conditions.&lt;/li&gt;
&lt;li&gt;Isolate multi-threading code for clarity.&lt;/li&gt;
&lt;li&gt;Avoid making every code structure configurable and dynamic.&lt;/li&gt;
&lt;li&gt;Utilize Dependency Injection for managing dependencies.&lt;/li&gt;
&lt;li&gt;Follow the Single Responsibility Principle; a class should know only its dependencies.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Scenario: Imagine a class handling various configurations in an application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Bad Code
class AppConfig:
    config = {}

    def set_config(self, key, value):
        self.config[key] = value

    def get_config(self, key):
        return self.config.get(key, None)
# Good Code
class AppConfig:
    def __init__(self):
        self.configurations = {}

    def set_configuration(self, key, value):
        self.configurations[key] = value

    def get_configuration(self, key):
        return self.configurations.get(key, None)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store Configured Data: Use clear variable and method names.&lt;/li&gt;
&lt;li&gt;Prefer Polymorphism: Simplify with separate methods for setting and getting configurations.&lt;/li&gt;
&lt;li&gt;Isolate Multi-Threading Code: Handle threading concerns separately.&lt;/li&gt;
&lt;li&gt;Avoid Configurable Dynamism: Keep class configurations straightforward.&lt;/li&gt;
&lt;li&gt;Utilize Dependency Injection: Consider dependencies in the class constructor.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tips for Understandability ( C ):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Maintain consistency in methods and structures.&lt;/li&gt;
&lt;li&gt;Use descriptive variable names.&lt;/li&gt;
&lt;li&gt;Encapsulate variables and logic comprehensively to avert scattered implementations.&lt;/li&gt;
&lt;li&gt;Favor primitive types over object types (Immutable).&lt;/li&gt;
&lt;li&gt;Minimize logical dependencies, preventing unrelated method dependencies within the same class.&lt;/li&gt;
&lt;li&gt;Minimize the use of negative conditions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Scenario: Consider a function that calculates the interest on a loan.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Bad Code
def calculate_interest(principal, rate, time):
    i = (principal * rate * time) / 100
    return i
# Good Code
def calculate_loan_interest(principal_amount, interest_rate, time_period):
    interest_amount = (principal_amount * interest_rate * time_period) / 100
    return interest_amount
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Maintain Consistency: Use consistent naming conventions.&lt;/li&gt;
&lt;li&gt;Use Descriptive Variable Names: Clearly express the purpose of each variable.&lt;/li&gt;
&lt;li&gt;Encapsulate Variables and Logic: Organize code blocks cohesively.&lt;/li&gt;
&lt;li&gt;Favor Primitive Types: Use basic types for simplicity.&lt;/li&gt;
&lt;li&gt;Minimize Logical Dependencies: Keep the logic focused on the task.&lt;/li&gt;
&lt;li&gt;Minimize Negative Conditions: Use positive conditionals for clarity.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples illustrates how a professional programmer applies clean code principles in different aspects of code development, making the codebase readable, maintainable, and extendable.&lt;/p&gt;

&lt;p&gt;If you need further information or have specific questions, feel free to ask! Tahsin Soyak &lt;a href="mailto:tahsinsoyakk@gmail.com"&gt;tahsinsoyakk@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>tutorial</category>
      <category>python</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Code Smells - Recognizing Poor Code Quality</title>
      <dc:creator>tahsinsoyak</dc:creator>
      <pubDate>Sun, 07 Apr 2024 09:15:00 +0000</pubDate>
      <link>https://dev.to/tahsinsoyak/code-smells-recognizing-poor-code-quality-57o5</link>
      <guid>https://dev.to/tahsinsoyak/code-smells-recognizing-poor-code-quality-57o5</guid>
      <description>&lt;p&gt;Recognizing when code exhibits poor quality is crucial for maintaining a healthy and maintainable software project. Here are common indicators of suboptimal code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Rigidity: When modifying the software becomes excessively challenging, requiring changes in numerous places.&lt;/li&gt;
&lt;li&gt;Fragility: Small changes in the code lead to unintended consequences, breaking functionality in various parts of the application.&lt;/li&gt;
&lt;li&gt;Immobility: If you can reuse certain parts of your code in other projects, it indicates flexibility and mobility.&lt;/li&gt;
&lt;li&gt;Needless Complexity: Avoiding unnecessary complexity is essential for code maintainability and understanding.&lt;/li&gt;
&lt;li&gt;Needless Repetition: Repetition in the code can lead to maintenance issues; reducing redundancy enhances code quality.&lt;/li&gt;
&lt;li&gt;Opacity: Code should be readable and transparent; if it is hard to understand, it diminishes its quality.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Understanding these code smells helps developers identify areas for improvement and refactoring. Eliminating these issues enhances code maintainability, readability, and overall project health.&lt;/p&gt;

&lt;p&gt;Example: Consider a scenario where a developer encounters a method that performs the same operation in multiple places throughout the codebase. By refactoring and consolidating this functionality into a single function, the developer reduces needless repetition, promoting cleaner and more maintainable code.&lt;/p&gt;

&lt;p&gt;Below is a professional and explanatory example illustrating the "Needless Repetition" code smell and how to address it through refactoring.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Original Code with Needless Repetition
class ReportGenerator:
    def generate_report_v1(self, data):
        # Code for generating version 1 of the report
        print("Generating version 1 of the report...")
        # ... (repeated code)

    def generate_report_v2(self, data):
        # Code for generating version 2 of the report
        print("Generating version 2 of the report...")
        # ... (repeated code)

# Refactored Code to Eliminate Needless Repetition
class ReportGenerator:
    def generate_report(self, data, version):
        # Code for generating the report based on the specified version
        print(f"Generating version {version} of the report...")
        # ... (shared code)

# Example Usage
report_generator = ReportGenerator()

# Generating version 1 of the report
report_generator.generate_report(data_v1, version=1)

# Generating version 2 of the report
report_generator.generate_report(data_v2, version=2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the original code, there are two methods (&lt;em&gt;generate_report_v1&lt;/em&gt; and &lt;em&gt;generate_report_v2&lt;/em&gt;) that share a significant portion of repeated code, violating the DRY (Don't Repeat Yourself) principle.&lt;/p&gt;

&lt;p&gt;In the refactored code, the repetition is eliminated by introducing a single method (&lt;em&gt;generate_report&lt;/em&gt;) that takes the report version as a parameter. This approach adheres to the DRY principle, making the code more maintainable and reducing the likelihood of introducing errors when changes are made.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; In this example, the developer recognizes the needless repetition code smell and addresses it by consolidating redundant code into a single, reusable function. This not only improves code quality but also simplifies future maintenance efforts.&lt;/p&gt;

&lt;p&gt;If you need further information or have specific questions, feel free to ask! Tahsin Soyak &lt;a href="mailto:tahsinsoyakk@gmail.com"&gt;tahsinsoyakk@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
    <item>
      <title>Mastering Python OOP: All in One Example</title>
      <dc:creator>tahsinsoyak</dc:creator>
      <pubDate>Sun, 31 Mar 2024 09:11:00 +0000</pubDate>
      <link>https://dev.to/tahsinsoyak/mastering-python-oop-all-in-one-example-1oon</link>
      <guid>https://dev.to/tahsinsoyak/mastering-python-oop-all-in-one-example-1oon</guid>
      <description>&lt;p&gt;Mastering Python OOP: All in One Example&lt;br&gt;
Unlock the full potential of Python's Object-Oriented Programming (OOP) with a deep dive into key concepts. Explore the power of encapsulation, inheritance, polymorphism, and abstraction through professional examples. Elevate your coding skills and design cleaner, modular, and efficient Python applications.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from abc import ABC, abstractmethod

# Abstract class for Employee
class Employee(ABC):
    def __init__(self, name, salary):
        self.name = name
        self.salary = salary

    @abstractmethod
    def calculate_bonus(self):
        pass

# Concrete class representing a Developer
class Developer(Employee):
    def __init__(self, name, salary, programming_language):
        super().__init__(name, salary)
        self.programming_language = programming_language

    def calculate_bonus(self):
        return self.salary * 0.1

# Concrete class representing a Manager
class Manager(Employee):
    def __init__(self, name, salary, team_size):
        super().__init__(name, salary)
        self.team_size = team_size

    def calculate_bonus(self):
        return self.salary * 0.15 + self.team_size * 1000

# Concrete class representing a Company
class Company:
    def __init__(self, name):
        self.name = name
        self.employees = []

    def hire_employee(self, employee):
        self.employees.append(employee)

    def display_employee_info(self):
        for employee in self.employees:
            print(f"{employee.name} - Salary: ${employee.salary}, Bonus: ${employee.calculate_bonus()}")

# Example Usage
if __name__ == "__main__":
    # Creating instances of employees
    dev1 = Developer("Tahsin Soyak", 80000, "Python")
    manager1 = Manager("Bilge Özcan", 100000, 5)

    # Creating a company
    company = Company("Tech Innovators")

    # Hiring employees
    company.hire_employee(dev1)
    company.hire_employee(manager1)

    # Displaying employee information
    company.display_employee_info()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s a breakdown of the context:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Abstract Class (Employee):&lt;/strong&gt;&lt;br&gt;
The &lt;em&gt;Employee _ class is defined as an abstract class. Abstract classes serve as blueprints for other classes and contain at least one abstract method. In this example, _calculate_bonus()&lt;/em&gt; is the abstract method. All subclasses must implement this method.&lt;br&gt;
The &lt;em&gt;Employee&lt;/em&gt; class includes common attributes and methods for all types of employees.&lt;br&gt;
&lt;strong&gt;Concrete Class (Developer):&lt;/strong&gt;&lt;br&gt;
The Developer class is a concrete subclass of &lt;em&gt;Employee&lt;/em&gt; .&lt;br&gt;
It includes additional attributes, such as programming_language.&lt;br&gt;
It implements the abstract method &lt;em&gt;calculate_bonus()&lt;/em&gt; specific to developers. In this example, the bonus is calculated as 10% of the salary.&lt;br&gt;
&lt;strong&gt;Concrete Class (Manager):&lt;/strong&gt;&lt;br&gt;
The Manager class is another concrete subclass of Employee.&lt;br&gt;
It includes additional attributes, such as &lt;em&gt;team_size&lt;/em&gt; .&lt;br&gt;
It implements the abstract method &lt;em&gt;calculate_bonus()&lt;/em&gt; specific to managers. In this example, the bonus is calculated based on both the salary and the size of the team managed.&lt;br&gt;
&lt;strong&gt;Company Class:&lt;/strong&gt;&lt;br&gt;
The Company class represents a company that can hire employees.&lt;br&gt;
It has methods to hire employees and display information about all employees.&lt;br&gt;
&lt;strong&gt;Example Usage:&lt;/strong&gt;&lt;br&gt;
Two employees are created: one &lt;em&gt;Developer&lt;/em&gt; and one &lt;em&gt;Manager&lt;/em&gt; .&lt;br&gt;
A Company instance is created, named &lt;em&gt;Tech Innovators&lt;/em&gt; .&lt;br&gt;
Employees are hired by the company.&lt;br&gt;
Information about the employees is displayed, including their name, salary, and calculated bonus.&lt;br&gt;
The example demonstrates the following OOP concepts:&lt;/p&gt;

&lt;p&gt;Encapsulation: Attributes are encapsulated within classes.&lt;br&gt;
Inheritance: Subclasses are created from a base class.&lt;br&gt;
Polymorphism: Different classes implement the same method in different ways.&lt;br&gt;
Abstraction: An abstract class is used to define a blueprint, ensuring methods are implemented by subclasses.&lt;/p&gt;

&lt;p&gt;If you need further information or have specific questions, feel free to ask! Tahsin Soyak &lt;a href="mailto:tahsinsoyakk@gmail.com"&gt;tahsinsoyakk@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>beginners</category>
      <category>python</category>
      <category>programming</category>
    </item>
    <item>
      <title>OOP Python 4- Understanding Abstraction in Python</title>
      <dc:creator>tahsinsoyak</dc:creator>
      <pubDate>Sun, 24 Mar 2024 08:24:00 +0000</pubDate>
      <link>https://dev.to/tahsinsoyak/oop-python-4-understanding-abstraction-in-python-170i</link>
      <guid>https://dev.to/tahsinsoyak/oop-python-4-understanding-abstraction-in-python-170i</guid>
      <description>&lt;p&gt;Abstraction, a foundational concept in Python, allows developers to create a superclass that carries common features and functions of subclasses without having an object of its own.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Concepts:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Common Features: Abstraction enables the creation of a superclass that encapsulates shared attributes and methods of subclasses.&lt;/li&gt;
&lt;li&gt;Template Definition: Methods in the abstract class can serve as templates to be overridden by subclasses.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits of Abstraction:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simplified Design: Abstract classes provide a blueprint for subclasses, simplifying the overall design.&lt;/li&gt;
&lt;li&gt;Modularity: Encapsulation of common features enhances code modularity and maintainability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example: Animal Hierarchy Consider an abstract class "Animal" with an abstract method "make_sound." Subclasses like "Dog" and "Cat" will implement this method according to their specific sound.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
from abc import ABC, abstractmethod

class Animal(ABC):
    @abstractmethod
    def make_sound(self):
        pass  # Abstract method to be implemented by subclasses

class Dog(Animal):
    def make_sound(self):
        return "Woof!"

class Cat(Animal):
    def make_sound(self):
        return "Meow!"

# Usage
dog_instance = Dog()
cat_instance = Cat()

print(dog_instance.make_sound())  # Output: Woof!
print(cat_instance.make_sound())  # Output: Meow!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, abstraction allows the "Animal" superclass to define a common method, "make_sound," which is implemented differently by its subclasses (Dog and Cat). This promotes a clean and modular design in Python.&lt;/p&gt;

&lt;p&gt;If you need further information or have specific questions, feel free to ask! Tahsin Soyak &lt;a href="mailto:tahsinsoyakk@gmail.com"&gt;tahsinsoyakk@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
    <item>
      <title>OOP Python 3- Understanding Polymorphism in Python</title>
      <dc:creator>tahsinsoyak</dc:creator>
      <pubDate>Sun, 17 Mar 2024 07:32:00 +0000</pubDate>
      <link>https://dev.to/tahsinsoyak/oop-python-3-understanding-polymorphism-in-python-5gb5</link>
      <guid>https://dev.to/tahsinsoyak/oop-python-3-understanding-polymorphism-in-python-5gb5</guid>
      <description>&lt;p&gt;Polymorphism, a key feature in Python, empowers the language to process different data types and classes in distinct ways. To put it simply, it's the ability to redefine methods and derived classes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Concepts:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dynamic Processing: Polymorphism allows Python to dynamically process various data types and classes.&lt;/li&gt;
&lt;li&gt;Method Redefinition: The ability to redefine methods enables flexibility and adaptability in programming.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits of Polymorphism:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Versatility: Write code that can seamlessly handle different data types and class instances.&lt;/li&gt;
&lt;li&gt;Adaptability: Redefine methods based on specific use cases, enhancing code adaptability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example: Shape Class Imagine a "Shape" class; polymorphism allows programmers to determine the areas of different shapes using distinct methods. Regardless of the specific shape, the program will provide the correct area to the user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Shape:
    def calculate_area(self):
        pass  # Method to be overridden in derived classes

class Circle(Shape):
    def calculate_area(self, radius):
        return 3.14 * radius * radius

class Square(Shape):
    def calculate_area(self, side_length):
        return side_length * side_length

# Usage
circle_instance = Circle()
square_instance = Square()

print(circle_instance.calculate_area(5))  # Output: 78.5
print(square_instance.calculate_area(4))  # Output: 16
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, polymorphism allows each shape (Circle, Square) to define its own method for calculating the area, showcasing the power and adaptability of polymorphic behavior in Python.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>OOP Python 2- Understanding Inheritance in Python : A Comprehensive Guide with Examples</title>
      <dc:creator>tahsinsoyak</dc:creator>
      <pubDate>Sun, 10 Mar 2024 07:30:00 +0000</pubDate>
      <link>https://dev.to/tahsinsoyak/oop-python-2-understanding-inheritance-in-python-a-comprehensive-guide-with-examples-4ddc</link>
      <guid>https://dev.to/tahsinsoyak/oop-python-2-understanding-inheritance-in-python-a-comprehensive-guide-with-examples-4ddc</guid>
      <description>&lt;p&gt;Discover the power and versatility of Python inheritance with this in-depth guide. Explore single, multiple, multilevel, hierarchical, and hybrid inheritance through professionally crafted examples. Enhance your understanding of object-oriented programming and inheritance in Python.&lt;/p&gt;

&lt;p&gt;Inheritance is a mechanism in Python that establishes a parent-child relationship when deriving one class from another. It enables the usage of common methods and properties across these classes, facilitating code reusability and structure.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a. Single Inheritance: The subclass inherits all properties of a single superclass. &lt;/li&gt;
&lt;li&gt;b. Multiple Inheritance: The subclass inherits all properties of multiple superclasses. &lt;/li&gt;
&lt;li&gt;c. Multilevel Inheritance: It involves creating a subclass of a class, and then creating a subclass of that subclass. &lt;/li&gt;
&lt;li&gt;d. Hierarchical Inheritance: A superclass serves as the base class for multiple subclasses. &lt;/li&gt;
&lt;li&gt;e. Hybrid Inheritance: This type combines two or more other inheritance types.
Inheritance promotes code organization, reduces redundancy, and allows for more maintainable and scalable code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example with all types of inheritance:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Inheritance Example with All Types

# Single Inheritance
class Animal:
    def __init__(self, name):
        self.name = name

    def speak(self):
        return "Generic animal sound"

class Dog(Animal):
    def speak(self):
        return "Woof!"

# Multiple Inheritance
class Flyable:
    def fly(self):
        return "Flying"

class Bird(Animal, Flyable):
    def speak(self):
        return "Tweet!"

# Multilevel Inheritance
class Poodle(Dog):
    def speak(self):
        return "Bark softly"

# Hierarchical Inheritance
class Cat(Animal):
    def speak(self):
        return "Meow!"

# Hybrid Inheritance
class SuperDog(Dog, Flyable):
    pass

# Using Inheritance
dog = Dog("Buddy")
bird = Bird("Robin")
poodle = Poodle("Fluffy")
cat = Cat("Whiskers")
super_dog = SuperDog("Super Buddy")

print(dog.speak())      # Output: Woof!
print(bird.speak())     # Output: Tweet!
print(poodle.speak())   # Output: Bark softly
print(cat.speak())      # Output: Meow!
print(super_dog.speak()) # Output: Woof!  (inherits from Dog)

# Using Multiple Inheritance
print(bird.fly())       # Output: Flying

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

&lt;/div&gt;



&lt;p&gt;This example showcases all types of inheritance in Python with well-structured and professional coding practices. It includes single, multiple, multilevel, hierarchical, and hybrid inheritance. Each class demonstrates the specific characteristics associated with its inheritance type.&lt;/p&gt;

&lt;p&gt;If you need further information or have specific questions, feel free to ask! Tahsin Soyak &lt;a href="mailto:tahsinsoyakk@gmail.com"&gt;tahsinsoyakk@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
    <item>
      <title>OOP Python 1 -Understanding Encapsulation in Python</title>
      <dc:creator>tahsinsoyak</dc:creator>
      <pubDate>Sun, 03 Mar 2024 07:30:00 +0000</pubDate>
      <link>https://dev.to/tahsinsoyak/understanding-encapsulation-in-python-3jjg</link>
      <guid>https://dev.to/tahsinsoyak/understanding-encapsulation-in-python-3jjg</guid>
      <description>&lt;p&gt;Encapsulation: Encapsulation is one of the fundamental concepts in OOP (Object-Oriented Programming). It involves setting limits on what aspects of data, classes, and methods can be viewed and modified by users. There are three access modifiers: Public, Private, and Protected.&lt;/p&gt;

&lt;p&gt;Public:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Everyone can view and modify it.&lt;/li&gt;
&lt;li&gt;It is the least secure class type.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Protected:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More secure than the Public modifier.&lt;/li&gt;
&lt;li&gt;Can be viewed or accessed within the same class.&lt;/li&gt;
&lt;li&gt;Can also be viewed or accessed by upper classes, classes derived from it, and classes within the same package.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Private:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The most secure access modifier.&lt;/li&gt;
&lt;li&gt;Private elements can only be viewed or accessed by the class they are in.&lt;/li&gt;
&lt;li&gt;Both classes and the data they hold can be private.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits of Encapsulation:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Security: Protects sensitive data from unauthorized access.&lt;/li&gt;
&lt;li&gt;Flexibility: Allows the internal representation of an object to change without affecting the overall system.&lt;/li&gt;
&lt;li&gt;Modularity: Encapsulated code is easier to maintain and update.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Professional Example: Consider a scenario in a banking application where customer account details are encapsulated as private information. The account balance, being a private property, can only be accessed and modified through specific methods defined in the class, ensuring secure and controlled interaction with sensitive financial data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class BankAccount:
    def __init__(self, account_holder, balance):
        # Private attributes
        self._account_holder = account_holder
        self._balance = balance

    # Getter method for account holder
    def get_account_holder(self):
        return self._account_holder

    # Setter method for balance with validation
    def set_balance(self, new_balance):
        if new_balance &amp;gt;= 0:
            self._balance = new_balance
        else:
            print("Invalid balance. Balance cannot be negative.")

    # Getter method for balance
    def get_balance(self):
        return self._balance

# Creating an instance of BankAccount
account1 = BankAccount("Tahsin Soyak", 1000)

# Accessing account holder (get method)
print("Account Holder:", account1.get_account_holder())

# Accessing balance (get method)
print("Initial Balance:", account1.get_balance())

# Trying to set a negative balance (set method)
account1.set_balance(-500)

# Setting a valid balance (set method)
account1.set_balance(1500)

# Accessing updated balance (get method)
print("Updated Balance:", account1.get_balance())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Account Holder: Tahsin Soyak&lt;br&gt;
Initial Balance: 1000&lt;br&gt;
Invalid balance. Balance cannot be negative.&lt;br&gt;
Updated Balance: 1500&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The BankAccount class has private attributes _account_holder and _balance.&lt;/li&gt;
&lt;li&gt;Getter methods (get_account_holder and get_balance) allow access to these private attributes.&lt;/li&gt;
&lt;li&gt;Setter method (set_balance) allows modifying the balance with validation to ensure it's not negative.&lt;/li&gt;
&lt;li&gt;Outside the class, we access and modify the attributes through the getter and setter methods, ensuring encapsulation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This example showcases encapsulation by restricting direct access to private attributes and providing controlled access through methods.&lt;/p&gt;

&lt;p&gt;If you need further information or have specific questions, feel free to ask! Tahsin Soyak &lt;a href="mailto:tahsinsoyakk@gmail.com"&gt;tahsinsoyakk@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
    <item>
      <title>RESTful API Explained: Unraveling the World of APIs and REST</title>
      <dc:creator>tahsinsoyak</dc:creator>
      <pubDate>Sun, 25 Feb 2024 06:04:00 +0000</pubDate>
      <link>https://dev.to/tahsinsoyak/restful-api-explained-unraveling-the-world-of-apis-and-rest-3l8m</link>
      <guid>https://dev.to/tahsinsoyak/restful-api-explained-unraveling-the-world-of-apis-and-rest-3l8m</guid>
      <description>&lt;p&gt;Dive into the world of RESTful APIs, learning what REST and API mean, and how they facilitate seamless communication between applications. Discover the fundamental principles of REST and explore a real-world example, unraveling the efficiency and modularity they bring to applications, using Python and Flask to showcase the implementation process.&lt;/p&gt;

&lt;h2&gt;
  
  
  API Overview:
&lt;/h2&gt;

&lt;p&gt;API, or Application Programming Interface, constitutes a set of rules defining how applications or devices can connect and communicate with each other. API integration involves connecting multiple applications (two or more) through APIs to exchange data and accomplish a common functionality, thus facilitating interaction between applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  REST Overview:
&lt;/h2&gt;

&lt;p&gt;REST, or Representational State Transfer, operates as an architecture working over the HTTP protocol, facilitating communication between client and server. It transports data, typically in XML or JSON format, by carrying resources. In REST architecture, operations are conducted through the concept of resources, identified by a resource URI, which can be a method definition or a variable. Operations in REST are entirely carried out through HTTP methods. For instance, fetching all information about a product in sale can be achieved by sending a GET request to the URI "/product/15."&lt;br&gt;
Additionally, REST can return values in desired data types such as JSON, XML, TXT, or HTML. However, JSON is commonly preferred.&lt;/p&gt;
&lt;h2&gt;
  
  
  RESTful API:
&lt;/h2&gt;

&lt;p&gt;Services employing the REST architecture are termed RESTful services (RESTful APIs). Various websites like Amazon, Google, Facebook, LinkedIn, and Twitter utilize REST-based APIs, enabling users to communicate with these cloud services. Working with a service written in REST requires only a URL. When making a request to a URL, it returns a response in JSON or XML format, which is then parsed, completing your service integration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Advantages:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Interoperability: RESTful APIs facilitate seamless interaction between different systems and applications.&lt;/li&gt;
&lt;li&gt;Scalability: The stateless nature of REST allows for easy scalability, making it ideal for distributed systems.&lt;/li&gt;
&lt;li&gt;Flexibility: Supports various data formats, providing flexibility in data exchange.&lt;/li&gt;
&lt;li&gt;Simplicity: Simple and intuitive, making it easier for developers to work with.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Professional Example:&lt;/strong&gt; Consider a scenario where you're developing an e-commerce application. Utilizing a RESTful API, you can easily retrieve product details, update inventory, or process orders by sending HTTP requests to specific URIs. This streamlined communication enhances the efficiency and modularity of your application, showcasing the power of RESTful APIs in real-world applications.&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 import Flask, request, jsonify

app = Flask(__name__)

# Sample product data (for demonstration purposes)
products = [
    {"id": 1, "name": "Product A", "price": 20.0, "quantity": 100},
    {"id": 2, "name": "Product B", "price": 30.0, "quantity": 50},
]

# Endpoint to retrieve all products
@app.route('/products', methods=['GET'])
def get_all_products():
    return jsonify(products)

# Endpoint to retrieve a specific product by ID
@app.route('/products/&amp;lt;int:product_id&amp;gt;', methods=['GET'])
def get_product(product_id):
    product = next((p for p in products if p['id'] == product_id), None)
    if product:
        return jsonify(product)
    else:
        return jsonify({"message": "Product not found"}), 404

# Endpoint to update the quantity of a product
@app.route('/products/&amp;lt;int:product_id&amp;gt;/update_quantity', methods=['PUT'])
def update_product_quantity(product_id):
    data = request.get_json()
    new_quantity = data.get('quantity')

    product = next((p for p in products if p['id'] == product_id), None)
    if product and new_quantity is not None:
        product['quantity'] = new_quantity
        return jsonify({"message": "Quantity updated successfully"})
    else:
        return jsonify({"message": "Product not found or invalid quantity"}), 404

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

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;The /products endpoint retrieves all products.&lt;/li&gt;
&lt;li&gt;The /products/ endpoint retrieves a specific product by its ID.&lt;/li&gt;
&lt;li&gt;The /products//update_quantity endpoint allows updating the quantity of a specific product using a PUT request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can run this Flask application, and using tools like curl or Postman, you can make HTTP requests to interact with the API, such as retrieving product details or updating the quantity of a product.&lt;/p&gt;

&lt;p&gt;If you need further information or have specific questions, feel free to ask! Tahsin Soyak &lt;a href="mailto:tahsinsoyakk@gmail.com"&gt;tahsinsoyakk@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
    <item>
      <title>Iterator in Python: Unveiling the Essence of Iteration</title>
      <dc:creator>tahsinsoyak</dc:creator>
      <pubDate>Sun, 18 Feb 2024 06:05:00 +0000</pubDate>
      <link>https://dev.to/tahsinsoyak/iterator-in-python-unveiling-the-essence-of-iteration-26ne</link>
      <guid>https://dev.to/tahsinsoyak/iterator-in-python-unveiling-the-essence-of-iteration-26ne</guid>
      <description>&lt;p&gt;In the realm of Python, iterators are objects that allow traversal, yielding one element at a time. Any object from which we can create an iterator is inherently an iterable object. Examples include tuples, lists, and strings, all of which are iterable objects&lt;br&gt;
.&lt;br&gt;
For an object to be iterable, it must define the essential methods: &lt;strong&gt;iter()&lt;/strong&gt; and &lt;strong&gt;next()&lt;/strong&gt;. The process of creating an iterator object from an iterable one (e.g., a list, tuple, or string) involves using the iter() function to create the iterator and the next() function to retrieve the next element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list = [1,4,7,9]
# Iterator Creation
iterator = iter(list)
# Accessing Next Element
next(iterator)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;While traversing an iterable object with an iterator, the StopIteration error is encountered when there are no more elements to retrieve. Interestingly, Python's for loops silently leverage iterators behind the scenes.&lt;/p&gt;

&lt;p&gt;Now, how can we make our custom data types iterable? To achieve this, our created classes must explicitly define the &lt;strong&gt;iter()&lt;/strong&gt; and &lt;strong&gt;next()&lt;/strong&gt; methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class RemoteControl:
    def __init__(self, channel_list):
        self.channel_list = channel_list
        self.index = -1

    def __iter__(self):
        return self

    def __next__(self):
        self.index += 1
        if self.index &amp;lt; len(self.channel_list):
            return self.channel_list[self.index]
        else:
            self.index = -1
            raise StopIteration

# Creating an instance of the class
remote = RemoteControl(["Channel A", "TRT", "ATV", "Fox", "Bloomberg"])

# Creating an iterator
iterator = iter(remote)
print(next(iterator))
print(next(iterator))
print(next(iterator))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Channel A&lt;/code&gt;&lt;br&gt;
&lt;code&gt;TRT&lt;/code&gt;&lt;br&gt;
&lt;code&gt;ATV&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Iterators enable sequential access to elements in an iterable object, optimizing memory usage during traversal.&lt;/p&gt;

&lt;p&gt;The __iter() and __next() methods define the iteration protocol, facilitating custom iterable classes.&lt;/p&gt;

&lt;p&gt;Custom iterable classes empower developers to create specialized data structures, enhancing code flexibility and readability.&lt;/p&gt;

&lt;p&gt;Imagine a scenario where you have a custom data structure representing a playlist. By implementing the iterator protocol, you can seamlessly iterate through the playlist, offering a clean and efficient way to manage multimedia content in your application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Playlist:
    def __init__(self, songs):
        self.songs = songs
        self.current_index = 0

    def __iter__(self):
        return self

    def __next__(self):
        if self.current_index &amp;lt; len(self.songs):
            current_song = self.songs[self.current_index]
            self.current_index += 1
            return current_song
        else:
            self.current_index = 0
            raise StopIteration

# Creating a playlist
my_playlist = Playlist(["Song A", "Song B", "Song C", "Song D"])

# Iterating through the playlist
for song in my_playlist:
    print(f"Now playing: {song}")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Now playing: Song A&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Now playing: Song B&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Now playing: Song C&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Now playing: Song D&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In this example, the Playlist class is made iterable, allowing for seamless traversal of songs in the playlist. This demonstrates the power of custom iterators in managing diverse data structures.&lt;/p&gt;

&lt;p&gt;If you need further information or have specific questions, feel free to ask! Tahsin Soyak &lt;a href="mailto:tahsinsoyakk@gmail.com"&gt;tahsinsoyakk@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
  </channel>
</rss>
