<?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: Soumendra Kumar Sahoo</title>
    <description>The latest articles on DEV Community by Soumendra Kumar Sahoo (@soumendrak).</description>
    <link>https://dev.to/soumendrak</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F491896%2F2aabf788-9b19-438c-b10b-2534c87647af.png</url>
      <title>DEV Community: Soumendra Kumar Sahoo</title>
      <link>https://dev.to/soumendrak</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/soumendrak"/>
    <language>en</language>
    <item>
      <title>Prompt vs Context vs Harness vs Loop Engineering</title>
      <dc:creator>Soumendra Kumar Sahoo</dc:creator>
      <pubDate>Sun, 21 Jun 2026 08:14:58 +0000</pubDate>
      <link>https://dev.to/soumendrak/prompt-vs-context-vs-harness-vs-loop-engineering-2jl5</link>
      <guid>https://dev.to/soumendrak/prompt-vs-context-vs-harness-vs-loop-engineering-2jl5</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuj0oqpjhq5t0hf942jzh.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuj0oqpjhq5t0hf942jzh.webp" alt="Different Engineering discipline evolution in AI Agents" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One night my AI agent Hermes, which I run 24/7 on my own hardware, spent 47 turns trying to "fix" a script. Every turn it ran the same broken command, got the same error, apologized and tried again. I sat there watching the token counter climb like a Tatkal queue at 10 AM, and I genuinely could not tell what had gone wrong. Was the prompt bad? Was it missing context? Was a tool broken? Was the loop just never going to stop? I am an AI Observability Architect, and I was staring at my own agent unable to name which layer had failed.&lt;/p&gt;

&lt;p&gt;That night is what this post is about. A production AI agent is not one skill, it is five, and when something breaks at 2 AM you need to know exactly which one to blame.&lt;/p&gt;

&lt;p&gt;Everyone talks about prompt engineering. Fewer people talk about context engineering. Almost nobody talks about harness, loop or evaluation engineering, even though they're the difference between a demo that works once and a system that survives a night alone on my server.&lt;/p&gt;

&lt;p&gt;An AI observability architect who doesn't understand the full stack of agent engineering is just a person who reads dashboards. So I sat down and split it into the five disciplines that actually make up a production agent: what each one is, how they differ and how they fit together.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Five Disciplines
&lt;/h2&gt;

&lt;p&gt;Before the definitions, one metaphor ties all five together: &lt;strong&gt;a worker doing a job at a workbench.&lt;/strong&gt; I reuse it for every discipline so the boundaries stay sharp.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prompt&lt;/strong&gt; is the &lt;strong&gt;job description&lt;/strong&gt; pinned to the wall: what to do and how to do it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Context&lt;/strong&gt; is the &lt;strong&gt;briefing packet&lt;/strong&gt; on the desk: the facts for this one task, not the whole library.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Harness&lt;/strong&gt; is the &lt;strong&gt;workbench and the tools&lt;/strong&gt; bolted to it: what the worker can physically reach and operate, plus the safety guards.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Loop&lt;/strong&gt; is the &lt;strong&gt;work rhythm&lt;/strong&gt;: do a step, check the result, decide the next step and know when to down tools.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Evaluation&lt;/strong&gt; is the &lt;strong&gt;QA inspector&lt;/strong&gt; who checks finished pieces and reports trends.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keep that worker in your head. The whole post hangs off it.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Prompt Engineering
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; Writing the instructions that tell the model what to do, how to do it, and what format to return.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The job:&lt;/strong&gt; Craft system prompts, few-shot examples, output format constraints, and chain-of-thought scaffolding that produce reliable outputs from the model. There are different styles of prompting (zero-shot, few-shot, chain-of-thought, tree-of-thought) and different techniques (role prompting, constraint prompting, format prompting) that can be combined in various ways.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What you're optimizing for:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Output quality, &lt;/li&gt;
&lt;li&gt;Instruction adherence, &lt;/li&gt;
&lt;li&gt;Format consistency, &lt;/li&gt;
&lt;li&gt;Token efficiency of the prompt itself.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Failure mode:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Over-prompting. &lt;/li&gt;
&lt;li&gt;A 2000-token system prompt that tries to cover every edge case but degrades model performance because the model loses focus on what matters. Hermes' system prompt is 200+ lines, and I have learned the hard way that every rule I add to squash one bug quietly makes three others more likely.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; "You are a Python debugging assistant. Given a traceback and the relevant code, identify the root cause and suggest a fix. Always output: 1) Root cause, 2) Fix (as a code block), 3) Explanation. Do not hallucinate functions that don't exist in the code."&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Context Engineering
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; Deciding what information goes into the model's context window and in what order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In the metaphor:&lt;/strong&gt; the briefing packet you hand the worker for this task. Not the whole library, just the pages that matter right now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The job:&lt;/strong&gt; Build retrieval pipelines (RAG), manage conversation history, compress old context, inject relevant documents, and structure the information so the model can use it effectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What you're optimizing for:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Retrieval precision, &lt;/li&gt;
&lt;li&gt;Context window utilization, &lt;/li&gt;
&lt;li&gt;Signal-to-noise ratio, &lt;/li&gt;
&lt;li&gt;Cost per query (fewer irrelevant tokens = lower cost).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Failure mode:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Context stuffing. &lt;/li&gt;
&lt;li&gt;Dumping 100K tokens of "relevant" documents into the context window when the model only needs 5K. The model gets distracted, costs spike, and quality drops. My first version of Hermes' memory shoved everything it had ever seen into context, and the bill at the end of the month taught me restraint faster than any blog post could.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; Instead of passing an entire 500-page PDF, you chunk it into sections, embed each chunk, retrieve the top-5 most relevant sections based on the query, and inject only those, with a summary of what was excluded so the model knows the full document exists.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Harness Engineering
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; Building the infrastructure that wraps the model, tool definitions, API integrations, execution environments, and safety rails.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In the metaphor:&lt;/strong&gt; the workbench, the power tools and the safety guards. It is what the worker can reach and operate, nothing more. This is the &lt;em&gt;static&lt;/em&gt; part: it exists before the agent runs a single step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The job:&lt;/strong&gt; Define the tool schemas the model can call. Wire up the terminal, file system, web browser, and external APIs. Enforce permissions, rate limits, and sandboxing. Handle retries, timeouts, and error recovery.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What you're optimizing for:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tool call reliability, &lt;/li&gt;
&lt;li&gt;Execution safety, &lt;/li&gt;
&lt;li&gt;Latency, &lt;/li&gt;
&lt;li&gt;Breadth of capabilities available to the agent.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Failure mode:&lt;/strong&gt; The agent calls a tool that doesn't exist, or a tool that exists but returns an error the model can't interpret. The agent spirals into retry loops or hallucinates a successful outcome. Half of Hermes' early "successes" were it cheerfully telling me a task was done while the tool had actually thrown a stack trace it never bothered to read.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; Defining a &lt;code&gt;read_file&lt;/code&gt; tool with a clear schema (&lt;code&gt;path: string, offset: int, limit: int&lt;/code&gt;), a &lt;code&gt;check_fn&lt;/code&gt; that verifies the file exists before the tool is exposed to the model, and an error handler that returns structured JSON the model can act on instead of a raw stack trace.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Loop Engineering
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; Designing the agent's reasoning loop, how it decides what to do next, when to stop, and when to ask for help.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In the metaphor:&lt;/strong&gt; the work rhythm. If the harness is the machine on the bench, the loop is the worker pressing "go" again and again, checking the result each time, until the piece is finished or the foreman gets called. This is the &lt;em&gt;dynamic&lt;/em&gt; part: it only exists while the agent is running.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://digg.com/ai/7ifyvmb9" rel="noopener noreferrer"&gt;Peter Steinberger&lt;/a&gt;, the creator of OpenClaw, put the same idea more provocatively in June 2026: "You shouldn't be prompting coding agents anymore. You should be designing loops that prompt your agents." His framing adds a sharp point I love: a good loop corrects itself against &lt;em&gt;objective signals&lt;/em&gt; (tests, type checkers, linters, runtime errors) rather than against your patience. That is the difference between an agent that runs while you sleep and one that needs you babysitting every turn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The job:&lt;/strong&gt; Choose the loop pattern (ReAct, Plan-and-Execute, Tree of Thoughts). Set the max turns. Implement context compression when the conversation gets long. Decide when the agent should pause for human approval vs. proceed autonomously.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What you're optimizing for:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Task completion rate, &lt;/li&gt;
&lt;li&gt;Loop efficiency (fewer turns for the same outcome), &lt;/li&gt;
&lt;li&gt;Autonomous depth, &lt;/li&gt;
&lt;li&gt;Graceful degradation when the agent gets stuck.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Failure mode:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Infinite loops. &lt;/li&gt;
&lt;li&gt;The agent calls a tool, gets an unexpected result, retries with the same approach, gets the same result, and burns through 50 turns without progress. This is the exact 47-turn night from the top of this post: pure Loop Engineering failure. &lt;/li&gt;
&lt;li&gt;Or the opposite: the agent stops too early, declaring success when the task is half-done.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; A ReAct loop that caps at 90 turns, compresses context at 50% utilization, and falls back to asking the user for clarification after 3 consecutive failed tool calls on the same sub-task.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Evaluation Engineering
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it is:&lt;/strong&gt; Designing the systems that tell you whether the other four are working.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The job:&lt;/strong&gt; Build eval datasets. Configure LLM-as-a-Judge pipelines. Run regression tests on every model change. Aggregate scores, track trends, and set alerting thresholds for quality degradation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What you're optimizing for:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Evaluation accuracy (does the eval correlate with real quality?), &lt;/li&gt;
&lt;li&gt;Evaluation cost (are you spending more on eval than on the agent itself?), &lt;/li&gt;
&lt;li&gt;Signal timeliness (how fast do you learn about a regression?).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Failure mode:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Evaluating the wrong thing. &lt;/li&gt;
&lt;li&gt;A judge model that scores "helpfulness" but actually rewards verbosity. Or a regression suite that passes every time because the test cases are too easy. You feel confident while quality silently degrades. This is the failure that scares me the most, because unlike the 47-turn night, it makes no noise at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; A Langfuse evaluator that classifies every agent trace by query type (coding, research, ops), scores output quality on a 1-5 rubric, and alerts when the research query quality score drops below 3.5 for two consecutive days.&lt;/p&gt;

&lt;h2&gt;
  
  
  How are Context, Harness, and Loop different?
&lt;/h2&gt;

&lt;p&gt;This is the part that trips everyone up, including me. Prompt and Evaluation are easy to tell apart. The blur is between Context, Harness and Loop, because all three feel like "stuff around the model." Here is the cleanest way I have found to separate them.&lt;/p&gt;

&lt;h3&gt;
  
  
  One word each
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Discipline&lt;/th&gt;
&lt;th&gt;One word&lt;/th&gt;
&lt;th&gt;The question it answers&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Context&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;KNOW&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;What does the model get to &lt;em&gt;see&lt;/em&gt;?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Harness&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;DO&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;What can the model actually &lt;em&gt;touch&lt;/em&gt; in the real world?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Loop&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;DECIDE&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;How many times, in what order, and when does it &lt;em&gt;stop&lt;/em&gt;?&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Or, borrowing a line I like from LangChain: prompt shapes behavior, context shapes reasoning, harness shapes execution. The loop is the slice of execution that repeats.&lt;/p&gt;

&lt;h3&gt;
  
  
  The same bug, three different owners
&lt;/h3&gt;

&lt;p&gt;Here is the trick that finally made it click. Take one task, "fix the failing test," and one symptom, "the agent didn't fix it." Who gets paged depends entirely on &lt;em&gt;why&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It never saw the test file or the error output. &lt;strong&gt;Context&lt;/strong&gt; bug: the knowledge was missing.&lt;/li&gt;
&lt;li&gt;It had no &lt;code&gt;run_tests&lt;/code&gt; tool, or the tool crashed. &lt;strong&gt;Harness&lt;/strong&gt; bug: the capability was missing.&lt;/li&gt;
&lt;li&gt;It saw the file, ran the test once, ignored the red and quit (or looped 50 times getting nowhere). &lt;strong&gt;Loop&lt;/strong&gt; bug: the decision was missing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Same task. Same surface failure. Three different engineers fix it. Once you can sort a failure into KNOW, DO or DECIDE, the blur is gone.&lt;/p&gt;

&lt;h3&gt;
  
  
  Harness vs Loop: the machine and the "go" button
&lt;/h3&gt;

&lt;p&gt;Harness and Loop blur the most, so be precise. Honestly, the industry itself is not fully settled here: LangChain treats the loop as one component &lt;em&gt;inside&lt;/em&gt; the harness, while others treat Loop Engineering as a separate layer on top. The split I use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Harness is the &lt;em&gt;static&lt;/em&gt; part.&lt;/strong&gt; Everything that exists before the agent runs: tool schemas, sandbox, file system, permissions, guard rails. The machine on the bench.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Loop is the &lt;em&gt;dynamic&lt;/em&gt; part.&lt;/strong&gt; The act, observe, decide, repeat cycle plus the stopping condition. The worker pressing "go" on that machine until the goal is met.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The one-liner that sticks: &lt;strong&gt;the harness runs the agent once, the loop runs the harness until the job is done.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  One agent turn, three zones
&lt;/h3&gt;

&lt;p&gt;Forget the big architecture diagram for a second. Here is a single turn of the agent, with each discipline owning exactly one segment:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4izo3n2yw537f322uwsj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4izo3n2yw537f322uwsj.png" alt="high level overview" width="800" height="204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;They do not overlap. &lt;strong&gt;Context is the arrow going in. Harness is the arrow going out to the world and back. Loop is the circle plus the exit gate.&lt;/strong&gt; That is the whole difference in one picture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Side-by-Side Comparison
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dimension&lt;/th&gt;
&lt;th&gt;Prompt Engineering&lt;/th&gt;
&lt;th&gt;Context Engineering&lt;/th&gt;
&lt;th&gt;Harness Engineering&lt;/th&gt;
&lt;th&gt;Loop Engineering&lt;/th&gt;
&lt;th&gt;Evaluation Engineering&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;What you build&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Instructions for the model&lt;/td&gt;
&lt;td&gt;Information pipeline into the model&lt;/td&gt;
&lt;td&gt;Tool infrastructure around the model&lt;/td&gt;
&lt;td&gt;Reasoning cycle for the model&lt;/td&gt;
&lt;td&gt;Measurement system over the model&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Core artifact&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;System prompt, few-shot examples&lt;/td&gt;
&lt;td&gt;RAG pipeline, context compressor, chunking strategy&lt;/td&gt;
&lt;td&gt;Tool schemas, API adapters, sandbox&lt;/td&gt;
&lt;td&gt;Agent loop (ReAct, Plan-Execute, ToT)&lt;/td&gt;
&lt;td&gt;Eval datasets, judge prompts, score dashboards&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Key question&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;"What should the model do?"&lt;/td&gt;
&lt;td&gt;"What does the model need to know?"&lt;/td&gt;
&lt;td&gt;"What can the model do?"&lt;/td&gt;
&lt;td&gt;"How does the model decide what to do next?"&lt;/td&gt;
&lt;td&gt;"Is the model actually doing it well?"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Optimizes for&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Output quality, instruction adherence&lt;/td&gt;
&lt;td&gt;Signal-to-noise ratio, retrieval precision&lt;/td&gt;
&lt;td&gt;Tool reliability, execution safety&lt;/td&gt;
&lt;td&gt;Task completion, loop efficiency&lt;/td&gt;
&lt;td&gt;Evaluation accuracy, regression detection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Failure mode&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Over-prompting, instruction dilution&lt;/td&gt;
&lt;td&gt;Context stuffing, retrieval noise&lt;/td&gt;
&lt;td&gt;Tool errors, missing safety rails&lt;/td&gt;
&lt;td&gt;Infinite loops, premature stopping&lt;/td&gt;
&lt;td&gt;False confidence, measuring the wrong thing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Measured by&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Eval scores, format compliance&lt;/td&gt;
&lt;td&gt;Retrieval precision/recall, token cost&lt;/td&gt;
&lt;td&gt;Tool call success rate, latency&lt;/td&gt;
&lt;td&gt;Turn count, completion rate&lt;/td&gt;
&lt;td&gt;Judge-human agreement, alert precision&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;When it breaks&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Outputs are wrong format, off-topic&lt;/td&gt;
&lt;td&gt;Model hallucinates from missing context&lt;/td&gt;
&lt;td&gt;Agent can't act on its environment&lt;/td&gt;
&lt;td&gt;Agent gets stuck or loops forever&lt;/td&gt;
&lt;td&gt;You don't know quality is degrading&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Who typically owns it&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Prompt engineer, ML engineer&lt;/td&gt;
&lt;td&gt;RAG engineer, data engineer&lt;/td&gt;
&lt;td&gt;Platform engineer, infra engineer&lt;/td&gt;
&lt;td&gt;Agent engineer, ML engineer&lt;/td&gt;
&lt;td&gt;AI observability engineer, QA engineer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Maturity in industry&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;High (everyone does it)&lt;/td&gt;
&lt;td&gt;Medium (RAG is mainstream)&lt;/td&gt;
&lt;td&gt;Growing (agent frameworks emerging)&lt;/td&gt;
&lt;td&gt;Early (most teams have simple loops)&lt;/td&gt;
&lt;td&gt;Lowest (most teams skip it entirely)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  How They Fit Together
&lt;/h2&gt;

&lt;p&gt;Each discipline feeds into the next, and Evaluation wraps around all of them. Here's what a production AI agent system looks like when all five are in place, from the user's question to the final answer:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmc5pn5iwqsmajh7umxco.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmc5pn5iwqsmajh7umxco.png" alt="how all loop in together" width="625" height="989"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For better resolution image, please check the &lt;a href="https://www.soumendrak.com/blog/2026/06/ai-engineering-disciplines/#how-they-fit-together" rel="noopener noreferrer"&gt;OG post&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The dotted arrows are the key insight. Evaluation Engineering doesn't just sit at the end, it feeds back into every other discipline. When eval scores drop, you don't know which layer is broken until you instrument all five.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Happens When You Skip One?
&lt;/h2&gt;

&lt;p&gt;I've seen each of these failure modes in production. They're not hypothetical.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Skip This&lt;/th&gt;
&lt;th&gt;What Happens&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Prompt Engineering&lt;/td&gt;
&lt;td&gt;Model outputs inconsistent formats, ignores constraints, hallucinates expected behavior&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Context Engineering&lt;/td&gt;
&lt;td&gt;Model answers from stale or irrelevant information. Token costs 5-10x higher than necessary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Harness Engineering&lt;/td&gt;
&lt;td&gt;Agent can't interact with the real world. Every tool call is a potential crash&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Loop Engineering&lt;/td&gt;
&lt;td&gt;Agent runs forever on simple tasks, or stops too early on complex ones&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Evaluation Engineering&lt;/td&gt;
&lt;td&gt;You ship a model update and quality drops 20% and nobody notices for a week&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Evaluation Engineering is the most skipped and the most dangerous to skip.&lt;/strong&gt; Every other discipline has a visible failure mode, the output is wrong, the agent crashes, costs spike. Evaluation failure is invisible. Everything looks fine until a user complains.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where Is the Industry?
&lt;/h2&gt;

&lt;p&gt;Most teams today are at different maturity levels for each discipline: Prompt Engineering is high (everyone does it), Context Engineering is medium (RAG is mainstream), Harness Engineering is growing, Loop Engineering is early, and Evaluation Engineering is the lowest, often skipped entirely.&lt;/p&gt;

&lt;p&gt;The gap between Prompt Engineering (everyone does it) and Evaluation Engineering (almost nobody does it well) is where most production AI systems fail silently. This is also where the most interesting work is happening right now, LLM-as-a-Judge, automated regression pipelines, and observability-driven development.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I Apply This
&lt;/h2&gt;

&lt;p&gt;I run an AI agent (Hermes) 24/7 on my own infrastructure. Here's how the five disciplines map to real decisions I make:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prompt Engineering:&lt;/strong&gt; My agent's system prompt is 200+ lines defining its role, constraints, and output format. I tweak it when eval scores drop, not when I "feel like" the output is off.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Context Engineering:&lt;/strong&gt; My agent has persistent memory (user preferences, environment facts, session history). I manage a memory budget, when it hits 8000 chars, older entries are compressed or pruned. Context window management is a real engineering problem.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Harness Engineering:&lt;/strong&gt; My agent has access to terminal, file system, web browser, and 50+ tools. Each tool has a &lt;code&gt;check_fn&lt;/code&gt; that verifies requirements before the tool is exposed to the model. Destructive commands require approval.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Loop Engineering:&lt;/strong&gt; Max 90 turns per session. Auto-compress context at 50% utilization. Fallback to user clarification after consecutive failures. I've tuned these numbers over months of watching the agent get stuck and unstuck.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Evaluation Engineering:&lt;/strong&gt; I'm building an LLM-as-a-Judge pipeline in Langfuse that scores every agent trace. This is how I know whether my prompt changes actually improve output quality or just shift the failure modes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Bottom Line
&lt;/h2&gt;

&lt;p&gt;If you're building AI systems, you're doing all five of these whether you call them "engineering" or not. The question is whether you're doing them deliberately.&lt;/p&gt;

&lt;p&gt;Prompt Engineering is table stakes. Context Engineering is where most teams spend their RAG effort. Harness Engineering is where agent frameworks add value. Loop Engineering is where most teams have the most room to grow. Evaluation Engineering is where most teams are flying blind.&lt;/p&gt;

&lt;p&gt;If you can't measure it, you can't improve it. Start with Evaluation Engineering, even a simple LLM-as-a-Judge over your existing traces will tell you more about your system than months of intuition.&lt;/p&gt;




&lt;h2&gt;
  
  
  Related Articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.soumendrak.com/blog/advancing-ai-observability/" rel="noopener noreferrer"&gt;Advancing AI Observability: From Metrics to Meaningful Insights&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.soumendrak.com/blog/llm-evals/" rel="noopener noreferrer"&gt;The Hidden Cost of LLM-as-a-Judge: When More Evaluation Means Less Value&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.soumendrak.com/blog/2026/05/subagents-fabricate-data/" rel="noopener noreferrer"&gt;My Subagents Lied to Me: What Happened When I Let AI Research Autonomously&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.soumendrak.com/series/practical-observability-with-python/" rel="noopener noreferrer"&gt;Practical Observability with Python&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>promptengineering</category>
      <category>contextengineering</category>
      <category>harnessengineering</category>
      <category>loopengineering</category>
    </item>
    <item>
      <title>Why should you use attrs more</title>
      <dc:creator>Soumendra Kumar Sahoo</dc:creator>
      <pubDate>Tue, 20 Aug 2024 01:51:15 +0000</pubDate>
      <link>https://dev.to/soumendrak/why-should-you-use-attrs-more-4dim</link>
      <guid>https://dev.to/soumendrak/why-should-you-use-attrs-more-4dim</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Python's &lt;code&gt;attrs&lt;/code&gt; library is a game-changer for developers looking to simplify class creation and reduce boilerplate code. This libray is even trusted by NASA.&lt;br&gt;
Created by &lt;a href="https://hynek.me/" rel="noopener noreferrer"&gt;Hynek Schlawack&lt;/a&gt; in 2015, &lt;code&gt;attrs&lt;/code&gt; has quickly become a favorite tool among Python developers for its ability to automatically generate special methods and provide a clean, declarative way to define classes.&lt;br&gt;
&lt;code&gt;dataclasses&lt;/code&gt; is a kind of subset of attrs.&lt;/p&gt;

&lt;p&gt;Why &lt;code&gt;attrs&lt;/code&gt; is useful:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduces boilerplate code&lt;/li&gt;
&lt;li&gt;Improves code readability and maintainability&lt;/li&gt;
&lt;li&gt;Provides powerful features for data validation and conversion&lt;/li&gt;
&lt;li&gt;Enhances performance through optimized implementations&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  2. Getting Started with attrs
&lt;/h2&gt;

&lt;p&gt;Installation:&lt;br&gt;
To get started with attrs, you can install it using pip:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;attrs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Basic usage:&lt;br&gt;
Here's a simple example of how to use attrs to define a class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;

&lt;span class="nd"&gt;@attr.s&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# Creating an instance
&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Alice&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Person(name='Alice', age=30)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Core Features of attrs
&lt;/h2&gt;

&lt;h3&gt;
  
  
  a. Automatic method generation:
&lt;/h3&gt;

&lt;p&gt;attrs automatically generates &lt;strong&gt;init&lt;/strong&gt;, &lt;strong&gt;repr&lt;/strong&gt;, and &lt;strong&gt;eq&lt;/strong&gt; methods for your classes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@attr.s&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;author&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;year&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;book1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1984&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;George Orwell&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1949&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;book2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1984&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;George Orwell&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1949&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;book1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Book(title='1984', author='George Orwell', year=1949)
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;book1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;book2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# True
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  b. Attribute definition with types and default values:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;typing&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;

&lt;span class="nd"&gt;@attr.s&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Library&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;books&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Factory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;capacity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;library&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Library&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;City Library&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;library&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Library(name='City Library', books=[], capacity=1000)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  c. Validators and converters:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;must_be_positive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;attribute&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Value must be positive&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@attr.s&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;converter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;validator&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;validators&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;instance_of&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;must_be_positive&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Book&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;29.99&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Product(name='Book', price=29.99)
&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Invalid&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;ValueError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Value must be positive
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Advanced Usage
&lt;/h2&gt;

&lt;h3&gt;
  
  
  a. Customizing attribute behavior:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;

&lt;span class="nd"&gt;@attr.s&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;_password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;repr&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Exclude from repr
&lt;/span&gt;
    &lt;span class="nd"&gt;@property&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_password&lt;/span&gt;

    &lt;span class="nd"&gt;@password.setter&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Simple hashing for demonstration
&lt;/span&gt;
&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;alice&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;secret123&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# User(username='alice')
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  b. Frozen instances and slots:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@attr.s&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frozen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# slots=True is the default
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Point&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;point&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Point&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;point&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;  &lt;span class="c1"&gt;# This will raise an AttributeError
&lt;/span&gt;&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;AttributeError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# can't set attribute
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  c. Factory functions and post-init processing:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;

&lt;span class="nd"&gt;@attr.s&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;factory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uuid4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;factory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;init&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__attrs_post_init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@attr.s&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Book&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;10.99&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Pen&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1.99&lt;/span&gt;&lt;span class="p"&gt;)])&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Order(id=UUID('...'), items=[Item(name='Book', price=10.99), Item(name='Pen', price=1.99)], total=12.98)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Best Practices and Common Pitfalls
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Best Practices:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use type annotations for better code readability and IDE support&lt;/li&gt;
&lt;li&gt;Leverage validators for data integrity&lt;/li&gt;
&lt;li&gt;Use frozen classes for immutable objects&lt;/li&gt;
&lt;li&gt;Take advantage of automatic method generation to reduce code duplication&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Common Pitfalls:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Forgetting to use @attr.s decorator on the class&lt;/li&gt;
&lt;li&gt;Overusing complex validators that could be separate methods&lt;/li&gt;
&lt;li&gt;Not considering the performance impact of extensive use of factory functions&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. attrs vs Other Libraries
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Library&lt;/th&gt;
&lt;th&gt;Features&lt;/th&gt;
&lt;th&gt;Performance&lt;/th&gt;
&lt;th&gt;Community&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;attrs&lt;/td&gt;
&lt;td&gt;Automatic method generation, attribute definition with types and default values, validators and converters&lt;/td&gt;
&lt;td&gt;Better performance than manual code&lt;/td&gt;
&lt;td&gt;Active community&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;pydantic&lt;/td&gt;
&lt;td&gt;Data validation and settings management, automatic method generation, attribute definition with types and default values, validators and converters&lt;/td&gt;
&lt;td&gt;Good performance&lt;/td&gt;
&lt;td&gt;Active community&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;dataclasses&lt;/td&gt;
&lt;td&gt;Built into Python 3.7+, making them more accessible&lt;/td&gt;
&lt;td&gt;Tied to the Python version&lt;/td&gt;
&lt;td&gt;Built-in Python library&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;attrs and dataclasses are faster than pydantic&lt;sup id="fnref1"&gt;1&lt;/sup&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Comparison with dataclasses:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;attrs is more feature-rich and flexible&lt;/li&gt;
&lt;li&gt;dataclasses are built into Python 3.7+, making them more accessible&lt;/li&gt;
&lt;li&gt;attrs has better performance in most cases&lt;/li&gt;
&lt;li&gt;dataclasses are tied to the Python version, while attrs as an external library can be used with any Python version.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Comparison with pydantic:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;pydantic is focused on data validation and settings management&lt;/li&gt;
&lt;li&gt;attrs is more general-purpose and integrates better with existing codebases&lt;/li&gt;
&lt;li&gt;pydantic has built-in JSON serialization, while attrs requires additional libraries&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to choose attrs:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;For complex class hierarchies with custom behaviors&lt;/li&gt;
&lt;li&gt;When you need fine-grained control over attribute definitions&lt;/li&gt;
&lt;li&gt;For projects that require Python 2 compatibility (though less relevant now)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  7. Performance and Real-world Applications
&lt;/h2&gt;

&lt;p&gt;Performance:&lt;br&gt;
attrs generally offers better performance than manually written classes or other libraries due to its optimized implementations.&lt;/p&gt;

&lt;p&gt;Real-world example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;attr&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;define&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Factory&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;typing&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;

&lt;span class="nd"&gt;@define&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Customer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Order&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Factory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@define&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;
    &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;OrderItem&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Factory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@define&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderItem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;

&lt;span class="nd"&gt;@define&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;

&lt;span class="c1"&gt;# Usage
&lt;/span&gt;&lt;span class="n"&gt;customer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Customer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Alice&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;alice@example.com&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Book&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;29.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;A great book&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;order_item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OrderItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;59.98&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;order_item&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8. Conclusion and Call to Action
&lt;/h2&gt;

&lt;p&gt;attrs is a powerful library that simplifies Python class definitions while providing robust features for data validation and manipulation. Its ability to reduce boilerplate code, improve readability, and enhance performance makes it an invaluable tool for Python developers.&lt;/p&gt;

&lt;p&gt;Community resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GitHub repository: &lt;a href="https://github.com/python-attrs/attrs" rel="noopener noreferrer"&gt;https://github.com/python-attrs/attrs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Documentation: &lt;a href="https://www.attrs.org/" rel="noopener noreferrer"&gt;https://www.attrs.org/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;PyPI page: &lt;a href="https://pypi.org/project/attrs/" rel="noopener noreferrer"&gt;https://pypi.org/project/attrs/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Try attrs in your next project and experience its benefits firsthand. Share your experiences with the community and contribute to its ongoing development. Happy coding!&lt;/p&gt;




&lt;ol&gt;

&lt;li id="fn1"&gt;
&lt;p&gt;&lt;a href="https://stefan.sofa-rockers.org/2020/05/29/attrs-dataclasses-pydantic/" rel="noopener noreferrer"&gt;https://stefan.sofa-rockers.org/2020/05/29/attrs-dataclasses-pydantic/&lt;/a&gt;&amp;nbsp;↩&lt;/p&gt;
&lt;/li&gt;

&lt;/ol&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>Production Readiness Checklist</title>
      <dc:creator>Soumendra Kumar Sahoo</dc:creator>
      <pubDate>Sun, 04 Aug 2024 09:13:58 +0000</pubDate>
      <link>https://dev.to/soumendrak/production-readiness-checklist-1io5</link>
      <guid>https://dev.to/soumendrak/production-readiness-checklist-1io5</guid>
      <description>&lt;p&gt;I have been working on multiple pojects where I have moved applications from PoC to Production.&lt;br&gt;
These are the checklists I have prepared for myself and my team to ensure we are ready for production.&lt;br&gt;
Here the checklists are in focus as the application is in Python programming language and deployed to AWS via Kubernetes.&lt;br&gt;
Not all of these are mandatory, but they are the ones I have found most useful.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Alerts &amp;amp; Metrics
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Are there alerts set up for infrastructure issues (e.g., memory or CPU usage increase, service unavailability)?&lt;/li&gt;
&lt;li&gt;[ ] Are there alerts set up for critical application-specific logic failures?&lt;/li&gt;
&lt;li&gt;[ ] Can we view historical data (past few hours/days) of infrastructure and resource usage?&lt;/li&gt;
&lt;li&gt;[ ] Is there a real-time monitoring dashboard in place?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Dashboard and SOP
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Is there an SOP document for handling alerts and known issues?&lt;/li&gt;
&lt;li&gt;[ ] Are there runbooks available for common scenarios?&lt;/li&gt;
&lt;li&gt;[ ] Is there an incident response plan in place?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. On-call mapping and cadence
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Is there an on-call person mapping for application-level issues?&lt;/li&gt;
&lt;li&gt;[ ] Is there an on-call person mapping for infrastructure-related issues?&lt;/li&gt;
&lt;li&gt;[ ] Is there a defined rotation schedule and escalation policy?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Deployment
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Has the appropriate instance type (GPU or CPU) been determined?&lt;/li&gt;
&lt;li&gt;[ ] Has the required server type been specified?&lt;/li&gt;
&lt;li&gt;[ ] Is there multi-availability zone support for failover?&lt;/li&gt;
&lt;li&gt;[ ] Is there support for multiple regions?&lt;/li&gt;
&lt;li&gt;[ ] Is auto-scaling set up (e.g., HPA, Keda) for traffic spikes?&lt;/li&gt;
&lt;li&gt;[ ] Are health checks configured for the server?&lt;/li&gt;
&lt;li&gt;[ ] Have resource limits been defined and documented?&lt;/li&gt;
&lt;li&gt;[ ] Is there a blue-green or canary deployment strategy in place?&lt;/li&gt;
&lt;li&gt;[ ] Is there a defined rollback plan and procedure?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Observability and tracing
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Is there a dashboard showing relevant metrics (e.g., request count, HTTP status codes, usage)?&lt;/li&gt;
&lt;li&gt;[ ] Can we trace a single request end-to-end for debugging purposes?&lt;/li&gt;
&lt;li&gt;[ ] Is there a log aggregation and analysis system in place?&lt;/li&gt;
&lt;li&gt;[ ] Is distributed tracing implemented?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. Load tests
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Has capacity planning been performed to determine the server's load handling capabilities?&lt;/li&gt;
&lt;li&gt;[ ] Are there defined performance benchmarks?&lt;/li&gt;
&lt;li&gt;[ ] Has stress testing been conducted?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  7. Quality
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Are there automated unit tests?&lt;/li&gt;
&lt;li&gt;[ ] Are there automated integration tests?&lt;/li&gt;
&lt;li&gt;[ ] Is static code analysis (e.g., complexity checks) performed?&lt;/li&gt;
&lt;li&gt;[ ] Is code coverage measured and at an acceptable level?&lt;/li&gt;
&lt;li&gt;[ ] Are there production sanity test cases?&lt;/li&gt;
&lt;li&gt;[ ] Is there a CI/CD pipeline in place?&lt;/li&gt;
&lt;li&gt;[ ] Are security scans and vulnerability assessments performed regularly?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8. Release
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Is Swagger/OpenAPI documentation available and up-to-date?&lt;/li&gt;
&lt;li&gt;[ ] Is there a versioning system for APIs and releases?&lt;/li&gt;
&lt;li&gt;[ ] Is there an established communication channel for scheduled maintenance?&lt;/li&gt;
&lt;li&gt;[ ] Is there a change management process?&lt;/li&gt;
&lt;li&gt;[ ] Are feature flags used for gradual rollout of new features?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  9. Disaster Recovery and Business Continuity
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Are backup and restore procedures in place and tested?&lt;/li&gt;
&lt;li&gt;[ ] Is there a data replication strategy?&lt;/li&gt;
&lt;li&gt;[ ] Have Recovery Time Objective (RTO) and Recovery Point Objective (RPO) been defined?&lt;/li&gt;
&lt;li&gt;[ ] Are regular disaster recovery drills conducted?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  10. Compliance and Security
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Is data encrypted at rest and in transit?&lt;/li&gt;
&lt;li&gt;[ ] Are access control and authentication mechanisms in place?&lt;/li&gt;
&lt;li&gt;[ ] Are regular security audits conducted?&lt;/li&gt;
&lt;li&gt;[ ] Does the application comply with relevant industry standards (e.g., GDPR, HIPAA)?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  11. Documentation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Is system architecture documentation available and up-to-date?&lt;/li&gt;
&lt;li&gt;[ ] Is API documentation complete and current?&lt;/li&gt;
&lt;li&gt;[ ] Are operational procedures documented?&lt;/li&gt;
&lt;li&gt;[ ] Is there a comprehensive troubleshooting guide?&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>devops</category>
      <category>python</category>
      <category>kubernetes</category>
      <category>aws</category>
    </item>
    <item>
      <title>@property in Python</title>
      <dc:creator>Soumendra Kumar Sahoo</dc:creator>
      <pubDate>Fri, 24 Mar 2023 09:25:11 +0000</pubDate>
      <link>https://dev.to/soumendrak/property-in-python-1naf</link>
      <guid>https://dev.to/soumendrak/property-in-python-1naf</guid>
      <description>&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Introduction&lt;br&gt;&lt;br&gt;
Sure! Here's an introduction to Python's &lt;code&gt;@property&lt;/code&gt; decorator with code snippets:&lt;/p&gt;

&lt;p&gt;In Python, a decorator is a special function that can modify other functions' behavior. You can think of decorators as a way to "wrap" one function with another. This can be useful for adding functionality to functions without changing their code.&lt;/p&gt;

&lt;p&gt;One built-in decorator in Python is &lt;code&gt;@property&lt;/code&gt;, which is used with the &lt;code&gt;property()&lt;/code&gt; function. Here's an example that shows how you can use &lt;code&gt;@property&lt;/code&gt; to define a read-only property for a class:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;

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

&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 5
&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="c1"&gt;# AttributeError: can't set attribute
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;In this example, we define a class &lt;code&gt;Circle&lt;/code&gt; with a private attribute &lt;code&gt;_radius&lt;/code&gt;. We then use the &lt;code&gt;@property&lt;/code&gt; decorator to define a method &lt;code&gt;radius()&lt;/code&gt; that returns the value of &lt;code&gt;_radius&lt;/code&gt;. When we create an instance of &lt;code&gt;Circle&lt;/code&gt;, we can access the value of &lt;code&gt;_radius&lt;/code&gt; using the &lt;code&gt;.radius&lt;/code&gt; property. However, since we haven't defined a setter method for &lt;code&gt;.radius&lt;/code&gt;, trying to set its value will result in an error.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use Cases&lt;/p&gt;

&lt;p&gt;Here's an explanation of why you should use &lt;code&gt;@property&lt;/code&gt; with example usages:&lt;/p&gt;

&lt;p&gt;Using the &lt;code&gt;@property&lt;/code&gt; decorator can be helpful in several ways when defining properties in a class. Here are some examples:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Encapsulation&lt;/strong&gt;: By using &lt;code&gt;@property&lt;/code&gt;, you can control access to an attribute by defining getter, setter, and deleter methods. This allows you to hide the implementation details of an attribute and only expose a public interface for accessing it.
&lt;/li&gt;
&lt;/ol&gt;

&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;

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

&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 5
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;In this example, we define a class &lt;code&gt;Circle&lt;/code&gt; with a private attribute &lt;code&gt;_radius&lt;/code&gt;. We then use the &lt;code&gt;@property&lt;/code&gt; decorator to define a method &lt;code&gt;radius()&lt;/code&gt; that returns the value of &lt;code&gt;_radius&lt;/code&gt;. When we create an instance of &lt;code&gt;Circle&lt;/code&gt;, we can access the value of &lt;code&gt;_radius&lt;/code&gt; using the &lt;code&gt;.radius&lt;/code&gt; property.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Validation&lt;/strong&gt;: You can use the setter method to validate the value being assigned to an attribute. For example, you can check if the value is within a specific range or meets certain conditions before assigning it.
&lt;/li&gt;
&lt;/ol&gt;

&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;

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

    &lt;span class="nd"&gt;@radius.setter&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Radius cannot be negative&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;

&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 5
&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="c1"&gt;# ValueError: Radius cannot be negative
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;In this example, we define a class &lt;code&gt;Circle&lt;/code&gt; with a private attribute &lt;code&gt;_radius&lt;/code&gt;. We then use the &lt;code&gt;@property&lt;/code&gt; decorator to define a method &lt;code&gt;radius()&lt;/code&gt; that returns the value of &lt;code&gt;_radius&lt;/code&gt;, and the &lt;code&gt;.setter&lt;/code&gt; decorator to define a method &lt;code&gt;radius()&lt;/code&gt; that sets the value of &lt;code&gt;_radius&lt;/code&gt; .&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Ease of use&lt;/strong&gt;: Using &lt;code&gt;@property&lt;/code&gt; makes it easy to define properties without manually calling the &lt;code&gt;property()&lt;/code&gt; function. This can make your code more readable and easier to understand.
&lt;/li&gt;
&lt;/ol&gt;

&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_radius&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_radius&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;set_radius&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Radius cannot be negative&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;

    &lt;span class="n"&gt;radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;property&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;get_radius&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;set_radius&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 5
&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="c1"&gt;# ValueError: Radius cannot be negative
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;In this example, we define a class &lt;code&gt;Circle&lt;/code&gt; with a private attribute &lt;code&gt;_radius&lt;/code&gt;. We then define methods &lt;code&gt;get_radius()&lt;/code&gt; and &lt;code&gt;set_radius()&lt;/code&gt; for getting and setting the value of &lt;code&gt;_radius&lt;/code&gt;. We use the &lt;code&gt;property()&lt;/code&gt; function to create a property &lt;code&gt;.radius&lt;/code&gt; that uses these methods.&lt;/p&gt;

&lt;p&gt;This code achieves the same result as the previous example but is less readable and harder to understand. Using &lt;code&gt;@property&lt;/code&gt; makes it easier to define properties more intuitively.&lt;/p&gt;

&lt;p&gt;Overall, using &lt;code&gt;@property&lt;/code&gt; can help you write cleaner and more maintainable code when defining properties in a class.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Syntax and Examples&lt;/p&gt;

&lt;p&gt;This example shows how you can use &lt;code&gt;@property&lt;/code&gt;, along with the &lt;code&gt;.setter&lt;/code&gt; and &lt;code&gt;.deleter&lt;/code&gt; decorators to define a property with getter, setter, and deleter methods:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;

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

    &lt;span class="nd"&gt;@radius.setter&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Radius cannot be negative&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;

    &lt;span class="nd"&gt;@radius.deleter&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;del&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_radius&lt;/span&gt;

&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 5
&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 10
&lt;/span&gt;&lt;span class="k"&gt;del&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;In this example, we define a class &lt;code&gt;Circle&lt;/code&gt; with a private attribute &lt;code&gt;_radius&lt;/code&gt;. We then use the &lt;code&gt;@property&lt;/code&gt; decorator to define a method &lt;code&gt;radius()&lt;/code&gt; that returns the value of &lt;code&gt;_radius&lt;/code&gt;. We also use the &lt;code&gt;.setter&lt;/code&gt; decorator to define a method &lt;code&gt;radius()&lt;/code&gt; that sets the value of &lt;code&gt;_radius&lt;/code&gt;, and the &lt;code&gt;.deleter&lt;/code&gt; decorator to define a method &lt;code&gt;radius()&lt;/code&gt; that deletes &lt;code&gt;_radius&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When we create an instance of &lt;code&gt;Circle&lt;/code&gt;, we can access and modify the value of &lt;code&gt;_radius&lt;/code&gt; using the &lt;code&gt;.radius&lt;/code&gt; property. We can also delete &lt;code&gt;_radius&lt;/code&gt; using the &lt;code&gt;del&lt;/code&gt; statement.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Key points and benefits of using &lt;code&gt;@property&lt;/code&gt;:&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* `@property` is a decorator that can be used to define properties in a class.
* It allows you to control access to an attribute by defining getter, setter, and deleter methods.
* Using `@property` can help you achieve encapsulation by hiding the implementation details of an attribute and only exposing a public interface for accessing it.
* You can use the setter method to validate the value being assigned to an attribute before assigning it.
* Using `@property` makes it easy to define properties without manually calling the `property()` function. This can make your code more readable and easier to understand.

Overall, using `@property` can help you write cleaner and more maintainable code when defining properties in a class.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;First published on &lt;a href="https://blog.soumendrak.com/property-in-python" rel="noopener noreferrer"&gt;my primary blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>python</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Usage of backward slash (\) in Python</title>
      <dc:creator>Soumendra Kumar Sahoo</dc:creator>
      <pubDate>Sat, 10 Dec 2022 05:55:53 +0000</pubDate>
      <link>https://dev.to/soumendrak/usage-of-backward-slash-in-python-3cbn</link>
      <guid>https://dev.to/soumendrak/usage-of-backward-slash-in-python-3cbn</guid>
      <description>&lt;p&gt;In Python, the backslash (\) character is used for several purposes, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To specify escape sequences, like &lt;code&gt;\n&lt;/code&gt; for a newline, &lt;code&gt;\t&lt;/code&gt; for a tab, etc.&lt;/li&gt;
&lt;li&gt;To escape special characters - the backward slash is used to escape special characters such as quotation marks and newline characters in strings. For example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# escaping special characters in a string
&lt;/span&gt;
&lt;span class="n"&gt;my_string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;This is a string with a &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt;quotation mark&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s"&gt; and a newline character &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt; in it&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To split a string into multiple lines by using the \ character at the end of each line. For example, the following code will print hello world on two lines:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# continuing a line of code
&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;This is a very long line of code that cannot fit on one line&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; \
      &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;so we are using the backward slash to continue it on the next line&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's important to note that in Python, the backslash character is used for escaping characters, and it is not the same as the forward slash (/) character, which is used for division. For example, the following code will print 5.0:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may further be interested in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://blog.soumendrak.com/usage-of-forward-slash-in-python" rel="noopener noreferrer"&gt;Usage of forward slash (/) in Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.soumendrak.com/5-usages-of-an-asterisk-in-python" rel="noopener noreferrer"&gt;5 usages of an asterisk (*) in Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.soumendrak.com/usage-of-the-underscore-in-python" rel="noopener noreferrer"&gt;Usage of the Underscore(_) in Python&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>opensource</category>
      <category>software</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Usage of forward slash (/) in Python</title>
      <dc:creator>Soumendra Kumar Sahoo</dc:creator>
      <pubDate>Tue, 06 Dec 2022 04:48:12 +0000</pubDate>
      <link>https://dev.to/soumendrak/usage-of-forward-slash-in-python-41no</link>
      <guid>https://dev.to/soumendrak/usage-of-forward-slash-in-python-41no</guid>
      <description>&lt;p&gt;In Python, the forward-slash (/) has several different uses depending on the context in which it appears. Some of the main uses of the forward slash in Python include:&lt;/p&gt;

&lt;h2&gt;
  
  
  Division
&lt;/h2&gt;

&lt;p&gt;When used between two numeric values, the forward slash performs division. &lt;br&gt;
For example, 10 / 3 evaluates to 3.3333333333333335.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="mf"&gt;3.3333333333333335&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Floor division
&lt;/h2&gt;

&lt;p&gt;When used between two numeric values, the forward slash followed by another forward slash (//) performs floor division, which rounds the result down to the nearest integer. &lt;br&gt;
For example, 10 / 3 evaluates to 3, and 10 // 3 evaluates to 3.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Paths
&lt;/h2&gt;

&lt;p&gt;In strings, the forward slash is often used as a separator in file paths or URLs. &lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;C:/Users/john/Documents/file.txt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://www.example.com/path/to/resource&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Regular expressions
&lt;/h2&gt;

&lt;p&gt;In regular expressions, the forward slash is often used to escape special characters. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;

&lt;span class="n"&gt;pattern&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\d+/\d+/\d+&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;The date is 01/01/2021&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thanks for reading, you can further check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://blog.soumendrak.com/5-usages-of-an-asterisk-in-python" rel="noopener noreferrer"&gt;5 usages of an asterisk (*) in Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.soumendrak.com/usage-of-the-underscore-in-python" rel="noopener noreferrer"&gt;Usage of the Underscore(_) in Python&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This article was first published &lt;a href="https://blog.soumendrak.com/usage-of-forward-slash-in-python" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>adonis</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Factory Design Pattern</title>
      <dc:creator>Soumendra Kumar Sahoo</dc:creator>
      <pubDate>Thu, 01 Dec 2022 12:51:33 +0000</pubDate>
      <link>https://dev.to/soumendrak/factory-design-pattern-ac2</link>
      <guid>https://dev.to/soumendrak/factory-design-pattern-ac2</guid>
      <description>&lt;p&gt;There are several design patterns that are commonly used in Python programming. Some of the most common design patterns include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Singleton: This design pattern ensures that a class has only one instance, and provides a global point of access to it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Factory: This design pattern provides a way to create objects without specifying the exact class of object that will be created.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Adapter: This design pattern allows classes with incompatible interfaces to work together by wrapping the original class and providing a new interface.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Decorator: This design pattern allows new functionality to be added to an existing object without modifying its structure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Observer: This design pattern allows objects to observe and react to changes in other objects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Strategy: This design pattern allows the behavior of an algorithm to be changed at runtime.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Template: This design pattern defines the skeleton of an algorithm, allowing subclasses to provide specific implementation details.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Command: This design pattern allows you to encapsulate a request as an object, separating the request from the object that executes it.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These are just a few examples of the many design patterns that are available in Python. There are many more design patterns that can be used to solve common programming problems in Python, and choosing the right design pattern for a given situation can help to make your code more maintainable and scalable.&lt;/p&gt;

&lt;p&gt;The factory design pattern is a popular object-oriented programming technique in Python. It is used to create new objects, hiding the complexity of object creation from the user. This allows for a more flexible and modular approach to object creation, as well as promoting code reuse.&lt;/p&gt;

&lt;p&gt;The factory design pattern works by defining a factory class that is responsible for creating objects. The factory class has a method, typically called &lt;code&gt;create()&lt;/code&gt;, that takes in the necessary parameters for creating an object and returns the newly created object. The user of the factory class does not need to know the details of how the object is created, they just call the &lt;code&gt;create()&lt;/code&gt; method and get back the new object.&lt;/p&gt;

&lt;p&gt;One of the key benefits of using the factory design pattern is that it allows for the creation of objects without specifying their exact class. This means that the factory can be used to create different types of objects, depending on the input provided to the &lt;code&gt;create()&lt;/code&gt; method. This is useful when working with systems that may have different implementations of the same concept, such as different types of vehicles in a transportation application.&lt;/p&gt;

&lt;p&gt;Another benefit of the factory design pattern is that it promotes code reuse. Since the factory class abstracts away the details of object creation, it can be used to create objects of different types without duplicating code. This means that the code for creating objects can be centralized in the factory class, making it easier to maintain and update.&lt;/p&gt;

&lt;p&gt;To illustrate how the factory design pattern works in Python, let's consider a simple example. Suppose we have a &lt;code&gt;Vehicle&lt;/code&gt; class that represents different types of vehicles, such as cars and trucks. We can use the factory design pattern to create instances of the &lt;code&gt;Vehicle&lt;/code&gt; class by defining a &lt;code&gt;VehicleFactory&lt;/code&gt; class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;type&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;VehicleFactory&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nd"&gt;@staticmethod&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;car&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;truck&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Truck&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Vehicle&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;super&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;car&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Truck&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Vehicle&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;super&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;truck&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# create a car using the factory
&lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;VehicleFactory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;car&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Honda Civic&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2021&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# create a truck using the factory
&lt;/span&gt;&lt;span class="n"&gt;truck&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;VehicleFactory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;truck&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Ford F-150&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2020&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;VehicleFactory&lt;/code&gt; class has a &lt;code&gt;create()&lt;/code&gt; method that takes in the &lt;code&gt;type&lt;/code&gt;, &lt;code&gt;model&lt;/code&gt;, and &lt;code&gt;year&lt;/code&gt; of the vehicle to be created. Depending on the &lt;code&gt;type&lt;/code&gt; provided, the &lt;code&gt;create()&lt;/code&gt; method creates and returns an instance of either the &lt;code&gt;Car&lt;/code&gt; or &lt;code&gt;Truck&lt;/code&gt; class, which inherit from the &lt;code&gt;Vehicle&lt;/code&gt; class. This allows us to create different types of vehicles without specifying their exact class, and without duplicating code for creating objects.&lt;/p&gt;

&lt;p&gt;In conclusion, the factory design pattern is a useful technique in Python programming for creating objects in a flexible and modular way. It can help you to create a more scalable and maintainable codebase by abstracting away the details of object creation and allowing for a more flexible approach to object creation.&lt;/p&gt;

&lt;p&gt;Disclaimer: The above text is generated by the &lt;a href="https://chat.openai.com/chat" rel="noopener noreferrer"&gt;chat GPT&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow me on Twitter &lt;a href="https://www.twitter.com/soumendrak_" rel="noopener noreferrer"&gt;soumendrak&lt;/a&gt; for more such posts.&lt;/p&gt;

&lt;p&gt;This post was first published on: &lt;a href="https://blog.soumendrak.com/factory-design-pattern" rel="noopener noreferrer"&gt;https://blog.soumendrak.com/factory-design-pattern&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
    </item>
    <item>
      <title>Learn Python Programming</title>
      <dc:creator>Soumendra Kumar Sahoo</dc:creator>
      <pubDate>Tue, 08 Nov 2022 09:46:10 +0000</pubDate>
      <link>https://dev.to/soumendrak/learn-python-programming-3l0g</link>
      <guid>https://dev.to/soumendrak/learn-python-programming-3l0g</guid>
      <description>&lt;p&gt;Python has been around since the 90s and an enormous amount of content is there to learn Python. While this is good for any language this creates information overload and decision paralysis in learning in a structured manner.&lt;br&gt;
&lt;em&gt;Note: There is no official certification for Python programming&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here is a list of materials to help beginners in Python programming:&lt;/p&gt;

&lt;h2&gt;
  
  
  Interactive way
&lt;/h2&gt;

&lt;p&gt;Here you can try on coding on the browser itself without installing anything.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.learnpython.org/" rel="noopener noreferrer"&gt;https://www.learnpython.org/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.codecademy.com/learn/learn-python-3" rel="noopener noreferrer"&gt;CodeAcademy&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Books
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://automatetheboringstuff.com/2e/chapter0/" rel="noopener noreferrer"&gt;Automate the Boring Stuff with Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learnpythonthehardway.org/book/" rel="noopener noreferrer"&gt;Learn Python The Hard Way&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diveinto.org/python3/table-of-contents.html" rel="noopener noreferrer"&gt;Dive Into Python 3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://greenteapress.com/thinkpython2/html/thinkpython2002.html" rel="noopener noreferrer"&gt;Think Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.python-guide.org/#the-hitchhiker-s-guide-to-python" rel="noopener noreferrer"&gt;The Hitchhiker’s Guide to Python!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;A more extensive list of books can be found at &lt;a href="https://github.com/junnplus/awesome-python-books" rel="noopener noreferrer"&gt;awesome python books&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Courses
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.coursera.org/learn/python" rel="noopener noreferrer"&gt;Programming for Everybody&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Videos
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=_uQrJ0TkZlc" rel="noopener noreferrer"&gt;Programming with Mosh&lt;/a&gt; : 6hr long Python course&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/c/Coreyms/playlists" rel="noopener noreferrer"&gt;Corey Schafer&lt;/a&gt; : Python short tutorials&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/c/Intellipaat/search?query=python" rel="noopener noreferrer"&gt;Intellipaat&lt;/a&gt;: Python long tutorials in Hindi and all&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=8ext9G7xspg" rel="noopener noreferrer"&gt;freeCodeCamp&lt;/a&gt;: 12 beginner Python projects&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/c/NeuralNine/playlists" rel="noopener noreferrer"&gt;NeuralNine&lt;/a&gt;: Python beginner, intermediate and advanced playlists&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/c/realpython" rel="noopener noreferrer"&gt;RealPython&lt;/a&gt;: Python tips and tricks&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/c/sentdex/featured" rel="noopener noreferrer"&gt;sentdex&lt;/a&gt;: Python beginner to advanced tutorials.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=mDKM-JtUhhc" rel="noopener noreferrer"&gt;clearCode&lt;/a&gt;: Learn Python by making games&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;For more search awesome Youtube visit &lt;a href="https://github.com/JoseDeFreitas/awesome-youtubers" rel="noopener noreferrer"&gt;awesome-youtubers&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tutorials
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/practical-tutorials/project-based-learning#python" rel="noopener noreferrer"&gt;Project-based learning&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Much more can be found at &lt;a href="https://github.com/huangsam/ultimate-python" rel="noopener noreferrer"&gt;Ultimate Python&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Newsletters
&lt;/h2&gt;

&lt;p&gt;Newsletters usually published weekly keep you up to date on the latest developments in the Python world.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://python.libhunt.com/newsletter" rel="noopener noreferrer"&gt;Awesome Python Newsletter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://pycoders.com/" rel="noopener noreferrer"&gt;Pycoder's Weekly&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://realpython.com/python-tricks/" rel="noopener noreferrer"&gt;Python Tricks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.pythonweekly.com/" rel="noopener noreferrer"&gt;Python Weekly&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Podcasts
&lt;/h2&gt;

&lt;p&gt;If you are a podcast person, here is a list of podcasts related to Python.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pythonbytes.fm" rel="noopener noreferrer"&gt;Python Bytes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://talkpython.fm/" rel="noopener noreferrer"&gt;Talk Python To Me&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://realpython.com/podcasts/rpp/" rel="noopener noreferrer"&gt;The Real Python Podcast&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This list will be updated from time to time whenever required.&lt;br&gt;
Follow &lt;a href="https://www.twitter.com/soumendrak_" rel="noopener noreferrer"&gt;soumendrak_&lt;/a&gt; for more such contents.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Aggregate Code timing in Python</title>
      <dc:creator>Soumendra Kumar Sahoo</dc:creator>
      <pubDate>Wed, 20 Jul 2022 03:53:17 +0000</pubDate>
      <link>https://dev.to/soumendrak/aggregate-code-timing-in-python-fj4</link>
      <guid>https://dev.to/soumendrak/aggregate-code-timing-in-python-fj4</guid>
      <description>&lt;p&gt;There are many ways to get how much time a function takes in Python. Here is an easy decorator implementation to check how much time a function takes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;functools&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;wraps&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;timeit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nd"&gt;@wraps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;timeit_wrapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;start_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;perf_counter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;end_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;perf_counter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;total_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;end_time&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start_time&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Function &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="si"&gt;}{&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; took &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;total_time&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; seconds&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;timeit_wrapper&lt;/span&gt;

&lt;span class="nd"&gt;@timeit&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;my_func&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="c1"&gt;# do stuff
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This decorator can be used by decorating a function to get the time spent.&lt;br&gt;
What if you want to aggregate this timing data in a timeframe, like how many times this function has been called, and what the maximum time is taken, for that, we need to use a library called &lt;a href="https://github.com/realpython/codetiming" rel="noopener noreferrer"&gt;codetiming&lt;/a&gt;.&lt;br&gt;
Here is a sample use case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# pip install codetiming
# pip install humanfriendly
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;codetiming&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Timer&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;humanfriendly&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;format_timespan&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;loguru&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;logger&lt;/span&gt;


&lt;span class="nd"&gt;@Timer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;my_func&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;secs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;my_func elapsed time: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;format_timespan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;my_func&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_aggregated_timings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cls&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;timed_function&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;my_func&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;timed_function&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; count: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Timer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timed_function&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;total: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Timer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timed_function&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;max: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Timer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timed_function&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;min: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Timer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timed_function&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mean: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Timer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timed_function&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;standard deviation: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Timer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stdev&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timed_function&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;median: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Timer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;median&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timed_function&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;Timer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clear&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;  &lt;span class="c1"&gt;# clears all the timer data
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will find the aggregated time spent by &lt;code&gt;my_func&lt;/code&gt;. Let's go through what each one of them will log:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;count&lt;/em&gt;: Number of times the function has been called.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;total&lt;/em&gt;: Sum of all the seconds elapsed in the function&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;max&lt;/em&gt;: Maximum time spent on a single flow&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;min&lt;/em&gt;: Minimum time spent on a single flow&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;mean&lt;/em&gt;: The average of all the time spent on that function&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;median&lt;/em&gt;: The median of all elapsed time&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;stdev&lt;/em&gt;: The standard deviation of all elapsed time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At the end &lt;code&gt;Timer.timers.clear()&lt;/code&gt; clears the data stored In memory and starts from fresh for the next iteration.&lt;/p&gt;

&lt;p&gt;Do you want to use an in-memory LRU cache with a timeout, you may check out this article:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.soumendrak.com/cache-heavy-computation-functions-with-a-timeout-value" rel="noopener noreferrer"&gt;Cache functions with timeout&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I post on Python programming on my Twitter handle, you can follow me &lt;a href="https://www.twitter.com/soumendrak_" rel="noopener noreferrer"&gt;@soumendrak_&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Originally posted at: &lt;a href="https://blog.soumendrak.com/aggregate-code-timing-in-python" rel="noopener noreferrer"&gt;my blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>performance</category>
      <category>programming</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Top Software Engineering Blogs</title>
      <dc:creator>Soumendra Kumar Sahoo</dc:creator>
      <pubDate>Sun, 17 Jul 2022 05:58:00 +0000</pubDate>
      <link>https://dev.to/soumendrak/software-engineering-blogs-2dn1</link>
      <guid>https://dev.to/soumendrak/software-engineering-blogs-2dn1</guid>
      <description>&lt;p&gt;This is a growing collection of blogs by software companies that you can read to get Engineering practices and Software Architecture ideas.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://medium.com/airbnb-engineering" rel="noopener noreferrer"&gt;Airbnb&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.developer.atlassian.com/" rel="noopener noreferrer"&gt;Altassian&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.asana.com/category/eng/" rel="noopener noreferrer"&gt;Asana&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://engineering.bittorrent.com/" rel="noopener noreferrer"&gt;BitTorrent&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://canvatechblog.com/" rel="noopener noreferrer"&gt;Canva&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.cloudera.com/category/technical/" rel="noopener noreferrer"&gt;Cloudera&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.cloudflare.com/tag/engineering/" rel="noopener noreferrer"&gt;CLoudflare&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://engineering.cred.club/" rel="noopener noreferrer"&gt;Cred&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.docker.com/blog/category/engineering/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dropbox.tech/" rel="noopener noreferrer"&gt;Dropbox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.dunzo.com/tagged/engineering" rel="noopener noreferrer"&gt;Dunzo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tech.ebayinc.com/engineering/" rel="noopener noreferrer"&gt;eBay&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.blog/category/engineering/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/groupon-eng" rel="noopener noreferrer"&gt;Groupon&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://engineering.hackerearth.com/" rel="noopener noreferrer"&gt;Hackerearth&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://instagram-engineering.com/" rel="noopener noreferrer"&gt;Instagram&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.intercom.com/blog/engineering/" rel="noopener noreferrer"&gt;Intercom&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://engineering.linkedin.com/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://eng.lyft.com/tagged/mobile" rel="noopener noreferrer"&gt;Lyft&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://engineering.fb.com/" rel="noopener noreferrer"&gt;Meta&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mixpanel.com/blog/" rel="noopener noreferrer"&gt;MixPanel&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://netflixtechblog.com/" rel="noopener noreferrer"&gt;Netflix&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://engblog.nextdoor.com/" rel="noopener noreferrer"&gt;Nextdoor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/paypal-tech" rel="noopener noreferrer"&gt;Paypal&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/practo-engineering" rel="noopener noreferrer"&gt;Practo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://quoraengineering.quora.com/" rel="noopener noreferrer"&gt;Quora&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.redditinc.com/blog" rel="noopener noreferrer"&gt;Reddit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.salesforce.com/blogs" rel="noopener noreferrer"&gt;Salesforce&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://shopify.engineering/" rel="noopener noreferrer"&gt;Shopify&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://slack.engineering/" rel="noopener noreferrer"&gt;Slack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.soundcloud.com/blog/" rel="noopener noreferrer"&gt;Soundcloud&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://engineering.atspotify.com/" rel="noopener noreferrer"&gt;Spotify&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stripe.com/blog/engineering" rel="noopener noreferrer"&gt;Stripe&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bytes.swiggy.com/" rel="noopener noreferrer"&gt;Swiggy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/thumbtack-engineering" rel="noopener noreferrer"&gt;Thumbstack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://yahooeng.tumblr.com/" rel="noopener noreferrer"&gt;Tumblr&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.twitter.com/engineering/en_us/topics/insights" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://eng.uber.com/" rel="noopener noreferrer"&gt;Uber&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://engineeringblog.yelp.com/" rel="noopener noreferrer"&gt;Yelp&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://zerodha.tech/" rel="noopener noreferrer"&gt;Zerodha&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.zomato.com/blog/category/technology" rel="noopener noreferrer"&gt;Zomato&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/zoom-developer-blog" rel="noopener noreferrer"&gt;Zoom&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can download this &lt;a href="https://drive.google.com/file/d/1br6haCJETLhMLRpIQZ3RCbB0qAOLea-V/view?usp=sharing" rel="noopener noreferrer"&gt;Bookmarks file&lt;/a&gt; and import it into your browser.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Python vs Golang vs Rust</title>
      <dc:creator>Soumendra Kumar Sahoo</dc:creator>
      <pubDate>Tue, 17 May 2022 07:23:42 +0000</pubDate>
      <link>https://dev.to/soumendrak/python-vs-golang-vs-rust-fh6</link>
      <guid>https://dev.to/soumendrak/python-vs-golang-vs-rust-fh6</guid>
      <description>&lt;h2&gt;
  
  
  Test scenario
&lt;/h2&gt;

&lt;p&gt;I have taken the &lt;a href="https://leetcode.com/problems/two-sum/" rel="noopener noreferrer"&gt;Two sum problem&lt;/a&gt; from Leetcode.&lt;/p&gt;

&lt;p&gt;The problem statement:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.&lt;/p&gt;

&lt;p&gt;You may assume that each input would have exactly one solution, and you may not use the same element twice.&lt;/p&gt;

&lt;p&gt;You can return the answer in any order. &lt;/p&gt;

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

&lt;p&gt;Input: nums = [2,7,11,15], target = 9&lt;br&gt;
Output: [0,1]&lt;br&gt;
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].&lt;/p&gt;

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

&lt;p&gt;Input: nums = [3,2,4], target = 6&lt;br&gt;
Output: [1,2]&lt;/p&gt;

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

&lt;p&gt;Input: nums = [3,3], target = 6&lt;br&gt;
Output: [0,1]&lt;/p&gt;

&lt;p&gt;Constraints:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2 &amp;lt;= nums.length &amp;lt;= 104
-109 &amp;lt;= nums[i] &amp;lt;= 109
-109 &amp;lt;= target &amp;lt;= 109
Only one valid answer exists.
&lt;/code&gt;&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;I have used a hash map to solve this problem across all three languages.&lt;/p&gt;

&lt;h3&gt;
  
  
  Python
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;twoSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="n"&gt;hash_table&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="n"&gt;target_num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;hash_table&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hash_table&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;hash_table&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;target_num&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Python stats
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Run time: &lt;strong&gt;40ms&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Memory usage: &lt;strong&gt;14.5 MB&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Golang
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;twoSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;hashMap&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;found&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;hashMap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]];&lt;/span&gt; &lt;span class="n"&gt;found&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;ans&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hashMap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]]}&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ans&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;hashMap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Golang stats
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Run time: &lt;strong&gt;4ms&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Memory usage: &lt;strong&gt;4.3 MB&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Rust
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;collections&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;HashMap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;Solution&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;two_sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;hash_table&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;HashMap&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="nf"&gt;.len&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// println!("Processing number: {}", nums[i]);&lt;/span&gt;
        &lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="n"&gt;hash_table&lt;/span&gt;&lt;span class="nf"&gt;.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]){&lt;/span&gt;
            &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nd"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="nb"&gt;None&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;hash_table&lt;/span&gt;&lt;span class="nf"&gt;.insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nd"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Rust stats
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Run time: &lt;strong&gt;2ms&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Memory usage: &lt;strong&gt;2.2 MB&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;As per the results, Rust took the least memory and was the fastest of all three.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more such insights follow me on &lt;a href="https://twitter.com/soumendrak_" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;.&lt;br&gt;
Original post: &lt;a href="https://blog.soumendrak.com/python-vs-golang-vs-rust" rel="noopener noreferrer"&gt;Hashnode&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>go</category>
      <category>rust</category>
      <category>programming</category>
    </item>
    <item>
      <title>When to stop code refactoring</title>
      <dc:creator>Soumendra Kumar Sahoo</dc:creator>
      <pubDate>Sun, 17 Jan 2021 13:32:56 +0000</pubDate>
      <link>https://dev.to/soumendrak/when-to-stop-code-refactoring-4p72</link>
      <guid>https://dev.to/soumendrak/when-to-stop-code-refactoring-4p72</guid>
      <description>&lt;ul&gt;
&lt;li&gt;Taking too much time to refactor, which is blocking other dependent applications and priority tasks.&lt;/li&gt;
&lt;li&gt;For developers CR is like a drug, a developer can refactor can keep on refactoring a complex codebase for ages. If CR is limited to no ROI (Return On Investment) the activity needs to be stopped.&lt;/li&gt;
&lt;li&gt;Refactoring is not same as redesigning the code. It is easier to start the coding from scratch than to refactor your somebody else's or your own code. This needs to be learned before CR starts.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>coderefactoring</category>
    </item>
  </channel>
</rss>
