<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Lord_Sarcastic</title>
    <description>The latest articles on DEV Community by Lord_Sarcastic (@lordsarcastic).</description>
    <link>https://dev.to/lordsarcastic</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F315507%2F732ac2af-ffc7-4381-a31d-ecaf11190eeb.jpg</url>
      <title>DEV Community: Lord_Sarcastic</title>
      <link>https://dev.to/lordsarcastic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lordsarcastic"/>
    <language>en</language>
    <item>
      <title>Rust macros in few sentences</title>
      <dc:creator>Lord_Sarcastic</dc:creator>
      <pubDate>Tue, 28 Jun 2022 04:37:29 +0000</pubDate>
      <link>https://dev.to/lordsarcastic/rust-macros-in-few-sentences-5fnb</link>
      <guid>https://dev.to/lordsarcastic/rust-macros-in-few-sentences-5fnb</guid>
      <description>&lt;h2&gt;
  
  
  Table (List?) of content
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Claimers and disclaimers

&lt;ul&gt;
&lt;li&gt;What this article is about&lt;/li&gt;
&lt;li&gt;What this article is not about&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Let's go (Actual content of the article)&lt;/li&gt;
&lt;li&gt;But then... (Types of macros)

&lt;ul&gt;
&lt;li&gt;Declarative macros&lt;/li&gt;
&lt;li&gt;Procedural macros&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Where else can I see macros?&lt;/li&gt;
&lt;li&gt;Thank you&lt;/li&gt;
&lt;li&gt;Best in inclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, you've been writing Rust for a few days or so; or even a few weeks or months, or years, or decades. But! you've heard macros and have been burning to know what it's all about.&lt;/p&gt;

&lt;h2&gt;
  
  
  Claimers and disclaimers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What this article is about
&lt;/h3&gt;

&lt;p&gt;It just explains what macros are in Rust with a few references&lt;/p&gt;

&lt;h3&gt;
  
  
  What this article is not about
&lt;/h3&gt;

&lt;p&gt;It does not:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Teach you how to create macros or how to use them&lt;/li&gt;
&lt;li&gt;Lead you to a blissful world of Rust including the use of macros&lt;/li&gt;
&lt;li&gt;Contain expressive code examples of macros&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Let's go
&lt;/h2&gt;

&lt;p&gt;Macros are simply a feature of Rust (if not the most powerful) that allows you to write code that writes other code. I'll show you what I mean:&lt;/p&gt;

&lt;p&gt;So, let's say I wanted to write a code that ensure that when invoked on an expression or assignment or statement, would print "Hello world" before the operation is carried out; I can write a special function that would insert the line for "Hello world" in a safe place within that expression, assignment or statement. Code example in pseudocode (why? because it will take long for me to explain the actual code in Rust and I'm sure you read the Disclaimer section):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# define a macro
macro_rules hello_world (thing: expression, assignment or statement) -&amp;gt; Valid_Code {
    var final_code = Valid_Code();
    final_code.append('print("Hello, World!")');
    final_code.append(thing);
    return final_code.to_valid_code();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I can use my macro like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hello_world!(
    add(4, 8)
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and it will print "Hello, World!" before executing the code.&lt;/p&gt;

&lt;p&gt;You get the concept?&lt;/p&gt;

&lt;p&gt;Now if you've got pretty good eye, you'll say "That exclamation mark after &lt;code&gt;hello_world&lt;/code&gt; is familiar, cos I've used it to pipe content to stdout using &lt;code&gt;println!&lt;/code&gt;". Yeah, that's because &lt;code&gt;println!&lt;/code&gt; is a macro...&lt;/p&gt;

&lt;h3&gt;
  
  
  But then...
&lt;/h3&gt;

&lt;p&gt;Actually, there are two types of macros you'll see:&lt;/p&gt;

&lt;h4&gt;
  
  
  Declarative macros
&lt;/h4&gt;

&lt;p&gt;This macro tends to match against patterns and replace the code you've dropped with other code. An example of this macro is the &lt;code&gt;vec!&lt;/code&gt; macro.&lt;/p&gt;

&lt;h4&gt;
  
  
  Procedural macros
&lt;/h4&gt;

&lt;p&gt;These macros (there are three types of them) are more magical and tend to accept some code as an input, operate on that code, and produce some code as an output (as quoted from the Rust book). They are the ones you impose on structs like &lt;code&gt;#[derive()]&lt;/code&gt; or the &lt;code&gt;#[tokio::main]&lt;/code&gt; we use when using the &lt;a href="https://actix.rs"&gt;Actix&lt;/a&gt; framework.&lt;/p&gt;

&lt;p&gt;Hoping your imaginations are as wild as Abraham the Mage in The Secrets of the Immortal (very nice book I'm reading), you'll begin to see limitless ways macros can be used.&lt;/p&gt;

&lt;p&gt;You can literally add any feature to structs, add methods to structs, attributes and so on.&lt;br&gt;
You can make work easier for people when using piece of functionality like they did when &lt;a href="https://github.com/graydon"&gt;Graydon's&lt;/a&gt; boys gave we Rustaceans &lt;code&gt;vector = vec![1, 2, 3, 4]&lt;/code&gt; to use instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let vector = Vec::new();
vector.push(1);
vector.push(2);
vector.push(3);
vector.push(4);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Where else can I see macros?
&lt;/h2&gt;

&lt;p&gt;They are everywhere. From that &lt;code&gt;#[derive()]&lt;/code&gt; syntax you see to the &lt;code&gt;println!&lt;/code&gt; you tend to use instead of an actual debugger. The Rust Book talks &lt;a href="https://doc.rust-lang.org/book/ch19-06-macros.html"&gt;more extensively&lt;/a&gt; about macros and you'll learn to use them more and creating them by reading that book.&lt;br&gt;
You can also read &lt;a href="https://veykril.github.io/tlborm/"&gt;The Little Book of Rust Macros&lt;/a&gt; to shit yourself on macros.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank you
&lt;/h2&gt;

&lt;p&gt;Do this by liking and sharing this article with your handsome and beautiful friends.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best in inclusion
&lt;/h2&gt;

&lt;p&gt;Yeah, I know the "bold of me to assume people define friends with articles such as 'handsome' and 'beautiful'". I was hoping to use a &lt;code&gt;compliment_someone!&lt;/code&gt; macro there, but you'll need to read the link I put up there to understand it.&lt;/p&gt;

&lt;p&gt;San kyo :fire&lt;/p&gt;

</description>
      <category>rust</category>
      <category>todayilearned</category>
      <category>functional</category>
    </item>
    <item>
      <title>Digital images: How images work</title>
      <dc:creator>Lord_Sarcastic</dc:creator>
      <pubDate>Wed, 22 Jun 2022 19:53:22 +0000</pubDate>
      <link>https://dev.to/lordsarcastic/digital-images-how-images-work-586h</link>
      <guid>https://dev.to/lordsarcastic/digital-images-how-images-work-586h</guid>
      <description>&lt;p&gt;Whole images on the screen hold little or no significance compared to the everyday objects you see, digital images hold much water among the wonders of computers. We'll basically be looking at how images work in this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pixels (The phone copied the concept not the other way round)
&lt;/h2&gt;

&lt;p&gt;So, pixels are the tiniest bit of controllable element on a display or I'd say an image. It's a hardware component on your screen (I'll show you later). So images are made up of pixels. Perhaps you've heard of the term "pixelated image" or when you refer to an images as being pixelated; well when you look at such images, you find it minutely split into neat (in my opinion) boxes of color.&lt;br&gt;
While this may fascinate you if you're a weak mortal, pixels actually look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2gpyrgwwop3nn7z2xuym.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2gpyrgwwop3nn7z2xuym.jpeg" alt="a close up look of a pixel"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes, you saw red, green and blue rectangles.&lt;/p&gt;
&lt;h3&gt;
  
  
  What are pixels made of
&lt;/h3&gt;

&lt;p&gt;If you ever wrote CSS and specified colors using RGB values, this may strike a chord in the depths of your vain soul. In CSS, you do stuff like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.some-glorified-text-no-one-will-read&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What this does on a lower level is specify the &lt;em&gt;quantity&lt;/em&gt; of red, green and blue colors on each pixel that makes up the text with such wonderful class.&lt;br&gt;
Pixels are really just these three lights and every colour (British English, please) is a product of a permutative combination of these three.&lt;br&gt;
I'm tired, so you should read up on CMYK &lt;a href="https://www.techtarget.com/whatis/definition/CMYK-cyan-magenta-yellow-key" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The intensities
&lt;/h3&gt;

&lt;p&gt;To produce each color, each of these &lt;em&gt;bulbs&lt;/em&gt; are given a number mostly between 0 and 255 (255 because binary - I shouldn't tell you everything...). This then produces the venerable colours that you see on your screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of images
&lt;/h2&gt;

&lt;p&gt;I cringe, quite intensely at my use of the word "types" cos it doesn't seem to me that way, but I have little say.&lt;br&gt;
On the abstracted side, images... Lemme explain:&lt;br&gt;
Abstracted in the sense that: "on a higher level", "on a higher power" (yes it's from Coldplay), "on the user-facing side of things";&lt;br&gt;
So, "On the abstracted side, images" are represented in beatiful formats you'd recognize. I'll touch just four of them, because there are four elements in Avatar: The Last Airbender; and I love it. &lt;a href="https://en.wikipedia.org/wiki/Image_file_format" rel="noopener noreferrer"&gt;This is a link&lt;/a&gt; if you're greedy to know other formats. The four are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JPEG&lt;/li&gt;
&lt;li&gt;PNG&lt;/li&gt;
&lt;li&gt;GIF&lt;/li&gt;
&lt;li&gt;Vector Images.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They would sound familiar except you've never touched a phone before. These exist due to different tradeoffs needed to be made on the images and maybe for the fun of it. This ranges from size vs quality, compression benefits and the sorts.&lt;/p&gt;

&lt;h3&gt;
  
  
  JPEG (I hate it when Dillion calls it "JPENGS")
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://twitter.com/iamdillion" rel="noopener noreferrer"&gt;This&lt;/a&gt; is Dillion and he calls it "JPENGS"; however, JPEG is an acronym for Joint Photographic Experts Group, a group of nerds who love images.&lt;br&gt;
The JPEG format is the most popular of all image formats and is usually the one you post every sunday. Its main focus is on giving the flexibility between image size and quality. With this, JPEG images have a maximum allowed resolution of 65,535 x 65,535 pixels. It has an extension of .jpeg or .jpg. There are a million others, but brevity &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  PNG
&lt;/h3&gt;

&lt;p&gt;This is on the layman side identical to JPEG format, except in the RGB representation, it has an extra 'A' to it referred to as 'Alpha Channel' (remember RGBA in CSS?). This 'A' has to do with transparency of an image. This means that while you can have an image with a transparent background with PNGs, you can't have such with JPEG images. By the way, it is legal to pronounce 'PNG' as 'Ping. Actually, non-rgb formats are not allowed in PNG, so bye-bye CMYK (it's not even fine to pronounce in the first place). It's extension is .png.&lt;/p&gt;

&lt;h3&gt;
  
  
  GIFs
&lt;/h3&gt;

&lt;p&gt;GIF is an image format that literally gives you a movie but with images. If you ever saw those images that moves on Whatsapp (well, I prefer stickers), you're seeing a GIF in action. GIFs are image formats that have animation support, except you're limited in the number of colours you can use, namely 256 (yes, binary).&lt;br&gt;
This is a GIF:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjm2e3yo7oaidc3vca08q.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjm2e3yo7oaidc3vca08q.gif" alt="A GIF of a mouse walking"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Vector Images
&lt;/h3&gt;

&lt;p&gt;Rather than deal with pixels, vector images are based off calculations. This means the position of each content in the image is actually calculated dynamically so you can have infinite pixels for one image. This means that you can scale up a vector image without losing quality. They are generally used for icons and fonts on this page you're reading.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cooking images
&lt;/h2&gt;

&lt;p&gt;Well, this section refers to image manipulation and stuffs you could do with images. I've outlined three here:&lt;/p&gt;

&lt;h3&gt;
  
  
  Cropping
&lt;/h3&gt;

&lt;p&gt;If an image is too big or if there are some parts you don't want to show, you can crop it. Cropping will remove sections of the image and focus attention on other parts of your picture. It's like amputation but for images, and there's no blood. Only unhappy pixels.&lt;/p&gt;

&lt;h3&gt;
  
  
  Contrast
&lt;/h3&gt;

&lt;p&gt;Changing the contrast will make the image duller or more vibrant. Changing the brightness will make the image lighter or darker. You can manipulate the contrast of an image making it look better through contrast. Check your favourite photo editor for this option. It's quite neat stuff.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scaling
&lt;/h3&gt;

&lt;p&gt;Sometimes you want to resize an image, which means making it bigger or smaller. Pixel-based images can be made smaller but when you increase the size they will lose quality and pixelate. This is because scaling up a pixel is quite dicey and would show the individual colors in the boxes as they are. I'm sure you don't like it. Vector graphics can be resized without any change in quality.&lt;/p&gt;

&lt;h2&gt;
  
  
  Image compression
&lt;/h2&gt;

&lt;p&gt;Image compression is really just reducing the size of images. I use a Redmi Note 10 Pro and images sometimes get up to 15 - 20 MB, especially with good lighting. This is an evil thing and exorcism does not work so, they invented image compression for my sake.&lt;br&gt;
There are two types (I have mood swings, so they created two):&lt;/p&gt;

&lt;h3&gt;
  
  
  Lossy compression
&lt;/h3&gt;

&lt;p&gt;Lossy compression works by removing some of the data in the image binary. The quality of the file will be reduced. If you're not so concerned about quality, you'd want to use this form of compression.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lossless compression
&lt;/h3&gt;

&lt;p&gt;Lossless compression works by rewriting the data so it is stored more efficiently. Read up on data compression &lt;a href="https://www.techtarget.com/searchstorage/definition/compression" rel="noopener noreferrer"&gt;here&lt;/a&gt;. The quality of the file will stay the same. In this case, you can be rest assured your body parts will remain intact in the image. However, not all image formats supports this type.&lt;/p&gt;

&lt;h2&gt;
  
  
  Other fun stuffs about images you'd want to know
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A video is essentially lots of images shown in a small frame of time. They are called frames. The more frames per second, the smoother the video… Play games more, you’ll see these stuffs&lt;/li&gt;
&lt;li&gt;Filters on apps such as Tiktok (such a lovely creation) and Snapchat (such despicable thing) are made by simply solving calculus with pixels. No time to explain, you should have listened in maths class.&lt;/li&gt;
&lt;li&gt;You can manipulate your own images too. Check out the Pillow library in Python to see how you can do stuffs like these.&lt;/li&gt;
&lt;li&gt;Resolution is usually how many pixels you have per metric unit… See DPI and MPs&lt;/li&gt;
&lt;li&gt;You can send images from one device to another. Surprising, no?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Some....body
&lt;/h2&gt;

&lt;p&gt;So, &lt;a href="https://www.linkedin.com/in/abiodun-adebowale-97aa7978/" rel="noopener noreferrer"&gt;Abiodun&lt;/a&gt;, a venerable colleague at &lt;a href="https://formpl.us" rel="noopener noreferrer"&gt;Formplus&lt;/a&gt;, seeing my activities concerning images, enlightened me on signal processing and dropped resources you'd love.&lt;br&gt;
Now, you may have wondered how Google Meet knows where your head is so they'll blur your background. Well, it has to do with those mathematics we all hated in school: matrixes, laplace transforms and (literal tears here) calculus things. With algorithms, computers are able to detect images and object in the context of another image. If you're interested in the how a wonderful algorithm like &lt;a href="https://en.wikipedia.org/wiki/Haar_wavelet" rel="noopener noreferrer"&gt;Haar's Transform&lt;/a&gt;, can be used for face detection and object detections, look &lt;a href="https://towardsdatascience.com/face-detection-with-haar-cascade-727f68dafd08" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;br&gt;
Love Python and want to see some other algos? &lt;a href="https://neptune.ai/blog/image-processing-python" rel="noopener noreferrer"&gt;here are some of them&lt;/a&gt;.&lt;br&gt;
Lastly, on scaling images and compression, Fourier Trasform (I'm sorry, I also had PTSD from seeing this too) is useful and you can &lt;a href="https://docs.opencv.org/4.x/de/dbc/tutorial_py_fourier_transform.html" rel="noopener noreferrer"&gt;see its applications&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;Now, child, I have shown you the best of my knowledge on images, formats and types, how to cook them and how to serve them.&lt;br&gt;
This blog post is my first in months and only due to a presentation I made on images. &lt;a href="https://docs.google.com/presentation/d/1uR198lNz0XiJunzc_IQxV0Y_omzS645VRev2R8Ey0-k/edit?usp=sharing" rel="noopener noreferrer"&gt;These are the slides&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you want to know about Isaac, a fellow who is usually a core individual in my articles, read my previous article on &lt;a href="https://dev.to/lordsarcastic/whats-that-args-stuff-in-python-emh"&gt;What's that *args stuff in Python&lt;/a&gt;&lt;/p&gt;

</description>
      <category>images</category>
      <category>python</category>
      <category>programming</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>What's that *args stuff in Python?</title>
      <dc:creator>Lord_Sarcastic</dc:creator>
      <pubDate>Thu, 14 Oct 2021 03:10:39 +0000</pubDate>
      <link>https://dev.to/lordsarcastic/whats-that-args-stuff-in-python-emh</link>
      <guid>https://dev.to/lordsarcastic/whats-that-args-stuff-in-python-emh</guid>
      <description>&lt;p&gt;We've all called functions or methods of a class and then we see our editor show stuffs like so:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx8fc76sequyjy00nfsir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx8fc76sequyjy00nfsir.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The focus is on &lt;code&gt;*values&lt;/code&gt; part of the picture.&lt;/p&gt;

&lt;p&gt;Most times, we just use the thing and go our way.&lt;/p&gt;

&lt;p&gt;In this post, we'll see the purpose of that asterisk stuff (usually called &lt;code&gt;*args&lt;/code&gt;) and how to use it to eliminate boredom and reduce tension in our Python functions and methods.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;Y'all remember &lt;a href="https://blog.lordsarcastic.dev/eliminate-boredom-and-reduce-tension-with-abstract-models-in-django" rel="noopener noreferrer"&gt;Isaac&lt;/a&gt;? Well, he's got a problem here.&lt;/p&gt;

&lt;p&gt;Isaac has been employed by &lt;a href="https://en.wikipedia.org/wiki/Genghis_Khan" rel="noopener noreferrer"&gt;Genghis Khan&lt;/a&gt;, one of the &lt;a href="https://qr.ae/pGJ4Nm" rel="noopener noreferrer"&gt;greatest men the world will ever see&lt;/a&gt;, to automate the process of ending the lives of his enemies.&lt;/p&gt;

&lt;p&gt;This is Isaac's second serious job and he is ready to impress the Emperor of the Mongol Empire, so he creates an &lt;code&gt;dispatch_foe&lt;/code&gt; function that accepts a list of names of people and then reduce pollution by &lt;em&gt;doing what is necessary&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;He churns a function like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from GenghisKhan.actions import kill

def dispatch_foe(name: str) -&amp;gt; bool:
    success: bool = kill(name) # ends the life

    return success
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The issue
&lt;/h2&gt;

&lt;p&gt;Calling this function on lots of people involves doing something like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for name in list_of_names:
    dispatch_foe(name)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This could be quite laborious for the soldiers involved and only does the dirty work for them. It does not really automate lots.&lt;/p&gt;

&lt;h2&gt;
  
  
  A small solution
&lt;/h2&gt;

&lt;p&gt;Well, Isaac then decides to make his function accept a list of the names and then do the rest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from typing import List
from GenghisKhan.actions import kill

def dispatch_foe(names: List) -&amp;gt; bool:
    success: bool = True
    for name in names:
        success = success and kill(name) # tells us if and only if everyone died

    return success
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and we can call &lt;code&gt;dispatch_foe&lt;/code&gt; like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# people who we both share mutual hate
enemies = ["Erons", "Victor Aiyeola", "Davidemi"]

# test to confirm that they were successfully dispatched
assert True is dispatch_foe(enemies)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  An actual solution (The why)
&lt;/h2&gt;

&lt;p&gt;While Isaac's solution works, it is stupid. Why? Simply because if we accept it, I'll never be able to teach you what &lt;code&gt;*args&lt;/code&gt; does. That means you'll wallow in complete ignorance till the end of your life span.&lt;/p&gt;

&lt;p&gt;This has a dangerous effect. In the event the life of someone can only be saved by &lt;code&gt;*args&lt;/code&gt;, our refusal to reject Isaac's answer will spell the end of that person who may be a key soul to solving world hunger and therefore lead to millions and billions of deaths. This is why we always have to reject Isaac's first solution to solving any problem.&lt;/p&gt;

&lt;p&gt;Actually... lol&lt;/p&gt;

&lt;p&gt;Most times, you'd want your function to accept a variable number of arguments without specifying a default. &lt;code&gt;*args&lt;/code&gt; is a beautiful and pythonic way to do that.&lt;/p&gt;

&lt;p&gt;So we'd use it instead of lists or tuples or dictionaries (ah, there's a trick to this one, I'll write an article on it someday) or sets or arrays or vectors or linked lists or doubly linked lists or triply linked lists or quadruply linked lists or ...&lt;/p&gt;

&lt;h2&gt;
  
  
  An actual solution (The real stuff, without ment attached)
&lt;/h2&gt;

&lt;p&gt;So, we'll rework Isaac's solution so soldiers can pass as many enemies as possible without having to pack them into a list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from typing import Sequence
from GenghisKhan.actions import kill

def dispatch_foe(*names: Sequence[str]) -&amp;gt; bool:
    success: bool = True
    for name in names:
        success = success and kill(name) # tells us if and only if everyone died

    return success
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and we can call our function in different ways like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# 'do' Erons alone
assert True is dispatch_foe("Erons")

# 'do' Erons and someone else
assert True is dispatch_foe("Erons", "Someone else")

# 'do' people who hate me
assert True is dispatch_foe("Erons", "Davidemi", "Victor Aiyeola")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The end
&lt;/h2&gt;

&lt;p&gt;And there, little mortal one, is an elegant solution to Isaac's problem. Genghis khan did use Isaac's solution for solving the problem of enemies. Unfortunately, Isaac's name isn't in the history books. Yeah because some organizations and some successful products don't give their engineers enough praise.&lt;/p&gt;

&lt;p&gt;It's important to know that the '*' character was introduced by &lt;a href="https://www.python.org/dev/peps/pep0448/" rel="noopener noreferrer"&gt;PEP448&lt;/a&gt; and is usually referred to as iterable unpacking operator.&lt;/p&gt;

&lt;p&gt;Know also, that the usage of &lt;code&gt;*args&lt;/code&gt; and &lt;code&gt;**kwargs&lt;/code&gt; (we'll learn this later) can make debugging quite evil. So you'd want to watch your back whilst using them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Disclaimer
&lt;/h2&gt;

&lt;p&gt;There is no &lt;code&gt;GenghisKhan&lt;/code&gt; module implemented anywhere in the Python standard library or Pypi index or anywhere. No murders were committed in the course of this code and my &lt;em&gt;enemies&lt;/em&gt; are excellent engineers with happy jobs (I don't have one, so I don't like them at all).&lt;/p&gt;

&lt;p&gt;Also, there is no proof that Genghis Khan actually asked Isaac to write this function. I must have written this article while dreaming.&lt;/p&gt;

&lt;h2&gt;
  
  
  The actual end
&lt;/h2&gt;

&lt;p&gt;May the force of the snaky language dwell richly in your soul and may you find what is that good, pleasing and perfect will of The One Above All.&lt;/p&gt;

</description>
      <category>python</category>
      <category>functional</category>
    </item>
  </channel>
</rss>
