Pages

Is Clean Code Really matters ?

So, here we are again, IS CLEAN CODE REALLY MATTERS ?
YES, YES and HELL YES.

And the other question is WHAT FOR ?
That's what we talk about here..

OK lets go for it..
What is Clean code ? Actually we don't have the exact definition for this. But there are some definitions that create by geniuses. Below are some of these...

Bjarne Stroustrup, Inventor C++ and author of The C++ Programming Language
 I like my code to be elegant and efficient. The logic should be straightforward to make it hard  
 for 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 optimizations. Clean code does one thing  
 well.  

Dave Thomas, founder of OTI, godfather of the Eclipse strategy,
 Clean code can be read, and enhanced by a developer other than its original author. It has  
 unit and acceptance tests. It has meaningful names. It provides one way rather than many  
 ways for doing one thing. It has minimal dependencies, which are explicitly defined, and provides a clear and minimal API. Code should be literate since depending on the language, not all necessary information can be expressed clearly in code alone.  

Michael Feathers, author of working Effectively with Legacy Code,
 I could list all of the qualities that I notice in clean code, but there is one overarching quality that leads to all of them. Clean code always looks like it was written by someone who cares. There is nothing obvious that you can do to make it better. All of those things were thought  
 about by the code’s author, and if you try to imagine improvements, you’re led back to  
 where you are, sitting in appreciation of the code someone left for you—code left by someone  
 who cares deeply about the craft.  

and there are many more ...

But the HELL Question remains... WHY WE NEED THIS ? WHY WE NEED CLEAN CODE ?
If your a programmer with more than one year you know what I mean..

First take a look at bad code or a mess code.
Suppose you get a new requirement and you need to add the new functionality to your existing code which is really bad and messy. Before adding any new thing to your code first you need to understand the exiting code. That means you need to READ your existing code. Since its a bad code you will go through really pain full time to understand what the code says. For example imaging a code with no comments, no meaning full variables, no meaning full function definitions with hell of big line of codes that does too many things within single code block , this will drive you crazy.
So this will take more than time than you'r expecting(Or your PM) to read and understand only others code. Every programmer knows about the damn dead lines and our heads will bump up.
If it is a clean code it must full fill the READABILITY.

That's one of the basic thing that each and every code must have. But there are more. Formatting, Unit testing, avoid writing bad comments, Error handling  are some of. So will talk about all of these things in near future. Basically we will talk HOW TO WRITE CLEAN CODE. stay tuned :)




How to restore single table from large mysql dump ?

In this post I will briefly explain how to restore single table from a large mysql dump file. Its not that much hard what it says :)

BTW, first you need to know how to dump the database, so no worries ,some time back I wrote a blog post how to take a database dump. Take a look at this.

OK so lets get back to topic,
Here is the simple command that you can make it happen.

 sed -n -e '/CREATE TABLE.*mytable/,/CREATE TABLE/p' mydump.sql > table.sql  

mytable is the table name that you want to extract from the dump file.
mydump is the large dump file that contains dumped data
table is the file that will create after . (contains table creation data as well as insert data)
SO that's all. enjoy it :)