Have you ever stumbled across a project and just think to yourself why does this class exist, or more specifically why did they use this design pattern? Recently I happened across one of those projects, in it the project used a Factory class that’s purpose was to instantiate and return a single class. In essence the developers knew what the Factory pattern was and utilized it without having any purpose to do so. Instead they created additional worthless code. This use of a programming pattern without the need of the pattern is known as Cargo Cult Programming

Cargo Cult Programming

The Cargo Cult Programming anti-pattern is the use of patterns, structures, or code in a project because you either always do or simply because you don’t know what it is doing but are copying it from another project or programmer. This style of programming causes unnecessary abstraction, code bloat and increases the difficulty of maintaining the project over its life span.

Want to be a better programmer? Then understand your code, don’t blindly copy/paste or use a pattern just because you can. Take your time and think is this needed, does it provide a useful functionality or enhancement to my project? or does it simply add additional code and size to the project. Don’t fall pray to becoming a Cargo Cult Programmer

Resources

, , , ,

When it comes to Search Engine Optimization for your WordPress powered website or blog there are 2 main choices: All In One SEO Pack and Platinum SEO Pack. To help you make an informed decision on which to use I have compiled a comparison of the plugins’ features.

Feature Comparison

Feature All In One SEO Platinum SEO
Canonical URLs
Overwrite Titles
Automatically Generate Meta Tags
Automatic 301 Redirects
Support for Spider Specific Meta Tags (noindex, noarchive, etc)
Auto Meta Plugin Compatible
Ultimate Tag Warrior Plugin Compatible

As can be seen the two plugins contain the same base SEO functionality with the Platinum SEO Pack having a few additional options that are mainly used by advanced SEO optimizers.

Plugin Usability

The main configuration screen of the two plugins are almost identical with the exception of a few varying options and that the All In One SEO Pack screen displays ads front and center to donate and for buying WordPress themes as can be seen in the below screen shot.

The Platinum SEO Pack Plugin however displays the normal links navigation across the top that can be found in most WordPress plugins. The page / post level editors for the two plugins however don’t contain any real differences beyond the additional META tag support options that is available only in Platinum SEO Pack.

Which SEO Plugin should you use?

Simply put in my opinion the best SEO Plugin you can have at the moment is Platinum SEO Pack. This Plugin is easy to use contains all the SEO features your site will require and also doesn’t contain annoying advertisements like the All In One SEO Pack plugin. If you are currently using the All In One SEO Pack Plugin don’t worry switching is easy as the Platinum SEO Pack is able to import your settings from the All In One SEO Pack.

Resources

, , , ,

Over the lifespan of a software’s code source you will inevitably have to rename functions and properties of classes and maybe even remove them all together. This is not a major issue on simple projects but when your project is used by multiple applications then you may find that you need to keep these deprecated functions until other projects update their code to the new values. The Javadoc deprecated tag is how you mark a function or property as no longer in use and link to the new property or function to use.

The Deprecated Tag

The deprecated tag marks the current property or function as no longer in use. To use the tag simply add it into your Javadoc comments on its own line proceeded by the @ symbol.

/**
 * VIEW - ACTION TYPE
 * @deprecated 
 */
public static final String VIEW = "View";

The Link Tag

When you mark a property or function as deprecated it is always a good idea to link to the new property or function by use of the link tag. You can link to a property/value in the current class or to a property/value in another class.

Link in the current class

/**
 * VIEW - ACTION TYPE
 * @deprecated replaced by {@link #ACTION_VIEW}
 */
public static final String VIEW = "view";

Link in another class

/**
 * filters valid records
 * @deprecated replaced by {@link com.test.TestClass#filter()}
 */

Resources

, , ,

Database maintenance can be a full -time job when working within a large corporation. Cleanup or deletion of records can especially be time-consuming and error prone when dealing with large data tables with millions of records. Often developers will try to run a basic delete statement without knowing about batching or truncating the activity log. Below is a simple method for performing a batch delete.

Define you DELETE statement

The first step is to define your DELETE statement with the appropriate WHERE clause. If for example you want to delete all records before a set date then your query would look similar to:

DELETE FROM my_table WHERE action_ts < '06/01/2009'

Implementing the basic batch loop

To implement a basic loop we need to define some variables to keep track of a few variables. First we define @err to obtain the error id if an error occours, and @nCount to hold the total number of rows deleted.

DECLARE @err INT, @nCount INT
SELECT @nCount=0

Next we implement or while statement to execute or delete statement while more records are available to be deleted. In this example we will test if any rows exist matching or deletion statement.

WHILE EXISTS (SELECT * FROM my_table WHERE action_ts < '06/01/2009')
BEGIN
    ... 
END

In our while loop we will delete our records in batches by use of the TOP command that limits how many records are effected. We will be using a batch size of 10000.

DELETE TOP 10000 FROM my_table WHERE action_ts < '06/01/2009'

After our delete query we want to check if any errors occurred and if so break out of our batch loop. This is done by obtaining the current error status and if an error occurred then breaking out of the loop by the break command.

SELECT @err=@@ERROR, @nCount=@nCount+@@ROWCOUNT
IF @err=0
BEGIN
    ...
END
ELSE
BEGIN
    RAISERROR 20001 'Failed to delete date from table my_table'
    BREAK
END

Dumping the activity log and output statements

To be notified on how many rows are being deleted we can output the @nCount variable that is udpated after every deletion with the number of rows affected by the last delete statement. We can use the print statement to output the number.

PRINT '%l! rows deleted', @nCount

Also when dealing with a large amount of rows it is possible for the activity log to get full for the database. To clean up the log use the dump tran command with the truncate_only option.

DUMP TRAN my_db WITH TRUNCATE_ONLY

The Full Batch Delete Script

Putting the entire script together we end up with:

DECLARE @err INT, @nCount INT
SELECT @nCount=0
 
WHILE EXISTS (SELECT * FROM my_table WHERE action_ts < '06/01/2009')
BEGIN
 
    DELETE TOP 10000 FROM my_table WHERE action_ts < '06/01/2009'
 
    SELECT @err=@@ERROR, @nCount=@nCount+@@ROWCOUNT
    IF @err=0
        BEGIN
            DUMP TRAN my_db WITH TRUNCATE_ONLY
            PRINT '%l! rows deleted', @nCount
        END
    ELSE
        BEGIN
            RAISERROR 20001 'Failed to delete date from table my_table'
            BREAK 
        END
END

For those that worry about the extra time needed for doing the exists select clause in the while loop you could optionally use a separate variable to hold the latest row count and test for if the row count is greater than 0.

, , , , , ,

XCOPY is a dos command used to copy files or directories from one location to another. Most Windows user may never need to use the dos command prompt to migrate files between network drives but those of us that utilize both mac and pcs may find the need. Recently I obtained a new Windows 7 notebook to use at home and have since been in the process of syncing up my files from my apple macbook. While trying to transfer files off of my network drive I noticed that the transferred would fail silently with no files being copied to my notebook.

As it turned out windows didn’t like some of the file formats and so would quit on the copy without specifying an errors to the user… way to go Microsoft… Luckily for me I have experience with the command line and fired up the ms-dos prompt to see what was happening. After running a quick copy of the folder in question I found out immediately that a folder was unrecognizable by windows and was causing the copy to fail. To transfer the files I ended up using the XCOPY command as it allows you to continue the copy even if an error occurs. For others that may experience similar behavior below is a short How To on the XCOPY command.

Basic Command Format

The basic XCOPY requires 2 parameters the file / folder to be copied and the location the file / folder is to be copied to. If you want to copy a folders content and sub folders then be sure to use the * wild card.

XCOPY -SOURCE FILE- -DESTINATION- -OPTIONS-

Available Options

The XCOPY command has many options the ones we are intereseted in are listed below.

  • /C – copy continues even if an error occurs
  • /S – copy sub folders and files
  • /I – default destination to a folder if command is unsure of destination

Example

XCOPY M:\users\user1\* C:\users\user1 /c /s /i

Resources

, , , ,