<?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 Siddhartha Dhar Choudhury on Medium]]></title>
        <description><![CDATA[Stories by Siddhartha Dhar Choudhury on Medium]]></description>
        <link>https://medium.com/@sdharchou?source=rss-efb835d9b4a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*__apNzfESvd10sj1o9lyJQ.jpeg</url>
            <title>Stories by Siddhartha Dhar Choudhury on Medium</title>
            <link>https://medium.com/@sdharchou?source=rss-efb835d9b4a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 17:55:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sdharchou/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[Running Small Language Model to take actions on Android devices — Part I]]></title>
            <link>https://medium.com/@sdharchou/running-small-language-model-to-take-actions-on-android-devices-ad1225829a2f?source=rss-efb835d9b4a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad1225829a2f</guid>
            <dc:creator><![CDATA[Siddhartha Dhar Choudhury]]></dc:creator>
            <pubDate>Sun, 18 Jan 2026 23:18:55 GMT</pubDate>
            <atom:updated>2026-01-19T00:39:29.432Z</atom:updated>
            <content:encoded><![CDATA[<p>Introduction to mobile actions and language models that run on mobile devices and take actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z1RPGf19uj0QZ6IfLkGgtA.webp" /><figcaption><strong>Source: </strong><a href="https://blog.google/innovation-and-ai/technology/developers-tools/gemma-open-models/">Google Gemma Blog</a></figcaption></figure><h3>Introduction</h3><p>In this series of posts we will use a Small Language Model (SLM) that runs on mobile devices and can take a set of pre-defined actions on the device. This is the first post in this series of five posts (can be more or less), this one will introduce the core idea and motivation of the project.</p><p>Before we move on, we need to know about three important pieces of this project — Google’s Gemma family of models, Google’s Edge Gallery mobile application, and the Mobile Actions Dataset. This part will mostly discuss the theoretical concepts to build on that, which will help us in the subsequent posts as we get our hands dirty in some code. Let’s get started.</p><h3>Disclaimer</h3><p>This is an exploratory project, I have no idea if this will work or not. The aim is to find out if it will work, and if not learn some new things. All comments about the idea or its feasibility are welcome.</p><h3>Model Disclosure</h3><p>I did not use any LLMs to produce any of the content in this post. The content is purely hand crafted, unadulterated organic model-slop-free human brain produced. I love reading posts written without the use of models, they let you see the personality of the human who wrote the article. They may be subpar at times (especially mine <strong>😛</strong>), but that’s ok, this is not a scientific journal anyway.</p><h3>Gemma family of models</h3><p>Gemma is a series of open weights model by Google DeepMind. These were first launched in early 2024, see their <a href="https://blog.google/innovation-and-ai/technology/developers-tools/gemma-open-models/">official blog</a> for more details. In 2025, the team launched <a href="https://ai.google.dev/gemma/docs/gemma-3n">Gemma-3N</a> which is a series of models optimized to run on mobile devices. Another interesting release was made by the team in December 2025, when they launched <a href="https://blog.google/innovation-and-ai/technology/developers-tools/functiongemma/">Function Gemma</a>, which is a 270M parameter model trained specifically with the ability to call functions, these functions are similar to functions in a programming language.</p><p>At a high level functions are special tokens that the model can generate which can then be interpreted and perform specific function (as defined by the function’s definition).</p><h3>Google Edge Gallery</h3><p>Edge Gallery is a mobile application created by Google that allows us to run these Gemma-3N and Function Gemma models on mobile devices. We will primarily focus on the android application, as the source code is open source and is available in <a href="https://github.com/google-ai-edge/gallery">this GitHub repository</a>. Throughout this series of posts, we will make a series of changes to this codebase.</p><h3>Mobile Actions Dataset</h3><p><a href="https://huggingface.co/datasets/google/mobile-actions">Mobile Actions</a> is a dataset for fine tuning models so that they can generate functions that can then be executed by the edge gallery mobile app. This dataset is also presented in Google’s <a href="https://ai.google.dev/gemma/docs/mobile-actions">blog</a> for fine tuning Function Gemma for Mobile Actions.</p><p>Here’s an example from the dataset:</p><pre>{<br>  &quot;metadata&quot;: &quot;train&quot;,<br>  &quot;tools&quot;: [<br>    {<br>      &quot;function&quot;: {<br>        &quot;name&quot;: &quot;send_email&quot;,<br>        &quot;description&quot;: &quot;Sends an email.&quot;,<br>        &quot;parameters&quot;: {<br>          &quot;type&quot;: &quot;OBJECT&quot;,<br>          &quot;properties&quot;: {<br>            &quot;body&quot;: {<br>              &quot;type&quot;: &quot;STRING&quot;,<br>              &quot;description&quot;: &quot;The body of the email.&quot;<br>            },<br>            &quot;subject&quot;: {<br>              &quot;type&quot;: &quot;STRING&quot;,<br>              &quot;description&quot;: &quot;The subject of the email.&quot;<br>            },<br>            &quot;to&quot;: {<br>              &quot;type&quot;: &quot;STRING&quot;,<br>              &quot;description&quot;: &quot;The email address of the recipient.&quot;<br>            }<br>          },<br>          &quot;required&quot;: [<br>            &quot;to&quot;,<br>            &quot;subject&quot;<br>          ]<br>        }<br>      }<br>    },<br>    {<br>      &quot;function&quot;: {<br>        &quot;name&quot;: &quot;open_wifi_settings&quot;,<br>        &quot;description&quot;: &quot;Opens the Wi-Fi settings.&quot;,<br>        &quot;parameters&quot;: {<br>          &quot;type&quot;: &quot;OBJECT&quot;,<br>          &quot;properties&quot;: {}<br>        }<br>      }<br>    },<br>    {<br>      &quot;function&quot;: {<br>        &quot;name&quot;: &quot;create_calendar_event&quot;,<br>        &quot;description&quot;: &quot;Creates a new calendar event.&quot;,<br>        &quot;parameters&quot;: {<br>          &quot;type&quot;: &quot;OBJECT&quot;,<br>          &quot;properties&quot;: {<br>            &quot;title&quot;: {<br>              &quot;type&quot;: &quot;STRING&quot;,<br>              &quot;description&quot;: &quot;The title of the event.&quot;<br>            },<br>            &quot;datetime&quot;: {<br>              &quot;type&quot;: &quot;STRING&quot;,<br>              &quot;description&quot;: &quot;The date and time of the event in the format YYYY-MM-DDTHH:MM:SS.&quot;<br>            }<br>          },<br>          &quot;required&quot;: [<br>            &quot;title&quot;,<br>            &quot;datetime&quot;<br>          ]<br>        }<br>      }<br>    },<br>    {<br>      &quot;function&quot;: {<br>        &quot;name&quot;: &quot;create_contact&quot;,<br>        &quot;description&quot;: &quot;Creates a contact in the phone&#39;s contact list.&quot;,<br>        &quot;parameters&quot;: {<br>          &quot;type&quot;: &quot;OBJECT&quot;,<br>          &quot;properties&quot;: {<br>            &quot;last_name&quot;: {<br>              &quot;type&quot;: &quot;STRING&quot;,<br>              &quot;description&quot;: &quot;The last name of the contact.&quot;<br>            },<br>            &quot;first_name&quot;: {<br>              &quot;type&quot;: &quot;STRING&quot;,<br>              &quot;description&quot;: &quot;The first name of the contact.&quot;<br>            },<br>            &quot;email&quot;: {<br>              &quot;type&quot;: &quot;STRING&quot;,<br>              &quot;description&quot;: &quot;The email address of the contact.&quot;<br>            },<br>            &quot;phone_number&quot;: {<br>              &quot;type&quot;: &quot;STRING&quot;,<br>              &quot;description&quot;: &quot;The phone number of the contact.&quot;<br>            }<br>          },<br>          &quot;required&quot;: [<br>            &quot;first_name&quot;,<br>            &quot;last_name&quot;<br>          ]<br>        }<br>      }<br>    },<br>    {<br>      &quot;function&quot;: {<br>        &quot;name&quot;: &quot;show_map&quot;,<br>        &quot;description&quot;: &quot;Shows a location on the map.&quot;,<br>        &quot;parameters&quot;: {<br>          &quot;type&quot;: &quot;OBJECT&quot;,<br>          &quot;properties&quot;: {<br>            &quot;query&quot;: {<br>              &quot;type&quot;: &quot;STRING&quot;,<br>              &quot;description&quot;: &quot;The location to search for. May be the name of a place, a business, or an address.&quot;<br>            }<br>          },<br>          &quot;required&quot;: [<br>            &quot;query&quot;<br>          ]<br>        }<br>      }<br>    },<br>    {<br>      &quot;function&quot;: {<br>        &quot;name&quot;: &quot;turn_off_flashlight&quot;,<br>        &quot;description&quot;: &quot;Turns the flashlight off.&quot;,<br>        &quot;parameters&quot;: {<br>          &quot;type&quot;: &quot;OBJECT&quot;,<br>          &quot;properties&quot;: {}<br>        }<br>      }<br>    },<br>    {<br>      &quot;function&quot;: {<br>        &quot;name&quot;: &quot;turn_on_flashlight&quot;,<br>        &quot;description&quot;: &quot;Turns the flashlight on.&quot;,<br>        &quot;parameters&quot;: {<br>          &quot;type&quot;: &quot;OBJECT&quot;,<br>          &quot;properties&quot;: {}<br>        }<br>      }<br>    }<br>  ],<br>  &quot;messages&quot;: [<br>    {<br>      &quot;role&quot;: &quot;developer&quot;,<br>      &quot;content&quot;: &quot;Current date and time given in YYYY-MM-DDTHH:MM:SS format: 2024-11-27T00:51:02\nDay of week is Wednesday\nYou are a model that can do function calling with the following functions\n&quot;<br>    },<br>    {<br>      &quot;role&quot;: &quot;user&quot;,<br>      &quot;content&quot;: &quot;Can you show me the location of the World Health Organization headquarters in Geneva on a map?&quot;<br>    },<br>    {<br>      &quot;role&quot;: &quot;assistant&quot;,<br>      &quot;tool_calls&quot;: [<br>        {<br>          &quot;function&quot;: {<br>            &quot;name&quot;: &quot;show_map&quot;,<br>            &quot;arguments&quot;: {<br>              &quot;query&quot;: &quot;World Health Organization headquarters in Geneva&quot;<br>            }<br>          }<br>        }<br>      ]<br>    }<br>  ]<br>}</pre><p>It contains all the available functions, and their signatures, and a bunch of messages which contains the system prompt, the user’s prompt and the model’s response containing the function call that the model will make.</p><p>Now that we have gone through all the core components of interest, let’s shift focus to some pre-requisite knowledge and then move on to the problem statement.</p><h3>Pre-requisites</h3><p>I am going to assume that you have good understanding of the following concepts, if not then this article is probably not for you. Here are the topics:</p><ul><li>A high level overview of how LMs work, how they are trained and fine tuned using techniques like Supervised Fine Tuning.</li><li>Kotlin, common android APIs and programming techniques.</li><li>Domain Specific Languages and basics of language and interpreter design.</li></ul><p>Still here? Then let’s dive deeper into the problem we are tackling and the solution and the steps we will take to get a working solution for this project.</p><h3>Problem Statement</h3><p>As we saw above, the functions have strict signatures which is nice as we want the LLM to provide us with all the inputs required for executing a function call on the device. But at the same time, it also poses a challenge: What if we want to add more actions, maybe multi-step actions. The current solution will be to get more training data, describe new functions, and define their implementation in the android application. Even if we were to actually do this, we don’t know for sure if a model like Function Gemma can handle so many different functions in its prompt. So, is there a better solution?</p><h3>Possible Solutions</h3><p>The simplest solution then might be to use a bigger model to generate data for the new actions to be added and try to fine tune Function Gemma with this new data. I feel like it might not be the best idea, given with only 7 functions (in the current dataset), the model’s performance is not that good, it calls incorrect functions a lot of times.</p><p>Ok then, maybe we just get rid of Function Gemma in favor of a larger (yet still small enough to run on a phone) model like <a href="https://huggingface.co/google/gemma-3n-E2B-it">Gemma-3N-E2B-it</a>? We sure can do that, and it might just as well work better than Function Gemma. The only problem is that Gemma-3N is not pre-trained with function calling capabilities, as Function Gemma was. So, maybe it can still learn to call the functions (given enough fine tuning data). But even after all that, we still end up with a model that can generate output from strictly the set of functions it has been trained on. I think we can do better.</p><h3>Proposed Solution</h3><p>Let’s take a step back, and think about the training data of Gemma-3N-E2B. We don’t know much about the data, but from the model card in HuggingFace we see a list of <a href="https://huggingface.co/google/gemma-3-1b-it">high level topics</a>, and the item of interest is code. It has been trained on code, and it can produce code. See where I am going with this?</p><p>What if we just do a very simple Domain Specific Language (DSL), that has python like syntax? So basically a small subset of python. This guarantees that it has knowledge about the syntax, all it needs is fine tuning for generating the program for performing actions using the DSL. This DSL can be designed to have some primitives and simple programming constructs, that can be combined to perform complex multi step operations on the device.</p><p>So, what will it take to create this?</p><ul><li>A dataset of course, containing user prompts and the DSL program. Basically, in the same format as the Mobile Actions dataset, but with a program at the end instead of a bunch of function calls.</li><li>A fine tuned Gemma-3N-E2B-it (or the <a href="https://huggingface.co/google/gemma-3n-E4B-it">E4B variant</a>) on this dataset.</li><li>Finally a basic DSL interpreter that runs on the phone, this can be added to the edge gallery android app that currently processes the functions defined in mobile actions dataset.</li></ul><h3>Plan of Action</h3><p>Now we have got a high level idea of the steps of the project. Let’s dive in a bit to create a plan of action.</p><p>First things first, before we can do any of the above steps, we need a DSL syntax. If this is designed poorly, we will end up with a bad model. It has to be simple and python-like and at the same time it has to be expressive enough so it provides the model the ability to take multi-step actions. This will be the focus of the next post.</p><p>Once we have the DSL, we can use a giant LLM to generate a bunch of programs and user prompts, which will make up our dataset. Since, the programs will be generated by an LM, we cannot trust it blindly. So, we will be writing a hacky interpreter for our DSL that can verify the generated code.</p><p>Next step would be using the dataset to fine tune Gemma-3N and get a LiteRT model file. This would follow pretty much from Google’s <strong>Fine-tune FunctionGemma 270M for Mobile Actions</strong> blog linked above.</p><p>Finally, we will make changes to the android app. This will involve writing the interpreter that can parse and run the programs generated by the model on device.</p><p>This concludes the introductory post that presented the idea. In the next one, we will dive into some language design principles and design our DSL for mobile actions. See you in the next one :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad1225829a2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I can make a python library too — Part 1]]></title>
            <link>https://medium.com/@sdharchou/i-can-make-a-python-library-too-part-1-29a33bf7d04c?source=rss-efb835d9b4a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/29a33bf7d04c</guid>
            <category><![CDATA[pypi]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Siddhartha Dhar Choudhury]]></dc:creator>
            <pubDate>Mon, 08 Aug 2022 03:36:37 GMT</pubDate>
            <atom:updated>2022-08-08T03:36:37.851Z</atom:updated>
            <content:encoded><![CDATA[<h3>I can make a python library too — Part 1</h3><p><em>How simple is it to make your own python library and share it on pypi.org?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HeN8TmS4nHgkKN3a-dQMuw.jpeg" /><figcaption><strong>Source: </strong><a href="http://analyticsvidhya.com/blog/2021/05/4-python-libraries-to-take-your-data-science-projects-to-the-next-level/">Analytics Vidhya</a></figcaption></figure><p>If you have worked with python then you must have come across pip — python’s awesome package manager. Pip eases the process of installing libraries, just do a pip install and you are good to go. If you have been working with python for a long time, then in your journey you must have used hundreds of third-party libraries, but have you ever thought about how these libraries are made and distributed using pip? Today I am here to answer this question for you. In this two-part article, we will make two different python libraries — one which can be used in your python scripts and another which can be used as a CLI application.</p><p>In this first article, we will tackle the first problem — creating a library that can be imported into other python scripts. Let’s start.</p><h3>The Tool</h3><p>To generate a new library project we will use a tool called <a href="https://github.com/frankhart2018/genpylib">GenPyLib</a>. GenPyLib is a command line tool that helps you develop a new library project. This saves you from creating the files required for all libraries, saves you some work, and introduces consistency in your projects.</p><p>Apart from helping you with basic template generation, GenPyLib also allows you to deploy your library to <a href="https://pypi.org/">PyPI</a>. PyPI is the repository from where pip pulls the required files to install a library in your system, in simple terms you can think of it as a GitHub for python libraries. GenPyLib eases this process by providing a single command to deploy your python library and make it accessible to millions of python users in PyPI.</p><p>Since GenPyLib is yet another python library, it can be installed using pip as:</p><pre>user@programmer~:$ pip install genpylib</pre><p>Let’s now understand the library we are going to create before we move on to the actual work.</p><h3>The Library</h3><p>Have you used the command wc ? It is a UNIX program to count the number of words (wc = word counter) in a file or output of another command. It has various options to count lines, words, and characters. For simplicity, we are going to implement just the part which counts number of words in a file. So, the task can be divided into three parts:</p><ol><li>Read the input file.</li><li>Count the number of words.</li><li>Return the count.</li></ol><p>We will be creating this in two ways:</p><ol><li>A library with a function called word_counter that takes in a file path and returns the number of words in that file (this will be done in this post).</li><li>A CLI application that takes the file path as a command line argument and returns the number of words to STDOUT, which is your terminal, mostly (we will do this in the next post).</li></ol><h3>The Instructions</h3><p>There are three steps to this:</p><ol><li>Generate a new project using GenPyLib.</li><li>Write your code.</li><li>Deploy to PyPI using GenPyLib.</li></ol><p>Let’s start with generating a new project, in your command line type:</p><pre>user@programmer~:$ genpylib -g</pre><p>or</p><pre>user@programmer~:$ genpylib --generate</pre><p>This will ask you for some inputs on the basis of which, your project will be generated:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*B7u5BY6gKwZASdw3D1JWPg.png" /><figcaption><strong>GenPyLib Generate</strong></figcaption></figure><p>We are calling our library — wclib. I entered some mock information in some of the fields. Let’s add support from python 3.6 to python 3.12. I selected lib because we want to create a library that can be imported, and finally pressed enter in the version field to select the default of 0.0.1-alpha0 . With this, we are done with generating our project, now let’s move inside the project directory (the directory will be named after the name of the project):</p><pre>user@programmer~:$ cd wclib/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*UzEYNaFFn2YkhGnpmiHN1w.png" /><figcaption><strong>Directory Contents</strong></figcaption></figure><p>This should be the file structure. It created a setup.py file which is actually used to install your library. There is a README for your library users. It also added a .gitignore and added some python related ignores. We also see a __init__.py file that contains the version of the library.</p><p>Have you ever checked the version of a library like this?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*vCn-BH_fS1b6JU6dixdklQ.png" /></figure><p>This actually makes use of the __version__ , a variable that is defined in the __init__.py file.</p><p>Now, that we have the project ready, let’s write some code. We will create a file inside the wclib directory (the one which contains __init__.py and not the outer level wclib directory). Let’s call it counter.py:</p><pre>user@programmer~:$ touch wclib/counter.py</pre><p>Add the following code to the file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f3882ef0a91d946d4cad3a8b3c5c725/href">https://medium.com/media/6f3882ef0a91d946d4cad3a8b3c5c725/href</a></iframe><p>This function does the following steps:</p><ol><li>Reads the contents of the file.</li><li>Gets individual lines.</li><li>Gets the number of words in each line.</li><li>Adds the number of words for all lines.</li><li>Returns the count.</li></ol><p>With this, we are done with step 2. Let’s move to the final step of our python library creation — deploying.</p><p><strong>Important Note: </strong>Please do not try to push this to pypi.org, as the library name is unique and someone might need this name much more than you. I have an alternative to the deploy command which you can run.</p><p>To deploy, we simply need to run:</p><pre>user@programmer~:$ genpylib -d</pre><p>or</p><pre>user@programmer~:$ genpylib --deploy</pre><p>This performs the following steps:</p><ol><li>Checks if your code requires any third-party libraries to work with, and if it does then it adds those libraries as dependencies in the install_requires argument passed to the setup() function in setup.py.</li><li>Builds your package and generates two files — a tarball with your code and a wheel file (which is what pip uses to install packages).</li><li>Tests your package (both the tarball and the wheel).</li><li>Pushes the package to pypi.org. For this, you need an account in pypi.org as it will ask you for your credentials in order to push to PyPI.</li></ol><p>This is the level of abstraction GenPyLib provides you. With this, you have successfully deployed your library to pypi.org.</p><p>An alternative to actually deploying is to mock the deployment process. The mock deployment involves steps 1–3 mentioned above but skips the part where the package is uploaded to pypi.org. You can do that using:</p><pre>user@programmer~:$ genpylib -m</pre><p>or</p><pre>user@programmer~:$ genpylib --mock</pre><p>With this, you are done. If you want to test out your library locally, just run:</p><pre>user@programmer~:$ python setup.py install</pre><p>This will install the library locally for you and then you can use it as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*GNbPUkJ_dl8Ui6m2MZLF7g.png" /><figcaption><strong>Use your library</strong></figcaption></figure><p>I hope you found this process easy enough and will be encouraged to share your code with others on pypi.org. Just make sure that something similar doesn’t exist already. Go ahead and share your awesome code with the world and help other python developers alongway, happy coding :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29a33bf7d04c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sane Argument Parsing in Rust]]></title>
            <link>https://medium.com/@sdharchou/sane-argument-parsing-in-rust-5e81752b2e8?source=rss-efb835d9b4a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e81752b2e8</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[Siddhartha Dhar Choudhury]]></dc:creator>
            <pubDate>Sun, 19 Jun 2022 06:55:55 GMT</pubDate>
            <atom:updated>2022-06-19T21:07:06.301Z</atom:updated>
            <content:encoded><![CDATA[<h4>The difficulties I faced while exploring Rust’s argument parsing libraries and my solution.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QzMfB7NA_V0IqGjX9yJxPA.jpeg" /><figcaption>Source: <a href="https://www.freecodecamp.org/news/command-line-for-beginners/"><strong>Free Code Camp</strong></a></figcaption></figure><p>In this article, I want to discuss argument parsing, the problems I faced while trying to find a good argument parsing library (or crate as they say in Rust land, I will use them interchangeably throughout), and the solution I came up with. Before I move on to the actual problem, let’s discuss the term “argument parsing”.</p><h3>What is Argument Parsing?</h3><p>If we are going to discuss argument parsing, we better start with command-line arguments. Command-line arguments are inputs passed to a program when it is run through the command line, everything that follows the name of your program is a command-line argument (it actually includes the name of the program too).</p><p>Moving on to the topic of our interest — argument parsing. Argument parsing simply means parsing the command line arguments passed, in a certain way so as to identify different parts of it. Confused? Don’t worry, let us consider an example from GCC (a popular C compiler):</p><pre>user@programmer~:$ gcc test.c -o test</pre><p>We can see that there are three different arguments here:</p><p>i) <strong>test.c: </strong>The path to the C file which is to be compiled</p><p>ii) <strong>-o: </strong>An input that tells GCC that the binary (or executable in windows) should have a certain name.</p><p>iii) <strong>test: </strong>The name of the binary</p><p>From the above example, it is clear that not all command-line arguments have the same purpose — they are used to mention the name of a file, as an input parameter, for the actual value of those parameters, or for setting flags. It is clear by now that there needs to be some parsing (structuring) done, in order to classify the various command-line arguments into different categories so that they can be easily handled in your program.</p><p>Now that we understand what argument parsing is, (and we are all on the same page) I want to talk a bit about the problem that I was facing.</p><h3>The Problem</h3><p>I have been fascinated by Rust for almost a year now, and have spent some time learning the language and building a few projects using it, but since I have not done anything serious in Rust yet I still consider myself a noob in it.</p><p>One day I came across a problem that required me to add certain flags and input parameters to the command line interface of the program. Since this was my first time tackling such a problem in Rust, I started finding crates for it (Rust has a great collection of libraries or crates at <a href="https://crates.io/">crates.io</a>) and going through blogs or StackOverflow threads.</p><p><strong>Disclaimer: </strong>The thought that I am presenting in the next paragraph is a personal thought, and you (the reader) may or may not agree with it. Maybe you do use those libraries and find them very easy to use.</p><p>Soon enough I did find two different crates that did the job, let’s call them A and B. I got started with A, tried to use it, and failed. Moved on to B, and the same results. But why? Am I a horrible programmer? (well maybe 😝), but the primary reason I found it difficult to use these libraries in my project was their terrible design and API. I was used to Python’s <a href="https://docs.python.org/3/library/argparse.html">argparse</a> (it is an awesome library, do check it out if you haven’t), which has a very intuitive syntax to add new variables and flags and parse those values. This is something that these libraries lacked, they had very contorted syntax.</p><p>I spent about 3–4 hours trying to get them to work, but to no use. Finally, I gave up. I thought there has to be a library that uses the beautiful API that Python’s argparse provides and so I set out to work on my solution.</p><h3>My Solution</h3><p>Since I absolutely needed the library and was well aware of argparse, I started writing my own argument parsing library. I called this — sargparse, which is short for Sane Argument Parse (the other libraries did drive me insane 😵‍💫). My first priority was to get input parameters to work, followed by flags. These were some things that I needed in my project. I spent the rest of the day, writing a parser to handle these cases. At the end of the day, I had a decent enough parser and I decided to share it with others using Rust’s seamless platform — <a href="https://crates.io/">crates.io</a>. Using the in-built cargo tool, it was super easy to publish the crate (check this <a href="https://doc.rust-lang.org/cargo/reference/publishing.html">link</a> out, if you don’t know how to publish your package to crates) to crates.io.</p><p>So, I got v0.1 out. But, then I realized, I needed in-place arguments (arguments that have a definitive position in a list of command-line arguments and which do not require an input parameter to be specified), I spent the next day working on it and I got v0.2 out. So, this was a short overview of how I spent my time writing the library, let’s get to the actual important stuff, installing the library and using it in your own projects.</p><h3>Getting started with sargparse</h3><p>As with every other Rust crate, all you have to do to install this is to add a single line in your Cargo.toml file’s dependency section:</p><pre>[dependencies]<br>sargparse = &quot;~0.2.2&quot;</pre><p>Make sure, you use at least 0.2.2 (that’s what the ~ before the version means).</p><p>Once, you have that in place, you are just three steps away from hassle-free argument parsing:</p><ol><li>Instantiate the parser:</li></ol><pre>use sargparse::{ArgumentParser, ArgumentType, InnerData};</pre><pre>let mut parser = ArgumentParser::new(None);</pre><p>2. Add your arguments to the parser:</p><pre>parser.add_argument(&quot;-i&quot;, &quot;--input&quot;, &quot;Input string for awesome program&quot;, true, None, ArgumentType::STR);</pre><p>3. Parse the arguments (into a HashMap):</p><pre>let args = parser.parse_args().unwrap();</pre><p>You can now use those arguments using:</p><pre>let input = args.get(&quot;input&quot;).unwrap().get_str();</pre><p><strong>Note: </strong>The method get_*() depends on the type of argument and returns data of that type accordingly.</p><p>Wasn’t that very easy? If you are a Python person, you might recognize this syntax. So, in just three very easy steps you are done with argument parsing.</p><p>If you found this interesting, you can check the project out:</p><ul><li><a href="https://github.com/frankhart2018/sargparse">GitHub</a></li><li><a href="https://crates.io/crates/sargparse">Crates.io Page</a></li><li><a href="https://github.com/frankhart2018/sargparse/blob/master/docs.md">Documentation</a></li></ul><h3>Concluding Remarks</h3><p>Again I would like to reiterate that I do not intend to demean other existing argument parsing libraries, it is just my personal opinion. I hope this library helps you in your projects too as much as it does in mine, happy coding :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e81752b2e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python and a generation of crippled software engineers]]></title>
            <link>https://medium.com/@sdharchou/python-and-a-generation-of-crippled-software-engineers-86b9da28c8d3?source=rss-efb835d9b4a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/86b9da28c8d3</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Siddhartha Dhar Choudhury]]></dc:creator>
            <pubDate>Sun, 29 May 2022 21:42:02 GMT</pubDate>
            <atom:updated>2022-06-16T23:30:51.432Z</atom:updated>
            <content:encoded><![CDATA[<h4>I know its hard to listen to, but you have to agree if it’s true</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WQOgJ6Wo7sVokUUkTk_KxQ.jpeg" /><figcaption>Source: <a href="https://www.pinterest.com/pin/368943394475315465/">Pinterest</a></figcaption></figure><h3>Disclaimer</h3><p>This post is not meant to spread hate or misinformation about the <strong>Python Programming Language</strong>. Neither is this post meant to hurt the sentiments of people using python. I personally love python and use it on a daily basis. This is just a viewpoint and not meant to inspire any thoughts. I have presented one view here, and one can make arguments for the opposing view too.</p><h3>Background</h3><p>Before we dive into the article, let us spend some time understanding the background of python (although most of you might already be familiar with the language).</p><p>Python is an interpreted scripting language that was developed in 1991 (the first public release) by <a href="https://en.wikipedia.org/wiki/Guido_van_Rossum"><strong>Guido Van Rossum</strong></a>. He created Python, using design ideas from a project that he was working on called <a href="https://en.wikipedia.org/wiki/ABC_(programming_language)"><strong>ABC</strong></a><strong> </strong>which was an interpreted language. He developed it as an intermediate solution to programming in C and writing shell scripts while working on the project called <a href="https://en.wikipedia.org/wiki/ABC_(programming_language)"><strong>Amoeba</strong></a><strong> </strong>which was a distributed operating system.</p><p>Since the early days of Python, it was designed with ease of use in mind. It was meant to be a programming language that people can use to write software faster with the use of syntax with high levels of abstraction. This meant letting go of control that C provided, but in certain use cases, this is what programmers really needed.</p><p>Today Python is used in a wide range of applications like Machine Learning (and Deep Learning), Backend development, Scientific Computing, and Data Analysis or Visualization. It has made its way to the list of most popular programming languages and enjoys a huge community of developers from all around the globe.</p><p>Now that we have a high-level overview of Python’s background. Let’s move on to understand why it gained so much popularity.</p><h3>Rise of Python</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B55KQgwoXvsrTD4xPFzzaA.png" /><figcaption>Python popularity according to TIOBE; Source: <a href="https://www.tiobe.com/tiobe-index/">TIOBE</a></figcaption></figure><p>The above graph is taken from <a href="https://www.tiobe.com/tiobe-index/">TIOBE’s index</a> on the popularity of programming languages. From this graph, we see that although Python was released to the public in 1991, it didn’t gain much popularity until 2001. Since 2001 Python has constantly been gaining popularity but, what led to this popularity?</p><h4>Ease of use</h4><p>Programming in Python or getting started with this language is pretty straightforward, greatly owing to its simple and easy-to-understand design choices and higher levels of abstraction. The language is so easy to dive into that at this point most schools consider Python as a viable option to introduce students to programming, as is evident from the syllabus of most popular Intro to Programming classes. The rich standard library adds to this, by providing popular data structures and algorithms. The inner workings of these concepts are abstracted away from the library user. Initially, this attracted people to the language, which brings us to the second reason for Python’s popularity.</p><h4>A plethora of third party libraries</h4><p>As people got interested in this language, they started writing third-party libraries which could be easily distributed to users using the native package manager called <strong>pip </strong>(short for Pip installs Packages). There is always a pretty good chance that there is a library for what you are trying to implement, written by someone who has already done the hard work so that you can just import it and use it in your application.</p><p>As this trend continued, more people started shifting to Python. This led to the formation of a huge community, wherein each sector works on a certain domain thus making it easier for the user to reach out, with the problem of their interest.</p><h4>Machine Learning</h4><p>Unlike the above reasons, this one is in fact an area of application. As Machine Learning (especially Deep Learning) grew in popularity, groups of people started working on packages and frameworks that help build these models with much ease. All the heavy math is implemented in these libraries and users just have to import and use them in their programs. The choice of Python for Machine Learning was pretty easy due to the above-mentioned reasons.</p><p>As the popularity of this field increased (mostly due to the fancy applications all over the internet), so did the popularity of Python and thus Python became the standard language to go to for ML models and applications. Compared to the earlier stages of ML/DL when people had to write complex parallel code and had to actually understand the algorithm and the math involved in order to implement these models, the same can be done today by using common frameworks like TensorFlow, PyTorch, or Jax in just 20–30 lines of code for most applications.</p><h3>Ok, we heard you but why is it crippling people?</h3><p>That is a good question. At this point, you might not see my point. Of course, it is a good choice and most people choose Python as their preferred language to code in. Today Python has made diving into programming much easier than ever before, and people across different industries have started programming in Python, this is definitely good right? Everyone is learning to program and solve their problems with computers, that is a delight isn’t it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*ba5gXp-FojD1eH5vLaODIg.jpeg" /><figcaption>Source: <a href="https://imgflip.com/memegenerator">Imgflip Meme Generator</a></figcaption></figure><p>Well, I believe the answer is yes and no.</p><p>Yes, because I believe that it has made programming much easier, and people can solve their own problems using this programming language. It has also made prototyping much easier, using the wide range of third-party and standard libraries thus getting things done much faster than ever before.</p><p>But hear me out, here are the reasons why I think Python is not good for us, and why is it crippling us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*wqrg63w-T-J3QEqcbEeRIA.jpeg" /><figcaption>Source: <a href="https://imgflip.com/memegenerator">Imgflip Meme Generator</a></figcaption></figure><h3>Why did I claim that Python is crippling us?</h3><h4>Lack of knowledge</h4><p>If you think about it, by using third-party libraries to get your job done in a language with much higher levels of abstraction and less control, you are heavily relying on the library to work correctly so that you can build your codebase on top of it. But are you actually learning anything about the algorithm that you are using?</p><p>Why learn these things when you can use libraries you may say. I would then argue that libraries do not always have the functionalities that you may wish for in your code, what will you do then? You will have to spend time reading about that topic and implement the thing yourself. Wouldn’t it be better if you were forced to learn the same at an earlier stage so that you would have saved time now completely or maybe would just have to check some minor implementation details?</p><h4>Security</h4><p>When you depend on someone’s code, there’s always a chance that their code has some security vulnerabilities which can affect your application in the long run. Does this mean that each time you want to write software, you should reinvent the wheel and write all the required algorithms yourself? Absolutely not, but distributing libraries has become so easy, thanks to <strong>pip, </strong>that people who might not have in-depth knowledge of the subject, can also publish their own package, which at times might have serious security issues. One such example is the recent <a href="https://logging.apache.org/log4j/2.x/security.html"><strong>Log4j vulnerabilities</strong></a><strong> </strong>(I am not claiming that it was written by incompetent engineers, it is just an example)<strong>.</strong></p><h4>Cost</h4><p>The ease of use of Python comes at a cost — it’s a very slow language as most interpreted languages are. This means if you have software written in Python, then the cost of distributing and maintaining it for users, is much higher as compared to compiled languages. This is because it would require much more computational resources in order to scale it to a point where it can be served to users with low latency.</p><h4>Inability to code in other languages</h4><p>If you are someone who started their journey in programming with Python, then (no offense) there’s a pretty good chance (although not 100%) that you cannot code in any other language (especially a compiled language). Even after trying too hard, you can decide against shifting to other languages. The primary reason behind this is the abstraction layer, since people get accustomed to working at those levels, they can never imagine having to do things manually (things that Python automated for you in the first place). This is what cripples you as a Software Engineer, who according to me should be someone capable of solving complex problems using programming, something which you cannot do with just Python.</p><h3>Concluding Remarks</h3><p>Finally, as I mentioned in the disclaimer up top, there are no hard feelings and I personally love Python. At the same time, I believe that Python is the worst choice when it comes to your first programming language, but is definitely a language worth keeping in your arsenal.</p><p>And as <a href="https://en.wikipedia.org/wiki/Bjarne_Stroustrup"><strong>Bjarne Stroustrup</strong></a><strong> </strong>(the creator of C++), says:</p><blockquote>Obviously, a professional should know several languages…</blockquote><blockquote>Good learning of foreign language and foreign culture is important, it helps you think and be a better person with programming languages, you become a better programmer, a better designer with the second language, and once you have got two, the way to five is not that long…</blockquote><p>I hope reading this article was worth your time. I would love to hear your comments. Happy learning :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86b9da28c8d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>