New certifications available for Delphi Developers

Last June 12th, 2011, I received an Embarcadero Community Newsletter pointing out that “certification exams are now available for Delphi developers.  Embarcadero's Delphi Certification Program offers two levels: Delphi Certified Developer and Delphi Certified Master Developer. “

I just passed the Delphi Developer Certification exam and thus I became a Certified Delphi Developer.
Certified Delphi Developer
 Now, I want you to become certified as well :-) So, mind this: 
  • This exam is conducted over the Internet without supervision. That means you can take the exam at home (or wherever you prefer) at your own pace. You don’t need to go to a particular place to take the exam: you just need an Internet connection and that’s pretty much it.
  •  The exam is cheap. It only costs $49USD.Consider for example that the prices for .NET or Java certifications are much higher.    
  • You can pay for the exam code online (you need an exam code to take the certification exam). Theoretically, you can pay it using VISA, MasterCard and Paypal. Warning: I tried with my VISA and Master Card cards and it didn’t work. It seems that there is (was) something wrong with the payment system. At the end, I managed to perform the payment through Paypal.
  • The exam contains 60 questions to be answered in 60 minutes. The time is plenty; so, don’t worry about it.
  • Be careful with the syntax questions: even if you are an experienced Delphi programmer, I would advise you to review the syntactical elements of the language before taking the test. Most times our memory becomes dusty after too much time relaying on the code completion features of the IDE.
  • Take a look at the Delphi Developer Certification Study Guide. Make sure you cover all the topics targeted for the exam. Remember: all topics go under examination.
I wanted to take the Delphi Master Developer Certification exam as well, but guess what? - This exam is supervised and I would need to travel to USA to take it. I think I will wait until it becomes available (hopefully) in Canada.

I belief the introduction of these certification programs is proof that Embarcadero is willing to gain a good portion of the programming market. By taking the exams you become part of the effort of bringing Delphi to the arena once more…I believe it’s worthy.

I recently found this Delphi Certification Webinar video by Andreano Lanusse.

Big-O notation: Which algorithm performs better?

Suppose (ideally… again, ideally) that you have created different algorithms to solve a particular problem. Now, suppose that you have determined the order for those algorithms using Big-O notation. Which algorithm performs better? 

This ABC goes like this:

O(1) < O(log N) < O(N) < O(N log N) < O(N^2) < O(2^N) < O(N!) < O(N^N)

Constant running time is the best… then logarithmic, linear, linearithmic, quadratic, exponential, factorial and I leave the name of the last one to you :-)

Having constant, logarithmic and linear algorithms should be you goal, although this might be difficult to achieve. In real world problems, if your solution algorithm is higher than quadratic, I would advise you to drop it…

I have seen lots of people get frozen with a simple question: which function grows faster? Remember the correlation above…it’s easy.
 
Notice: Having a O(1) ,O(log N) or O(N) algorithm doesn’t guarantee that your code is well written or optimized. Even with those orders there might be place for improvements and refactoring.

Calculating the factorial of a number in Delphi: Recursive and iterative methods

The factorial function can be defined in both recursive and iterative ways. Take a look at the following definitions borrowed from Wikipedia.

Recursive definition:

Factorial Recursive definition







Iterative definition:

Factorial Iterative Definition





For both the above definitions we have that:

Zero Factorial



The purpose here is not the mathematical stuff, but two provide the implementation of such definitions in Delphi (Object Pascal).

First, I bring you one recursive implementation of the factorial function. Notice how the function calls itself, which is what the recursion really is:

function Factorial(aNumber: Integer):
Integer;
begin
 
if aNumber < 0 then
    raise Exception.Create('
The factorial function is not
  defined for negative integers.
');

 
Result:= 1;
  if aNumber > 0 then
    Result:= Factorial(aNumber-1) * aNumber;
end;

Second, I present you one iterative implementation of the factorial function. You can easily see the iteration performed in the “for” loop below:

function Factorial(aNumber:
Integer): Integer;
var
  i: Integer;
begin
  if aNumber < 0 then
    raise Exception.Create('
The factorial function is not
  defined for negative integers.
');

  Result:= 1;
  for i:=1 to aNumber do
    Result:= Result * i;
end;


Big-O considerations:
The recursive factorial function implemented before has a linear growth O(n), not O (n!). In addition, the iterative factorial function is also linear
O(n).

Submit Blogger sitemap to Google, Yahoo and Bing

Sitemaps let search engines to know more about the structure of your website. Blogs, like any other websites, can improve their visibility on the Internet, by adding their XML sitemaps to the major search engines (Google, Yahoo and Bing).

The problem with Blogger is that you can’t upload your own sitemap or any other file to your blogspot sub-domain root (ex. http://sub-domain.blogspot.com/) or custom domain root (ex. http://www.yanniel.info/).

No panic! There’s a workaround for this: luckily for bloggers, sitemaps can be generated as feeds; meaning that you can actually submit an RSS or Atom feed as a valid sitemap.

Blogger supports both RSS and Atom formats. Anyway, I advice you use the Atom feed URL, because I have had problems when submitting the RSS URL. What problems?  Well, I don’t recall now, but I’m pretty sure I had problems ;-)

Here is the Atom sitemap URL for Blogger (it does work for both blogspot sub-domain and custom domains):

http://sub-domain.blogspot.com/atom.xml?redirect=false&start-index=1&max-results=500

http://www. customdomain/atom.xml?redirect=false&start-index=1&max-results=500

Basically, the important part is:

atom.xml?redirect=false&start-index=1&max-results=500

A brief explanation:
  • atom.xml express the fact that you are requesting an XML Atom feed.
  • redirect=false prevents  Blogger from redirecting your sitemap to a third-party sitemap burner. This is very useful if you are using FeedBurner, because FeedBurner feeds are not recognized as valid sitemaps in most cases.
  • start-index=1 indicates that you want to syndicate starting on your first post. If you chose 10, for instance, your sitemap will start at post number 10.
  • max-results=500 tells Blogger to include 500 posts in your sitemap.  You can change this number as well, but the maximum count of posts syndicated in your feed will never exceed 500.
So, what happens if my blog has more than 500 posts? Well, you simply add a second sitemap, a third and so on. See the URLs:

http://sub-domain.blogspot.com/atom.xml?redirect=false&start-index=1&max-results=500

http://sub-domain.blogspot.com/atom.xml?redirect=false&start-index=501&max-results=500

http://sub-domain.blogspot.com/atom.xml?redirect=false&start-index=1001&max-results=500
................................................

There’s only one thing pending: you need to add your sitemaps to the major search engines…
Submitting your sitemaps for each search engine is a slightly different process. I might cover those SEO topics in future posts.

Fetching a web page with Delphi

This function fetches the HTML content of a given web page. It takes the page's URL as parameter and returns the corresponding HTML text. The name CURL comes from the PHP Client URL Library that can be used (among other things) for the same purpose.
.................
implementation

uses
  IdHTTP;

function Curl(aURL: string): string;
const
  cUSER_AGENT = 'Mozilla/4.0 (MSIE 6.0; Windows NT 5.1)';
var
  IdHTTP: TIdHTTP;
  Stream: TStringStream;
begin
  Result := '';
  IdHTTP := TIdHTTP.Create(nil);
  Stream := TStringStream.Create;
  try
    IdHTTP.Request.UserAgent := cUSER_AGENT;
    try
      IdHTTP.Get(aURL, Stream);
      Result := Stream.DataString;
    except
      Result := '';
    end;
  finally
    Stream.Free;
    IdHTTP.Free;
  end;
end;
.................

You can modify this routine to have the web page saved to a file instead. For that, you only need to use the TStringStream.SaveToFile method in substitution of TStringStream.DataString.

One final observation: you may change the cUSER_AGENT constant to whatever value you decide. If you don’t specify a user agent, then a default value will be provided.

Ah! Don’t forget to add IdHTTP to the uses clause!