4 Ways to Solve The Problem | Quick-Notes

Problem-solving requires two types of mental skills, analytical and creative. I know this sounds very high level So let’s talk about the basic fundamentals what generally I try to follow in day to day professional and personal activities.

  1. Listen carefully You need to pay very close attention to any information in the problem description. The optimal solution for a sorted vs unsorted array will be totally different so don’t miss anything.
  2. Brute Force Yes correct, Get the brute force solution as soon as possible, don’t think about the optimal solution. I always catch the first thought that comes to my mind. Don’t think about code, the algorithm just rough idea.
  3. Optimize Now it’s time to work on your Brute Force with some BUD (Bottlenecks, Unnecessary work and last Duplicated work) techniques.
    1. Remove the unused information.
    2. Solve it manually on paper with an example.
    3. Reverse engineer your thought process. HOW DID YOU DO?
    4. Make a Time VS Space trade-off.  CAN YOU REDUCE-IT MORE?
  4. Implement Congratulations now you have an optimal solution on paper. The last goal is to write beautiful, modularize code.

If you are trying to solve the problem in interview KEEP TALKING because your interviewer wants to hear how you’re going to approach the problem and it will make the interview more interactive.

Thanks a lot for reading the quick-notes!

Clean Code | TDD | Swift | iOS | Quick Notes

TDD is a way of writing software, where we write as little code as possible to make the test pass and then late refactor the code.

Golden laws from Uncle Bob

  • You may not write production code until you have written a failing unit test.
  • You may not write more of a unit test that is sufficient to fail and not comping is failing.
  • You may not write more production code that is sufficient to pass the currently failing test.

Whenever we create a new iOS app, we start with UI/ViewController/Business Login directly but Idea here is to start with the Test-cases. How? Let’s say you want to add the functionality to find out the divisible or not as below mentioned the code. Write down the test-case first.

func testIsDivisibleByThree() {
let brain = Brain()  
let result = brain.isDivisibleByFive(number: 5)
XCTAssertEqual(result, true)
}

But we don’t have the class Brain till now!!! So create a class adds the function, don’t forget the aim is to write as minimum code as you can.

class Brain {
    func isDivisibleByThree(number: Int) -> Bool {
        return true
    }
}

Because as of now, we are returning static boolean value, test-case will be a pass for sure. Same pattern we need to follow for each and every code we are going to write.

Simple words I can say there are 4 stages in TDD.

RED – Write down the test case
GREEN – Write just enough code to make the test-case pass
REFACTOR – Clean up existing code
REPEAT – repeat the cycle

In above codebase we have done RED and GREEN, let consider the stage 3rd, REFACTOR.

Let’s say now we have to write a function where we need to check whether a number is divisible by given number or not, like this

func isDivisibleBy(divisor: Int, number: Int) -> Bool {
  return number % divisor == 0
}

So we have refactored the code, Utilizing it like.

func isDivisibleByThree(number: Int) -> Bool {
    return isDivisibleBy(divisor:3, number:number)
 }

the idea is to repeat these steps so we can make sure when we are making any new changes, is it breaking some existing functionality.

I have tried to create short notes on how to follow TDD but also Idea is here is to decouple your code from UIViewController as much as possible so that it will give you more testability scope (for implementing this I have tried MVVM design pattern in few my recent projects, will share one quick notes on that as well).

Thanks for reading.

Clean Code | Quick Notes

51bPR2V9fBL._SX258_BO1,204,203,200_

A handbook of agile software craftsmanship by Robert C.Martin.

Two reasons for reading this book, you’re a programmer or you want to be. So by the end of this, we’ll know how to write good code because we are going to look code in each and every direction.

There will be a code, some peoples say we are at the end of the code and we don’t need the programmers because business people will generate the program from the specification.  That’s not true because at some level details can’t be ignored so we have to be specified.

It is bad code that brings the company down.

Why do we write the bad code? go fast, in a rush, don’t have to time to think before writing the line of code. One thing we’ve all said we’d go back and clean it up later. But we didn’t know LeBlanc’s Law: Later Equals Never.

The Total Cost of Owning a Mess, we all see teams that were moving fast at the beginning of a project can find themselves moving at a snail’s pace. Every change they make to the code breaks two, three other parts of the code. As the mess builds, the productivity of the team continues to decrease. Now management adds new developer to increase it but it creates the new mess because the new developers are not aware of current architecture and then together they create more mess.

The Grand Redesign in the Sky, eventually team rebels and they inform management that they cannot continue with the codebase and they demand redesign, Management doesn’t want to expend the resources but they can’t deny because productivity is 0. A new tiger team is selected and everyone wants to be on that team, now they have to develop same what old app is doing also the new changes that are coming in. It takes time but after some time, the developers of tiger team is gone and current developers demand new because it’s mess.

Attitude, Why does this happen to code? we complain that the change in requirements, schedules that were too tight, we blame stupid managers, intolerant customers etc. but the fault is in ourselves we are unprofessional.

The only way to make the deadline, the only way to go fast is to make your code clean as much as possible.

What is Clean Code? there are lots of definition given by different deep experience programmers, here I have mentioned one that I like most.

Bjarne Stroustrup, Inventor of C++. I like my code to be elegant and efficient. The logic should be straightforward to make it harder bugs to hide, the dependencies minimal to ease maintenance, error handling complete according to an articulated strategy and performance close to optimal so as not to tempt people to make the code messy with unprincipled optimisations. clean code does one thing well.

Thanks for reading this, here I am also including my point what I like most and I must recommend this book to each and every person who is responsible for writing/reviewing code. For more just buy the book.

Clean Code | Introduction | Quick Notes

51bPR2V9fBL._SX258_BO1,204,203,200_.jpg

A handbook of agile software craftsmanship by Robert C.Martin.

Writing clean code is what you must do in order to call yourself a professional, there is no excuse to do anything less than your best.

In this series of quick notes, I am going to share the quick notes from this book with you, So welcome aboard, let’s start with the introduction.

So think 2 mins, what is the valid measurement of code quality for you? The answer according to the book is funny but its WTFs/minute. haha 🙂 Now you can easily measure the quality of your code.

Next question will be, How to handle bad code? the answer is Craftsmanship. There are two parts of learning Craftsmanship: Knowledge and Work. It means you must gain the knowledge of principles, patterns and best practices and you must also grind the knowledge into your finders, eyes by working hard.

Yes, that’s why this book is divided into three parts.

  1. First will teach you principles, patterns, and best practices.
  2. Second, Case studies of ever-increasing complexity. Here you have to think and give the reason for making each change.
  3. Third, a list of heuristics and smells gathered while creating the case studies.

Thanks for reading this, I am also including what I like most and I must recommend this book to each and every person who is responsible for writing/reviewing code. For more just buy the book.

10 Ways To Make People Like You | Quick Notes

Currently I am reading one of the best book ever by Dale Carnegie – How to win friends and influence people and decided to share beautiful things that I found as quick notes. 

  • Become genuinely interested in other people, the only way to make genuine and long lasting friendship is to show interested and give respect to others.
  • Always smile, Smiles are free to give and have an amazing ability to make others feel wonderful.
  • Remember the person’s name, because people love there names.
  • Good listener, listen to them always maintain 80-20 principle (listen 80% and talk 20%).
  • Make other people feel important, give equal response to everyone. The golden rule is to treat other people how we would like to be treated.
  • Avoid the argument, because it does not matter if you win or lose as we always lose.
  • Never ever say you’re wrong better ask questions to them, so that they can realize it better.
  • If you’re wrong admit it quickly.
  • Call attention to people mistakes indirectly, no one likes to make mistake so scolding and blaming them only serves humiliate. Listen, share and discuss they will appreciate.
  • Talk about your mistakes before criticizing others.

Thanks for reading.

10 Ways To Make People Like You | Quick Notes

Currently, I am reading one of the best books ever by Dale Carnegie – How to win friends and influence people and decided to share beautiful things that I found as quick notes.

  • Become genuinely interested in other people, the only way to make genuine and long lasting friendship is to show interesting and give respect to others.
  • Always smile, Smiles are free to give and have an amazing ability to make others feel wonderful.
  • Remember the person’s name, because people love their names.
  • Good listener, listen to them always maintain 80-20 principle (listen 80% and talk 20%).
  • Make other people feel important, give the equal response to everyone. The golden rule is to treat other people how we would like to be treated.
  • Avoid the argument, because it does not matter if you win or lose as we always lose.
  • Never ever say you’re wrong better ask questions to them so that they can realize it better.
  • If you wrong admit it quickly.
  • Call attention to people mistakes indirectly, no one likes to make mistake so scolding and blaming them only serve to humiliate. Listen, share and discuss they will appreciate.
  • Talk about your mistakes before criticizing others.

Thank you for reading! If you really want to read more please share your feedback it will help a lot and it will be appreciated.

 

Fundamentals Technique for Handling Peoples | Quick Notes

Handling people is one of the biggest deal, because different peoples different views so for making long lasting relationships in personal or professional we need to add few things. Today I was learning new book `How to win friends and influence people by ` so sharing quick note here.

Fundamentals Technique for Handling Peoples.

  1. Don’t Criticize or Complain

Human nature does not like to admit fault, when people are criticized they rarely response you well so never ever criticize or complain because it will never result in the behavior what we want.

  1. Give Honest Appreciation

when it comes to appreciation, it’s the powerful key to win heart. Honest appreciation brings out their best and it must be sincere, meaningful and with love.

  1. Listen to them

To get what we want from other people we have to first listen them careful and see things from the point of view of others. So if you are a better listener it will already solve lots of conflicts.

  1. Mutually Achievement

So follow the 3rd point and then we can combine our desires with their wants after that they will become eager to work with you, now you can mutually achieve out objectives.

Thank you for reading! If you really want to read more please share your feedback it will help a lot and it will be appreciated.