Keyword research and analysis can be a daunting task, when done correctly, and expert keyword research is the foundation to a successful SEO campaign. Many new website owners think the keyword research analysis process is easy. They think free tools, such as the Overture Search Term Suggestion Tool is the profít pill that will bring them ínstant results.
Unfortunately, the frëe tools will only give you a rough guide and a quick indication whether a hunch is worth further research. These frëe keyword research tools are limited to basic information. When performed correctly, expert keyword research exposes so much more - all the gems that are tucked away deep.
Real keyword research requires research AND analysis. There are so many aspects to the process that cannot be left to chance. Attempting to do the keyword research on your own is like going to a veterinarian to fix your car. My advise to all clients I do SEO consulting services for is to simply leave this task to the experts who have the correct keyword research tools and expertise.
Following are 5 tips for effective keyword research analysis:
1. Latent Semantic Indexing (LSI) - Use multi-word phrases
Latent Semantic Indexing (LSI) is a vital element in Search Engine Optimization (SEO) for better keyword rankings in search results. LSI is based on the relationship, the "clustering" or positioning, the variations of terms and the iterations of your keyword phrases.
Expertly knowing LSI and how it can be most useful and beneficial for your SEO and the importance it has with the algorithm updates to search engines like Google, MSN and Yahoo which will benefit your keyword research for best practice SEO.
LSI is NOT new. Those doing keyword research over the years have always known to use synonyms and "long tail" keyword terms which is a simpler "explanation" to LSI. More often than not, these long tail, less generic terms bring more traffíc to your site than the main keyword phrases. The real bottom line is that Latent Semantic Indexing is currently a MUST in keyword research and SEO.
2. Page Specific Keyword Research - Target your niche keyword phrases for each site page
Probably the most common mistake in keyword research is using a plethora of keywords and pasting the same meta keyword tag on every web site page. This is SO not effective! Your keyword research needs to be page specific and only focusing on 2 to 5 keywords per page. It's more work, but combined with best practice SEO, gives each site page a chance for higher ranking on its own.
3. Country Specific Keyword Research and Search Engine Reference
Keep in mind that keyword search terms can be country specific. Even though a country is English speaking, there are different keyword terms you must research - and then reference that country's search engine when doing your initial keyword research. For instance, UK and Australia may have different expressions, terminology and spellings (i.e. colour, personalised). Referencing the terms in the corresponding search engine is an important element to keyword research that is often forgotten. So for example, be sure to chëck the search terms on google.co.uk or au.yahoo.com. And, of course, if you have 3 to 4 really comprehensive research tools in your arsenal, you will be able to search for historical, global and country specific search terms easily and effectively.
4. Keyword Analysis - Cross referencing in the search engines
Once the majority of the keyword research has been done for a site page, it's time to plug those terms into the search engines to determine:
If it is really the desired niche keyword for that page
To assess the competitiveness of your keywords. Along with checking the competitiveness of your keywords you should look at the strength of the competition.
Are the other sites listed for your keywords truly your competitors?
Are the sites listed for your keyword even related to your industry, products or services?
These critical analyses of keyword phrases are often forgotten. Since the keyword research and analysis is the foundation of a successful SEO campaign, you certainly don't want to build your on-page optimization on the wrong niche keywords!
5. Ongoing Keyword Research - Repeat your keyword research on a consistent basis
While you may think that you have completed your keyword research analysis and laid a solid foundation for your SEO, you need to keep monitoring your keywords and tweak as necessary. Keywords can change from month to month as keyword search terms change, genres change and/or if your niche is within social portal networking sites - to name just a few. Maintaining ongoing keyword research is essential for best practice SEO.
Most Successful Strategy to Streamline Your Keyword Research Efforts:
Yes, many website owners will opt to do the keyword research and analysis themselves with only a marginal effect on an SEO campaign. It's not the most successful strategy to use for the most effective results.
To be certain of your keyword data, accurate keyword analysis should be performed - and cross referenced - across multiple expert keyword tools.
Effective keyword research lays the ground work for effective SEO results and can help you kick-start the ranking process - perhaps even giving you a step up on your competitors.
The most successful strategy to streamline your keyword research efforts is to hire an expert. Focus your business efforts on your strengths and expertise and allow the SEO experts to effectively perform the keyword research analysis correctly.
Wednesday, July 18, 2007
Friday, June 29, 2007
21 Essential SEO Tips & Techniques
Small businesses are growing more aware of the need to understand and implement at least the basics of search engine optimization. But if you read a variety of small businesses blogs and Web sites, you'll quickly see that there's a lot of uncertainty over what makes up "the basics." Without access to high-level consulting and without a lot of experience knowing what SEO resources can be trusted, there's also a lot of misinformation about SEO strategies and tactics.
This article is the second in a two-part SEO checklist specifically for small business owners and webmasters. Last week, I shared 20 "don'ts." Naturally, this week addresses the "Do's"—things to make sure you include whether you're hiring an SEO company or doing it yourself.
Small Business SEO Checklist: The Do's
1. Commit yourself to the process. SEO isn't a one-time event. Search engine algorithms change regularly, so the tactics that worked last year may not work this year. SEO requires a long-term outlook and commitment.
2. Be patient. SEO isn't about instant gratification. Results often take months to see, and this is especially true the smaller you are, and the newer you are to doing business online.
3. Ask a lot of questions when hiring an SEO company. It's your job to know what kind of tactics the company uses. Ask for specifics. Ask if there are any risks involved. Then get online yourself and do your own research—about the company, about the tactics they discussed, and so forth.
4. Become a student of SEO. If you're taking the do-it-yourself route, you'll have to become a student of SEO and learn as much as you can. Luckily for you, there are plenty of great Web resources (like Search Engine Land) and several terrific books you can read. Aaron Wall's SEO Book, Jennifer Laycock's Small Business Guide to Search Engine Marketing, and Search Engine Optimization: An Hour a Day by Jennifer Grappone and Gradiva Couzin are three I've read and recommend.
5. Have web analytics in place at the start. You should have clearly defined goals for your SEO efforts, and you'll need web analytics software in place so you can track what's working and what's not.
6. Build a great web site. I'm sure you want to show up on the first page of results. Ask yourself, "Is my site really one of the 10 best sites in the world on this topic?" Be honest. If it's not, make it better.
7. Include a site map page. Spiders can't index pages that can't be crawled. A site map will help spiders find all the important pages on your site, and help the spider understand your site's hierarchy. This is especially helpful if your site has a hard-to-crawl navigation menu. If your site is large, make several site map pages. Keep each one to less than 100 links. I tell clients 75 is the max to be safe.
8. Make SEO-friendly URLs. Use keywords in your URLs and file names, such as yourdomain.com/red-widgets.html. Don't overdo it, though. A file with 3+ hyphens tends to look spammy and users may be hesitant to click on it. Related bonus tip: Use hyphens in URLs and file names, not underscores. Hyphens are treated as a "space," while underscores are not.
9. Do keyword research at the start of the project. If you're on a tight budget, use the free versions of Keyword Discovery or WordTracker, both of which also have more powerful paid versions. Ignore the numbers these tools show; what's important is the relative volume of one keyword to another. Another good free tool is Google's AdWords Keyword Tool, which doesn't show exact numbers.
10. Open up a PPC account. Whether it's Google's AdWords or Yahoo's Search Marketing or something else, this is a great way to get actual search volume for your keywords. Yes, it costs money, but if you have the budget it's worth the investment. It's also the solution if you didn't like the "Be patient" suggestion above and are looking for instant visibility.
11. Use a unique and relevant title and meta description on every page. The page title is the single most important on-page SEO factor. It's rare to rank highly for a primary term (2-3 words) without that term being part of the page title. The meta description tag won't help you rank, but it will often appear as the text snippet below your listing, so it should include the relevant keyword(s) and be written so as to encourage searchers to click on your listing. Related bonus tip: You can ignore the Keywords meta altogether if you'd like; it's close to inconsequential. If you use it, put misspellings in there, and any related keywords that don't appear on the page.
12. Write for users first. Google, Yahoo, etc., have pretty powerful bots crawling the web, but to my knowledge these bots have never bought anything online, signed up for a newsletter, or picked up the phone to call about your services. Humans do those things, so write your page copy with humans in mind. Yes, you need keywords in the text, but don't stuff each page like a Thanksgiving turkey. Keep it readable.
13. Create great, unique content. This is important for everyone, but it's a particular challenge for online retailers. If you're selling the same widget that 50 other retailers are selling, and everyone is using the boilerplate descriptions from the manufacturer, this is a great opportunity. Write your own product descriptions, using the keyword research you did earlier (see #9 above) to target actual words searchers use, and make product pages that blow the competition away. Plus, retailer or not, great content is a great way to get inbound links.
14. Use your keywords as anchor text when linking internally. Anchor text helps tells spiders what the linked-to page is about. Links that say "click here" do nothing for your search engine visibility.
15. Build links intelligently. Submit your site to quality, trusted directories such as Yahoo, DMOZ, Business.com, Aviva, and Best of the web. Seek links from authority sites in your industry. If local search matters to you (more on that coming up), seek links from trusted sites in your geographic area—the Chamber of Commerce, etc. Analyze the inbound links to your competitors to find links you can acquire, too.
16. Use press releases wisely. Developing a relationship with media covering your industry or your local region can be a great source of exposure, including getting links from trusted media web sites. Distributing releases online can be an effective link building tactic, and opens the door for exposure in news search sites. Related bonus tip: Only issue a release when you have something newsworthy to report. Don't waste journalists' time.
17. Start a blog and participate with other related blogs. Search engines, Google especially, love blogs for the fresh content and highly-structured data. Beyond that, there's no better way to join the conversations that are already taking place about your industry and/or company. Reading and commenting on other blogs can also increase your exposure and help you acquire new links. Related bonus tip: Put your blog at yourdomain.com/blog so your main domain gets the benefit of any links to your blog posts. If that's not possible, use blog.yourdomain.com.
18. Use social media marketing wisely. If your small business has a visual element, join the appropriate communities on Flickr and post high-quality photos there. If you're a service-oriented business, use Yahoo Answers to position yourself as an expert in your industry. With any social media site you use, the first rule is don't spam! Be an active, contributing member of the site. The idea is to interact with potential customers, not annoy them.
19. Take advantage of local search opportunities. Online research for offline buying is a growing trend. Optimize your site to catch local traffic by showing your address and local phone number prominently. Write a detailed Directions/Location page using neighborhoods and landmarks in the page text. Submit your site to the free local listings services that the major search engines offer. Make sure your site is listed in local/social directories such as CitySearch, Yelp, Local.com, etc., and encourage customers to leave reviews of your business on these sites, too.
20. Take advantage of the tools the search engines give you. Sign up for Google's webmaster Central and Yahoo's Site Explorer to learn more about how the search engines see your site, including how many inbound links they're aware of.
21. Diversify your traffic sources. Google may bring you 70% of your traffic today, but what if the next big algorithm update hits you hard? What if your Google visibility goes away tomorrow? Newsletters and other subscriber-based content can help you hold on to traffic/customers no matter what the search engines do. In fact, many of the DOs on this list—creating great content, starting a blog, using social media and local search, etc.—will help you grow an audience of loyal prospects and customers that may help you survive the whims of search engines.
Just like last week, this list could continue well beyond these 21 "DOs." Your additions are welcome in the comments.
With this checklist and last week's list of "Don'ts," you should be able to develop a good plan of attack for your SEO efforts for your small business.
Matt McGee is the SEO Manager for Marchex, Inc., a search and media company offering search marketing services through its TrafficLeader subsidiary. The Small Is Beautiful column appears on Thursdays at Search Engine Land.
This article is the second in a two-part SEO checklist specifically for small business owners and webmasters. Last week, I shared 20 "don'ts." Naturally, this week addresses the "Do's"—things to make sure you include whether you're hiring an SEO company or doing it yourself.
Small Business SEO Checklist: The Do's
1. Commit yourself to the process. SEO isn't a one-time event. Search engine algorithms change regularly, so the tactics that worked last year may not work this year. SEO requires a long-term outlook and commitment.
2. Be patient. SEO isn't about instant gratification. Results often take months to see, and this is especially true the smaller you are, and the newer you are to doing business online.
3. Ask a lot of questions when hiring an SEO company. It's your job to know what kind of tactics the company uses. Ask for specifics. Ask if there are any risks involved. Then get online yourself and do your own research—about the company, about the tactics they discussed, and so forth.
4. Become a student of SEO. If you're taking the do-it-yourself route, you'll have to become a student of SEO and learn as much as you can. Luckily for you, there are plenty of great Web resources (like Search Engine Land) and several terrific books you can read. Aaron Wall's SEO Book, Jennifer Laycock's Small Business Guide to Search Engine Marketing, and Search Engine Optimization: An Hour a Day by Jennifer Grappone and Gradiva Couzin are three I've read and recommend.
5. Have web analytics in place at the start. You should have clearly defined goals for your SEO efforts, and you'll need web analytics software in place so you can track what's working and what's not.
6. Build a great web site. I'm sure you want to show up on the first page of results. Ask yourself, "Is my site really one of the 10 best sites in the world on this topic?" Be honest. If it's not, make it better.
7. Include a site map page. Spiders can't index pages that can't be crawled. A site map will help spiders find all the important pages on your site, and help the spider understand your site's hierarchy. This is especially helpful if your site has a hard-to-crawl navigation menu. If your site is large, make several site map pages. Keep each one to less than 100 links. I tell clients 75 is the max to be safe.
8. Make SEO-friendly URLs. Use keywords in your URLs and file names, such as yourdomain.com/red-widgets.html. Don't overdo it, though. A file with 3+ hyphens tends to look spammy and users may be hesitant to click on it. Related bonus tip: Use hyphens in URLs and file names, not underscores. Hyphens are treated as a "space," while underscores are not.
9. Do keyword research at the start of the project. If you're on a tight budget, use the free versions of Keyword Discovery or WordTracker, both of which also have more powerful paid versions. Ignore the numbers these tools show; what's important is the relative volume of one keyword to another. Another good free tool is Google's AdWords Keyword Tool, which doesn't show exact numbers.
10. Open up a PPC account. Whether it's Google's AdWords or Yahoo's Search Marketing or something else, this is a great way to get actual search volume for your keywords. Yes, it costs money, but if you have the budget it's worth the investment. It's also the solution if you didn't like the "Be patient" suggestion above and are looking for instant visibility.
11. Use a unique and relevant title and meta description on every page. The page title is the single most important on-page SEO factor. It's rare to rank highly for a primary term (2-3 words) without that term being part of the page title. The meta description tag won't help you rank, but it will often appear as the text snippet below your listing, so it should include the relevant keyword(s) and be written so as to encourage searchers to click on your listing. Related bonus tip: You can ignore the Keywords meta altogether if you'd like; it's close to inconsequential. If you use it, put misspellings in there, and any related keywords that don't appear on the page.
12. Write for users first. Google, Yahoo, etc., have pretty powerful bots crawling the web, but to my knowledge these bots have never bought anything online, signed up for a newsletter, or picked up the phone to call about your services. Humans do those things, so write your page copy with humans in mind. Yes, you need keywords in the text, but don't stuff each page like a Thanksgiving turkey. Keep it readable.
13. Create great, unique content. This is important for everyone, but it's a particular challenge for online retailers. If you're selling the same widget that 50 other retailers are selling, and everyone is using the boilerplate descriptions from the manufacturer, this is a great opportunity. Write your own product descriptions, using the keyword research you did earlier (see #9 above) to target actual words searchers use, and make product pages that blow the competition away. Plus, retailer or not, great content is a great way to get inbound links.
14. Use your keywords as anchor text when linking internally. Anchor text helps tells spiders what the linked-to page is about. Links that say "click here" do nothing for your search engine visibility.
15. Build links intelligently. Submit your site to quality, trusted directories such as Yahoo, DMOZ, Business.com, Aviva, and Best of the web. Seek links from authority sites in your industry. If local search matters to you (more on that coming up), seek links from trusted sites in your geographic area—the Chamber of Commerce, etc. Analyze the inbound links to your competitors to find links you can acquire, too.
16. Use press releases wisely. Developing a relationship with media covering your industry or your local region can be a great source of exposure, including getting links from trusted media web sites. Distributing releases online can be an effective link building tactic, and opens the door for exposure in news search sites. Related bonus tip: Only issue a release when you have something newsworthy to report. Don't waste journalists' time.
17. Start a blog and participate with other related blogs. Search engines, Google especially, love blogs for the fresh content and highly-structured data. Beyond that, there's no better way to join the conversations that are already taking place about your industry and/or company. Reading and commenting on other blogs can also increase your exposure and help you acquire new links. Related bonus tip: Put your blog at yourdomain.com/blog so your main domain gets the benefit of any links to your blog posts. If that's not possible, use blog.yourdomain.com.
18. Use social media marketing wisely. If your small business has a visual element, join the appropriate communities on Flickr and post high-quality photos there. If you're a service-oriented business, use Yahoo Answers to position yourself as an expert in your industry. With any social media site you use, the first rule is don't spam! Be an active, contributing member of the site. The idea is to interact with potential customers, not annoy them.
19. Take advantage of local search opportunities. Online research for offline buying is a growing trend. Optimize your site to catch local traffic by showing your address and local phone number prominently. Write a detailed Directions/Location page using neighborhoods and landmarks in the page text. Submit your site to the free local listings services that the major search engines offer. Make sure your site is listed in local/social directories such as CitySearch, Yelp, Local.com, etc., and encourage customers to leave reviews of your business on these sites, too.
20. Take advantage of the tools the search engines give you. Sign up for Google's webmaster Central and Yahoo's Site Explorer to learn more about how the search engines see your site, including how many inbound links they're aware of.
21. Diversify your traffic sources. Google may bring you 70% of your traffic today, but what if the next big algorithm update hits you hard? What if your Google visibility goes away tomorrow? Newsletters and other subscriber-based content can help you hold on to traffic/customers no matter what the search engines do. In fact, many of the DOs on this list—creating great content, starting a blog, using social media and local search, etc.—will help you grow an audience of loyal prospects and customers that may help you survive the whims of search engines.
Just like last week, this list could continue well beyond these 21 "DOs." Your additions are welcome in the comments.
With this checklist and last week's list of "Don'ts," you should be able to develop a good plan of attack for your SEO efforts for your small business.
Matt McGee is the SEO Manager for Marchex, Inc., a search and media company offering search marketing services through its TrafficLeader subsidiary. The Small Is Beautiful column appears on Thursdays at Search Engine Land.
Sunday, June 17, 2007
Determining the Size of a Class Object
There are many factors that decide the size of an object of a class in C++. These factors are:
Size of all non-static data members
Order of data members
Byte alignment or byte padding
Size of its immediate base class
The existence of virtual function(s) (Dynamic polymorphism using virtual functions).
Compiler being used
Mode of inheritance (virtual inheritance)
Size of all non-static data membersOnly non-static data members will be counted for calculating sizeof class/object. class A {
private:
float iMem1;
const int iMem2;
static int iMem3;
char iMem4;
};
For an object of class A, the size will be the size of float iMem1 + size of int iMem2 + size of char iMem3. Static members are really not part of the class object. They won't be included in object's layout. <2>Order of data members
The order in which one specifies data members also alters the size of the class. class C {
char c;
int int1;
int int2;
int i;
long l;
short s;
};
The size of this class is 24 bytes. Even though char c will consume only 1 byte, 4 bytes will be allocated for it, and the remaining 3 bytes will be wasted (holes). This is because the next member is an int, which takes 4 bytes. If we don't go to the next (4th) byte for storing this integer member, the memory access/modify cycle for this integer will be 2 read cycles. So the compiler will do this for us, unless we specify some byte padding/packing. If I re-write the above class in different order, keeping all my data members like below: class C {
int int1;
int int2;
int i;
long l;
short s;
char c;
};
Now the size of this class is 20 bytes. In this case, it is storing c, the char, in one of the slots in the hole in the extra four bytes.
Byte alignment or byte paddingAs mentioned above, if we specify 1 byte alignment, the size of the class above (class C) will be 19 in both cases.
Size of its immediate base classThe size of a class also includes size of its immediate base class. Lets take an example: Class B {
...
int iMem1;
int iMem2;
}
Class D: public B {
...
int iMem;
}
In this case, sizeof(D) is will also include the size of B. So it will be 12 bytes.
The existence of virtual function(s)Existence of virtual function(s) will add 4 bytes of virtual table pointer in the class, which will be added to size of class. Again, in this case, if the base class of the class already has virtual function(s) either directly or through its base class, then this additional virtual function won't add anything to the size of the class. Virtual table pointer will be common across the class hierarchy. That is class Base {
public:
...
virtual void SomeFunction(...);
private:
int iAMem
};
class Derived : public Base {
...
virtual void SomeOtherFunction(...);
private:
int iBMem
};
In the example above, sizeof(Base) will be 8 bytes--that is sizeof(int iAMem) + sizeof(vptr). sizeof(Derived) will be 12 bytes, that is sizeof(int iBMem) + sizeof(Derived). Notice that the existence of virtual functions in class Derived won't add anything more. Now Derived will set the vptr to its own virtual function table.
Compiler being usedIn some scenarios, the size of a class object can be compiler specific. Lets take one example: class BaseClass {
int a;
char c;
};
class DerivedClass : public BaseClass {
char d;
int i;
};
If compiled with the Microsoft C++ compiler, the size of DerivedClass is 16 bytes. If compiled with gcc (either c++ or g++), size of DerivedClass is 12 bytes. The reason for sizeof(DerivedClass) being 16 bytes in MC++ is that it starts each class with a 4 byte aligned address so that accessing the member of that class will be easy (again, the memory read/write cycle).
Mode of inheritance (virtual inheritance)In C++, sometimes we have to use virtual inheritance for some reasons. (One classic example is the implementation of final class in C++.) When we use virtual inheritance, there will be the overhead of 4 bytes for a virtual base class pointer in that class. class ABase{
int iMem;
};
class BBase : public virtual ABase {
int iMem;
};
class CBase : public virtual ABase {
int iMem;
};
class ABCDerived : public BBase, public CBase {
int iMem;
};
And if you check the size of these classes, it will be:
Size of ABase : 4
Size of BBase : 12
Size of CBase : 12
Size of ABCDerived : 24 Because BBase and CBase are dervied from ABase virtually, they will also have an virtual base pointer. So, 4 bytes will be added to the size of the class (BBase and CBase). That is sizeof ABase + size of int + sizeof Virtual Base pointer.
Size of all non-static data members
Order of data members
Byte alignment or byte padding
Size of its immediate base class
The existence of virtual function(s) (Dynamic polymorphism using virtual functions).
Compiler being used
Mode of inheritance (virtual inheritance)
Size of all non-static data membersOnly non-static data members will be counted for calculating sizeof class/object. class A {
private:
float iMem1;
const int iMem2;
static int iMem3;
char iMem4;
};
For an object of class A, the size will be the size of float iMem1 + size of int iMem2 + size of char iMem3. Static members are really not part of the class object. They won't be included in object's layout. <2>Order of data members
The order in which one specifies data members also alters the size of the class. class C {
char c;
int int1;
int int2;
int i;
long l;
short s;
};
The size of this class is 24 bytes. Even though char c will consume only 1 byte, 4 bytes will be allocated for it, and the remaining 3 bytes will be wasted (holes). This is because the next member is an int, which takes 4 bytes. If we don't go to the next (4th) byte for storing this integer member, the memory access/modify cycle for this integer will be 2 read cycles. So the compiler will do this for us, unless we specify some byte padding/packing. If I re-write the above class in different order, keeping all my data members like below: class C {
int int1;
int int2;
int i;
long l;
short s;
char c;
};
Now the size of this class is 20 bytes. In this case, it is storing c, the char, in one of the slots in the hole in the extra four bytes.
Byte alignment or byte paddingAs mentioned above, if we specify 1 byte alignment, the size of the class above (class C) will be 19 in both cases.
Size of its immediate base classThe size of a class also includes size of its immediate base class. Lets take an example: Class B {
...
int iMem1;
int iMem2;
}
Class D: public B {
...
int iMem;
}
In this case, sizeof(D) is will also include the size of B. So it will be 12 bytes.
The existence of virtual function(s)Existence of virtual function(s) will add 4 bytes of virtual table pointer in the class, which will be added to size of class. Again, in this case, if the base class of the class already has virtual function(s) either directly or through its base class, then this additional virtual function won't add anything to the size of the class. Virtual table pointer will be common across the class hierarchy. That is class Base {
public:
...
virtual void SomeFunction(...);
private:
int iAMem
};
class Derived : public Base {
...
virtual void SomeOtherFunction(...);
private:
int iBMem
};
In the example above, sizeof(Base) will be 8 bytes--that is sizeof(int iAMem) + sizeof(vptr). sizeof(Derived) will be 12 bytes, that is sizeof(int iBMem) + sizeof(Derived). Notice that the existence of virtual functions in class Derived won't add anything more. Now Derived will set the vptr to its own virtual function table.
Compiler being usedIn some scenarios, the size of a class object can be compiler specific. Lets take one example: class BaseClass {
int a;
char c;
};
class DerivedClass : public BaseClass {
char d;
int i;
};
If compiled with the Microsoft C++ compiler, the size of DerivedClass is 16 bytes. If compiled with gcc (either c++ or g++), size of DerivedClass is 12 bytes. The reason for sizeof(DerivedClass) being 16 bytes in MC++ is that it starts each class with a 4 byte aligned address so that accessing the member of that class will be easy (again, the memory read/write cycle).
Mode of inheritance (virtual inheritance)In C++, sometimes we have to use virtual inheritance for some reasons. (One classic example is the implementation of final class in C++.) When we use virtual inheritance, there will be the overhead of 4 bytes for a virtual base class pointer in that class. class ABase{
int iMem;
};
class BBase : public virtual ABase {
int iMem;
};
class CBase : public virtual ABase {
int iMem;
};
class ABCDerived : public BBase, public CBase {
int iMem;
};
And if you check the size of these classes, it will be:
Size of ABase : 4
Size of BBase : 12
Size of CBase : 12
Size of ABCDerived : 24 Because BBase and CBase are dervied from ABase virtually, they will also have an virtual base pointer. So, 4 bytes will be added to the size of the class (BBase and CBase). That is sizeof ABase + size of int + sizeof Virtual Base pointer.
Monday, June 4, 2007
Class Design in C++ Understanding Interfaces
When you're designing a class in C++, the first thing you should decide is the public interface for the class. The public interface determines how your class will be used by other programmers (or you), and once designed and implemented it should generally stay pretty constant. You may decide to add to the interface, but once you've started using the class, it will be hard to remove functions from the public interface (unless they aren't used and weren't necessary in the first place). But that doesn't mean that you should include more functionality in your class than necessary just so that you can later decide what to remove from the interface. If you do this, you'll just make the class harder to use. People will ask questions like, "why are there four ways of doing this? Which one is better? How can I choose between them?" It's usually easier to keep things simple and provide one way of doing each thing unless there's a compelling reason why your class should offer multiple methods with the same basic functionality. At the same time, just because adding methods to the public interface (probably) won't break anything that doesn't mean that you should start off with a tiny interface. First of all, if anybody decides to inherit from your class and you then choose a function with the same name, you're in for a boatload of confusion. First, if you don't declare the function virtual, then an object of the subclass will have the function chosen depending on the static type of the pointer. This can be messy. Moreover, if you do declare it virtual, then you have the issue that it might provide a different type of functionality than was intended by the original implementation of that function. Finally, you just can't add a pure virtual function to a class that's already in use because nobody who has inherited from it will have implemented that function. The public interface, then, should remain as constant as possible. In fact, a good approach to designing classes is to write the interface before the implementation because it's what determines how your class interacts with the rest of the world (which is more important for the program as a whole than how the class is actually implemented). Moreover, if you write the interface first, you can get a feel for how the class will work with other classes before you actually dive into the implementation details.
Inheritance and Class DesignThe second issue of your class design is what should be available to programmers who wish to create subclasses. This interface is primarily determined by virtual functions, but you can also include protected methods that are designed for use by the class or its subclasses (remember that protected methods are visible to subclasses while private methods are not). A key consideration is whether it makes sense for a function to be virtual. A function should be virtual when the implementation is likely to differ from subclass to subclass. Vice-versa, whenever a function should not change, then it should be made non-virtual. The key idea is to think about whether to make a function virtual by asking if the function should always be the same for every class. For example, if you have a class is designed to allow users to monitor network traffic and you want to allow subclasses that implement different ways of analyzing the traffic, you might use the following interface: class TrafficWatch
{
public:
// Packet is some class that implements information about network
// packets
void addPacket (const Packet& network_packet);
int getAveragePacketSize ();
int getMaxPacket ();
virtual bool isOverloaded ();
};
In this class, some methods will not change from implementation to implementation; adding a packet should always be handled the same way, and the average packet size isn't going to change either. On the other hand, someone might have a very different idea of what it means to have an overloaded network. This will change from situation to situation and we don't want to prevent someone from changing how this is computed--for some, anything over 10 Mbits/sec of traffic might be an overloaded network, and for others, it would require 100 Mbits/sec on some specific network cables. Finally, when publicly inheriting from any class or designing for inheritance, remember that you should strive for it to be clear that inheritance models is-a. At heart, the is-a relationship means that the subclass should be able to appear anywhere the parent class could appear. From the standpoint of the user of the class, it should not matter whether a class is the parent class or a subclass. To design an is-a relationship, make sure that it makes sense for the class to include certain functions to be sure that it doesn't include that subclasses might not actually need. One example of having an extra function is that of a Bird class that implements a fly function. The problem is that not all birds can fly--penguins and emus, for instance. This suggests that a more prudent design choice might be to have two subclasses of birds, one for birds that can fly and one for flightless birds. Of course, it might be overkill to have two subclasses of bird depending on how complex your class hierarchy will be. If you know that nobody would ever expect use your class for a flightless bird, then it's not so bad. Of course, you won't always know what someone will use your class for and it's much easier to think carefully before you start to implement an entire class hierachy than it will be to go back and change it once people are using it.
Inheritance and Class DesignThe second issue of your class design is what should be available to programmers who wish to create subclasses. This interface is primarily determined by virtual functions, but you can also include protected methods that are designed for use by the class or its subclasses (remember that protected methods are visible to subclasses while private methods are not). A key consideration is whether it makes sense for a function to be virtual. A function should be virtual when the implementation is likely to differ from subclass to subclass. Vice-versa, whenever a function should not change, then it should be made non-virtual. The key idea is to think about whether to make a function virtual by asking if the function should always be the same for every class. For example, if you have a class is designed to allow users to monitor network traffic and you want to allow subclasses that implement different ways of analyzing the traffic, you might use the following interface: class TrafficWatch
{
public:
// Packet is some class that implements information about network
// packets
void addPacket (const Packet& network_packet);
int getAveragePacketSize ();
int getMaxPacket ();
virtual bool isOverloaded ();
};
In this class, some methods will not change from implementation to implementation; adding a packet should always be handled the same way, and the average packet size isn't going to change either. On the other hand, someone might have a very different idea of what it means to have an overloaded network. This will change from situation to situation and we don't want to prevent someone from changing how this is computed--for some, anything over 10 Mbits/sec of traffic might be an overloaded network, and for others, it would require 100 Mbits/sec on some specific network cables. Finally, when publicly inheriting from any class or designing for inheritance, remember that you should strive for it to be clear that inheritance models is-a. At heart, the is-a relationship means that the subclass should be able to appear anywhere the parent class could appear. From the standpoint of the user of the class, it should not matter whether a class is the parent class or a subclass. To design an is-a relationship, make sure that it makes sense for the class to include certain functions to be sure that it doesn't include that subclasses might not actually need. One example of having an extra function is that of a Bird class that implements a fly function. The problem is that not all birds can fly--penguins and emus, for instance. This suggests that a more prudent design choice might be to have two subclasses of birds, one for birds that can fly and one for flightless birds. Of course, it might be overkill to have two subclasses of bird depending on how complex your class hierarchy will be. If you know that nobody would ever expect use your class for a flightless bird, then it's not so bad. Of course, you won't always know what someone will use your class for and it's much easier to think carefully before you start to implement an entire class hierachy than it will be to go back and change it once people are using it.
Wednesday, May 23, 2007
Introduction to SEO
A search engine is through which most of your potential visitors will discover your site. But for that to happen you first need the search engines in turn to discover your site.
It is only when the search engines 'understand' that your site is one of the best online places to find the kind of quality content that your site provides, is when they 'recommend' your site to people interested in similar content.
If all that sounds a bit abstract, allow me to elaborate.
Search Engines like Google, Yahoo and MSN routinely search the web for content and try to relate content to some keywords which they consider the focus of your content. So for example this tutorial on SEO is related to the term SEO. A web surfer looking for articles on SEO will query these search engines for the term 'SEO' and will get results based upon what search engines think are good sites for content related to the term 'SEO'.
In fact, a search on Google for SEO yields about 17,600,000 results at the time of the writing of this tutorial. Our web surfer looking for SEO related content would definitely not look beyond 15 or at most 20 initial links. The question then is how does the search engine decide which links to place before the other ones on such a search result.
Search Engines rank the pages for the specific search term and then show the pages in the order of those rankings. Google associates what is called a PageRank for each site. PageRank measures from 1 to 10, with a PageRank of 10 specifying a highly relevant site, and the relevancy decreasing in the order of the PageRank. Other search engines like Yahoo and MSN have similar ranking strategies. SERP (Search Engine Result Page) rankings in Google depend on the PageRank and also on how well the web site relates to your searched words. Given two web sites which relate equally well to your search term, the web site with a higher PageRank will be ranked higher in the SERP's.
Search Engine Optimization or SEO refers to how you can optimize your site such that your site is more aligned to the criteria that search engines use to rank web sites.
There is a lot of content online which will tell you a lot of stuff that you can do for SEO. Unfortunately most of these articles will tell you stuff that will waste a lot of your time and will not yield any desirable results. Worse, quite a few will tell you stuff that is outright wrong and are considered search engine spamming by major search engines. Using such techniques can result in your site being black-listed from their SERP's. Fortunately, there are still a lot of right things that you can do so that search engines rank your site favorably on your targeted search term.
The best part is, right here on this tutorial we tell you everything you should be doing and everything you shouldn't be doing for SEO.
It is only when the search engines 'understand' that your site is one of the best online places to find the kind of quality content that your site provides, is when they 'recommend' your site to people interested in similar content.
If all that sounds a bit abstract, allow me to elaborate.
Search Engines like Google, Yahoo and MSN routinely search the web for content and try to relate content to some keywords which they consider the focus of your content. So for example this tutorial on SEO is related to the term SEO. A web surfer looking for articles on SEO will query these search engines for the term 'SEO' and will get results based upon what search engines think are good sites for content related to the term 'SEO'.
In fact, a search on Google for SEO yields about 17,600,000 results at the time of the writing of this tutorial. Our web surfer looking for SEO related content would definitely not look beyond 15 or at most 20 initial links. The question then is how does the search engine decide which links to place before the other ones on such a search result.
Search Engines rank the pages for the specific search term and then show the pages in the order of those rankings. Google associates what is called a PageRank for each site. PageRank measures from 1 to 10, with a PageRank of 10 specifying a highly relevant site, and the relevancy decreasing in the order of the PageRank. Other search engines like Yahoo and MSN have similar ranking strategies. SERP (Search Engine Result Page) rankings in Google depend on the PageRank and also on how well the web site relates to your searched words. Given two web sites which relate equally well to your search term, the web site with a higher PageRank will be ranked higher in the SERP's.
Search Engine Optimization or SEO refers to how you can optimize your site such that your site is more aligned to the criteria that search engines use to rank web sites.
There is a lot of content online which will tell you a lot of stuff that you can do for SEO. Unfortunately most of these articles will tell you stuff that will waste a lot of your time and will not yield any desirable results. Worse, quite a few will tell you stuff that is outright wrong and are considered search engine spamming by major search engines. Using such techniques can result in your site being black-listed from their SERP's. Fortunately, there are still a lot of right things that you can do so that search engines rank your site favorably on your targeted search term.
The best part is, right here on this tutorial we tell you everything you should be doing and everything you shouldn't be doing for SEO.
Subscribe to:
Posts (Atom)