quinta-feira, março 27, 2008

Delphi 2007 Cheat Sheet

This week I started reading the Marco Cantú's Delphi 2007 Handbook, and it inspired me to make this cheat sheet.

I learned several new Delphi 2007 shortcuts that helps a lot to improve productivity.

I made a compilation of the shortcuts which I think are essentials to every Delphi developer.

Download: Delphi 2007 Cheat Sheet.pdf

Just a few comments about some of the shortcuts:

Ctrl + /: This slash is the phisical slash key, it is located on the left side of the right shift key.
Ctrl + O, U: This shotcut inverts the case so CaSe becomes cAsE, you have to select the text, press Ctrl + O, release the Ctrl key and then press U


terça-feira, março 11, 2008

How to use TortoiseSVN to create a local Subversion repository

In my last post I explained how version control works, today I'll explain how to create your first local subversion repository using the tortoiseSVN subversion client.

There are several ways to have a Subversion repository, you can create an open source application and host in Google Project Hosting, you can sign up for a professional subversion hosting like wush.net, and you can keep it simple (stupid), and create your own local subversion repository.

A repository is basically the main subversion database where subversion tracks all modifications you do to any files added to it. So in order to use subversion you need a repositoy.

First of all you will need the TortoiseSVN client, just grab it and install.

After installing it, it will add some new options to you Windows Explorer context menu, so right click in any folder and you will see 2 options, SVN Checkout and a TortoiseSVN sub menu.

First of all, you will need to create a folder to be your repository, this folder will store a copy of your projects stored in the subversion repository and keep track of their modifications, so create a folder called MyRepository in any place you like.

After creating the folder, right click on it, go to the TortoiseSVN menu and click on Create Repository Here.



That's all you need to create a local repository.

No you will need some code to add to it, so create a folder or just create a folder called temp and a HelloWorld.txt, open the HelloWorld.txt file and type something on it.
Now, right click on the temp folder and on the TortoiseSVN menu, select import.



You will need to select where you repository is, to do so, click on the "..." button on the top right corner, and select the MyRepository folder.

Type Initial Import on the Import Message and click OK.

I'll explain what you just did, because it can be tricky to understand.

When you created your Repository, you just created an empty database, and the import you just did, added your project to that database, so now you can access your project using the database and send your changes to the database.

Create a new folder anywhere and call it MyWorkingCode, now, right click on this folder and select SVN Checkout, this window should pop up:



As you did in the import process, click on the top right button and select the MyRepository folder, don't change the checkout directory, now just click the OK and you will notice that Subversion starts adding your files to your MyWorkingCode folder.

Notice that now your MyWorkingCode folder has a green icon on it, it means that the source code in that folder wasn't modified and it is exactly how it was on the subversion repository when you checked it out.

Inside this folder you should find your HelloWorld.txt, change something in this file and save it, after saving you will notice that both the file and the folder containing it will have a red icon on them, that means that they were modified.

Now you have two options, send those modifications to the database, or revert the stated of the file back to the state it was when you checked it out, it is a very powerfull thing, because now you can just mess everything up and with just a click you have everything back to normal in seconds!

Try it out, delete the HelloWorld.txt file and after that right click on your MyWorkingCode folder and select Revert on the TortoiseSVN sub menu, click OK on the window that will pop up and feel the power, your file that was deleted was restored!

Now, Edit your HelloWorld.txt again and save it. After that, right click on you MyWorkingCode folder and select SVN Commit, you will notice that a Window will pop up and in the bottom panel, you will see your modified File, double click on it, you should see this window:




It shows the differences between your working file and the state the file was when you checked it out, just close this window and click on the OK button in the Commit window, it will send your modifications to the database and show the new revision number, this means that now you have 2 versions of this file on the repository, and you can get them at any time, just checking out the specific revision, and also you can revert the file to any past revision you like.

For now it's just it, I don't want to scare you as I was scared by the SVN Book, so I'll try to post a better explanation of commit and other subversion features in a near future, stay tunned.

segunda-feira, março 10, 2008

How version control works

I can't believe how stupid I was for not using a version control software since I started programming, I was always lazy about reading about it, also the SVN Book scared me do death.

First of all you will need to understand what version control really means.

You can find a lot of information about version control, but sometimes they are too extensive or maybe too complicated for beginners, I don't know if when people write about it they want to scare the begginners so they can learn the hard way as I did, but anyway I'll try explain with my own words, how version control works.

Every developer who has written more than "hello world" applications have faced this kind of situation:

You have a software that says that 1 plus 1 is 2, and then you change some stuff and it start saying that 1 plus 1 is -1, well, you changed a lot of stuff and it was working yesterday, but today you can make it work anymore, and also you changed so many things that it is almost impossible to figure out what caused the problem, it would be nice to have something to say what was changed since yesterday so you can quickly get a clue about what went wrong and what modification added the bug.

Well, version control could do that for you...

Now another situation, what if you accidentally deleted a file by mistake? What are you going to do? Search for backups? What if your backup is one week old and you changed a lot of stuff since then, well I guess you will have to do everything again, good luck.

Even people who already use version control sometimes don't know about everything it can do and how it really works.

First of all you need to understand that version control just stores the differences of your files, it creates a database and after you add a file for the first time, from that point on, every time you modify it, it will store only the difference of the current file to the previous state, so you can get the original file any time you want, and also based on this, you can always keep track of every modification and restore a file to any state it once was.

Also, version control never removes anything, so even if you delete a file, you can always restore it from a previous point where it still existed.

Imagine a timeline, with version control you can just go back to a point in time when that file still existed and restore it, nice isn't it?

Most people start using version control after the first time they need to work with someone else in the same source code, because it's practically impossible to work in a team, modifying the same source code without version control.

Did you notice that I didn't talk about any advantages version control has when working in teams, well, Its because that is not the idea behind this post.

For some time now, I've been keeping a local subversion repository for all my personal application, even the useless ones, because every once in a while you need to do something in real life that you already did in some useless test application that you garbaged, if you have that piece of code in subversion, it's just a matter of minutes do find it, instead of losing some hours doing it again.

To learn how to create your own subversion repository, please read: How to use TortoiseSVN to create a local Subversion repository