Recursion – small exercise

In the highschool I’ve had a very good programming teacher. I remember her ‘famous’ quote – ‘keep your mind awake!’ (she liked so much this quote, that she was telling it several times on each curse). At that time I didn’t understand how true it was. Today I’ve had some free time and I remembered that I haven’t work for several months with recursion, so why not to make a small exercise? First component I’ve saw on the project I’m working it was a TMainMenu component. Simply, get with a recursion function, all items captions from a menu.

On a form, drop a TMainMenu component, and set several menu items. Also, drop a TMemo component on the form. Exercise is very simple: list on the TMemo all the menu’s items names. First time by using loops (choose from ‘for’, ‘while’ or ‘repeat’ – explication for each one of them can be found here) and second time by using recursion! In 5-10 minutes you should finish this exercise. Below is how I’ve resolved it. If you have find a better way, shout :)

procedure GetItemsCaption;
var wi:Integer;
 for wi:=MainMenu1.Items.Count-1 downto 0 do
  if MainMenu1.Items[wi] is TMenuItem then
    Memo1.Lines.Add( TMenuItem(MainMenu1.Items[wi]).Caption);
    For wj:=TMenuItem(MainMenu1.Items[wi]).Count-1 downto 0 do
     Memo1.Lines.Add( TMenuItem(MainMenu1.Items[wi]).Items[wj].Caption);

{recursion function bring it on!!!!} procedure GetRecursiveItemsCaption; var wj:Integer; function GetMenuItems(aMenuItem:TMenuItem):TStringList; var wi:integer; begin Memo1.Lines.Add(aMenuItem.Caption); wi:=aMenuItem.Count-1; while wi>=0 do begin GetMenuItems(aMenuItem.Items[wi]); dec(wi); end; end;//GetMenuItems ends here //body of a function/procedure from your form begin //first on the 'loop' style
procedure GetItemsCaption;
Memo1.Lines.Add('recursion'); //'recursive' style
For wj:=MainMenu1.Items.Count-1 downto 0 do GetMenuItems(MainMenu1.Items[wj]); end;

Is better sometimes to make this kind of exercises to remember some basic stuff.

Posted in Programming | Tagged | Leave a comment

Joel Test

You can find it here . I believe it is the most complete test for a Software Developer. But the business environment makes the rules, so, most of the companies don’t care about this(especially those who believe that Software Department are those guys who are ‘staring’ at their desk all day long), and don’t believe this is feasible. But the development process proofs that all those steps are real, and improving the development process has some costs. I believe that each Software Developer/Engineer should read that test, and think how he/she can apply most of those steps to their work.

Posted in Software Development | Tagged | Leave a comment

Delphi IDE Experts, components and tools for beginners and advanced users

As a software developer, I use every day several Tools/Components/IDE experts which help me on my work. I’ll mention only free tools, which, in my opinion can help either a beginner, either advanced user.

1) GExperts – is a free set of tools built to increase the productivity of Delphi and C++Builder programmers by adding several features to the IDE. GExperts is developed as Open Source software and they encourage users contribution to the project.

2) CnPack – these Chinese programmers made an incredible work. Their products include CnWizards, CnVCL, CVSTracNT and etc. All projects are Open Source and Free. They keep it up with nightly builds, but I prefer to wait the stable versions.

3) DDevExtensions - Andy made a very good work and his IDE expert is helping developers a lot.

4) Project JEDI – is a very large suite of components/API conversions/JCL/JVCL/etc, created by the Delphi community developers. Can help you a lot!

5) Code Formatter – made by Egbert van Nes, it’s helping you when you have several hundreds or thousands lines of code, and you want to properly format your code.

6) CodeToDoc – generates documentation for your Delphi code.

7) Programmer’s Notepad – a very good file editor.

If you know/use other tools(free) please let me know and I’ll add them to the list.


Posted in Programming | Tagged | Leave a comment