Wednesday, May 1, 2030

This a place to write down my thoughts, ideas, things that interest me and my progress so far.



- Umang Bhatt


Disclaimer: The ideas/views/thoughts presented here are completely my own and have nothing to do with my current/previous/next employer.

Wednesday, December 28, 2022

few words ....

I just wanted to say few words....

I know that these program are childish. But when I solved these programs before some years, they were quiet difficult and time consuming for me. I specially want to thank my professor Mr. Chirag I Patel for all the guidance in those early days.

Thanks for your encouragement and guidance. :-)

//Sofar .......


- Umang B Bhatt





(here my purpose of posting these programs here is to help juniors build logic and help them in understanding language)

and yes, if you like this blog then do write comments and start following

Friday, June 22, 2018

Book recommendation - Clean Code

I have heard a lot of people talk about Agile development methodology. The read agile manifesto and then they continue to do "waterfally" things. While this is a fairly interesting topic to discuss, I want to draw your attention towards people who created and signed this manifesto. I consider them the most influential people in the industry. It will be a very good idea to look at what they have to say about software. Let's pick one name "Robert C. Martin", popularly known as Uncle Bob.

Uncle Bob has authored and co-authored several books. He also has got an entire series of books under "Robert C Martin Series". I want to talk about a book that he has authored with title "Clean Code".

If there is just one book that you need to read then I would say that this is the book you need to read. At times people read books and then continue to produce shit, this is not such book. This will completely change the way you write your code. Although the examples are in Java, everything Uncle Bob says is mostly applicable to C#, Python, PHP etc. So, regardless of the technology you write your code in, do read this book. Don't be fooled by name of chapters in this book might sound simplistic to you (because there are entire chapters just of naming things, creating functions etc). This book has got potential to change the way you write your code forever. There is a lot of code in this book you have to take out time to read thru all of those and once you are done with the book; you will be a better developer.

What I just said might sound like a too big of promise to you. Just believe me, and buy this book.
Happy reading!

Friday, March 2, 2018

Flowers and dagger

Flowers and dagger. They don'td belong together. They are not related. Thinking of flowers; beauty, gentleness, peace and good appearance comes into mind. Opposite of flowers is dagger.

Now you must be thinking why am I describing dagger and flowers to you. The reason is to set background for question that rose in my mind during one of my closest family member's wedding; and my answer to it. As per the tradition, groom had to carry a dagger and a bunch of flowers in his hands all the time before wedding ceremony. Considering the fact that this custom was created by very thoughtful ancestors, I began to think of the reason behind coming up with this.

While looking at both together I was looking at the things around and realised that this was in indicator telling groom to prepare himself with a mindset that is both like flower and dagger. In the next phase of life he will have to use both flowers and dagger. At times he will have to be as gentle as flower and at times he will have to be as hard and threatening as dagger. Using flowers where dagger is needed would yeild wrong results and using dagger when flowers are needed would yeild wrong result.

Be mindful and always carry a dagger and a bunch of flowers.

Tuesday, December 19, 2017

problem 6

 /*
        The sum of the squares of the first ten natural numbers is,

        385
        The square of the sum of the first ten natural numbers is,

        3025
        Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.

        Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
     */
    class Program
    {
        static void Main(string[] args)
        {
            System.Numerics.BigInteger sumOfSquares = 0;
            for (System.Numerics.BigInteger i = 1; i <= 100; i++)
            {
                sumOfSquares += (i * i);
            }

            System.Numerics.BigInteger sums = 0;
            for (int i = 1; i <= 100; i++)
            {
                sums = sums + i;
            }
            System.Numerics.BigInteger squareOfSums = sums * sums;

            Console.WriteLine(squareOfSums - sumOfSquares );
        }

    }

Problem 5

    /*
    2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
    What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
     */
    class Program
    {
        static void Main(string[] args)
        {
            bool divisible = false;
            int number = 1;
            while(divisible == false)
            {
                divisible = true;
                for(int i = 1; i<=20; i++)
                {
                    if((number%i) !=0  )
                    {
                        divisible = false;
                        break;
                    }
                }
                if(divisible==true)
                {
                    Console.WriteLine(number);
                    break;
                }
                else
                {
                    number++;
                }
            }
        }
    }

Sunday, November 3, 2013

Is variable named "i" fine ?

At many places we see variable named "i","j","c" etc scattered every where around the code; in all the methods. The obvious question that rises is "is such short variable name (e.g., i,j,k,c,k etc) fine?". Many people says that the variable name should ALWAYS be long and descriptive but you sense of "code smell" says that it is fine. But some people says that it is fine. This might actually confuse you.

Here is the  rule to answer answer the above question:


Uncle Bob's Rule:
For variable:
           Longer the scope, the longer the name should be.
For function/methods and classes:
           Longer the scope, shorter the name should be.



Lets understand it with an example of variable name:

The code below with variable named "i" is fine because the scope of "i" is very short :
    private static int getSumOfCharsInString(String name)
    {
        int sum = 0;
        for (int i = 0; i < name.length(); i++)
        {
            sum += getIntValueForChar(name.charAt(i));
        }
        return sum;
    }


But here the following code with variable named "c" is NOT FINE because the scope of the variable named "c" is very long(Its up to you to decide how much length to be considered as "long"). The variable named "c" should be refactored to something meaningful and long.
int main()
{
    char c;
    void getfile();
    void getfname(char []);
    char temp[MAX];  
    getfile();
    getfname(temp);
    if ( source != '\0' && html != '\0' )
    {
        fprintf( html, "%s", "" );
        fclose( html );
        fclose( source );
        printf("\nThe file is now created");
    }
.
.
.
    do
    {
       c = getc( source );
       if ( c == EOF )
       {
          break;
       }
       else if ( c == '<' )
       {
          fprintf( html, "%s", "<" );
       }
       else if ( c == '>' )
      {
          fprintf( html, "%s", ">" );
      }
      else if ( c == '&' )
      {
         fprintf( html, "%s", "&" );
      }
      else
      {
         fprintf( html, "%c", c );
      }
  }
  while ( c != EOF );
.
. 
}