<?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: t4christ</title>
    <description>The latest articles on DEV Community by t4christ (@t4christ).</description>
    <link>https://dev.to/t4christ</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%2F188773%2Feb907a3e-3f64-447e-a73e-872d46a280a2.png</url>
      <title>DEV Community: t4christ</title>
      <link>https://dev.to/t4christ</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/t4christ"/>
    <language>en</language>
    <item>
      <title>Thinking Performance in Programming</title>
      <dc:creator>t4christ</dc:creator>
      <pubDate>Mon, 01 Jul 2019 10:21:09 +0000</pubDate>
      <link>https://dev.to/t4christ/thinking-performance-in-programming-ll0</link>
      <guid>https://dev.to/t4christ/thinking-performance-in-programming-ll0</guid>
      <description>&lt;p&gt;As a programmer we have written codes that ideally solves a problem, but do we take note of the performance when it comes to solving a huge size of the problem or do we just feel comfortable with "MY CODE WORKS". Well we can say as far as my code works then that is all. Don't stop there, take your thinking bigger than "MY CODE WORKS" to "CAN MY CODE SOLVE A HUGE SIZE OF PROBLEM" this is where thinking on a performance level comes in. For those who are not python programmers this will work for you too because it's more of the thought you put into your coding.&lt;/p&gt;

&lt;p&gt;We can only think performance when we think Big O. Hahahaha you wonder what i mean by "THINK BIG O" right? Not to worry all am saying is Big O Notation.Big O Notation simply means describing the performance or complexity of an algorithm. Big O Notation deals with solving performance issues, the big performance issue is where big o comes into the picture. I will strongly recommend you read on big o notation with this simplified guide &lt;a href="https://guide.freecodecamp.org/computer-science/notation/big-o-notation/"&gt;https://guide.freecodecamp.org/computer-science/notation/big-o-notation/&lt;/a&gt;. Enough of the theory let's see what i mean in practice. We will be looking at a simple mathematical problem in python. Let us assume we want to sum up all numbers from 1 to 100 with python we can simply do this.&lt;/p&gt;

&lt;p&gt;def sumNumber(number):&lt;br&gt;
sum = 0&lt;br&gt;
for num in number: ## Loop through an array of numbers&lt;br&gt;
sum +=num ## add number to initial sum value&lt;br&gt;
return sum  ## return sum after the loop&lt;br&gt;
number = range(100)&lt;br&gt;
sumNumber(number)&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
4950&lt;/p&gt;

&lt;p&gt;Ideally we have solved the problem with this few lines of code but does that mean this code will work well with a huge number. Lets take a look at the performance of this code when it comes to solving the same problem with one hundred million (100,000,000). Let's take a look at 3 different ways we can solve this problem and choose the best that performs well.&lt;/p&gt;

&lt;p&gt;Solution 1&lt;/p&gt;

&lt;p&gt;import timeit&lt;/p&gt;

&lt;p&gt;def sumNumber(number):&lt;br&gt;
    sum = 0&lt;br&gt;
    for n in number:&lt;br&gt;
        sum+=n&lt;br&gt;
    return sum&lt;/p&gt;

&lt;p&gt;number = range(100)&lt;br&gt;
start_time = timeit.default_timer()&lt;br&gt;
result = sumNumber(number)&lt;br&gt;
print(result,timeit.default_timer() - start_time)&lt;/p&gt;

&lt;p&gt;When we take a look at the solution above it took 15 seconds to solve the problem this is not really a good solution considering the size.&lt;/p&gt;

&lt;p&gt;Let us take a look at the second way of solving the same problem with the same size using python's built in sum method.&lt;/p&gt;

&lt;p&gt;Solution 2&lt;/p&gt;

&lt;p&gt;import timeit&lt;/p&gt;

&lt;p&gt;def sumNumber(number):&lt;br&gt;
    return sum(number)&lt;/p&gt;

&lt;p&gt;number = range(100000000)&lt;br&gt;
start_time = timeit.default_timer()&lt;br&gt;
sumNumber(number)&lt;br&gt;
print(timeit.default_timer() - start_time)&lt;/p&gt;

&lt;p&gt;Taking a look at solution 2 above it took it 5 seconds to solve the same problem which in my opinion I will say is better but it still dosen't look like the best solution to me. We can still make it better don't you think. Finally let us take a look at the third solution.&lt;/p&gt;

&lt;p&gt;Solution 3&lt;/p&gt;

&lt;p&gt;import timeit&lt;/p&gt;

&lt;p&gt;def sumNumber(number):&lt;br&gt;
    return number/2 *(1+number)&lt;/p&gt;

&lt;p&gt;number = 10000000000&lt;br&gt;
start_time = timeit.default_timer()&lt;br&gt;
sumNumber(number)&lt;br&gt;
print(timeit.default_timer() - start_time)&lt;/p&gt;

&lt;p&gt;Wow I can't believe what my eyes are seeing. This is really amazing, this solution solved the problem in approximately 0.00002 seconds. What a wide margin compared to the 15 and 5 seconds solution. Now this is what I mean by thinking performance when it comes to coding. No matter the problem you want to solve with your programming language of choice you can always think performance and you will be amazed by the results. Thank you so much for following along. Kindly drop your comments if you have any questions or addition.&lt;/p&gt;

</description>
      <category>performance</category>
    </item>
    <item>
      <title>Fixing Python Indentation</title>
      <dc:creator>t4christ</dc:creator>
      <pubDate>Mon, 01 Jul 2019 10:13:39 +0000</pubDate>
      <link>https://dev.to/t4christ/fixing-python-indentation-2fp6</link>
      <guid>https://dev.to/t4christ/fixing-python-indentation-2fp6</guid>
      <description>&lt;p&gt;Atimes or most times some of us face the problem of indentation when it comes to writing code in python. The weird thing is that despite the fact that you think you gave the right indentation in your code editor, popularly visual studio code, you still get stucked in an indentation error. This can be so frustrating because I can tell you confidently that I have experienced this so many times. Good news! I have a solution to any indentation problem you might face when coding with python, this solution works all the time, again I mean all the time. I have experimented this and I can confidently say it works all the time.&lt;/p&gt;

&lt;p&gt;The first thing you should do is select all the code block and press shift + tab to align all the code block to the left then hit the tab button the number of times you want to indent to the right. That is it, your indentation problem just got solved. For multiple blocks of code repeat the step above by pressing shift + tab to align the blocks of the code to left and hit tab the number of times you want to indent to the right and that solves the indentation issue.&lt;/p&gt;

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