Atlantic Business Technologies, Inc.

Category: Managed Services

  • Using .NET 3.5 List.Distinct()

    When I was working on a project today, I had a List of objects where I needed to grab objects that had a distinct property value (i.e. where MyObject.MyID is distinct).

    I discovered the Distinct() method on the List and I had never used it before so I wasn’t sure of the syntax. After further review, I learned you can use the IEqualityComparer interface to specify how to determine if the object is distinct.

    I’ll just show you the code because I feel it’s self explanatory:

    public class MyObjectMyIDComparer : IEqualityComparer
    {
      public bool Equals(MyObject x, MyObject y)
      {
        return x.MyID == y.MyID;
      }
    
      public int GetHashCode(MyObject obj)
      {
        return obj.ToString().GetHashCode();
      }
    }

    Now you can call the Distinct() method and pass in the class:

    List MyObjectDistinctMyIDList = MyObjectList.Distinct(new MyObjectMyIDComparer()).ToList();
  • Why Social Media Marketing is a Different Animal…And How to Take Advantage of It

    To the casual observer – or the too-busy-to-notice business owner or marketing manager – social media sites like Facebook, LinkedIn, and others might seem to just be the latest in online trends: something that’s hot today, but ultimately isn’t much different than search engine marketing or banner ads. The reality, though, is that they can be much more… but only if you use them correctly.

    linkedin-facebook-twitterThat’s because these platforms allow companies to achieve something they’ve been striving to reach for decades: interactivity. When users log onto sites like Facebook, it’s not just to see; they want to participate, give feedback, and share with their friends. The result is that it’s easier than ever to create a campaign that goes “viral,” in a big or small sense, because customers can pass along their impressions with a simple click of the mouse. They no longer have to search through their e-mail addresses or use bulky attachments – everyone they want to connect to is in one place.

    Of course, as with any new marketing technique, it takes some skill to get your message out in an effective way. If you are new to social network marketing, or have considered integrating it into your online sales strategy, here are a few tips to get you started:

    Geico Gecko
    Geico Gecko

    Get personal. There’s a reason that huge corporations use talking animals and other gimmicks online and off. Buyers like to get a sense of personality, even from Fortune 500 firms that they trust. Whether your company is traded on the stock exchange or operating from a spare room, try to make a connection with your customers and prospects by letting them see you are more than a collection of products.

    Avoid the silly. It’s one thing to let your clients see behind the curtain, and another one to seem completely unprofessional. Never forget that anything you post online could not only be seen by all of your customers and colleagues, but also archived or passed along. You can’t afford to have something offensive associated with your business, so always think twice before writing or showing anything that could come back to haunt you later.

    Advertise creatively. Don’t settle for simply broadcasting whatever is on sale for the week – you could do that on your home page, or in a newsletter. Instead, try to draw in visitors and fans by offering tips on better ways to use what you sell, or sharing some insight on how a specific product or employee came to your attention. Remember, social networking sites are places for very soft selling; you can have a sales message, but it needs to be wrapped in something funny or sweet.

    Organize events. Perhaps one of the most underutilized features of social networking sites is the ability to create groups and forums that can move from cyberspace and into your physical location. Are you having an event that would be of interest to the general public, or a free workshop that shows how to solve a common problem? These are ideal business uses for Twitter and Facebook, so be sure to spread the word.

    Think beyond text and photos. While there’s nothing wrong with filling out your profile, or your company’s, with the standard corporate images and descriptions, why not integrate video and links into the mix? Social networking sites are no place to post clips filled with industry jargon or insider information, but if you have something that’s fun, interesting, or just offbeat to use… then by all means use it! Remember, the goal isn’t to treat sites like Facebook as simply one more way to drub a marketing message into your clients, but to make your business a bit more accessible in a human way. If you can accomplish that, the bump in sales will follow.

    Social networking represents a revolution for marketers, not because of the technology behind it, but because of its intent. By allowing customers to use and share what they like about your company on their own terms, it encourages them to feel involved in the process. In other words, marketing becomes something they do with you, instead of you having to do it to them. Treated the right way, that makes it easier on both ends of the connection.

  • Using .NET 3.5 and Reflection to help with sorting a List

    The other day I was looking to be able to sort a list of products (List<Product>).  I was binding that list to a ListView and the client wanted to be able to sort the Products by Name (Z-A & A-Z) and by Price (Low-High and High-Low).

    I initially had something like this:

    public class SortProductsByPrice : IComparer
    {
      public int Compare(Product Prod1, Product Prod2)
      {
        return Prod1.Price.CompareTo(Prod2.Price);
      }
    }

    That works, but I didn’t want to write a class for everything I wanted to be able to sort by. For what the client wanted above I would have had to write 4 different classes.

    So I set off looking for an awesome way to write one sort method. Sparing you the endless results of clicking through many search results and articles, I ran across a couple things caught my attention: .Net Reflection, hey look I can see myself! and How to sort a ListView control by a column in Visual C#.

    Combining ideas from both of those examples above I produced a class that will Sort a List of any objects.

    public class Sort : IComparer
    {
      // Specifies the Property to be sorted
      public String SortBy { get; set; }
    
      // Specifies the order in which to sort (i.e. 'Ascending').
      public SortDirection OrderOfSort { get; set; }
    
      public Sort(String SortBy, SortDirection OrderOfSort)
      {
        this.SortBy = SortBy;
        this.OrderOfSort = OrderOfSort;
      }
    
      public int Compare(T x, T y)
      {
        int compareResult;
    
        Type MyTypeObject = typeof(T);
    
        PropertyInfo prop = MyTypeObject.GetProperty(SortBy);
    
        if (prop == null)
        {
          return 0;
        }
    
        switch (prop.PropertyType.Name)
        {
          case "String":
            compareResult = prop.GetValue(x, null).ToString().CompareTo(
              prop.GetValue(y, null).ToString());
            break;
          case "DateTime":
            compareResult = Convert.ToDateTime(prop.GetValue(x, null)).CompareTo(
              Convert.ToDateTime(prop.GetValue(y, null)));
            break;
          case "Double":
            compareResult = Convert.ToDouble(prop.GetValue(x, null)).CompareTo(
              Convert.ToDouble(prop.GetValue(y, null)));
            break;
          default:
            compareResult = 0;
            break;
        }
    
        switch (OrderOfSort)
        {
          case SortDirection.Ascending:
            return compareResult;
          case SortDirection.Descending:
            return (-compareResult);
          default:
            return 0;
        }
      }
    }

    Now I can utilize this awesome new class by calling it like this:

    ProductList.Sort("Price", SortDirection.Ascending);

    The concept here is you just pass the property you want to sort by (i.e. Price) and the direction and “Bam” (as Emeril says)!

    The next step here would just be to add some additional cases to my switch statement to check for other DataTypes (like Decimal, Int, etc).

  • Tip: Choose which browser to debug with in Visual Studio

    By default, Visual Studio uses Internet Explorer for debugging. If you’re looking for a way to change that, perhaps to harness the power of developer tools in Firefox or other browsers (or perhaps just because you don’t like IE), it’s pretty easy to do.

    1. Right-click your start-up project in Studio and click Browse With…
    2. Click Add
    3. Click the Browse button beside Program Name
    4. Select the browser you wish to use
    5. Click Ok
    6. Select the browser you just added and click Set as Default

    Here are the install locations of some of the more common browsers:

    • Firefox: C:Program FilesMozilla Firefox
    • Chrome: C:Documents and SettingsUserNameLocal SettingsApplication DataGoogleChromeApplication
    • Safari: C:Program FilesSafari
    • Opera: C:Program FilesOpera
    • IE: C:Program FilesInternet Explorer

    I find myself using Firefox the most, followed by Chrome. And as a best practice, don’t forget to test your projects in all browsers before putting them into production!

  • Database Performance Tuning, Part 1 – Keys and Data Types

    Database performance tuning is a pretty strong interest of mine, and I’ve been lucky enough to get to work on some really cool database-intensive projects in my time at Atlantic BT. I’ll be the first to admit that I’m still not an expert on the topic and probably won’t be for some time. But having said that, I’ve had to pick up on at least a few things to get by, and I’d like to share some of those over the course of my next few blog posts.

    Two Common, But Easily Correctable Problems

    Two of the most common problems I’ve seen in databases are a lack of primary and foreign key constraints and poorly typed data. These problems can and will lead to performance issues, and even worse, bad data. Luckily, these are also two of the easiest problems to correct.

    Keys

    Set Primary KeyIf you want to increase the performance of your database, then here’s a great starting point. Make sure that your tables have keys. EVERY table should have at least a primary key. But you shouldn’t stop there; you should also have foreign key constraints on many of your tables (keep in mind we call them “relational databases” for a reason – so create some relationships between the tables!). This has two benefits.

    The first is the preservation of data integrity. Consider a simple example for a moment – two tables, Members and Address. The Members table has 2 columns, Id and MemberName. The Address table has a MemberId column and all the expected fields for addresses. Let’s suppose there is an undetected bug in an application that updates or inserts to these tables. Now think about the application that would consume the data. What happens when two members have the same ID? What about when the MemberId in the Address table doesn’t correspond to an actual Id in the Members table?

    In software development, bugs are an unfortunate reality. Having strict key constraints in your database will add an additional degree of safety to your applications. In our example above, the Members table should have the Id column marked as a primary key and the Address table should have it’s MemberId column marked as a foreign key to the Member table’s Id field.

    The second benefit is increased performance. Foreign keys will help the optimizer establish relationships between tables and primary keys will auto-generate a clustered index on the table. I’ll touch on this in more detail later in this post as well as in my next post but these both offer gains in performance.

    Data Types

    Another common problem is poorly typed data. An extreme example of this is every column in a table being labeled as varchar(max) and allowing nulls, but lesser offenses can still cause problems. Pay attention to the type, max length, and nullability of your columns and make wise decisions in setting these properties. In general, your decisions should demonstrate simple logic – use varchar(2) instead of varchar(max) if you’re storing State abbreviations, use int instead of varchar if you’re storing a number, etc.

    An Example

    Both of these concepts are easy to demonstrate. If you have access to a testing environment, run the following script to create a couple of test tables.

    CREATE TABLE [dbo].[WidgetDescription]
    (
        [Id] [varchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
        [ItemName] [varchar](255) COLLATE  SQL_Latin1_General_CP1_CI_AS NOT NULL,
        [Description] varchar(255) COLLATE  SQL_Latin1_General_CP1_CI_AS NOT NULL
    )
    GO
    
    CREATE TABLE [dbo].[WidgetCount]
    (
        [Id] [varchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
        [WidgetId] [varchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
        [NumberProduced] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
    )
    
    DECLARE @i int
    SET @i = 0
    
    WHILE @i < 100000
    BEGIN
        INSERT INTO [WidgetDescription] (Id, ItemName, Description)
        VALUES (cast(@i as varchar), 'Widget' + cast(@i as varchar), 'Description of the Widget')
    
        INSERT INTO [WidgetCount] (Id, WidgetId, NumberProduced)
        VALUES (cast(@i as varchar), cast(@i as varchar), cast(@i as varchar))
    
        SET @i = @i + 1
    END

    We’ve created 2 (poorly designed) tables that contain information about widgets. Now let’s examine some simple queries. Note that I’m using STATISTICS TIME to monitor the run-time of the queries. To see this information, click the Messages tab in the output when the query is complete.

    SET STATISTICS TIME ON
    SELECT NumberProduced FROM WidgetCount WHERE WidgetId = 1
    SET STATISTICS TIME OFF
    
    SET STATISTICS TIME ON
    SELECT Description FROM WidgetDescription WHERE Id = 1
    SET STATISTICS TIME OFF

    My average run-time for the queries is in the 24 ms and 26 ms range, respectively.

    Run Time
    Run Time of our 2nd query before any optimizations

    Now let’s take some simple measures to improve the tables and see the difference it makes. First we’ll just make some simple data-type changes to the WidgetCount table. Our columns are meant to represent numbers, so they should all be of type int. For the WidgetDescription table, we’ll make similar data type changes and add a primary key. Make the Id column an int, set it to Identity with auto-increment, and make it a primary key. Shorten the ItemName column to only allow 25 characters and shorten the Description column to allow 100. (In a production environment, we would also set up a foreign key constraint between the WidgetId column of the WidgetCount table and the Id column of the WidgetDescription table, but this isn’t necessary for this example.)

    The same query after applying primary key and data type changes
    The same query after applying primary key and data type changes

    Now run the queries again, and you should see run-times averaging around 8 ms and 1 ms respectively. As you can see, changing the data types boosted performance, and adding a primary key additionally boosted performance. If a difference of a few milliseconds doesn’t seem like a big deal, try thinking of it this way. In the second query, making a few simple changes to our table resulted in a performance boost of 2500%. That is indeed a big deal. It might not be so noticeable when dealing with milliseconds, but when you bring a query that takes 10 seconds to run down to under 1, it will be.

    So how do we explain this boost? Two things. As for the data types, ints use less disc space for storage than varchars, and varchar(25) and varchar(100) use less than varchar(255). So there is simply less physical data to actually inspect and return. But the bigger difference is the primary key. Without the key, the optimizer can’t know that the values in the Id column are unique. So even though it finds a match after examining one row of data, it has to look at the other 99,999 to make sure there isn’t another match. However, once we add the key constraint, the optimizer knows it can stop looking after it finds a single match. The optimizer is doing a table scan (slow) in one instance and an index seek (fast) in the other. Again, I’ll cover this in more detail in my next post.

    To summarize, I’ve outlined two very easy rules to follow to ensure that your databases are well designed. You should also start to see some performance boosts as a result of enforcing these rules. In my next post, I’ll show you how to examine the optimizer’s execution plan to create indexes on your tables in order to further improve your database’s performance.

  • I Need Your Opinion! Social Validation Applied to E-Commerce

    No matter what we may think of the situation, we are (for the most part) all conformists. As a whole, we act upon what others do. We use social validation as a means to fit in with others around us. You can see evidence of this in areas of education, business, and yes…even the Internet.

    Why Won’t You Help Me?

    Great example of the Bystander Effect (source: carbonsmart)
    Great example of the Bystander Effect (source: carbonsmart)

    A couple of teenagers start a fight in the hallway at school. We’ve all been in this situation, whether we were a part of the fight or we were witness to it. How many people do you think will intervene and break up the fight? Very few. More often than not, others willl group around and witness the fight unfold before their eyes. We’ve all been there at some point in our life.

    The Bystander Effect refers to the phenomenon in which the likelihood of someone acting upon an emergency situation will decrease if the number of people around the situation is larger.

    (Source: psychology.about.com)

    Videos are posted all over the Internet about experiments and even real-life situations caught on camera where people simply ignore distress calls. At first, you probably would laugh at the situation but in reality it is pretty sad how we are hardwired to react a certain way based on our surroundings.

    Why do we ignore? Put simply, it’s a matter of trying to fit in with the crowd. If everybody else is just watching and not doing anything, therefore, I should act like them to fit in with the social norm.

    A study on the bystander effect, Markey (2000) tested how it played a role in getting help online through a chat service. Markey had three primary goals:

    1. Would gender determine the response time in receiving help?
    2. Does the amount of people needing help affect the response time?
    3. By asking help from a specific individual, would it decrease the response time?

    The results validated the bystander effect by proving all three questions. Gender did not have a distinctive effect on response time. The larger the number of people in the chat room increased the response time per person. By asking someone specific for help, the response time was rapidly reduced (as if nobody else were in the chat room).

    Only 5 to 10 percent of the population engages in behavior contrary to the social norm. Because we want to fit into these groups and maintain our membership with them, we conform our actions to the norm.

    The bystander effect is a great way to show the power of social validation. We tend to do what we think is best to fit in with the crowd, regardless of the situation.

    Online Shopping

    stars

    Shopping online is becoming more popular each and every day. It’s more convenient, cost less, and with websites becoming more focused on usability, it is much easier! The real challenge is the actual shopping itself.

    Questions start to come into play, such as:

    • What do I buy?
    • What color?
    • Which model?
    • Will my friends like me if I wear this shirt?

    Online shopping is a great example of how powerful social validation can be. Websites that allow user feedback or shopping statistics can provide a great experience for both the business as well as potential customers. It is used as a tool to reinforce their purchase.

    People look to others to decide what they should do. This is especially true when they are uncertain about whether or what action to take.

    (Source: Neuro Web Design (2009), Dr. Susan Weinschenk)

    Make It All About The User

    So what are some ways to enhance the user experience for online shoppers? Here are just a few that come to my mind and should be relatively easy to implement:

    • Product ratings
      These are typically a 5-star scale, ranging from 1- Not Good to 5- Highly Recommend. They are straight to the point and are based on the collective average.
    • Product reviews
      Whether they are from professionals or from actual customers, product reviews can provide a more qualitative analysis of a product. Users will listen more to those who appear to be in a similar lifestyle as them. Therefore, product reviews that relate more closely to the user’s use of the product will have a better effect.
    • Similar products
      When looking at products on a site, it can be beneficial to see a list of similar products. In a store environment, you would expect similar products to be grouped and placed in the same location. Why not mimic that for the web? By doing so, you allow your users to seamlessly flow between similar products without having to backtrack or go through the search process all over again.

    Hey Which Game Would You Buy?

    Highly rated game and was highly well sold worldwide (source: RockStar)
    Highly rated game and was highly well sold worldwide (source: RockStar)

    Let’s take video games for example. I personally go out and buy the latest and greatest video games on the market. I have my sources online that I go to daily and read up about the upcoming games. This is my strategy for figuring out whether my investments will be worth it in the end. After all, spending $60 per game adds up rather quickly. So when these games get reviewed (most get a review within a few days of its release date), I’ll read it and decide whether the game is going to provide me with an amazing experience. I am putting my trust on my sources. If my sources unanimously say that a game is amazing (i.e. Grand Theft Auto 4), then I will go out and buy that game. About 9 times out of 10 my sources are correct. I like those odds. In today’s economy, every dollar counts and I want to ensure that I am making a great purchase – every time.

    My strategy not only works for games, but it works for other big purchases, like a TV, surround sound, car, etc. People rely on others’ opinions in order to make an informed decision.

    Your Opinion Matters

    amazonitunes

    Amazon’s products have two very valuable pieces of information on their website: user ratings and similar products. As an online shopper, I find this very helpful when making a decision in buying a product. Most of the time, I’ll focus on why a product is necessarily bad rather than why it is good. It could be the functionality, the photo of the product was misleading, or the materials were below expectations. I like to do my research beforehand when buying stuff online. I’ll check professional reviews, read the product description on the manufacturer’s website, etc. I’ll know beforehand why it appears to be awesome. By reading what users rated and said about the product, I can filter out and find information that I want to know: reasons why I should not buy this product. Of course it is up to me to determine the validity of this information.

    How many times have we gone to the iTunes Store with the intention of buying just one or two songs and ended up downloading entire albums? Sounds good to Apple, but not so helpful on the wallet. Happens to me all the time. Not only is iTunes addicting to media lovers, but Apple now uses meta information in which it uses to suggest similar media (music, apps, videos, etc.) that pertain to your collection. This information organizes their media by tags, such as most downloaded, highest rated, similar genres, etc. Having this information at your fingertips is helpful – or hurtful, depending on which way you look at it.

    Related Articles

    Time to Speak Out!

    Social validation is hard at work in many ways. Ever feel pressured to buy something because everybody else has one? Did you grow up trying to be like one of the popular kids in school?

    This topic doesn’t end here today. I open it up to you guys. Got any stories about how social validation has helped or hurt you in a given situation?