Importance of good code

Posted: August 31, 2016 in General
Tags: , ,

There is a famous quote – “Any fool can write a code that computer can understand. Good programmers write code that humans can understand”.  Any idea what does it transpire to, doesn’t it mean that writing a code is one thing but writing a clean code is taking it to another level.

A good programmer should know how to write a clean code that can be understood by others too, not only himself. Good code can be beneficial for an organization but bad code can destroy it.

Robert Martin an american software engineer and author, wrote in his book named “Clean Code” the only valid measurement of code quality is the number of WTFs per minute while reviewing the code. Picture below is taken from the same book :


Martin further writes : Which door represents your code? Which door represents your team or your company? Why are we in that room? Is this just a normal code review or have we found a stream of horrible problems shortly after going live? Are we debugging in a panic, poring over code that we thought worked? Are customers leaving in droves and managers breathing down our necks? How can we make sure we wind up behind the right door when the going gets tough? The answer is: craftsmanship.

Their are infamous examples of bad code which caused lot of damage to companies . There is a great example such as space rockets being mislaunched due to a badly transcribed formula (a single line was missing that meant the rocket had to be terminated 293 seconds after launch ultimately costing around 20 million dollars) or take an example of bug in  radiation therapy machine called Theract-25 which  involved in at least six accidents between 1985 and 1987, in which patients were given massive overdoses of radiation. Why? Because of concurrent programming errors, it sometimes gave its patients radiation doses that were hundreds of times greater than normal, resulting in death or serious injury. This was a side effect of the buggy software powering the device. You can read more about it here.

A good quality code is highly important for stability and maintainability of a product or a system. Like a normal nature in any project / product, as new features are added or functionality is updated you encounter that a new developer or an entire new team working on the codebase. There is high possibility that earlier developer may not be anymore with organization or completely forgot the flow and details of the project. In such case if the quality of the code is not upto the mark, then adding complexity to the project is inevitable adding to the more salt to injury.

Below pictures shows how much a programmer’s time spent in coding –

If you observe closely at the chart you will understand where does the maximum time goes, does it go in writing the new piece of code? No. It basically goes in either fixing/modifying an existing code or understanding the code itself.

That’s why a good programmers considers themselves as someone who is writing a book which is readable. Remember the intended audience is not the computer, it is other programmers (and yourself worst case). You are constantly reading old code in order to write new code.

Writing clean code is essential and critical, since it is maintainable, stable and easy to understand for any future developer.

“Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program. “ – Linus Torvalds

Few quotes from Martin’s book of clean code –

  • “Later equals never.”
  • The only way to make the deadline , the only to go fast – is to keep the code as clean as possible all times.
  • Clean code always look like as if it was written by someone who cares.

On a lighter note :

Hey Developers,

Happy to bring new post after a while. Today I was working on one of my project where it was required to upload/move a file to a FTP server using PHP from your local folder. Initially was bit scared how to proceed with the uploading of a file to a remote FTP server. But when I started working on I googled and with friends help got to know how to execute that task. I can tell you guys its very simple, just you need to know is few basic PHP commands for performing that functionality. Here it how it goes:-

For Uploading file on FTP You must have some access credentials required for it like Hostname, Username and Password of the remote server where you want to move your local files to. So if you have all those details then it is very simple to deal with the issue.

Follow the following steps:-

1) Assign the FTP access credentials to PHP variables as follows:-

(Note following is just a example/dummy values)

$hostName = '';
$userName = 'chandreshmodi';
$passWord = 'xyz12345';

2) Now assign directory of the remote server to a PHP variable where you want to move your file:-

$destinationDirectory = '/projectname/flodername';

3) Now assign directory of the local server to a PHP variable from where you want to move your file:-

$localDirectory = "/usr/local/temp"; // define this as per local system

4) Get the temporary file name for the uploaded file

$tmpName = basename($_FILES['file']['tmp_name']);

5) Copy uploaded file into current directory. Perhaps you will use following function for it:-

move_uploaded_file($_FILES['file']['tmp_name'], $localDirectory."/".$tmpName) or die("Cannot move uploaded file to working directory");

6) Open connection for the FTP server

$connection = ftp_connect($hostName) or die ("Cannot initiate connection to host");

7) Send access parameters to login to FTP Server

ftp_login($connection, $userName, $passWord) or die("Cannot login");

8 ) Now Once You are logged in to FTP, you can perform file upload to remote server using php “ftp_put”

$upload =
ftp_put($conn, $destinationDirectory."/".$_FILES['file']['name'],

9) Now Check Upload Status if your file got uploaded successfully or not:-

if (!$upload) {

echo "Cannot upload";

} else {

echo "Upload complete";


10) Close the FTP connection that you have opened:-


That’s it If you have all the valid credentials and if you follow all the steps mentioned above properly, i guess you would end up performing the file uploading task quite easily. If still any problems you comment on the post and I woul love to help you out.

Happy Rocking and Happy Coding.🙂

Cloud Computing” many of you would have heard this terminology somewhere somehow. But you may not be familiar with it. So What it is?? What it does?? What is the hype all it is about Cloud Computing?? All this question may arise in your central CPU called Mind..:-)

Basically Cloud computing is a technology that uses the Internet and central remote servers to maintain data and applications. It allows site users to use applications without any installation and access their personal files at any computer  remotely with an Internet connection. This technology provides efficient computing by centralizing storage of data plus less memory usage, high processing speed and greater bandwidth.


Life before cloud computing :-

A Normal Business applications that one have is always cumbersome and expensive. The amount  of hardware and software aid required to maintain and run  them  was painstaking. It needed a whole team for  installing, configuring, testing, running, and updating those hardwares and softwares.

So far you have got an Idea that Cloud Computing deals with delivering hosted services over the Internet. Now may be some of you would be perplexed and would be asking yourself then how does it differ from traditional way of hosting services. Isn’t it same?? So, to answer your question, A cloud service has three distinct characteristics that differentiate it from traditional hosting :-

a) It is sold on demand, typically by the minute or the hour.

b) It is elastic means a user can have as much or as little of a service as they want at any given time

c) The service is fully managed by the provider (the consumer needs nothing but a personal computer and Internet access).

Thus the above 3 main characteristic differentiates the cloud computing from traditional way of hosting Internet services.

A simple example of cloud computing in daily life is Yahoo mail or Gmail. You don’t need any softwares to run them. What you really needs is a computer plus an Internet Connection. That’s it. Am I wrong?? Obviously not! With that resource you can start sending mails and chat and do whatever you want to do. The server and email management is all on the cloud and is managed by cloud service provider like yahoo, google etc. Consumer don’t need to bother how its happening, they can simply enjoy using service. Its as simple as that :- “If You want to eat Vegetable..Would you buy a farm.” Similarly the analogy applies for cloud computing too. If  you want to use any service why would you take trouble installing hardware and softwares for it, when cloud computing does it for you.

Above attached diagram shows how cloud computing basically works. You can see a cloud at center. This cloud actually contains all the softwares and hardwares(as described above) that an application needs to run on your machine.Mobile, database, PC are all the end users which uses the application installed in a cloud.

I hope  the description and the explanation given would be ample to help you understand what is really a cloud computing is and what it does! Even though if any further doubts or questions are there, these blog is open for comments and I will try my best to sort out your queries.



What is Phishing?

Posted: January 21, 2011 in MISCELLANEOUS

Many of you people would have heard this term Phishing. Some of you would be knowing what actually it is?? Some of you wont be knowing what is it?? So people who don’t know what is phishing, please don’t interrelate it with fishing. Their is nothing similar in between two except their pronunciation which is almost same. Now you would be thinking if they are not same then what the hell phishing is?? Relax and just Chill out..:-)… The following article will completely explain you what is phishing? How it is done? What are the effects?? Just tighten up your seat belts and read it carefully..:-)

First of all we should know what Fishing is

What is Phishing?
Phishing is an e-mail fraud designed to steal your web identity and capture your personal data like Credit/Debit Card numbers, bank account information, or other sensitive financial information. Phishing scams have rocked Internet users for some time now.
Cyber-criminals write programs and send junk/spam mails to user which in turn tells you enter your banking/personal details. If you provide your details, you will be almost screwed. So be careful.
Following is a sample example how a Phishing mail may looks like. The example is an excerpt that I have received from HDFC bank.

1. The phishing email you receive might look like the one shown below.


2.If you click on the CLICK HERE option, it will take you to a bogus income tax site as shown below:

3. You will be given options for various Indian Banks to choose from.

4. Whichever bank you choose, your Internet banking passwords and additional authentication details will be compromised.
5. Once you have entered your details, you will be given a confirmation which might look as shown below.

Thus, you will end up gifting your confidential banking details to cyber criminals. They can misuse those details. So, one should be careful while clicking on a link in an email which is not trustworthy. Don’t allow anyone to access your details until unless you are sure that the source to which you are providing details is genuine.

Several examples are live out  in market where Bank customers have been fooled by this phishing mails/scam. Bank of America, US Bank,  Bank of  Montreal, ANZ Bank of Australia are the examples of these scam.

Not only these their are commercial institutions which have been affected by the phishing. For eg:- Paypal, ebay, MSN, Yahoo..

All Internet users are poilitical targets. We can all be fooled. It take only few minutes to get fooled on a bad day. So be careful while clicking on any link that takes you other website and ask your confidential details.

Happy Surfing..:-)

Can a Array be stored In A Session?

Posted: January 20, 2011 in PHP STUFF

Here we go guys. Storing an array in a session. Can we do it? Is it possible?? I came across this question once when I have to work upon something which required an array to be stored in a session variable. Since before that I have used session variable to store a string or some value but for sure not an array. But this time I had to play around with an array. So, after doing some searches I came across solution which I was looking for. The solution goes here :-

// begin the session

// create an array
$array=array('cricket', 'football', 'tennis', 'badminton', 'golf', 'squash', 'chess', 'basketball');

// put the array in a session variable

// a little message to say we have done it
echo 'Putting array into a session variable';

As simple as that. You would be thinking dude that was so easy assigning an array. Yeah that was really very simple. Now some of you would be thinking after assigning this array how do I access the value of array from the session variable. Don’t bother that is as simple as the assigning of array to the session. I hope all of you would be familiar with Foreach Keyword in PHP. I used the same Keyword for accessing the value of array from the session variable. Below is the code which I used for it :-

// begin the session
// loop through the session array with foreach
foreach($_SESSION['animals'] as $key=>$value)
    // and print out the values
    echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' ';

That’s all that I have been requiring to accomplish my task at work. Hope it would help you also if You come across such situation where you require to assign an array to a session variable.

PHP Namespaces and How to Implement?

Posted: January 19, 2011 in PHP STUFF

So here we go guys…

Namespaces all the talks happening in programming world. What are actually Namespaces??

In the broadest definition namespaces are a way of binding or encapsulating items.
For example, in any operating system, directories serve to group related files, and act as a namespace for the files within them. As a concrete example, the file foo.txt can exist in both directory /home/greg and in /home/other, but two copies of foo.txt cannot co-exist in the same directory. In addition, to access the foo.txt file outside of the /home/greg directory, we must prepend the directory name to the file name using the directory separator to get /home/greg/foo.txt. This same principle extends to namespaces in the programming world.

In the PHP world, namespaces are designed to solve two problems that authors of libraries and applications encounter when creating re-usable code elements such as classes or functions:

1. Name collisions between code you create, and internal PHP classes/functions/constants or third-party classes/functions/constants.
2. Ability to alias (or shorten) Extra_Long_Names designed to alleviate the first problem, improving readability of source code.

Why Do We Need Namespaces?

As the size of your PHP code increases, there is risk that you end up accidentally re-defining a function or class name that has been declared before. That will result in errors in your PHP code. So to avoid Name collision problems namespaces have been introduced.

How are Namespaces Defined?

Namespaced code is defined using a single namespace keyword at the top of your PHP file. It must be the first command and no non-PHP code, HTML, or white-space can precede the command, e.g.

  // define this code in the 'MyStuff' namespace  
     namespace MyStuff1;  
     namespace MyStuff2;
     namespace MyStuff3; 

PHP allows you to define a hierarchy of namespaces so libraries can be sub-divided. Sub-namespaces are separated using a backslash (\) character,
e.g. MyProject\SubName, MyProject\Database\MySQL.

So above was a brief expanation regarding the namespace. What they are, their use, how to define and declare?. Hope now you would be comfortable using the namespaces in your code and hence avoid name conflicts.

Happy Coding🙂

Parsing a URL in PHP

Posted: January 18, 2011 in PHP STUFF

Hi Guys,

Once at work I had got an issue where parsing of a URL was required. I was using PHP as a programming language. After few searches I came across a very good article that helped in performing my task.

Here is a simple function which can be used to Parse the URL.

parse_url is a built in PHP function which can be used to parse url and get the type of request like whether its http or https or ftp, gives the domain name like and path and the query.

for eg. lets consider this url –

$url = “;;
$parts = parse_url($url);

In this url

if you execute parse_url function then it will show the following result.

 Output :-
scheme - http
url -
path - /category.php
query - cat_id=6

That’s it… That is what I wanted for performing my task. You can also use this function in PHP if you come across a situation where you have to parse a url.

Happy Coding🙂