<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Renan Moura &#8211; Software Engineering</title>
	<atom:link href="https://renanmf.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://renanmf.com/</link>
	<description>Software development, machine learning</description>
	<lastBuildDate>Sun, 16 Apr 2023 18:11:30 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.3</generator>

<image>
	<url>https://renanmf.com/wp-content/uploads/2020/03/cropped-android-chrome-512x512-2-32x32.png</url>
	<title>Renan Moura &#8211; Software Engineering</title>
	<link>https://renanmf.com/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Subtracting years from a date in Python</title>
		<link>https://renanmf.com/subtracting-years-from-a-date-in-python/</link>
		
		<dc:creator><![CDATA[Renan Moura]]></dc:creator>
		<pubDate>Tue, 15 Feb 2022 11:35:15 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://renanmf.com/?p=4070</guid>

					<description><![CDATA[<p>The easiest way to subtract years from a date in Python is to use the dateutil extension. Install it with pip: pip install python-dateutil The relativedelta object from the dateutil.relativedelta module allows you to subtract any number of years from a date object. In this example I always take the current date using the date.today() [&#8230;]</p>
<p>The content <a href="https://renanmf.com/subtracting-years-from-a-date-in-python/">Subtracting years from a date in Python</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The easiest way to subtract years from a date in Python is to use the <a href="https://dateutil.readthedocs.io/en/stable/">dateutil</a> extension.</p>
<p>Install it with pip:</p>
<pre><code>pip install python-dateutil</code></pre>
<p>The <code>relativedelta</code> object from the <code> dateutil.relativedelta</code> module allows you to subtract any number of years from a date object.</p>
<p>In this example I always take the current date using the <code>date.today()</code> method.</p>
<p>Then I set a <code>relativedelta</code> of 2 years and subtract it from <code>current_date</code>.</p>
<pre><code class="language-python">from datetime import date
from dateutil.relativedelta import relativedelta

current_date = date.today()

print(current_date)

future_date = current_date - relativedelta(years=2)

print(future_date)</code></pre>
<pre><code>2022-02-15
2020-02-15</code></pre>
<p>You can also check:</p>
<ul>
<li><a href="https://renanmf.com/subtract-days-from-date-python/">How to subtract days from a date in Python</a> </li>
<li><a href="https://renanmf.com/adding-days-to-a-date-python/">Adding days to a date in Python</a></li>
</ul>
<h2>Watch this on Youtube</h2>
<p><iframe width="560" height="315" src="https://www.youtube.com/embed/TJt60C1HBbg" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></p>
<p>The content <a href="https://renanmf.com/subtracting-years-from-a-date-in-python/">Subtracting years from a date in Python</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Adding years to a date in Python</title>
		<link>https://renanmf.com/adding-years-to-a-date-in-python/</link>
		
		<dc:creator><![CDATA[Renan Moura]]></dc:creator>
		<pubDate>Tue, 15 Feb 2022 11:30:17 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://renanmf.com/?p=4055</guid>

					<description><![CDATA[<p>The easiest way to add years to a date in Python is to use the dateutil extension. Install it with pip: pip install python-dateutil The relativedelta object from the dateutil.relativedelta module allows you to add any number of years to a date object. In this example I always take the current date using the date.today() [&#8230;]</p>
<p>The content <a href="https://renanmf.com/adding-years-to-a-date-in-python/">Adding years to a date in Python</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The easiest way to add years to a date in Python is to use the <a href="https://dateutil.readthedocs.io/en/stable/">dateutil</a> extension.</p>
<p>Install it with pip:</p>
<pre><code>pip install python-dateutil</code></pre>
<p>The <code>relativedelta</code> object from the <code> dateutil.relativedelta</code> module allows you to add any number of years to a date object.</p>
<p>In this example I always take the current date using the <code>date.today()</code> method.</p>
<p>Then I set a <code>relativedelta</code> of 2 years and add it to the <code>current_date</code>.</p>
<pre><code class="language-python">from datetime import date
from dateutil.relativedelta import relativedelta

current_date = date.today()

print(current_date)

future_date = current_date + relativedelta(years=2)

print(future_date)</code></pre>
<pre><code>2022-02-15
2024-02-15</code></pre>
<p>You can also check:</p>
<ul>
<li><a href="https://renanmf.com/subtract-days-from-date-python/">How to subtract days from a date in Python</a> </li>
<li><a href="https://renanmf.com/adding-days-to-a-date-python/">Adding days to a date in Python</a></li>
</ul>
<p>The content <a href="https://renanmf.com/adding-years-to-a-date-in-python/">Adding years to a date in Python</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to subtract months from a date in Python</title>
		<link>https://renanmf.com/how-to-subtract-months-from-a-date-in-python/</link>
		
		<dc:creator><![CDATA[Renan Moura]]></dc:creator>
		<pubDate>Tue, 15 Feb 2022 11:25:32 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://renanmf.com/?p=4064</guid>

					<description><![CDATA[<p>The easiest way to subtract months from a date in Python is to use the dateutil extension. Install it with pip: pip install python-dateutil The relativedelta object from the dateutil.relativedelta module allows you to subtract any number of months from a date object. In this example I always take the current date using the date.today() [&#8230;]</p>
<p>The content <a href="https://renanmf.com/how-to-subtract-months-from-a-date-in-python/">How to subtract months from a date in Python</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The easiest way to subtract months from a date in Python is to use the <a href="https://dateutil.readthedocs.io/en/stable/">dateutil</a> extension.</p>
<p>Install it with pip:</p>
<pre><code>pip install python-dateutil</code></pre>
<p>The <code>relativedelta</code> object from the <code> dateutil.relativedelta</code> module allows you to subtract any number of months from a date object.</p>
<p>In this example I always take the current date using the <code>date.today()</code> method.</p>
<p>Then I set a <code>relativedelta</code> of 2 months and subtract it from <code>current_date</code>.</p>
<pre><code class="language-python">from datetime import date
from dateutil.relativedelta import relativedelta

current_date = date.today()

print(current_date)

future_date = current_date - relativedelta(months=2)

print(future_date)</code></pre>
<pre><code>2022-02-15
2021-12-15</code></pre>
<p>You can also check:</p>
<ul>
<li><a href="https://renanmf.com/subtract-days-from-date-python/">How to subtract days from a date in Python</a> </li>
<li><a href="https://renanmf.com/adding-days-to-a-date-python/">Adding days to a date in Python</a></li>
</ul>
<p>The content <a href="https://renanmf.com/how-to-subtract-months-from-a-date-in-python/">How to subtract months from a date in Python</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Adding months to a date in Python</title>
		<link>https://renanmf.com/adding-months-to-a-date-in-python/</link>
		
		<dc:creator><![CDATA[Renan Moura]]></dc:creator>
		<pubDate>Tue, 15 Feb 2022 11:18:41 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://renanmf.com/?p=4053</guid>

					<description><![CDATA[<p>The easiest way to add months to a date in Python is to use the dateutil extension. Install it with pip: pip install python-dateutil The relativedelta object from the dateutil.relativedelta module allows you to add any number of months to a date object. In this example I always take the current date using the date.today() [&#8230;]</p>
<p>The content <a href="https://renanmf.com/adding-months-to-a-date-in-python/">Adding months to a date in Python</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The easiest way to add months to a date in Python is to use the <a href="https://dateutil.readthedocs.io/en/stable/">dateutil</a> extension.</p>
<p>Install it with pip:</p>
<pre><code>pip install python-dateutil</code></pre>
<p>The <code>relativedelta</code> object from the <code> dateutil.relativedelta</code> module allows you to add any number of months to a date object.</p>
<p>In this example I always take the current date using the <code>date.today()</code> method.</p>
<p>Then I set a <code>relativedelta</code> of 2 months and add it to the <code>current_date</code>.</p>
<pre><code class="language-python">from datetime import date
from dateutil.relativedelta import relativedelta

current_date = date.today()

print(current_date)

future_date = current_date + relativedelta(months=2)

print(future_date)</code></pre>
<pre><code>2022-02-15
2022-04-15</code></pre>
<p>You can also check:</p>
<ul>
<li><a href="https://renanmf.com/subtract-days-from-date-python/">How to subtract days from a date in Python</a> </li>
<li><a href="https://renanmf.com/adding-days-to-a-date-python/">Adding days to a date in Python</a></li>
</ul>
<p>The content <a href="https://renanmf.com/adding-months-to-a-date-in-python/">Adding months to a date in Python</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Beware of excess of &#8220;best practices&#8221;</title>
		<link>https://renanmf.com/beware-of-excess-of-best-practices/</link>
		
		<dc:creator><![CDATA[Renan Moura]]></dc:creator>
		<pubDate>Wed, 12 Jan 2022 16:27:13 +0000</pubDate>
				<category><![CDATA[Lab]]></category>
		<category><![CDATA[lab]]></category>
		<guid isPermaLink="false">https://renanmf.com/?p=3991</guid>

					<description><![CDATA[<p>Unlike other disciplines that are more rigid and regulated like Civil Engineering, Software Engineering doesn&#8217;t have a set of rules to follow by law enforcement. You won&#8217;t go to jail if you don&#8217;t do TDD (Test-Driven Design), or even write tests for your code. Your system can work just fine if you don&#8217;t follow any [&#8230;]</p>
<p>The content <a href="https://renanmf.com/beware-of-excess-of-best-practices/">Beware of excess of &#8220;best practices&#8221;</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Unlike other disciplines that are more rigid and regulated like Civil Engineering, Software Engineering doesn&#8217;t have a set of rules to follow by law enforcement.</p>
<p>You won&#8217;t go to jail if you don&#8217;t do TDD (Test-Driven Design), or even write tests for your code.</p>
<p>Your system can work just fine if you don&#8217;t follow any agile method.</p>
<p>You could deploy your next app in a bare-metal Linux machine instead of setting up Kubernetes on a cloud provider to autoscale your pods, and no one will complain about performance and such.</p>
<p>We have all read Clean Code, Clean Architecture, and some other &quot;bibles&quot; of the software development world which tell us what are the &quot;best practices&quot;.</p>
<p>We have all spent hours learning about Scrum or some similar methodology to manage a software project as opposed to old-fashioned cascade-like project management because that&#8217;s what works &quot;best&quot;.</p>
<p>We do tons of meetings, in Scrum alone we have: sprint planning, daily scrum, sprint review, and sprint retrospective.</p>
<p>There are days when I wonder if I attend meetings for a living instead of developing software.</p>
<p>So, what is all this rant about?</p>
<p>It is about not following blindly the so-called &quot;best practices&quot;.</p>
<p>I do X because Google does, I use Y because Facebook uses it.</p>
<p>This is a silly reason to do or use anything.</p>
<p>If you are not working with lots of people, in a huge project, with thousands of simultaneous users, following all the &quot;best practices&quot; can be a drawback instead of an advantage.</p>
<p>If you are working alone, in a small app with a handful of users, it is ok to commit directly into the main branch in your GitHub repo.</p>
<p>If your project is not database intensive, or only has to deal with very little data, you can use an embedded H2 database stored directly in your file system and it will work more than fine.</p>
<p>There are projects and teams where it makes sense to follow every single piece of advanced architecture and people management processes there are, but that&#8217;s totally not the case for your startup of three people.</p>
<p>It is easy to be misled by reading about the latest tech and thinking &quot;everybody is using this&quot;, when in fact they are not.</p>
<p><a href="https://renanmf.com/fomo-fear-of-missing-out-as-a-developer/">FOMO (Fear Of Missing Out) as a Developer</a> is real and you should be aware of this.</p>
<p>Choose the right tech for the right context in a rational way.</p>
<p>Choose the right project methodology for the right context in a rational way.</p>
<p>You don&#8217;t have to ditch Scrum in its entirety, you can adapt it and do only 2 of the meetings described instead of all of them.</p>
<p>You can spawn a cheap Linux VM and deploy your app by hand instead of spending hours setting up CI/CD for something you can do manually in 2 minutes.</p>
<p>If your app screen is a simple feature with one text field and a button (like Google&#8217;s home page), React/Angular/Vue is an overkill.</p>
<p>Learn all of those things, read the books, but use your best judgment to adapt the &quot;best practices&quot; to take advantage of what makes sense to your project and team, and not just because someone else said you should use it.</p>
<p>The content <a href="https://renanmf.com/beware-of-excess-of-best-practices/">Beware of excess of &#8220;best practices&#8221;</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>The hard part is to continue</title>
		<link>https://renanmf.com/the-hard-part-is-to-continue/</link>
		
		<dc:creator><![CDATA[Renan Moura]]></dc:creator>
		<pubDate>Wed, 15 Dec 2021 22:25:03 +0000</pubDate>
				<category><![CDATA[Lab]]></category>
		<category><![CDATA[lab]]></category>
		<guid isPermaLink="false">https://renanmf.com/?p=3702</guid>

					<description><![CDATA[<p>Starting out is easy, the hard part is to continue. Anything for a while is easy: Work out for a while Study for a while Diet for a while Work right for a while Take good care of the family for a while Save for a while Programming for a while For a while, everything [&#8230;]</p>
<p>The content <a href="https://renanmf.com/the-hard-part-is-to-continue/">The hard part is to continue</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Starting out is easy, the hard part is to continue.</p>
<p>Anything for a while is easy:</p>
<ul>
<li>Work out for a while</li>
<li>Study for a while</li>
<li>Diet for a while</li>
<li>Work right for a while</li>
<li>Take good care of the family for a while</li>
<li>Save for a while</li>
<li><strong>Programming for a while</strong></li>
</ul>
<p>For a while, everything is a piece of cake.</p>
<p>But what will get you there is not being brilliant for a while.</p>
<p>What takes you there is being consistent for a LONG time.</p>
<p>James Clear has an interesting take on this.</p>
<p>On the image below you can see how a tiny gain makes such a huge difference when compounded for long enough.</p>
<p>And also the opposite, how a tiny loss will throw you to 0 in the long run.</p>
<p><img decoding="async" src="https://renanmf.com/wp-content/uploads/2021/12/1_percent_better-e1639600795270.jpg" alt="" /></p>
<p>Liz Fosslien also illustrates this very well.</p>
<p>How seemingly small steps lead to big changes over time:</p>
<p><img decoding="async" src="https://renanmf.com/wp-content/uploads/2021/12/liz_small_steps-e1639600874413.jpeg" alt="" /></p>
<p>And finally, an illustration by Jack Butcher.</p>
<p>Where you can see how you put in a lot of work for some time and see no results and thinks &quot;This is pointless&quot;, and then, all of a sudden, you get some traction (this is especially true on the internet):</p>
<p><img decoding="async" src="https://renanmf.com/wp-content/uploads/2021/12/this_is_pointless-e1639600918965.png" alt="" /></p>
<p>Most people will never see curves like this in their own lives because they give up too soon.</p>
<p>The urge to give up quickly comes from the several examples of other people on the internet having results much faster, so one thinks that, if they are not getting results fast, they are just doing it wrong.</p>
<p>This is totally not the case.</p>
<p>These people are outliers, they just seem common because their word spreads fast on the web and makes you think that&#8217;s the norm when it&#8217;s not.</p>
<p>Everyone talks about their successes, few talk about their failures, simple human nature.</p>
<p>Everyone has their own rhythm, and the rule of thumb here is that you have to give a lot before asking for anything.</p>
<p>It&#8217;s very easy to get started when we&#8217;re excited.</p>
<p>Then it becomes a routine and the excitement is gone.</p>
<p>Only those with the discipline to go through the excitement abyss will reap the rewards of their effort.</p>
<p><a href="https://renanmf.com/learning-programming-is-non-linear/">Learning Programming is Non-Linear</a>, so you might feel stuck here and there, but this shouldn&#8217;t discourage you from learning and persevering.</p>
<p>By showing up every day you are already ahead of the majority of people.</p>
<p>You have to survive long enough in any game to start being noticed.</p>
<p>And a big chunk of any success is being present.</p>
<p>So don&#8217;t give up too quickly.</p>
<p>The hard part is to continue.</p>
<p>The content <a href="https://renanmf.com/the-hard-part-is-to-continue/">The hard part is to continue</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Python list drop duplicates</title>
		<link>https://renanmf.com/python-list-drop-duplicates/</link>
		
		<dc:creator><![CDATA[Renan Moura]]></dc:creator>
		<pubDate>Thu, 02 Dec 2021 14:38:33 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://renanmf.com/?p=3934</guid>

					<description><![CDATA[<p>Removing duplicates from a list is a task that might happen more often than you think. Maybe you are importing a bunch of rows from a CSV file and want to make sure you only have unique values. Or you are making sure to avoid repeated values for the sake of keeping your data sanitized. [&#8230;]</p>
<p>The content <a href="https://renanmf.com/python-list-drop-duplicates/">Python list drop duplicates</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Removing duplicates from a list is a task that might happen more often than you think.</p>
<p>Maybe you are importing a bunch of rows from a CSV file and want to make sure you only have unique values.</p>
<p>Or you are making sure to avoid repeated values for the sake of keeping your data sanitized.</p>
<p>Fortunately, you can drop duplicates from a list in Python with a single line.</p>
<p>This is one of those simple, but powerful features that Python gives us for free and can save you a lot of trouble by applying the Pythonic way of doing things.</p>
<h2>Removing duplicates with set</h2>
<p>In the code snippet below we are creating a list named <code>car_brands</code>.</p>
<p>Notice how <code>&#039;bmw&#039;</code> and <code>&#039;toyota&#039;</code> are repeated.</p>
<p><code>&#039;bmw&#039;</code> is included twice, while <code>&#039;toyota&#039;</code>  appears three times.</p>
<p>To drop these duplicates we just need to convert the list to a set and then convert the result back to a list.</p>
<pre><code class="language-python">car_brands = [&#039;bmw&#039;, &#039;mercedes&#039;, &#039;toyota&#039;, &#039;mclaren&#039;, &#039;toyota&#039;, &#039;bmw&#039;, &#039;toyota&#039;]

print(car_brands)

car_brands = list(set(car_brands))

print(car_brands)</code></pre>
<p>The output of the code above is:</p>
<pre><code>[&#039;bmw&#039;, &#039;mercedes&#039;, &#039;toyota&#039;, &#039;mclaren&#039;, &#039;toyota&#039;, &#039;bmw&#039;, &#039;toyota&#039;]

[&#039;toyota&#039;, &#039;mercedes&#039;, &#039;bmw&#039;, &#039;mclaren&#039;]</code></pre>
<p>This works because sets, by default, don&#8217;t allow duplicates, so converting the list to set will automatically remove the duplicates.</p>
<p>But there is a catch, sets don&#8217;t keep the order of your items, while lists do keep the order of the items</p>
<p>Notice how <code>&#039;toyota&#039;</code> appears as the first item in the final result, even though it was the third in the original list.</p>
<p>So, what to do if I want to remove the duplicates but keep the order of the items?</p>
<h2>Droping duplicates and keeping the order with dict</h2>
<p>The simple and &quot;straightforward&quot; (but not recommended) way would be to loop of the original list and add only new items to a new list.</p>
<p>The code below implements such logic.</p>
<pre><code class="language-python">car_brands = [&#039;bmw&#039;, &#039;mercedes&#039;, &#039;toyota&#039;, &#039;mclaren&#039;, &#039;toyota&#039;, &#039;bmw&#039;, &#039;toyota&#039;]
new_brands = []

for item in car_brands: 
    if item not in new_brands: 
        new_brands.append(item)

print(car_brands)
print(new_brands)</code></pre>
<p>The output is:</p>
<pre><code>[&#039;bmw&#039;, &#039;mercedes&#039;, &#039;toyota&#039;, &#039;mclaren&#039;, &#039;toyota&#039;, &#039;bmw&#039;, &#039;toyota&#039;]

[&#039;bmw&#039;, &#039;mercedes&#039;, &#039;toyota&#039;, &#039;mclaren&#039;]</code></pre>
<p>But, as always, there is a better way in Python!</p>
<p>As of Python 3.6, you can use the method <code>fromkeys</code> from <code>dict</code>.</p>
<p>It is slower than using sets to remove duplicates, but it is the best solution to drop duplicates <em>and</em> keep order.</p>
<p>It also takes only one line.</p>
<pre><code class="language-python">car_brands = [&#039;bmw&#039;, &#039;mercedes&#039;, &#039;toyota&#039;, &#039;mclaren&#039;, &#039;toyota&#039;, &#039;bmw&#039;, &#039;toyota&#039;]

car_brands = list(dict.fromkeys(car_brands))

print(car_brands)</code></pre>
<p>The output of the above is:</p>
<pre><code>[&#039;bmw&#039;, &#039;mercedes&#039;, &#039;toyota&#039;, &#039;mclaren&#039;]</code></pre>
<p>Since the solution with <code>dict</code> is slower, only use it if order is something you really need.</p>
<p>I recommend you to read <a href="https://renanmf.com/how-to-choose-data-structure-python/">How to choose a Data Structure in Python</a> to have a broad view of each one and when to use them.</p>
<p>The content <a href="https://renanmf.com/python-list-drop-duplicates/">Python list drop duplicates</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Learning Programming is Non-Linear</title>
		<link>https://renanmf.com/learning-programming-is-non-linear/</link>
		
		<dc:creator><![CDATA[Renan Moura]]></dc:creator>
		<pubDate>Tue, 16 Nov 2021 19:15:36 +0000</pubDate>
				<category><![CDATA[Lab]]></category>
		<category><![CDATA[lab]]></category>
		<guid isPermaLink="false">https://renanmf.com/?p=3872</guid>

					<description><![CDATA[<p>Learning is by no means a linear process, even in hard sciences like Math. It is very common to see people asking in groups, Reddit, and other forum-like places &#34;What path should I take to become a Software Developer&#34;. Unfortunately, learning programming is not linear. You will find many lists and articles giving you a [&#8230;]</p>
<p>The content <a href="https://renanmf.com/learning-programming-is-non-linear/">Learning Programming is Non-Linear</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Learning is by no means a linear process, even in hard sciences like Math.</p>
<p>It is very common to see people asking in groups, Reddit, and other forum-like places &quot;What path should I take to become a Software Developer&quot;.</p>
<p>Unfortunately, learning programming is not linear.</p>
<p>You will find many lists and articles giving you a path like: learn HTML, CSS, JavaScript&#8230;</p>
<p>They are not wrong in the sense that you should learn JavaScript before React, but they don&#8217;t warn you that you should not worry about mastering the previous topic before jumping to the next.</p>
<p>Those topics are all interconnected, which means they will &quot;click&quot; in your head only after you have some knowledge of each topic.</p>
<p>Learn some JavaScript and then some React.</p>
<p>If you decide to &quot;master&quot; Python before trying Django, good luck, you will never get to Django.</p>
<p>Python is a massive language, you can learn the basics very quickly, but mastering it is another matter.</p>
<p>That is what I had in mind when I wrote <a href="https://renanmf.com/python-guide-beginners/">The Python Guide for Beginners</a>.</p>
<p>You can learn the core of the language as fast as possible, and then move on to dive into Web Development, Data Science, or general use of Python as a programming language to automate your everyday tasks.</p>
<p>If you choose, say, Machine Learning, you will need to understand some details of the language specifically for some tasks, but you will have enough knowledge of the basics to google yourself out of any situation.</p>
<p>The &quot;click&quot; also happens as you expand your arsenal of tools.</p>
<p><a href="https://renanmf.com/learn-more-than-one-programming-language/">Learn More Than One Programming Language</a> and some concepts that you learned in language X will make much more sense after you learn language Y.</p>
<p>I&#8217;m challenging myself at the moment to dive more into web3, which is a new realm of software development and solutions revolving around blockchain and the crypto space.</p>
<p>Adaptation is <a href="https://renanmf.com/the-top-skill-for-a-software-developer/">The Top Skill for a Software Developer</a> and you have to keep improving yourself as new opportunities arise.</p>
<p>This means I won&#8217;t waste hundreds of hours to learn Solidity or understand every single concept about Smart Contracts.</p>
<p><a href="https://renanmf.com/the-only-way-to-learn-programming/">The Only Way To Learn Programming</a> is to take action with what you know.</p>
<p>So I will learn some things, apply them to a project and then I will be able to adapt myself to any situation that comes to me.</p>
<p>If you wait until you are 100% prepared, you will be already too late to take the best opportunities.</p>
<p>The content <a href="https://renanmf.com/learning-programming-is-non-linear/">Learning Programming is Non-Linear</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Python for loop increment by 2</title>
		<link>https://renanmf.com/python-for-loop-increment-by-2/</link>
		
		<dc:creator><![CDATA[Renan Moura]]></dc:creator>
		<pubDate>Sun, 31 Oct 2021 20:40:08 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://renanmf.com/?p=3906</guid>

					<description><![CDATA[<p>A regular for loop will increase its iteration counter by one in each iteration. But there are situations where you want to increment the iteration counter by 2. For some reason you might want to work with only even values. Let&#8217;s see a few solutions for this. range function The solution to increment a for [&#8230;]</p>
<p>The content <a href="https://renanmf.com/python-for-loop-increment-by-2/">Python for loop increment by 2</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A regular <code>for</code> loop will increase its iteration counter by one in each iteration.</p>
<p>But there are situations where you want to increment the iteration counter by 2.</p>
<p>For some reason you might want to work with only even values.</p>
<p>Let&#8217;s see a few solutions for this.</p>
<h2>range function</h2>
<p>The solution to increment a for loop by 2 in Python is to use the <code>range()</code> function.</p>
<p>This function allows you to specify three parameters: <code>start</code>, <code>stop</code>, and <code>step</code>.</p>
<p><code>start</code> is the counter&#8217;s initial value, <code>step</code> is by how much you want to increment until you reach the value of <code>stop - 1</code>, because the value of stop is included.</p>
<p>The example bellow shows how to use <code>range()</code> with a step of 2 starting from 0.</p>
<pre><code class="language-python">for i in range(0,20,2):
    print(i)</code></pre>
<p>The output:</p>
<pre><code>0
2
4
6
8
10
12
14
16
18</code></pre>
<p>Of course, you can use <code>range()</code> to specify any step you would like, so if you want a step of 5, just do:</p>
<pre><code class="language-python">for i in range(0,20,5):
    print(i)</code></pre>
<p>The output is:</p>
<pre><code>0
5
10
15</code></pre>
<h2>Slicing</h2>
<p>If you never heard of slicing before, I recommend you to read <a href="https://renanmf.com/slicing-python/">Understanding Slicing in Python</a> first, there is also a video linked in the article if you prefer.</p>
<p>Slicing is useful when you want to apply a different step when working with a pre-defined list.</p>
<p>In this case I have a list <code>numbers</code> with the number from 1 to 16.</p>
<p>The logic is very similar to <code>range()</code>, since you also have a <code>start</code>, a <code>stop</code>, and a <code>step</code>.</p>
<p>In this case I&#8217;m starting on index 1, which is the number 2 in the list, remember lists are 0-indexed in Python.</p>
<p>I won&#8217;t put any <code>stop</code> value since I want to go until the last index.</p>
<p>Finally, I put a step of 2.</p>
<pre><code class="language-python">numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]

for i in numbers[1::2]:
    print(i)</code></pre>
<p>The output will be:</p>
<pre><code>2
4
6
8
10
12
14
16</code></pre>
<p>Another way to implement the slicing from the code above is to combine <code>range()</code> with <a href="https://renanmf.com/get-number-elements-list-python/"><code>len()</code></a>:</p>
<pre><code class="language-python">numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]

for i in range(1, len(numbers), 2):
   print(numbers[i])</code></pre>
<p>The output is the same:</p>
<pre><code>2
4
6
8
10
12
14
16</code></pre>
<p>Again, the same way we could use any step in <code>range()</code>, we can change the step in slicing to anything we would like.</p>
<h2>What about about float values?</h2>
<p>An extra trick is how to achieve the same thing with float values.</p>
<p>In this case you have to use the library numpy and its function <code>arange</code>.</p>
<p>This way you can use floats as <code>start</code>, <code>stop</code>, and <code>step</code>.</p>
<pre><code class="language-python">import numpy as np

for i in np.arange(1.5, 2.5, 0.1):
    print (i)</code></pre>
<p>The output is:</p>
<pre><code>1.5
1.6
1.7000000000000002
1.8000000000000003
1.9000000000000004
2.0000000000000004
2.1000000000000005
2.2000000000000006
2.3000000000000007
2.400000000000001</code></pre>
<h2>Watch this on Youtube:</h2>
<p><iframe width="560" height="315" src="https://www.youtube.com/embed/tlI_DUE2IPg" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></p>
<p>The content <a href="https://renanmf.com/python-for-loop-increment-by-2/">Python for loop increment by 2</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Python 1 line for loop</title>
		<link>https://renanmf.com/python-1-line-for-loop/</link>
		
		<dc:creator><![CDATA[Renan Moura]]></dc:creator>
		<pubDate>Tue, 19 Oct 2021 21:43:25 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://renanmf.com/?p=3896</guid>

					<description><![CDATA[<p>Instead of using the same old way of iterating through lists, we can make our code simpler by using list comprehensions, which allow us to make a 1 line for loop in Python. Basic syntax of a 1 line for loop To use a one line for loop to replace a regular for loop, we [&#8230;]</p>
<p>The content <a href="https://renanmf.com/python-1-line-for-loop/">Python 1 line for loop</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Instead of using the same old way of iterating through lists, we can make our code simpler by using list comprehensions, which allow us to make a 1 line for loop in Python.</p>
<h2>Basic syntax of a 1 line for loop</h2>
<p>To use a one line for loop to replace a regular for loop, we can make:</p>
<pre><code class="language-python">[statement for i in list]</code></pre>
<p>Which is the same as doing:</p>
<pre><code class="language-python">for i in list:
    expression</code></pre>
<p>If we want some conditional to apply the expression, we have:</p>
<pre><code class="language-python">[statement for i in list if condition ]</code></pre>
<p>Which translates to:</p>
<pre><code class="language-python">for i in list:
    if condition:
        statement</code></pre>
<h2>Example 1: calculating the cube of a number</h2>
<p><strong>Regular way</strong></p>
<pre><code class="language-python">numbers = [10, 20, 30, 40, 50]
new_list = []

for n in numbers:
    new_list.append(n**3)

print(new_list)</code></pre>
<pre><code>[1000, 8000, 27000, 64000, 125000]</code></pre>
<p><strong>Using 1 line for loop</strong></p>
<pre><code class="language-python">numbers = [10, 20, 30, 40, 50]
new_list = []

new_list = [n**3 for n in numbers]

print(new_list)</code></pre>
<pre><code>[1000, 8000, 27000, 64000, 125000]</code></pre>
<h2>Example 2: calculating the cube of a number only if it is greater than 30</h2>
<p>Using the conditional, we can filter only the values we want the expression to be applied to.</p>
<p><strong>Regular way</strong></p>
<pre><code class="language-python">numbers = [10, 20, 30, 40, 50]
new_list = []

for n in numbers:
    if(n &gt; 30):
        new_list.append(n**3)

print(new_list)</code></pre>
<pre><code>[64000, 125000]</code></pre>
<p><strong>Using 1 line for loop</strong></p>
<pre><code class="language-python">numbers = [10, 20, 30, 40, 50]
new_list = []

new_list = [n**3 for n in numbers if n &gt; 30]

print(new_list)</code></pre>
<pre><code>[64000, 125000]</code></pre>
<h2>Example 3: calling functions with a 1 line for loop</h2>
<p>We can also call functions using the list comprehension syntax:</p>
<pre><code class="language-python">numbers = [10, 20, 30, 40, 50]
new_list = []

def cube(number):
    return number**3

new_list = [cube(n) for n in numbers if n &gt; 30]

print(new_list)</code></pre>
<pre><code>[64000, 125000]</code></pre>
<p>To know more about loops, check these posts on <a href="https://renanmf.com/for-loops-python/">for Loops in Python</a> and <a href="https://renanmf.com/while-loops-python/">While Loops in Python</a>.</p>
<p>The content <a href="https://renanmf.com/python-1-line-for-loop/">Python 1 line for loop</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
