<?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 Raghav Mishra on Medium]]></title>
        <description><![CDATA[Stories by Raghav Mishra on Medium]]></description>
        <link>https://medium.com/@LaVieEstDure?source=rss-10190054dacb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7YFwTQX2VCnIxPCQ02kAKw.jpeg</url>
            <title>Stories by Raghav Mishra on Medium</title>
            <link>https://medium.com/@LaVieEstDure?source=rss-10190054dacb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 14:59:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@LaVieEstDure/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[What new Python programmers should know]]></title>
            <link>https://medium.com/@LaVieEstDure/what-new-python-programmers-should-know-9b5ecb2f492e?source=rss-10190054dacb------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b5ecb2f492e</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Raghav Mishra]]></dc:creator>
            <pubDate>Thu, 19 Jul 2018 07:51:25 GMT</pubDate>
            <atom:updated>2018-07-19T07:51:25.912Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the major challenges new programmers face is transitioning from learning the basics of their language of choice to learning how to think like a programmer and solve the problems presented to them.</p><p>However, to design good maintainable software, one must not only know how to program, but also be comfortable with their language of choice so they can <br>utilise the features it provides for writing good code. While there are plenty of guides and references for individual features that different languages provide, there are few places which list what you <em>should </em>learn.</p><h3>Idiomatic Python</h3><p>Python is a language which emphasises readability of code, which is partly what makes it a very popular language for beginners. Two contributing factors to Python’s friendly nature are <strong>PEP8 </strong>and <strong>The Zen of Python.</strong></p><p><a href="https://www.python.org/dev/peps/pep-0008/"><strong>PEP8</strong></a> is Python’s style guide which gives recommendations on syntax and formatting of code. It suggests how variables should be named, how much spacing to put where, what type of indentation to use and so on. Following the style guide makes it is easy for everyone to read your code, and for you to read their code, with the least amount of resistance. In the Python community, PEP8 is almost religiously followed so it is important to be familiar with it.</p><p>The <a href="https://www.python.org/dev/peps/pep-0020/"><strong>Zen of Python</strong></a><strong> </strong>is a set of guiding principles that are used as a reference both in deciding what is good and <em>idiomatic</em> Python code, and in the ongoing development of the language as a whole. For example it lists principles such as:</p><blockquote>Beautiful is better than ugly.</blockquote><blockquote>Special cases aren&#39;t special enough to break the rules</blockquote><blockquote>There should be one-- and preferably only one --obvious way to do it.</blockquote><p>These principles help you decide how to write code and help the core developers decide which features should and should not be added to Python, and in what form.</p><h3>Advanced Python features</h3><p>Programming languages, at least the most popular ones, have a lot of overlap in how they are written and the constructs they allow (if/else statements, loops, OOP, etc). Here are some features that are less likely to be shared between common languages and are essential to understanding Python code:</p><ul><li><strong>Dunder methods</strong> — Dunder methods (<strong>d</strong>ouble <strong>under</strong>score), also called special methods or magic methods, are a set of functions that Python recognises as “special” and processes in a unique way. They’re called dunder methods because their names are surrounded by double underscores. You may have learnt of some, for example __init__ for initialising an object of a class. There are many more. For example, __str__ is what is called when you call str() on that object and __add__ is what is called when you try to use + with that object. Defining these dunder methods allows you to give special behaviour to your custom objects. <br>[<a href="https://dbader.org/blog/python-dunder-methods">Further reading</a>]</li><li><strong>First class objects</strong> — In Python, everything is an object. This includes classes and functions. That means you can manipulate and pass around functions and classes just like everything else. This is often used for callback functions for applications like GUI and in decorators.<br>[<a href="https://medium.com/@durgaswaroop/functions-as-first-class-citizens-in-python-2e70cdc6e357">Further reading</a>]</li><li><strong>Decorators</strong> — Decorators are things you would tag your functions with to modify their behaviour. They are essentially functions that take other functions as arguments and return a new or modified function. For example, the Discord API library discord.py uses@client.event to mark functions that will be called on specific events. The following function will print “Ready!” as soon as your Discord API client is ready:<br>[<a href="https://realpython.com/primer-on-python-decorators/">Further reading</a>]</li></ul><pre>@client.event<br>async def on_ready():<br>    print(&#39;Ready!&#39;)</pre><ul><li><strong>Context managers</strong> — Context managers are objects that define enter and exit dunder methods. You use them using the with context_manager as name: syntax. You might have seen them when interacting with files. They allow an initialisation and exit routine to be run in a more isolated block, often allowing “cleanup” of some sort to occur. For example, in the case of interacting with files, the context manager with open() opens and closes the file automatically and cleanly. <br>[<a href="https://jeffknupp.com/blog/2016/03/07/python-with-context-managers/">Further reading</a>]</li><li><strong>Python packages</strong> — Python packages are a set of modules in a folder with an __init__.py file. Using the packaging format, you can create libraries and programs that are easier and more natural to interface with. <br>[<a href="https://docs.python.org/3/tutorial/modules.html#packages">Further reading</a>]</li></ul><h3>Project and package management</h3><p>Nobody likes reinventing the wheel, so programmers make packages for others to use. I’m sure many reading have already installed packages using pip. However, Python installations are fragile and as you install more things, both in your Python environment and out, things tend to break. One way Python developers fix this is by using <strong>virtual environments</strong>.</p><p>Virtual environments are separate isolated installations of Python that you use on a project-to-project basis for reproducibility of project environments. However, managing virtual environments and their installed packages was a painful task, so a higher level tool that combined the features of pip and the standard virtual environment module virtualenv for more natural project management was created. This is <a href="https://github.com/pypa/pipenv"><strong>Pipenv</strong></a>.</p><p>Pipenv allows creating projects whose dependencies are configurable with a single configuration file, making package management for a project much simpler. The config file keeps a list of packages and settings and automatically creates virtual environments which it syncs with the intended settings, installing anything necessary and making sure the versions used are always correct and compatible with the project.</p><p>[<a href="https://realpython.com/pipenv-guide/">Introduction to Pipenv</a>]</p><h3>Concurrency</h3><p>Considering how much Python is used for web development, online bots and similar applications, it is helpful to learn what <strong>concurrency</strong> is and how it is done in Python.</p><p>Concurrency is when two or more different tasks are running at the same time. That might mean processing of multiple similar requests for a server, or completely different tasks entirely. This might be in the form of the program switching between different tasks repeatedly so that neither is “waiting” for the other, or it might be in the form of the processor processing multiple things at once. The latter way, where multiple things are being processed at the same time, is called <strong>parallelism</strong>. There are 3 major ways of achieving concurrency in Python:</p><ul><li><strong>asyncio</strong> — asyncio is Python’s module for asynchronous programming, or “programming where things are not run in any particular order”. There is an “event loop” to which you give a list of “tasks”, and the event loop just runs the tasks again and again and the execution control is passed on to another piece of code if the current execution is “blocked” or waiting for something (e.g. waiting for a download to finish). asyncio is used extensively in web tasks, including frameworks like Flask, and API libraries like discord.py. Important to note, <em>asyncio does not allow parallelism</em>. This just allows you a way to organise different things happening at the same time without slowdowns due to wasted time waiting for things.<br>(If we’re being pedantic, asynchronous programming isnt concurrency, but it is often talked about as such and often used in similar circumstances)</li><li><strong>threading</strong> — Your CPU is made of different cores that can process data at the same time. Additionally if your CPU allows <em>hyperthreading </em>like an Intel i7, you may be able to have available even more <em>virtual</em> cores. <em>Threading</em> is how your operating system manages execution happening in different cores. The Python threading module provides an interface for your operating system’s threading interface.<br> <br>While this might make it sound like using threading would speed up your program since multiple cores would be running your program allowing for parallelism, that is not true for Python as it has an internal mechanism called the <strong>Global Interpreter Lock (GIL) </strong>which causes a Python process to only be able to run Python code in one thread at a time. This might seem like a confusing design decision but it’s not an actual problem. I’ll explore why it isn’t an issue in a later post.</li><li><strong>multiprocessing</strong> — Multiprocessing is Python’s interface for creating new Python processes. It allows you to make a new, independent instance of Python, make a copy of your data, and pass that data to the new instance. Since different processes are independent and their execution is managed by the OS, it <em>does allow parallelism </em>since the OS can schedule different processes to run in parallel on its own. On the other hand, creating new processes is generally slower than threads.</li></ul><p>There are often reasons to use one way of concurrency over another. For example, asyncio works best when your program’s speed is limited by things such as network input/output since it can switch between processing different things while it waits for requests to be downloaded. And since the GIL limits only the execution of <em>Python</em> code, you can in fact use threading to speed up your code if its speed is limited by external code you’re calling into. For example, you can use threading to speed up numerical computation done by a library like numpy, since the computation in that case is happening in <em>external</em> code written in faster languages like C and FORTRAN.</p><h3>Further topics</h3><p>Although there are certainly more advanced things you may want to learn to become a master Pythonista that I wont go into here, here is a non-exhaustive list of things you could explore:</p><ul><li><strong>CPython specifics/C API</strong> — Specific implementations of things in CPython (the default implementation of Python written in C) which you can keep in mind for better development. How to write modules in C for Python for extra speed and other reasons.</li><li><strong>Other Python implementations</strong> — Cython, Pypy, Jython and other implementations which can do things like generate C code from Python, use Just-in-time compilation for speedups, run on language virtual machines for effortless interaction between different languages, and so on.</li><li><strong>Python compilation process </strong>— Python is often considered an “interpreted” language while Java is considered a “compiled” language despite there being little difference in process between the two (excluding JIT which not part of the JVM standard). Python is compiled into Python bytecode which is then immediately run by the Python VM. <a href="http://www.pgbovine.net/cpython-internals.htm">See more here</a></li><li><strong>Python in *nix </strong>— Python is often used in Linux/*nix programs and the process of distribution there is usually completely different from PyPa/pip way of installing things. You can learn how Python plays into *nix systems by learning about topics like debian (.deb) packaging, shebangs, pipes, and other related concepts which are used extensively in OS tools.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b5ecb2f492e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>