<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Somenath Mukhopadhyay on Medium]]></title>
        <description><![CDATA[Stories by Somenath Mukhopadhyay on Medium]]></description>
        <link>https://medium.com/@som.mukhopadhyay?source=rss-376c0cef2bf7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Cb-Z7LlP1hJLwGjj0yNjLg.png</url>
            <title>Stories by Somenath Mukhopadhyay on Medium</title>
            <link>https://medium.com/@som.mukhopadhyay?source=rss-376c0cef2bf7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 17:18:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@som.mukhopadhyay/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The reverse osmosis — the Factory Design Pattern written and executed using C++ and AngelScript…]]></title>
            <link>https://medium.com/@som.mukhopadhyay/the-reverse-osmosis-the-factory-design-pattern-written-and-executed-using-c-and-angelscript-47c1faf5947c?source=rss-376c0cef2bf7------2</link>
            <guid isPermaLink="false">https://medium.com/p/47c1faf5947c</guid>
            <dc:creator><![CDATA[Somenath Mukhopadhyay]]></dc:creator>
            <pubDate>Wed, 28 May 2025 07:47:52 GMT</pubDate>
            <atom:updated>2025-05-28T10:44:29.138Z</atom:updated>
            <content:encoded><![CDATA[<h3>The reverse osmosis — the Factory Design Pattern written and executed using C++ and AngelScript…</h3><p>I had always believed that knowledge flowed in one direction — from the old to the young, from teacher to student, from father to son. And for most of Ridit’s childhood, that seemed true. I had introduced him to Java, C++, even helped him debug his first Python script. To me, guiding my son through the world of code was like watching seeds grow into a tree.</p><p>But trees have roots. And sometimes, the water flows up.</p><p>One sultry afternoon, I sat at my desk, thinking about a simple script engine especially made for C++. I have already tried with Python.Boost and SWIG. But I wanted to get something which is especially made for C++.</p><p>“I wish I could just write the logic in a script file and have the engine read it on the fly,” I muttered.</p><p>Ridit, my son, now in class IX, overheard me while lounging nearby with his laptop. He casually said, “Why don’t you try AngelScript?”</p><p>I looked up. “What’s that?”</p><p>“It’s a scripting language for games and simulations. Super fast, safe, and looks almost like C++. I used it to modify that open-source shooter I play — remember the one with voxel maps?”</p><p>I was intrigued but skeptical. “Never heard of it. You sure it can interface with my C++ code cleanly?”</p><p>Ridit opened his laptop and pulled up a project. “Here, look. You register your C++ objects like this, and then scripts can call them directly. No weird glue code. It’s pretty smart.”</p><p>I leaned in, stunned at how elegant the integration looked. There it was — my solution, sitting quietly in my son’s world this whole time.</p><p>By midnight, I had AngelScript embedded. My singleton Factory class was being called from a .as file, creating Biscuit and Chocolate objects like magic. All without a single recompile.</p><p>As we sat there, I finally spoke, eyes twinkling:</p><p>“You know, reverse osmosis usually means filtering the purest water against pressure. Today, I think the wisdom flowed backward — from son to father, against tradition — but damn, was it pure.”</p><p>Ridit grinned. “Guess I’m your tech support now.”</p><p>From that day, whenever I hit a wall, I’d first ask myself:</p><p>“What would my son Ridit do?”</p><p>So…. here we go…</p><p>The source code of the Factory Design Pattern in C++ and AngelScript…</p><pre>/*<br><br> * Factory.h<br><br> *<br><br> *  Created on: Mar 10, 2021<br><br> *      Author: som<br><br> */<br><br><br><br>#ifndef FACTORY_H_<br><br>#define FACTORY_H_<br><br><br><br>#include &lt;iostream&gt;<br><br>#include &lt;string&gt;<br><br><br><br>#include &quot;Biscuit.h&quot;<br><br>#include &quot;Chocolate.h&quot;<br><br><br><br>using namespace std;<br><br><br><br>class Factory{<br><br>public:<br><br> static Factory* instance;<br><br> static Factory* getInstance();<br><br><br><br> Food* makeFood(const string&amp; type);<br><br><br><br>private:<br><br> Factory(){}<br><br><br><br> // Delete copy constructor &amp; assignment operator (Singleton pattern)<br><br> Factory(const Factory&amp;) = delete;<br><br> Factory&amp; operator=(const Factory&amp;) = delete;<br><br>};<br><br>//Factory* Factory:: instance =  NULL;<br><br>#endif /* FACTORY_H_ */<br><br><br>/*<br><br> * Factory.cpp<br><br> *<br><br> *  Created on: Jan 30, 2025<br><br> *      Author: som<br><br> */<br><br>#include &quot;Factory.h&quot;<br><br><br><br>Factory* Factory::instance = NULL;<br><br><br><br>Factory* Factory:: getInstance(){<br><br>  if(Factory::instance == NULL){<br><br>   Factory::instance = new Factory();<br><br>  }<br><br>  return Factory::instance;<br><br> }<br><br><br><br>Food* Factory::makeFood(const string&amp; type){<br><br>  if(type.compare(&quot;bi&quot;) == 0){<br><br>   return new Biscuit();<br><br>  }<br><br>  if(type.compare(&quot;ch&quot;) == 0){<br><br>   return new Chocolate();<br><br>  }<br><br><br>  std::cerr &lt;&lt; &quot;Unknown food type: &quot; &lt;&lt; type &lt;&lt; std::endl;<br><br>  return nullptr;<br><br> }<br><br>/*<br><br> * Food.h<br><br> *<br><br> *  Created on: Mar 10, 2021<br><br> *      Author: som<br><br> */<br><br><br><br>#ifndef FOOD_H_<br><br>#define FOOD_H_<br><br>#include &lt;string&gt;<br><br>using namespace std;<br><br>class Food {<br><br>public:<br><br> virtual string getName() = 0;<br><br> virtual ~Food(){<br><br> }<br><br>};<br><br>#endif /* FOOD_H_ */<br><br>/*<br><br> * Biscuit.h<br><br> *<br><br> *  Created on: Mar 10, 2021<br><br> *      Author: som<br><br> */<br><br>#ifndef BISCUIT_H_<br><br>#define BISCUIT_H_<br><br>#include &quot;Food.h&quot;<br><br><br>class Biscuit: public Food {<br><br>public:<br><br> Biscuit();<br><br> string getName();<br><br> ~Biscuit();<br><br>};<br><br>#endif /* BISCUIT_H_ */<br><br>/*<br><br> * Biscuit.cpp<br><br> *<br><br> *  Created on: Mar 10, 2021<br><br> *      Author: som<br><br> */<br><br>#include &lt;iostream&gt;<br><br>#include &quot;Biscuit.h&quot;<br><br>using namespace std;<br><br><br>Biscuit::Biscuit() {<br><br> // TODO Auto-generated constructor stub<br><br> cout&lt;&lt;&quot;Biscuit is made...&quot;&lt;&lt;endl;<br><br>}<br><br>Biscuit::~Biscuit(){}<br><br><br>string Biscuit::getName(){<br><br> return &quot;It&#39;s a Biscuit&quot;;<br><br>}<br><br><br>/*<br><br> * Chocolate.h<br><br> *<br><br> *  Created on: Mar 10, 2021<br><br> *      Author: som<br><br> */<br><br><br><br>#ifndef CHOCOLATE_H_<br><br>#define CHOCOLATE_H_<br><br><br>#include &lt;iostream&gt;<br><br>#include &quot;Food.h&quot;<br><br><br>class Chocolate: public Food {<br><br>public:<br><br> Chocolate();<br><br> virtual ~Chocolate();<br><br> string getName();<br><br>};<br><br>#endif /* CHOCOLATE_H_ */<br><br>/*<br><br> * Chocolate.cpp<br><br> *<br><br> *  Created on: Mar 10, 2021<br><br> *      Author: som<br><br> */<br><br><br>#include &quot;Chocolate.h&quot;<br><br>Chocolate::Chocolate() {<br><br> // TODO Auto-generated constructor stub<br><br> cout&lt;&lt;&quot;Chocolate is made...&quot;&lt;&lt;endl;<br><br>}<br><br>Chocolate::~Chocolate() {<br><br> // TODO Auto-generated destructor stub<br><br>}<br><br>string Chocolate::getName(){<br><br> return &quot;It&#39;s a Chocolate&quot;;<br><br>}<br><br><br>//Test.as<br><br><br>void main() {<br><br>    Factory@ factory = getFactory();<br><br>    if (factory is null) {<br><br>        print(&quot;Factory is null!&quot;);<br><br>        return;<br><br>    }<br><br>    Food@ item1 = factory.makeFood(&quot;ch&quot;);<br><br>    if (item1 is null) {<br><br>        print(&quot;item1 is null!&quot;);<br><br>    } else {<br><br>        print(item1.getName());<br><br>    }<br><br>    Food@ item2 = factory.makeFood(&quot;bi&quot;);<br><br>    if (item2 is null) {<br><br>        print(&quot;item2 is null!&quot;);<br><br>    } else {<br><br>        print(item2.getName());<br><br>    }<br><br>}<br><br><br>//============================================================================<br><br>// Name        : FactoryPattern.cpp<br><br>// Author      : Som<br><br>// Version     :<br><br>// Copyright   : som-itsolutions<br><br>// Description : Hello World in C++, Ansi-style<br><br>//============================================================================<br><br><br>#include &lt;iostream&gt;<br><br>#include &lt;angelscript.h&gt;<br><br>#include &lt;scriptstdstring.h&gt;<br><br>#include &lt;scriptbuilder.h&gt;<br><br><br>#include &quot;Factory.h&quot;<br><br>using namespace std;<br><br>void print(const std::string &amp;msg) {<br><br>    std::cout &lt;&lt; msg &lt;&lt; std::endl;<br><br>}<br><br>int RegisterWithAngelScript(asIScriptEngine* engine) {<br><br>    // Register std::string<br><br>    //RegisterStdString(engine);<br><br>    // Register base class<br><br>    int r;<br><br>    RegisterStdString(engine);<br><br>    r = engine-&gt;RegisterGlobalFunction(&quot;void print(const string &amp;in)&quot;, asFUNCTION(print), asCALL_CDECL);<br><br>    if (r &lt; 0) { std::cerr &lt;&lt; &quot;Failed to register print()\n&quot;; return -1; }<br><br><br>    r = engine-&gt;RegisterObjectType(&quot;Food&quot;, 0, asOBJ_REF | asOBJ_NOCOUNT);<br><br>    if (r &lt; 0) { std::cerr &lt;&lt; &quot;Failed to register Food\n&quot;; return -1; }<br><br>    engine-&gt;RegisterObjectMethod(&quot;Food&quot;, &quot;string getName()&quot;, asMETHOD(Food, getName), asCALL_THISCALL);<br><br>    // Register Factory<br><br>    engine-&gt;RegisterObjectType(&quot;Factory&quot;, 0, asOBJ_REF | asOBJ_NOCOUNT);<br><br>    engine-&gt;RegisterGlobalFunction(&quot;Factory@ getFactory()&quot;, asFUNCTION(Factory::getInstance), asCALL_CDECL);<br><br>    engine-&gt;RegisterObjectMethod(&quot;Factory&quot;, &quot;Food@ makeFood(const string &amp;in)&quot;, asMETHOD(Factory, makeFood), asCALL_THISCALL);<br><br><br>    return 0;<br><br>}<br><br><br>int main() {<br><br> //int r;<br>    asIScriptEngine* engine = asCreateScriptEngine();<br><br>    if (!engine) {<br><br>        std::cerr &lt;&lt; &quot;Failed to create script engine&quot; &lt;&lt; std::endl;<br><br>        return -1;<br><br>    }<br><br>    //RegisterStdString(engine);<br><br>    int ret = RegisterWithAngelScript(engine);<br><br><br><br>    if (ret &lt;0 ){<br><br>     std::cerr &lt;&lt; &quot;Failed to register&quot; &lt;&lt; std::endl;<br><br>     return -1;<br><br>    }<br><br><br><br>    CScriptBuilder builder;<br><br>    builder.StartNewModule(engine, &quot;MyModule&quot;);<br><br>    builder.AddSectionFromFile(&quot;src/test.as&quot;);<br><br>    int retValofBuilder = builder.BuildModule();<br><br><br><br>    if (retValofBuilder &lt; 0) {<br><br>        std::cerr &lt;&lt; &quot;Script build failed!&quot; &lt;&lt; std::endl;<br><br>        return -1;<br><br>    }<br><br>    asIScriptModule *mod = engine-&gt;GetModule(&quot;MyModule&quot;);<br><br>    asIScriptFunction *func = mod-&gt;GetFunctionByDecl(&quot;void main()&quot;);<br><br>    asIScriptContext *ctx = engine-&gt;CreateContext();<br><br>    ctx-&gt;Prepare(func);<br><br>    int r = ctx-&gt;Execute();<br><br>    if (r != asEXECUTION_FINISHED) {<br><br>        if (r == asEXECUTION_EXCEPTION) {<br><br>            std::cerr &lt;&lt; &quot;⚠️ Script Exception: &quot; &lt;&lt; ctx-&gt;GetExceptionString() &lt;&lt; std::endl;<br><br>            const asIScriptFunction *func = ctx-&gt;GetExceptionFunction();<br><br>            std::cerr &lt;&lt; &quot;⚙️ Function: &quot; &lt;&lt; func-&gt;GetDeclaration() &lt;&lt; std::endl;<br><br>            std::cerr &lt;&lt; &quot;📍 Line: &quot; &lt;&lt; ctx-&gt;GetExceptionLineNumber() &lt;&lt; std::endl;<br><br>        } else if (r == asEXECUTION_ABORTED) {<br><br>            std::cerr &lt;&lt; &quot;❌ Script was aborted.&quot; &lt;&lt; std::endl;<br><br>        } else if (r == asEXECUTION_SUSPENDED) {<br><br>            std::cerr &lt;&lt; &quot;⏸ Script was suspended.&quot; &lt;&lt; std::endl;<br><br>        } else {<br><br>            std::cerr &lt;&lt; &quot;❌ Script execution failed with code: &quot; &lt;&lt; r &lt;&lt; std::endl;<br><br>        }<br><br>    }<br><br>    ctx-&gt;Release();<br><br>    engine-&gt;ShutDownAndRelease();<br><br>    return 0;<br><br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47c1faf5947c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Do you want your python code to access C/C++ code? use SWIG…]]></title>
            <link>https://medium.com/@som.mukhopadhyay/do-you-want-your-python-code-to-access-c-c-code-use-swig-bc9728606f95?source=rss-376c0cef2bf7------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc9728606f95</guid>
            <category><![CDATA[swig]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Somenath Mukhopadhyay]]></dc:creator>
            <pubDate>Thu, 17 Oct 2024 04:28:28 GMT</pubDate>
            <atom:updated>2024-10-17T04:28:28.340Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/85/0*2KtVfm5dCGGrIU1N.png" /></figure><p>SWIG (Simplifies Wrapper and Interface Generator) is an interface compiler that connects programs written in C and C++ with scripting languages such as Perl, Python, Ruby, and Tcl. It works by taking the declarations found in C/C++ header files and using them to generate the wrapper code that scripting languages need to access the underlying C/C++ code.</p><p>Using SWIG, you can replace the main() function of a C/C++ program with a scripting interpreter from which you can control the application. This adds quite a lot of flexibility and makes the program “programmable.”</p><p>SWIG allows C/C++ programs to be placed in a scripting environment that can be used for testing and debugging. For example, you might test a library with a collection of scripts or use the scripting interpreter as an interactive debugger.</p><p>With SWIG, different C/C++ programs can be turned into scripting language extension modules. These modules can then be combined together to create new and interesting applications.</p><p>SWIG is sometimes compared to interface definition language (IDL) compilers such as those you find with systems such as CORBA and COM. Although there are a few similarities, the whole point of SWIG is to make it so you don’t have to add an extra layer of IDL specifications to your application.</p><p>SWIG requires little, if any, modifications to existing code. For the most part, it encourages you to keep a clean separation between C/C++ and its scripting interface.</p><p>The primary audience of SWIG is C/C++ programmers who want to add a scripting language component to their applications.</p><p>So… here we go…</p><h3>My experimentation with SWIG…</h3><h3>Step I. MyClass.h</h3><pre>#ifndef MYCLASS_H<br>#define MYCLASS_H<br><br>class MyClass {<br>public:<br>    MyClass();<br>    ~MyClass();<br>    void set_value(int val);<br>    int get_value() const;<br><br>private:<br>    int value;<br>};<br><br>#endif</pre><h3>Step II</h3><h3>MyClass.cpp</h3><pre>#include &quot;MyClass.h&quot;<br><br>MyClass::MyClass() : value(0) {}<br><br>MyClass::~MyClass() {}<br><br>void MyClass::set_value(int val) {<br>    value = val;<br>}<br><br>int MyClass::get_value() const {<br>    return value;<br>}</pre><h3>Step III</h3><h3>MyClass.i — the SWIG interface file…</h3><pre>%module MyClass<br>%{<br>#include &quot;MyClass.h&quot;<br>%}<br><br>%include &quot;MyClass.h&quot;</pre><h3>Step IV</h3><h3>Generate the Wrapper Code Using SWIG</h3><p>Run in terminal the following command</p><p><strong>swig -python -c++ MyClass.i</strong></p><p>This generates two files:</p><ul><li>MyClass_wrap.cxx: The C++ wrapper code SWIG generates.</li><li>MyClass.py: The Python module that SWIG creates, which interfaces with the C++ code</li></ul><h3>Step V</h3><p>Then compile the C++ code and the SWIG-generated wrapper using g++ or another compiler. Make sure to link against Python libraries as shown below</p><p><strong>g++ -fPIC -shared MyClass_wrap.cxx MyClass.cpp -I/usr/include/python3.x -o _MyClass.so</strong></p><p>Here:</p><ul><li>-fPIC ensures that the code is position-independent (required for shared libraries).</li><li>-shared tells the compiler to generate a shared library (_MyClass.so).</li><li>The -I flag specifies the path to Python headers.</li></ul><h3>Step VI</h3><p>Once compiled, you can use the MyClass module in Python:</p><pre>import MyClass<br><br># Create an instance of MyClass<br>obj = MyClass.MyClass()<br><br># Set and get value using the wrapped C++ methods<br>obj.set_value(100)<br>print(obj.get_value())  # Output: 100</pre><p><em>Originally published at </em><a href="https://som-itsolutions.blogspot.com/2024/10/do-you-want-your-python-code-to-access.html"><em>https://som-itsolutions.blogspot.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc9728606f95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Composite Pattern in Rust — my exploration continues…]]></title>
            <link>https://medium.com/@som.mukhopadhyay/composite-pattern-in-rust-my-exploration-continues-ab78b7901f90?source=rss-376c0cef2bf7------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab78b7901f90</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[composite-pattern]]></category>
            <dc:creator><![CDATA[Somenath Mukhopadhyay]]></dc:creator>
            <pubDate>Mon, 30 Sep 2024 04:49:47 GMT</pubDate>
            <atom:updated>2024-09-30T11:38:40.679Z</atom:updated>
            <content:encoded><![CDATA[<h3>Composite Pattern in Rust — my exploration continues…</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/85/0*43_tzExSzC8CErRK.png" /></figure><p>In this ever evolving world of programming languages when each day a new language pops up, it’s difficult to maintain sanity — that’s why impostor syndrome is very common in the software industry. But whatever may be the case, there are some fundamental concepts which remain intact. For example, the event handler loops are almost for every event driven OS. Similarly, the design pattern concepts — it’s truly language-agnostic.</p><p>Language syntax may change. But the basic principles of software design will remain the same — the same abstraction, encapsulation, inheritance, composition — all remain same.</p><p>That’s why learning design pattern is such an important goal in the software industry.</p><p>Design patterns provide reusable solutions to common problems in software design. The language may differ (like using inheritance in object-oriented languages or using traits in Rust), but the patterns are language-agnostic in concept.</p><p>It enforces us to rise above the language and look into a piece of code from a designer’s perspective.</p><p>So…. here we go…</p><p>My implementation of <strong>composite pattern </strong>in Rust.</p><pre>use std::vec;<br>use std::any::type_name;<br><br>// Define a trait with a default method to print the type name<br>trait GetTypeName {<br>    fn get_type_name(&amp;self) -&gt; &amp;&#39;static str {<br>        type_name::&lt;Self&gt;()<br>    }<br>}<br><br>// Implement the trait for any type<br>impl&lt;T&gt; GetTypeName for T {}<br><br>fn print_type_name(obj: &amp;dyn GetTypeName) {<br>    println!(&quot;The type name is: {}&quot;, obj.get_type_name());<br>}<br>trait Shape : ShapeClone{<br>    fn new() -&gt; Self where Self: Sized;<br>    fn add(&amp;mut self, shape : Box&lt;dyn Shape&gt;){<br>        println!(&quot;Aloha... It&#39;s a leaf.... can&#39;t add more components to it...&quot;);//default behavior<br>    }<br>    fn remove(&amp;mut self,shape : Box&lt;dyn Shape&gt;){<br>        println!(&quot;Aloha... It&#39;s a leaf.... can&#39;t remove components from it...&quot;);//default behaviour<br>    }<br>    fn get_parent(&amp;self) -&gt;  Option&lt;Box&lt;dyn Shape&gt;&gt;;<br>    fn set_parent(&amp;mut self, shape: Box&lt;dyn Shape&gt;);<br>    fn display(&amp;self);<br>}<br>trait ShapeClone {<br>    fn clone_box(&amp;self) -&gt; Box&lt;dyn Shape&gt;;<br>}<br><br>impl&lt;T&gt; ShapeClone for T<br>where<br>    T: &#39;static + Shape + Clone,<br>{<br>    fn clone_box(&amp;self) -&gt; Box&lt;dyn Shape&gt; {<br>        Box::new(self.clone())<br>    }<br>}<br><br>impl Clone for Box&lt;dyn Shape&gt; {<br>    fn clone(&amp;self) -&gt; Box&lt;dyn Shape&gt; {<br>        self.clone_box()<br>    }<br>}<br><br>#[derive(Clone)]<br>struct Point{<br>    x:i32,<br>    y:i32,<br>    parent: Option&lt;Box&lt;dyn Shape&gt;&gt;,<br>}<br>#[derive(Clone)]<br>struct CompositeShape{<br>    parent : Option&lt;Box&lt;dyn Shape&gt;&gt;,<br>    list_of_shapes : Vec&lt;Box&lt;dyn Shape&gt;&gt;,<br>}<br><br>impl Shape for CompositeShape{<br>    fn new() -&gt; Self<br>    where<br>        Self: Sized<br>    {<br>        Self {<br>            parent: None,<br>            list_of_shapes: Vec::new(),<br>        }<br>    }<br><br>    fn add(&amp;mut self, shape: Box&lt;dyn Shape&gt;){<br>        self.list_of_shapes.push(shape.clone());<br>    }<br>    fn remove(&amp;mut self, shape: Box&lt;dyn Shape&gt;){<br>        self.list_of_shapes.pop();<br>    }<br>    fn get_parent(&amp;self) -&gt; Option&lt;Box&lt;dyn Shape&gt;&gt;{<br>       self.parent.clone()<br>    }<br>    fn set_parent(&amp;mut self, shape: Box&lt;dyn Shape&gt;){<br>        self.parent = Option::from(shape);<br>    }<br>    fn display(&amp;self){<br>        for shape in self.list_of_shapes.iter(){<br>            shape.display();<br>        }<br>    }<br>}<br><br>impl Shape for Point{<br>    fn new() -&gt; Self<br>    where<br>        Self: Sized<br>    {<br>        Self { x:0, y:0, parent: None } // Can also write Point { x, y }<br>    }<br><br>    fn get_parent(&amp;self) -&gt; Option&lt;Box&lt;dyn Shape&gt;&gt;{<br>       self.parent.clone()<br>    }<br><br>    fn set_parent(&amp;mut self,  shape: Box&lt;dyn Shape&gt;) {<br>        self.parent = Option::from(shape);<br>    }<br><br>    fn display(&amp;self) {<br>       println!(&quot;X : {}, Y: {}&quot;, self.x, self.y);<br>    }<br>}<br><br>fn main() {<br>    let mut line1 : Box&lt;dyn Shape&gt; = Box ::new(CompositeShape::new());<br>    let mut quadrilateral1 : Box&lt;dyn Shape&gt; = Box ::new(CompositeShape::new());<br>    // Create points<br>    let mut p1:Box&lt;dyn Shape&gt; = Box::new(Point { x: 1, y: 1, parent: None });<br>    let mut p2:Box &lt;dyn Shape&gt; = Box::new(Point { x: 2, y: 2, parent: None });<br>    let mut p3:Box&lt;dyn Shape&gt; = Box::new(Point { x: 10, y: 20, parent: None });<br>    let mut p4:Box &lt;dyn Shape&gt; = Box::new(Point { x: 60, y: 90, parent: None });<br><br>    line1.add(p1.clone());<br>    line1.add(p2.clone());<br><br>    quadrilateral1.add(p1.clone());<br>    quadrilateral1.add(p2.clone());<br>    quadrilateral1.add(p3.clone());<br>    quadrilateral1.add(p4.clone());<br><br>    //setting the parents of the two points<br>    p1.set_parent(line1.clone());<br>    p2.set_parent(line1.clone());<br><br>    //Trying to add to a leaf<br>    p1.add(p2.clone());<br><br>    println!(&quot;The starting and ending points of the line1 are...&quot;);<br>    line1.display();<br>    println!(&quot;The four vertices of the quadrilateral are...&quot;);<br>    quadrilateral1.display();<br>}</pre><p>And here’s my exploration of the Composite Design Pattern back in 2008 using C++ and Python…</p><ul><li><a href="https://som-itsolutions.blogspot.com/2008/12/composite-design-pattern-is-structural.html">Composite Design Pattern</a></li><li><a href="https://som-itsolutions.blogspot.com/2023/08/composite-design-pattern-in-python.html">Composite Design Pattern in Python....</a></li></ul><p><em>Originally published at </em><a href="https://som-itsolutions.blogspot.com/2024/09/composite-pattern-in-rust-my.html"><em>http://som-itsolutions.blogspot.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab78b7901f90" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Bridge Pattern in Rust…]]></title>
            <link>https://medium.com/@som.mukhopadhyay/the-bridge-pattern-in-rust-8918b531c537?source=rss-376c0cef2bf7------2</link>
            <guid isPermaLink="false">https://medium.com/p/8918b531c537</guid>
            <category><![CDATA[rustlang]]></category>
            <category><![CDATA[bridge-pattern]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Somenath Mukhopadhyay]]></dc:creator>
            <pubDate>Sat, 21 Sep 2024 05:45:56 GMT</pubDate>
            <atom:updated>2024-09-21T05:45:56.170Z</atom:updated>
            <content:encoded><![CDATA[<p>In modern software design, using composition (via the Bridge pattern) instead of inheritance is often considered a better approach, particularly when working with flexible, scalable systems. The Bridge pattern is a structural design pattern that decouples an abstraction from its implementation, allowing the two to vary independently. This pattern promotes composition by separating the interface from the implementation, which solves many problems associated with inheritance.</p><p>Here is the code of Bridge pattern implemented in Rust…</p><pre>trait Color {<br>    fn new(&amp;self) {<br>    }<br>    fn get_name(&amp;self) -&gt; String;<br>}<br><br>struct Red;<br>struct Black;<br><br>impl Color for Red {<br>    fn new(&amp;self) {<br>        println!(&quot;The color is Black&quot;);<br>    }<br><br>    fn get_name(&amp;self) -&gt; String {<br>        &quot;Red&quot;.to_string()<br>    }<br>}<br><br>impl Color for Black {<br>    fn new(&amp;self) {<br>        println!(&quot;The color is Black&quot;);<br>    }<br><br>    fn get_name(&amp;self) -&gt; String {<br>        &quot;Black&quot;.to_string()<br>    }<br>}<br><br>trait Gear {<br>    fn new(&amp;self){<br>    }<br><br>    fn get_name(&amp;self) -&gt; String;<br>}<br><br>struct AutoGear;<br>struct ManualGear;<br><br>impl Gear for AutoGear {<br>    fn new(&amp;self){<br>        println!(&quot;The gear is AutoGear&quot;);<br>    }<br><br>    fn get_name(&amp;self) -&gt; String {<br>        &quot;AutoGear&quot;.to_string()<br>    }<br>}<br><br>impl Gear for ManualGear {<br>    fn new(&amp;self){<br>        println!(&quot;The gear is Manual Gear&quot;);<br>    }<br><br>    fn get_name(&amp;self) -&gt; String {<br>        &quot;ManualGear&quot;.to_string()<br>    }<br>}<br><br>trait Vehicle {<br><br>    fn set_color(&amp;mut self, color : Box&lt;dyn Color&gt;) {}<br>    fn set_gear (&amp;mut self, gear : Box&lt;dyn Gear&gt;) {}<br><br>    fn display_attributes(&amp;self) { }<br><br><br>}<br><br>#[derive()]<br>struct SmallCar{<br>    color: Box&lt;dyn Color&gt;,<br>    gear: Box&lt;dyn Gear&gt;,<br>}<br>#[derive()]<br>struct Truck{<br>    color: Box&lt;dyn Color&gt;,<br>    gear: Box&lt;dyn Gear&gt;,<br>}<br><br>impl Vehicle for SmallCar {<br>    fn set_color(&amp;mut self, color : Box&lt;dyn Color&gt;) {<br>        self.color = color;<br>    }<br>    fn set_gear(&amp;mut self, gear : Box&lt;dyn Gear&gt;) {<br>        self.gear = gear;<br>    }<br><br>    fn display_attributes(&amp;self) {<br>        println!(&quot;The vehicle color is {:?}&quot;, self.color.get_name());<br>        println!(&quot;The vehicle gear is {:?}&quot;, self.gear.get_name());<br>    }<br>}<br><br>impl Vehicle for Truck {<br>    fn set_color(&amp;mut self, color : Box&lt;dyn Color&gt;) {<br>        self.color = color;<br>    }<br>    fn set_gear(&amp;mut self, gear : Box&lt;dyn Gear&gt;) {<br>        self.gear = gear;<br>    }<br><br>    fn display_attributes(&amp;self) {<br>        println!(&quot;The vehicle color is {:?}&quot;, self.color.get_name());<br>        println!(&quot;The vehicle gear is {:?}&quot;, self.gear.get_name());<br>    }<br>}<br><br>fn main() {<br>    let color = Box::new(Red);<br>    let gear = Box::new(AutoGear);<br>    let truck = Truck {<br>        color: color, gear:gear,<br>    };<br>    truck.display_attributes();<br>}</pre><p>Let me tell you in detail what is there in this example.</p><p>Here we have a top-level root class called Vehicle having two attributes — color and gear.</p><p>The color may be Red and White whereas the Gear may be Manual and Auto.</p><p>Now if we put all of these in a monolithic class hierarchy, as shown in the left diagram — there will be many classes.</p><p>So, to do it in a better fashion, we maintain two different inheritance hierarchies namely one for Color and another for Gear. And the Vehicle hierarchy is maintained separately.</p><p>So from the vehicle hierarchy, we pick up any color and any type of Gear we want from the Color and Gear inheritance hierarchies respectively as shown in the right-side diagram.</p><p>The result is that there will be few classes to maintain.</p><p>This is exactly what is explained in the following section.</p><p>Look at the UML diagram on the left — that is the class hierarchy without using Bridge Pattern. Look at the number of classes — it’s many classes.</p><p>Now look at the class diagram at the right- look at how fewer classes can manage the same level of different classes if we use the Bridge Pattern</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*GF2QJhzlZEmXVcbS.png" /></figure><p>Using composition with the Bridge pattern is often a superior design choice compared to inheritance. It:</p><p>- Avoids the pitfalls of deep class hierarchies.</p><p>- Promotes code reuse and flexibility.</p><p>- Supports better maintainability and scalability.</p><p>By favoring composition over inheritance, we can create more modular, flexible, and maintainable systems, which align with modern software design principles such as SOLID.</p><p>Here’s my implementation of the Bridge pattern in other languages — C++ and Python…</p><p><a href="https://som-itsolutions.blogspot.com/2009/03/bridge-pattern_12.html">Bridge Pattern in C++, Python...</a></p><p><em>Originally published at </em><a href="https://som-itsolutions.blogspot.com/2024/09/the-bridge-pattern-in-rust.html"><em>http://som-itsolutions.blogspot.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8918b531c537" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My exploration of Rust continues… Mediator Design Pattern in Rust…]]></title>
            <link>https://medium.com/@som.mukhopadhyay/my-exploration-of-rust-continues-mediator-design-pattern-in-rust-f294374a2090?source=rss-376c0cef2bf7------2</link>
            <guid isPermaLink="false">https://medium.com/p/f294374a2090</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Somenath Mukhopadhyay]]></dc:creator>
            <pubDate>Thu, 19 Sep 2024 05:11:00 GMT</pubDate>
            <atom:updated>2024-09-19T05:11:00.417Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/85/0*DCDB1rD9a5wGIke6.png" /></figure><p>This design pattern lets you reduce chaotic dependencies between objects. The pattern restricts direct communications between the objects and forces them to collaborate only via a mediator object.</p><p>The Mediator interface declares a method used by components to notify the mediator about various events. The Mediator may react to these events and triggers specific components to execute different yet specific tasks.</p><p>The Base Component provides the basic functionality of storing a mediator’s reference inside the component.</p><p>Concrete Components implement various functionality. They don’t depend on other components.</p><p>Let me explain it to you with an example.</p><p>Suppose two students Ridit and Ishan take a lot of responsibility in a class. But something bad happens between them, and hence they don’t talk to each other. So, here comes the ClassMonitor — as a Mediator between Ishan and Ridit — if Ridit does anything that needs Ishan to do another task, Ridit notifies the Class Monitor, and then the Class Monitor asks Ishan to execute the necessary task.</p><p>There are many uses for this design pattern. This design pattern can be found in most of the widget message-passing systems — individual widgets don’t pass or communicate with each other — but they communicate through the container window.</p><p>For Android engineers — you remember how two fragments talk to each other through the container window.</p><p>Happy learning.</p><p>Here’s the source code for Mediator Pattern implemented through Rust.</p><pre>use std::cell::RefCell;<br>use std::rc::Rc;<br><br>trait BaseStudent {<br>    fn do_a(&amp;self);<br>    fn do_b(&amp;self);<br>    fn do_c(&amp;self);<br>    fn do_d(&amp;self);<br>    fn set_class_monitor(&amp;mut self, monitor: Rc&lt;RefCell&lt;dyn ClassMonitar&gt;&gt;);<br>}<br><br>struct Ridit {<br>    monitor: Option&lt;Rc&lt;RefCell&lt;dyn ClassMonitar&gt;&gt;&gt;,<br>}<br><br>struct Ishan {<br>    monitor: Option&lt;Rc&lt;RefCell&lt;dyn ClassMonitar&gt;&gt;&gt;,<br>}<br><br>impl BaseStudent for Ridit {<br>    fn do_a(&amp;self) {<br>        println!(&quot;Ridit does task A&quot;);<br>        if let Some(ref monitor) = self.monitor {<br>            monitor.borrow().notify(&quot;A&quot;.to_string());<br>        }<br>    }<br><br>    fn do_b(&amp;self) {<br>        println!(&quot;Ridit does task B&quot;);<br>    }<br><br>    fn do_c(&amp;self) {<br>        println!(&quot;Ridit does task C&quot;);<br>    }<br><br>    fn do_d(&amp;self) {<br>        println!(&quot;Ridit does task D&quot;);<br>    }<br><br>    fn set_class_monitor(&amp;mut self, monitor: Rc&lt;RefCell&lt;dyn ClassMonitar&gt;&gt;) {<br>        self.monitor = Some(monitor);<br>    }<br>}<br><br>impl BaseStudent for Ishan {<br>    fn do_a(&amp;self) {<br>        println!(&quot;Ishan does task A&quot;);<br>    }<br><br>    fn do_b(&amp;self) {<br>        println!(&quot;Ishan does task B&quot;);<br>        if let Some(ref monitor) = self.monitor {<br>            monitor.borrow().notify(&quot;B&quot;.to_string());<br>        }<br>    }<br><br>    fn do_c(&amp;self) {<br>        println!(&quot;Ishan does task C&quot;);<br>    }<br><br>    fn do_d(&amp;self) {<br>        println!(&quot;Ishan does task D&quot;);<br>    }<br><br>    fn set_class_monitor(&amp;mut self, monitor: Rc&lt;RefCell&lt;dyn ClassMonitar&gt;&gt;) {<br>        self.monitor = Some(monitor);<br>    }<br>}<br><br>trait ClassMonitar {<br>    fn notify(&amp;self, event: String);<br>}<br><br>#[derive(Clone)]<br>struct ConcreteClassMonitor {<br>    ridit: Option&lt;Rc&lt;RefCell&lt;dyn BaseStudent&gt;&gt;&gt;,<br>    ishan: Option&lt;Rc&lt;RefCell&lt;dyn BaseStudent&gt;&gt;&gt;,<br>}<br><br>impl ClassMonitar for ConcreteClassMonitor {<br>    fn notify(&amp;self, event: String) {<br>        if event == &quot;A&quot; {<br>            println!(&quot;ClassMonitor reacting to event A and asking Ishan to do task C&quot;);<br>            if let Some(ref ishan) = self.ishan {<br>                ishan.borrow().do_c();<br>            }<br>        }<br><br>        if event == &quot;B&quot; {<br>            println!(&quot;ClassMonitor reacting to event B and asking Ridit to do task D&quot;);<br>            if let Some(ref ridit) = self.ridit {<br>                ridit.borrow().do_d();<br>            }<br>        }<br>    }<br>}<br><br>fn main() {<br>    // Create instances of students as trait objects<br>    let ridit: Rc&lt;RefCell&lt;dyn BaseStudent&gt;&gt; = Rc::new(RefCell::new(Ridit { monitor: None }));<br>    let ishan: Rc&lt;RefCell&lt;dyn BaseStudent&gt;&gt; = Rc::new(RefCell::new(Ishan { monitor: None }));<br><br>    // Create ConcreteClassMonitor as trait object (ClassMonitar)<br>    let class_monitor: Rc&lt;RefCell&lt;dyn ClassMonitar&gt;&gt; = Rc::new(RefCell::new(ConcreteClassMonitor {<br>        ridit: Some(Rc::clone(&amp;ridit)),<br>        ishan: Some(Rc::clone(&amp;ishan)),<br>    }));<br><br>    // Set the monitor in the students<br>    ridit.borrow_mut().set_class_monitor(Rc::clone(&amp;class_monitor));<br>    ishan.borrow_mut().set_class_monitor(Rc::clone(&amp;class_monitor));<br><br>    // Test the functionality<br>    ridit.borrow().do_a(); // This will notify the monitor and trigger Ishan to do task C<br>    ishan.borrow().do_b(); // This will notify the monitor and trigger Ridit to do task D<br>}</pre><p><em>Originally published at </em><a href="http://som-itsolutions.blogspot.com/2024/09/my-exploration-of-rust-continues.html"><em>http://som-itsolutions.blogspot.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f294374a2090" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My tryst with Rust — through the subject of Design Pattern — implementation of Chain of…]]></title>
            <link>https://medium.com/@som.mukhopadhyay/my-tryst-with-rust-through-the-subject-of-design-pattern-implementation-of-chain-of-49b910394a0d?source=rss-376c0cef2bf7------2</link>
            <guid isPermaLink="false">https://medium.com/p/49b910394a0d</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[gang-of-four]]></category>
            <dc:creator><![CDATA[Somenath Mukhopadhyay]]></dc:creator>
            <pubDate>Tue, 17 Sep 2024 14:09:50 GMT</pubDate>
            <atom:updated>2024-09-17T14:09:50.251Z</atom:updated>
            <content:encoded><![CDATA[<h3>My tryst with Rust — through the subject of Design Pattern — implementation of Chain of Responsibility…</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/85/0*staivFbqv8UNBzj5.png" /></figure><p>I remember in my earlier phase as a software engineer, how I mapped the MFC’s command routing algorithm to Chain of Responsibility — and when finally it became clear, there was immense joy for me.</p><p>I always say to my students that we should approach a problem not only from how’s point of view but also from why’s point of views.</p><p>Curiosity is one of the greatest traits for a software engineer — nurture that, grow that — if you want to extract joy from your day-to-day journey as a software engineer.</p><p>So here we go.</p><p>My today’s contribution to the learning community — <strong>Chain of Responsibility</strong> design pattern using <strong>Rust</strong>.</p><p>The <strong>Chain of Responsibility</strong> design pattern is a behavioural design pattern that allows a request to pass through a series of handlers. Each handler can either handle the request or pass it to the next handler in the chain. This design pattern promotes loose coupling between the sender and receiver of a request, allowing more flexibility in handling specific actions.</p><h3>Key Features of the Chain of Responsibility Pattern:</h3><h3>Decoupling:</h3><p>The sender of the request doesn’t need to know which handler will process the request.</p><h3>Dynamic Chains:</h3><p>You can change the chain of handlers at runtime or configure it based on the application’s needs.</p><h3>Multiple Handlers:</h3><p>A request can be processed by a series of handlers in sequence until one of them handles the request, or it can propagate through all of them.</p><p>Here’s the source code…</p><pre>#[derive(Clone)]<br>struct Request{<br>    request_type : String,<br>}<br>impl Request{<br>    fn new(request_type : String) -&gt; Self{<br>       Request{<br>           request_type : request_type,<br>       }<br>    }<br>}<br><br>trait Employee {<br>    fn set_successor(&amp;mut self, successor:Box&lt;dyn Employee&gt;);<br>    fn handle_request(&amp;mut self, request: Request) ;<br>}<br><br>struct TeamLeader {<br>    successor: Option&lt;Box&lt;dyn Employee&gt;&gt;,<br>}<br>struct ProjectManager {<br>    successor: Option&lt;Box&lt;dyn Employee&gt;&gt;,<br>}<br>struct GeneralManager{<br>    successor: Option&lt;Box&lt;dyn Employee&gt;&gt;,<br>}<br><br>struct CTO {<br>    successor: Option&lt;Box&lt;dyn Employee&gt;&gt;,<br>}<br><br>impl Employee for CTO{<br><br>    fn set_successor(&amp;mut self, successor: Box&lt;dyn Employee&gt;) {<br>        //end of the chain... no successor<br>    }<br>    fn handle_request(&amp;mut self, request :  Request) {<br>        println!(&quot;I am the CTO... I must handle the request as this is the end of the chain&quot;);<br>        println!(&quot;The request is handled at the CTO level...&quot;);<br>    }<br>}<br><br>impl Employee for GeneralManager {<br>    fn set_successor(&amp;mut self, successor: Box&lt;dyn Employee&gt;) {<br>            self.successor = Some(successor);<br>    }<br><br>    fn handle_request(&amp;mut self, request : Request) {<br>        if request.request_type == &quot;generalmanager_level&quot; {<br>            println!(&quot;Handling the request at the General Manager level&quot;);<br>        }<br>        else if let Some(ref mut successor) = self.successor {<br>            println!(&quot;I am the general manager...Forwarding the request to CTO...&quot;);<br>            successor.handle_request(request);<br>        }<br>    }<br>}<br><br>impl Employee for ProjectManager {<br>    fn set_successor(&amp;mut self, successor: Box&lt;dyn Employee&gt;) {<br>            self.successor = Some(successor);<br>    }<br><br>    fn handle_request(&amp;mut self, request: Request) {<br>        if request.request_type == &quot;projectmanager_level&quot; {<br>            println!(&quot;Handling the request at the Project Manager level&quot;);<br>        } else if let Some(ref mut successor) = self.successor {<br>            println!(&quot;I am the Project Manager...Forwarding the request to General Manager&quot;);<br>            successor.handle_request(request);<br>        }<br>    }<br>}<br><br>impl Employee for TeamLeader {<br>    fn set_successor(&amp;mut self, successor: Box&lt;dyn Employee&gt;)  {<br>        self.successor = Some(successor);<br>    }<br><br>    fn handle_request(&amp;mut self, request : Request) {<br>        if request.request_type == &quot;teamleader_level&quot; {<br>            println!(&quot;Handling the request at the team_leader level&quot;);<br>        }<br>        else if let Some(ref mut successor) = self.successor {<br>            println!(&quot;I am the teamleader....Forwarding the request to Project Manager&quot;);<br>           successor.handle_request(request);<br>        }<br>    }<br>}<br><br>fn main() {<br>    let request1 = Request::new(&quot;teamleader_level&quot;.to_string());<br>    let request2 = Request::new(&quot;generalmanager_level&quot;.to_string());<br>    let request3 = Request::new(&quot;cto_level&quot;.to_string());<br>    let mut cto = CTO{successor: None};<br>    let mut gm = GeneralManager{successor: None};<br>    let mut manager = ProjectManager {successor: None};<br>    let mut teamLeader = TeamLeader {successor: None};<br>    gm.set_successor(Box::new(cto));<br>    manager.set_successor(Box::new(gm));<br>    teamLeader.set_successor(Box::new(manager));<br>    teamLeader.handle_request(request3);<br>}</pre><p><em>Originally published at </em><a href="http://som-itsolutions.blogspot.com/2024/09/my-tryst-with-rust-through-subject-of.html"><em>http://som-itsolutions.blogspot.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49b910394a0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Command Pattern in Rust — absolutely driven by intrinsic motivation…]]></title>
            <link>https://medium.com/@som.mukhopadhyay/command-pattern-in-rust-absolutely-driven-by-intrinsic-motivation-b36e11f0a670?source=rss-376c0cef2bf7------2</link>
            <guid isPermaLink="false">https://medium.com/p/b36e11f0a670</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[command-pattern]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Somenath Mukhopadhyay]]></dc:creator>
            <pubDate>Sun, 15 Sep 2024 06:27:15 GMT</pubDate>
            <atom:updated>2024-09-15T06:27:15.252Z</atom:updated>
            <content:encoded><![CDATA[<h3>Command Pattern in Rust — absolutely driven by intrinsic motivation…</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/85/0*wsjjJlYEmKMgdZt0.png" /></figure><h3>Key Components of the Command Pattern:</h3><ol><li><strong>Command Interface</strong>:</li></ol><ul><li>Defines a common interface with a method (usually called execute) that all concrete commands must implement. This allows different types of commands to be invoked in a uniform way.</li></ul><p><strong>Concrete Command</strong>:</p><ul><li>Implements the command interface and defines the actual behavior. It binds the <strong>Receiver</strong> (the object that knows how to carry out the operation) to an action. The execute method is used to invoke the receiver&#39;s method(s).</li></ul><p><strong>Invoker</strong>:</p><ul><li>The invoker (e.g., a Waiter in a restaurant analogy) is responsible for triggering the command by calling the execute method. It does not know or care about the specifics of the command, only that it can execute it.</li></ul><p><strong>Receiver</strong>:</p><p>The receiver (e.g., a Chef) is the object that performs the actual work. The command will delegate the action to the receiver.</p><h3>Example Scenario: Restaurant</h3><ul><li><strong>Invoker</strong>: The <strong>Waiter</strong> takes an order from the customer and passes it to the chef.</li><li><strong>Command</strong>: The <strong>FoodCommand</strong> tells the chef what food to prepare.</li><li><strong>Receiver</strong>: The <strong>Chef</strong> is responsible for actually preparing the food.</li></ul><p>The advantage of the Command Pattern is that the Waiter (invoker) doesn’t need to know the details of how food is prepared. It just knows how to pass the command. You could have different kinds of commands (e.g., DrinkCommand, FoodCommand, DessertCommand), and the invoker can execute them all the same way.</p><h3>Command Pattern Flow:</h3><ol><li>The <strong>Invoker</strong> issues a command.</li><li>The <strong>Concrete Command</strong> executes the command by calling methods on the <strong>Receiver</strong>.</li><li>The <strong>Receiver</strong> performs the action.</li></ol><p>Here is the source code of the command pattern in Rust…</p><p>#enjoy…</p><p>I must admit — I am yet to achieve the flow in Rust — the learning curve is really steep…</p><pre><br>trait Command {<br>    fn execute(&amp;self);<br>}<br><br>//Receiver<br>struct Chef;<br><br>impl Chef {<br>    pub(crate) fn prepare_food(&amp;self) {<br>        println!(&quot;Chef is preparing the food...&quot;);<br>    }<br>}<br><br>struct FoodCommand{<br>    chef : Chef,<br>}<br><br>impl Command for FoodCommand  {<br>    fn execute(&amp;self) {<br>        self.chef.prepare_food();<br>    }<br>}<br>//Invoker<br>struct Waiter {<br>    command : Box&lt;dyn Command&gt;,<br>}<br><br><br>impl Waiter {<br>    fn new () -&gt; Waiter{<br>        let waiter = Waiter {<br>            command : Box::new (FoodCommand {chef : Chef}),<br>        };<br>        waiter<br>    }<br><br>    fn pass_command_to_chef(&amp;self){<br>        self.command.execute();<br>    }<br>}<br><br>fn main() {<br>    let chef = Chef;<br>    let food_command = FoodCommand {chef};<br>    let waiter = Waiter {command : Box::new(food_command),};<br>    waiter.pass_command_to_chef();<br>}</pre><p><em>Originally published at </em><a href="https://som-itsolutions.blogspot.com/2024/09/command-pattern-in-rust-absolutely.html"><em>http://som-itsolutions.blogspot.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b36e11f0a670" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Will adoption of Rust for mission critical systems popularise GTK-RS and Linux overall?]]></title>
            <link>https://medium.com/@som.mukhopadhyay/will-adoption-of-rust-for-mission-critical-systems-popularise-gtk-rs-and-linux-overall-7a122e3ada63?source=rss-376c0cef2bf7------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a122e3ada63</guid>
            <category><![CDATA[gtk]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[Somenath Mukhopadhyay]]></dc:creator>
            <pubDate>Fri, 13 Sep 2024 13:23:52 GMT</pubDate>
            <atom:updated>2024-09-13T13:25:48.802Z</atom:updated>
            <content:encoded><![CDATA[<p>For so many years we have been fed with the infamous FUD that Linux is not good for desktops. However, as more and more organisations adopt Rust for mission-critical systems, I think GTK-RS (for developing cross-platform GUI using Rust) and Linux desktops will see a surge in numbers. At least my gut feeling is saying this.</p><p>The inherent memory safety system of Rust and the security system of Linux will make a perfect choice for mission-critical and embedded domains.</p><p>Rust’s adoption in mission-critical systems, many of which might run on Linux, could lead to a resurgence of interest in Linux as a development platform. Developers working on Rust projects might choose Linux for its compatibility, performance, and open-source nature. This could also lead to greater investment in Linux desktop environments, where GTK-RS could play a role.</p><p>I am sure in the near future, use of GTK-RS for SCADA system’s HMI development is unavoidable. Supervisory Control and Data Acquisition (SCADA) systems are crucial in industries like manufacturing, utilities, and energy management. They monitor and control industrial processes through a combination of hardware and software. SCADA systems require robust, reliable, and high-performance software for their Human-Machine Interface (HMI), and GTK-RS offers several advantages for these applications — the first and foremost among them is safety and security — making the HMI foolproof from being hacked.</p><p>Not only from security perspective, but there is a strong reasoning of using GTK-RS in SCADA system for performance. SCADA systems need to process multiple data streams concurrently. Rust’s strengths in concurrency and parallelism ensure that GTK-RS-based applications can handle these demands efficiently, providing a responsive interface even under heavy load.</p><p>Keeping this in mind, I was just playing around with GTK-RS, and here’s a simple GTK-RS-based application called Skip Counter.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FH-fSEKVvhPU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DH-fSEKVvhPU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FH-fSEKVvhPU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5076ab92b9a632936e4e0803fb06c0bb/href">https://medium.com/media/5076ab92b9a632936e4e0803fb06c0bb/href</a></iframe><p>You need GTK 3 to run this…</p><p>Here is the source code…</p><pre>extern crate gtk;<br>use gtk::prelude::*;<br>use gtk::{Application, ApplicationWindow, Button, Entry, Label, Box};<br>use std::rc::Rc;<br>use std::cell::RefCell;<br><br>fn main() {<br>    let application = Application::builder()<br>        .application_id(&quot;com.example.skip-counter&quot;)<br>        .build();<br><br>    application.connect_activate(|app| {<br>        // Create a new window<br>        let window = ApplicationWindow::new(app);<br>        window.set_title(&quot;Skip Counter&quot;);<br>        window.set_default_size(300, 150);<br><br>        // Create a vertical box to hold the label, entry, and button<br>        let vbox = Box::new(gtk::Orientation::Vertical, 5);<br>        window.set_child(Some(&amp;vbox));<br><br>        // Create a label to display the counter<br>        let label = Label::new(Some(&quot;Counter: 0&quot;));<br>        vbox.pack_start(&amp;label, false, false, 0); // Use pack_start in GTK3<br><br>        // Create an entry for the skip value<br>        let entry = Entry::new();<br>        entry.set_placeholder_text(Some(&quot;Enter skip value&quot;));<br>        vbox.pack_start(&amp;entry, false, false, 0); // Use pack_start in GTK3<br><br>        // Initial counter value<br>        let counter = Rc::new(RefCell::new(0));<br><br>        // Create a button to increment the counter<br>        let increment_button = Button::with_label(&quot;Increment&quot;);<br>        vbox.pack_start(&amp;increment_button, false, false, 0); // Use pack_start in GTK3<br><br>        // Create a button to increment the counter<br>        let reset_button = Button::with_label(&quot;Reset&quot;);<br>        vbox.pack_start(&amp;reset_button, false, false, 0); // Use pack_start in GTK3<br><br><br>        // Connect button click event<br>        let counter_clone = Rc::clone(&amp;counter);<br>        let label_clone = label.clone();<br>        let entry_clone = entry.clone();<br>        increment_button.connect_clicked(move |_| {<br>            let skip_value = entry_clone.text().parse::&lt;i32&gt;().unwrap_or(1);<br>            *counter_clone.borrow_mut() += skip_value;<br>            label_clone.set_text(&amp;format!(&quot;Counter: {}&quot;, *counter_clone.borrow()));<br>        });<br><br>        // Connect the reset button click event<br>        let counter_clone = Rc::clone(&amp;counter);<br>        let label_clone = label.clone();<br>        reset_button.connect_clicked(move |_| {<br>            *counter_clone.borrow_mut() = 0;<br>            label_clone.set_text(&quot;Counter: 0&quot;);<br>        });<br>        // Show the window<br>        window.show_all();<br>    });<br><br>    application.run();<br>}</pre><p><em>Originally published at </em><a href="http://som-itsolutions.blogspot.com/2024/09/will-adoption-of-rust-for-mission.html"><em>http://som-itsolutions.blogspot.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a122e3ada63" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Should you learn Rust NOW? My contribution to the Rust community — State Pattern in Rust…]]></title>
            <link>https://medium.com/@som.mukhopadhyay/should-you-learn-rust-now-my-contribution-to-the-rust-community-state-pattern-in-rust-cced67478fb8?source=rss-376c0cef2bf7------2</link>
            <guid isPermaLink="false">https://medium.com/p/cced67478fb8</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Somenath Mukhopadhyay]]></dc:creator>
            <pubDate>Fri, 13 Sep 2024 13:15:01 GMT</pubDate>
            <atom:updated>2024-09-13T13:17:26.474Z</atom:updated>
            <content:encoded><![CDATA[<h3>Should you learn Rust NOW? My contribution to the Rust community — State Pattern in Rust…</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/85/0*5GTqYeFIC1Wirdgh.png" /></figure><h3>1. Growing Popularity and Industry Adoption</h3><p>According to the 2024 Stack Overflow Developer Survey, Rust is the most admired programming language, with 83% of developers saying they want to use it again. This is the eighth year in a row that Rust has topped this chart. Major Companies Use Rust: Big tech companies like Microsoft, Amazon, Google, Facebook, Dropbox, and Mozilla use Rust in production systems. Learning Rust can open doors to career opportunities at companies that have adopted the language.</p><h3>2. Memory Safety Without Garbage Collection</h3><p>Rust’s borrow checker ensures that you manage memory safely without relying on a garbage collector. This makes Rust an ideal language for systems programming, embedded systems and performance-critical applications. If you want to work on low-level programming without common pitfalls like segmentation faults or data races, Rust is an excellent choice.</p><h3>3. Concurrency Without Fear</h3><p>Rust’s ownership model allows you to write highly concurrent programs while ensuring thread safety at compile-time. This is a game-changer for developers working on multi-threaded or parallel applications, and it’s a good reason to pick up Rust now as more modern software is built with concurrency in mind.</p><h3>4.Growing Ecosystem and Libraries</h3><p>Rust’s ecosystem is maturing. The package manager and build tool, Cargo, is widely praised for its ease of use.</p><h3>5. Community and Support</h3><p>The Rust community is known for being friendly, helpful, and inclusive. The language is also supported by an active working group and regular updates, making it a language that’s constantly evolving but staying stable.</p><p>Rust is the right choice for Systems programmers. It is a great alternative to C/C++ for writing system-level code (operating systems, device drivers, embedded systems).</p><p>So, here we go…</p><p>My contribution to the developers’ community — <strong>State Design Pattern</strong> in Rust.</p><p>The State Design Pattern is a behavioral design pattern that allows an object to change its behavior when its internal state changes. In other words, the object behaves differently depending on its current state, and the state transitions are handled internally. This pattern helps avoid complex conditional statements (like if-else or match in Rust) and organises the code to make it more maintainable.</p><p>Here is the source code of the implementation of State Pattern in Rust.</p><pre>use std::thread;<br>use std::time::Duration;<br><br>struct Mamma {<br>    state: Option&lt;Box&lt;dyn State&gt;&gt;,<br>}<br>trait State {<br>    fn wash(self: Box&lt;Self&gt;) -&gt; Box&lt;dyn State&gt;;<br>    fn marinate(self: Box&lt;Self&gt;) -&gt; Box&lt;dyn State&gt;;<br>    fn cook( self : Box&lt;Self&gt;)-&gt; Box&lt;dyn State&gt;;<br>    fn serve(self : Box &lt;Self&gt;) -&gt; Box&lt;dyn State&gt;;<br>}<br><br>impl Mamma {<br>    fn new() -&gt; Mamma {<br>        let mamma = Mamma {<br>            state: Some(Box::new(UncleanedState)),<br>        };<br>        mamma<br>    }<br><br>    fn startcooking(self) -&gt; () {<br>       self.state.unwrap().wash().marinate().cook().serve();<br>    }<br>}<br><br>struct UncleanedState;<br>struct CleanedState;<br>struct MarinatedState;<br>struct CookState;<br><br><br>impl State for UncleanedState {<br>    fn wash(self: Box&lt;Self&gt;) -&gt; Box&lt;dyn State&gt;{<br>        println!(&quot;The Chicken is in Uncleaned state. It&#39;s being washed...&quot;);<br>        thread::sleep(Duration::from_secs(5));  // Pause for 2 seconds<br>        Box::new(CleanedState{})<br>    }<br>    fn marinate(self: Box&lt;Self&gt;)-&gt;Box&lt;dyn State&gt;{<br>        self<br>    }<br><br>    fn cook(self: Box&lt;Self&gt;)-&gt;Box&lt;dyn State&gt;{<br>        self<br>    }<br><br>    fn serve(self : Box&lt;Self&gt;) -&gt;Box&lt;dyn State&gt;{<br>        self<br>    }<br><br>}<br><br>impl State for CleanedState {<br>    fn wash(self: Box&lt;Self&gt;) -&gt; Box&lt;dyn State&gt; {<br>        self<br>    }<br>    fn marinate(self: Box&lt;Self&gt;) -&gt; Box&lt;dyn State&gt; {<br>        println!(&quot;The chicken is in the Cleanedstate. It&#39;s being marinated...&quot;);<br>        thread::sleep(Duration::from_secs(5));<br>        Box::new(MarinatedState {})<br>    }<br><br>    fn cook(self: Box&lt;Self&gt;) -&gt; Box&lt;dyn State&gt; {<br>        self<br>    }<br><br>    fn serve(self: Box&lt;Self&gt;) -&gt; Box&lt;dyn State&gt; {<br>        self<br>    }<br>}<br><br><br>impl State for MarinatedState {<br>    fn wash(self: Box&lt;Self&gt;) -&gt; Box&lt;dyn State&gt; {<br>        self<br>    }<br>    fn marinate(self: Box&lt;Self&gt;) -&gt; Box&lt;dyn State&gt; {<br>       self<br>    }<br><br>    fn cook(self: Box&lt;Self&gt;) -&gt; Box&lt;dyn State&gt; {<br>        println!(&quot;The chicken is in the Marinatedstate state. It will be cooked now...&quot;);<br>        thread::sleep(Duration::from_secs(5));<br>        Box::new(CookState {})<br>    }<br><br>    fn serve(self: Box&lt;Self&gt;) -&gt; Box&lt;dyn State&gt; {<br>        self<br>    }<br>}<br><br>impl State for CookState {<br>    fn wash(self: Box&lt;Self&gt;) -&gt; Box&lt;dyn State&gt; {<br>        self<br>    }<br>    fn marinate(self: Box&lt;Self&gt;) -&gt; Box&lt;dyn State&gt; {<br>        self<br>    }<br><br>    fn cook(self: Box&lt;Self&gt;) -&gt; Box&lt;dyn State&gt; {<br>        self<br><br>    }<br><br>    fn serve(self: Box&lt;Self&gt;) -&gt; Box&lt;dyn State&gt; {<br>        println!(&quot;The chicken is in the Cookedstate&quot;);<br>        println!(&quot;This is the last state. I m sure the guests will enjoy the chicken...&quot;);<br>        self<br>    }<br>}<br><br>fn main() {<br>   let  mamma = Mamma::new();<br>    mamma.startcooking();<br>}</pre><p><em>Originally published at </em><a href="http://som-itsolutions.blogspot.com/2024/09/should-you-learn-rust-now-my.html"><em>http://som-itsolutions.blogspot.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cced67478fb8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C++ Concurrent profiling using Helgrind — a tool of Valgrind…]]></title>
            <link>https://medium.com/@som.mukhopadhyay/c-concurrent-profiling-using-helgrind-a-tool-of-valgrind-92551c7a190e?source=rss-376c0cef2bf7------2</link>
            <guid isPermaLink="false">https://medium.com/p/92551c7a190e</guid>
            <category><![CDATA[concurrency-programming]]></category>
            <category><![CDATA[profiling]]></category>
            <category><![CDATA[cpp]]></category>
            <dc:creator><![CDATA[Somenath Mukhopadhyay]]></dc:creator>
            <pubDate>Fri, 16 Aug 2024 04:01:59 GMT</pubDate>
            <atom:updated>2024-08-19T13:37:11.245Z</atom:updated>
            <content:encoded><![CDATA[<h3>C++ Concurrent profiling using Helgrind — a tool of Valgrind…</h3><p>On 15th August — my contribution to the learning community…</p><p>Concurrency profiling in C++ is essential for optimizing the performance of multi-threaded applications by identifying and addressing bottlenecks, inefficiencies, and issues like race conditions and deadlocks.</p><p>I am using the Helgrind tool of Valgrind in eclipse to do the experimentation on C++ race condition.</p><p>A data race occurs in a multithreaded application when two or more threads access shared data concurrently, and at least one of these accesses is a write operation without proper synchronization (e.g., without locks). This can lead to unpredictable behavior, crashes, or incorrect program output.</p><p>Here is some information about Helgrind.</p><h3>Helgrind:</h3><p>- Detects data races, potential deadlocks, and lock-order violations.</p><p>- Useful for debugging multi-threaded applications where data consistency is crucial.</p><p><strong>Data Race Detection:</strong></p><p>If Helgrind detects that two threads are accessing the same memory location concurrently without proper synchronization, and at least one of these accesses is a write, it flags this as a data race.</p><p>Please have a look at my video — it’s all explained here.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FgqZlrXSYlEA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DgqZlrXSYlEA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FgqZlrXSYlEA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2fd00d535d85217e64a11fe73462aa93/href">https://medium.com/media/2fd00d535d85217e64a11fe73462aa93/href</a></iframe><p>Concurrency profiling in C++ is crucial for developing high-performance multi-threaded applications.</p><p>Valgrind is a versatile tool for detecting a wide range of memory-related issues in C++ applications. Tools like Memcheck, Helgrind, DRD, and Massif provide comprehensive coverage of memory leaks, invalid accesses, uninitialized memory usage, threading issues, and memory management inefficiencies.</p><p>Using Valgrind in the development cycle can significantly improve the stability and performance of your application by identifying and allowing you to fix these memory-related issues.</p><p>Another important task that Helgrind does is to check whether there is any deadlock in a multithreaded C++ application — like Cyclic dependency.</p><p>Cyclic dependency deadlock occurs when two or more locks are acquired in a different order in two task executions, potentially leading to a deadlock when the program’s tasks execute in parallel.</p><p>A Lock order violation problem indicates the following timeline:</p><p>Task 1</p><p>Acquire lock A.</p><p>Acquire lock B.</p><p>Release lock B.</p><p>Release lock A.</p><p>Task 2</p><p>Acquire lock B.</p><p>Acquire lock A.</p><p>Release lock A.</p><p>Release lock B.</p><p>If these time lines are interleaved when the two tasks execute in parallel, a Deadlock occurs:</p><p>Task 1: Acquire lock A.</p><p>Task 2: Acquire lock B.</p><p>Task 1: Try to acquire lock B; wait until task 2 releases it.</p><p>Task 2: Try to acquire lock A; wait until task 1 releases it.</p><p>For example consider the following piece of code.</p><pre>//============================================================================<br><br>// Name        : CyclicDependencyDeadLock.cpp<br><br>// Author      : Som<br><br>// Version     :<br><br>// Copyright   : som-itsolutions<br><br>// Description : Hello World in C++, Ansi-style<br><br>//============================================================================<br><br><br><br>#include &lt;iostream&gt;<br><br>#include &lt;thread&gt;<br><br>#include &lt;mutex&gt;<br><br><br><br>using namespace std;<br><br><br><br>std::mutex lock1, lock2;<br><br><br><br>void threadA() {<br><br> int count = 0;<br><br>    std::lock_guard&lt;std::mutex&gt; guard1(lock1);<br><br>    for (int i = 0; i&lt;100000; i++){<br><br>     count++;<br><br>    }<br><br>    std::lock_guard&lt;std::mutex&gt; guard2(lock2);<br><br>    //cout&lt;&lt;&quot;Thread id &quot; &lt;&lt;this_thread::get_id()&lt;&lt;&quot; this is okay now because of correct lock order &quot; &lt;&lt;count&lt;&lt;endl;<br><br>    cout&lt;&lt;&quot;Thread id &quot; &lt;&lt;this_thread::get_id()&lt;&lt; &quot; this will never be printed...&quot;&lt;&lt;count&lt;&lt;endl;<br><br>}<br><br><br><br>void threadB() {<br><br>    std::lock_guard&lt;std::mutex&gt; guard2(lock2);<br><br>    int count = 0;<br><br>    for (int i = 0; i&lt;100000; i++){<br><br>     count++;<br><br>    }<br><br>    std::lock_guard&lt;std::mutex&gt; guard1(lock1);<br><br>    //cout&lt;&lt;&quot;Thread id &quot; &lt;&lt;this_thread::get_id()&lt;&lt;&quot; this is okay now because of correct lock order &quot; &lt;&lt;count&lt;&lt;endl;<br><br>    cout&lt;&lt;&quot;Thread id &quot; &lt;&lt;this_thread::get_id()&lt;&lt; &quot; this will never be printed...&quot;&lt;&lt;count&lt;&lt;endl;<br><br>}<br><br><br><br>int main() {<br><br>    std::thread t1(threadA);<br><br>    std::thread t2(threadB);<br><br><br><br>    t1.join();<br><br>    t2.join();<br><br><br><br>    return 0;<br><br>}</pre><p>And if we profile the above piece of code using Helgrind, it will show</p><p><strong><em>Thread #3: lock order “0x10E160 before 0x10E1A0” violated…</em></strong></p><p>Please have a look at the following video…</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fn1hlBpDOPDw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dn1hlBpDOPDw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fn1hlBpDOPDw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2a3fa872c23ce6a07e76cbbbd96a85c/href">https://medium.com/media/b2a3fa872c23ce6a07e76cbbbd96a85c/href</a></iframe><p>To avoid the lock order violation we must go for consistent global order for all the threads.</p><p>That’s all for today…</p><p>I hope this exploration will help the inquisitive minds of software engineers.</p><p>Jai Hind…. Jai Bharat…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92551c7a190e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>