Posts

GREP Cheatsheet

GREP stands for Global search using Regular Expressions and Print. It is a find command which returns all the line that has respective search patterns. Syntax : grep searchPattern searchLocation Parameter Output -n outputs line number -v outputs lines that doesn't contain the pattern -i ignores the case of searchPattern "searchPattern" search term (case sensitive in case -i not provided) ^ matches search pattern at the beginning of the line. e.g. ^"search". $ matches search pattern at the end of the line.,e.g. "search"$. If present at beginning then it ignores it completely. ^ matches search pattern at the beginning of the line. e.g. ^"search". \< matches search pattern at the beginning of the word. \> matches search pattern at the end of the word.  \b matches search pattern...

Dependency Inversion Principle (DIP) Explained

Image
Dependency Inversion Principle stats : A. High-level modules should not depend on low-level modules. Both should depend on abstractions. B. Abstractions should not depend on details. Details should depend on abstractions. Simply, Depend on Abstractions and not concretes.  This principle aims at reducing the coupling between different pieces of code. Why this principle ? Making change in highly coupled code is a risky task.  The same can be simplified by making high level abstraction of your low level details.  High level abstraction can be achieved by creating interface .  Abstract concepts like logging, caching by creating interface, so even if change happens in any of these concepts, the actual logical code will be unaffected by these changes. This will be simplified by following example : Consider we have a service which does some logical operations by getting data from FTP. We also cache and log the FTP data which you receive. In const...

"Don't Ask, Tell" Principle

Image
  Asking the object about its state (usually using if...else.. or switch statements), and then taking the decision on what to do next using that conditions leads to leaky abstraction. The behaviour of the object is exposed to outside world. The Don't Ask, Tell principle simply states to avoid querying or writing conditions on state of object outside its context.  The Logic is outside object context : The Logic is inside object context : Example :  1. Consider you want your game player to move, you don't make the legs move separately like  if(object.state === 'something') {       object.move(); } Instead you will : object.move() and write the condition, inside the method of object class.  The state and data is tightly coupled in this case. The code for the state and data in tightly coupled system should be present in same component.