Oct
21
2008
I’ve reinstalled my system a few days ago and upgraded all ports on my Mac.
Set up the new SVN server, created new repositories to store and keep my applications under version control. I’ve restored my folder from Time Machine which included the old .svn folders. Of course I wanted to remove all those ones before I import them to my new repository, so after some “googling” I’ve figured out how to do this from Terminal in the most efficient way.
Rather than going to each folder and delete all the old .svn folders and all the junk which had been left from my previous install, I managed to remove all these with one single command:
sudo find ~/Sites/myapp/ -name ".svn" -depth -exec rm -rf {} \;
If you are hardcore enough, you can also delete .DS_Store and .gitignore files too:
sudo find ~/Sites/myapp/ -name ".svn" -o -name ".DS_Store" -o -name ".gitignore" -depth -exec rm -rf {} \;
Article which helped me finding this method: find at dmiessler.com
Now you have a clean folder structure so you can start importing your application to your SVN repository
940 views | no comments, yet | tags: svn, terminal, tip
Oct
7
2008
I am just in the middle of a huge code re-factoring. I am dealing with a huge amount of code which was previously made by someone else. Most of you probably know that working with someone else’s code is most of the time a pain in the ass. It gets even worse when it leaks in documentation.
So, for this really simple reason I decided to start writing quick-tips about coding which will hopefully help keeping your code clean and easy to understand. Here’s the first one.
Use sensible and self-explanatory variable names
Think about how much time you often spend on figuring out what a variable is used for or what it is supposed to be. There are some bad examples:
# a lot of code before...
$b = SomeObject::getByID(12);
$na = "Cutting Edge";
$nu = 12;
$c = array('Audi', 'BMW', 'Mercedes', 'Aston Martin');
# a lot of code after...
Could you explain what those variables are meant to be? You will probably need to find the answer for that some other part of your code. A better way is to indicate the types and use self-explanatory variable names:
# a lot of code before...
$oBox = SomeObject::getByID(12);
$sName = "Cutting Edge";
$iNumber = 12;
$aCars = array('Audi', 'BMW', 'Mercedes', 'Aston Martin');
# a lot of code after...
In this example, the first characters indicate the data types of each variable (“o” means that the variable in subject is an object, “s” stands for strings, “i” indicates integers and so on. Pretty straight-forward.)
You may ask why this is a big deal. I tell you:
- Easier to understand,
- You know what to expect from a variable,
- Others will understand the structure of your code a lot faster,
- Also, it will be even easier for you too to maintain if you need to get back to your own code after a while.
So guys, please remember: Keep your code clean and sensible.
802 views | 1 comment | tags: tip