<?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: sksaifuddin</title>
    <description>The latest articles on DEV Community by sksaifuddin (@sksaifuddin).</description>
    <link>https://dev.to/sksaifuddin</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%2F171247%2Fd8bcf607-7402-448b-922e-a7a363baf798.jpg</url>
      <title>DEV Community: sksaifuddin</title>
      <link>https://dev.to/sksaifuddin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sksaifuddin"/>
    <language>en</language>
    <item>
      <title>What's the score of your functions?</title>
      <dc:creator>sksaifuddin</dc:creator>
      <pubDate>Sat, 16 Nov 2019 19:36:51 +0000</pubDate>
      <link>https://dev.to/sksaifuddin/what-s-the-score-of-your-functions-1h2k</link>
      <guid>https://dev.to/sksaifuddin/what-s-the-score-of-your-functions-1h2k</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Any fool can write code that a computer can understand. Good programmers write code that humans can understand&lt;/em&gt;. - Martin Fowler&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Functions are the basic building blocks of any programming language, but is your function clean and readable?&lt;/p&gt;

&lt;p&gt;Below is the list of Rules/Qualities of a good function along with its score.See if your functions follows these rules and score yourself.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;No&lt;/th&gt;
&lt;th&gt;Function Rules&lt;/th&gt;
&lt;th&gt;Score&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Small&lt;/td&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Do One Thing&lt;/td&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Descriptive Names&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Ideal Function Arguments&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Have no Side Effects&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Command Query Separation&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;DRY&lt;/td&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;Blocks and Indenting&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;The Step Down Rule&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;Structured Programming&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;TOTAL&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  1.&lt;strong&gt;Small&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;First rule of functions is that they should be small.&lt;/li&gt;
&lt;li&gt;The second rule of functions is that they should be smaller than that.&lt;/li&gt;
&lt;li&gt;Functions should hardly ever be 15 lines long.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2.&lt;strong&gt;Do One Thing&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;FUNCTIONS SHOULD DO ONE THING. THEY SHOULD DO IT WELL. THEY SHOULD DO IT ONLY.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Another way to know that function is doing more than "One Thing" is if you can extract another function from it with a name that is not merely a restatement of its implementation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3.&lt;strong&gt;Descriptive Names&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Functions should have verb or verb phrase names like postPayment, deletePage.&lt;/li&gt;
&lt;li&gt;Don't be afraid to make a name long. A long descriptive name is better than a long descriptive comment.&lt;/li&gt;
&lt;li&gt;Choosing descriptive names will clarify the design of the module in your mind and help you improve it.It is not at all uncommon that hunting for a good name results in favorable restructuring of the code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4.&lt;strong&gt;Ideal Function Arguments&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The ideal number of arguments for a function is zero(niladic).&lt;/li&gt;
&lt;li&gt;Next comes one(monadic).&lt;/li&gt;
&lt;li&gt;Followed closely by Two arguments(dyadic).&lt;/li&gt;
&lt;li&gt;More than three(polyadic) requires very special justification and then shouldn't be used anyway.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5.&lt;strong&gt;Have no Side Effects&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;According to wikipedia, In computer science, an operation, function or expression is said to have a side effect if it modifies some state variable value(s) outside its local environment, that is to say has an observable effect besides returning a value (the main effect) to the invoker of the operation.&lt;/li&gt;
&lt;li&gt;Side Effects are lies. Your function promises to do one thing, but it also does other hidden things.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6.&lt;strong&gt;Command Query Separation&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Function should either do something or answer something, but not both.&lt;/li&gt;
&lt;li&gt;Either your function should change the state of an object, or it should return some information about that object.&lt;/li&gt;
&lt;li&gt;Doing both often leads to confusion.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  7.&lt;strong&gt;Don't Repeat Yourself&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Duplication may be the root of all evil in software. &lt;/li&gt;
&lt;li&gt;Never write the same code twice, always create the reusable functions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8.&lt;strong&gt;Blocks and Indenting&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This implies that the blocks with &lt;strong&gt;if&lt;/strong&gt; statements, &lt;strong&gt;else&lt;/strong&gt; statements, &lt;strong&gt;while&lt;/strong&gt; statements and so on should be one line long. Probably that line should be a function call.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  9.&lt;strong&gt;The Stepdown Rule&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We want the code to read liek a top-down narrative.&lt;/li&gt;
&lt;li&gt;We want every function to be followed by those at the next level of abstraction so that we can read the program, descending one level of abstraction at a time as we read down the list of functions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  10.&lt;strong&gt;Structured Programming&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Dijkstra said that every function and every block with in a function, should have one entry and one exit.&lt;/li&gt;
&lt;li&gt;Following these rules means that there should only be one return statement  in a function, no break or continue statements in a loop and never,ever any goto statements.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How do you write a score 100 function ?
&lt;/h3&gt;

&lt;p&gt;The first draft might be clumsy and disorganized, so do you wordsmith it and restructure it and refine it until it read the way you want it to read(100 score). Just keep refactoring the code until you hit the score 100.&lt;/p&gt;

&lt;p&gt;Comment down your score and if you know more important function rules #discuss.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;P.S: These rules are taken from the book &lt;strong&gt;The Clean Code&lt;/strong&gt; by Robert C.Martin, I strongly recommend to read it, Its awesome.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is a series from my JEDI-JOURNEY, where we become the JEDIs by reading tons of books, you too can tag along,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;a href="https://github.com/sksaifuddin/jedi-journey"&gt;https://github.com/sksaifuddin/jedi-journey&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>codequality</category>
      <category>beginners</category>
      <category>code</category>
      <category>functional</category>
    </item>
    <item>
      <title>The Journey Begins</title>
      <dc:creator>sksaifuddin</dc:creator>
      <pubDate>Sun, 10 Nov 2019 16:57:30 +0000</pubDate>
      <link>https://dev.to/sksaifuddin/the-journey-begins-532g</link>
      <guid>https://dev.to/sksaifuddin/the-journey-begins-532g</guid>
      <description>&lt;p&gt;&lt;em&gt;"A long time a ago in a Galaxy far away begun a Journey to create a group of Coding Jedi with extra ordinary skills and regain the Balance in the Force."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;But to become a Jedi we need a Jedi master like Master Yoda 🙏🙏, who will teach us the secret lessons of code and life, but unfortunately all masters are gone a long ago 😔 leaving behind their knowledge in the form of books 📚, so that the people like you and me 👬 can find those books and follow the journey to become a Coding Jedi.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sfQjU-fp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://bayart.org/wp-content/uploads/2017/11/star-wars-wisdom-quotes.jpg%3Fezimgfmt%3Dng:webp/ngcb1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sfQjU-fp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://bayart.org/wp-content/uploads/2017/11/star-wars-wisdom-quotes.jpg%3Fezimgfmt%3Dng:webp/ngcb1" alt="" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, the plan is to read at least three books of different categories every month.&lt;br&gt;
The list of categories and books is on github here,&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://github.com/sksaifuddin/jedi-journey"&gt;https://github.com/sksaifuddin/jedi-journey&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;We will not only read about the coding books but also the books which teaches us philosophy, meaning of life and wisdom, so that we truly become &lt;strong&gt;The Jedi&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I will also try to write Important takes from the books in the form of summary, so the folks who doesn't time can also make use of our journey. &lt;/p&gt;

&lt;p&gt;I will be doing the research on good books and add them in list, you all can also suggest and contribute the list of books and summary.&lt;/p&gt;

&lt;p&gt;Follow along and remember,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Do or Do Not, There is No Try.&lt;/em&gt; – Master Yoda&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  💥 MAY THE FORCE BE WITH YOU 💥
&lt;/h2&gt;

</description>
      <category>books</category>
      <category>beginners</category>
      <category>github</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
