Friday, May 23, 2014

Graduation Coming? So you want a Dev Gig

This guy is ready (CC)
As I mentioned in my last post I am quickly approaching mid career. I am not that far gone that I am
jaded about junior developers.

I am however quite jaded when I see a senior developer in title and pay scale, but their chops are not quite up to snuff. They may even rank lower than a jaded college grad who thinks they know enough. First tip, don't be a dark matter developer. Your passion should be contagious and eventually confident. Be sure to relish in paying your dues. Reputation is formed when you think no one is watching. I am surprised by how many gigs I get just from networking and being a professional.

You will never get an intentional opportunity to focus on learning as you do in your first job. You will find that all you degree has afforded you is foundational knowledge and proof that you can focus and achieve goals. If you ever lose the ability to continually learn you are dying as a developer. Sure you can find a circuit of legacy apps to maintain, but your investment will depreciate quickly. And oh by the way it is good to assume you know nothing about programming straight out college. You will find you use less than 2% of your knowledge from college if you're any good. Again expect to pay dues. There will likely be a crash course in the technologies you're expected to use day to day.

Five books I would recommend for learning the grit of our business:

So I do not have a COMP SCI Degree

Congratulations you have focused on something you probably passionate about. Maybe you realized how much dust was on the Linux servers in the CS Department. Either way you clearly have valuable skills in multiple disciplines.

In effect it is not enough to say you are passionate in becoming a Developer. Its not even important at this point what focus you had in college. I ended up getting a Database Management focus with my Information Technology degree. I have an affinity for database development and administration. I have been doing line of business web development for nine years now. Although I was able to transfer my skills I learned with Oracle easily to the SQL Server data platform; it has not been my focus. I have concentrated on becoming well rounded incrementally. I set goals to get Security+, learn Server side binding, whatever in a time boxed fashion. When I wasn't working my day job I succeeded most consistently when I focused on an achievable goal in a given time period of less than three months. Expect to spend 30 minutes each day focused on learning on your on time. Have a long stretch (2-4 hours) on the weekends for deep dives. I would argue having time management and expectation management skills is in fact the key to success in any field.

Job Descriptions

Job descriptions will sometimes include:
Minimum Bachelor Degree in Computer science, Computer Engineering, Rocket Surgery, Digital Basket weaving, or related field.

This does not mean you can't hustle until you make. You are probably well qualified. This should be off putting in its lack of creativity. This will not be the last of boiler plate wording you will see in job posts.

In fact it is not uncommon companies to put a job posting out as a lure for several positions. So yes no one expects you to have ten years in Entity Framework 6.0, SISS, JAVA, PHP, and the ability to deal with whiney clients.

The job description may not even been written by anyone outside the recruiting department. In fact your potential boss or her boss may have just sent a list of keywords to the recruiter. The recruiter then crafted a plausible job description and cast a wide net.

Salary Negotiations

Eventually you will have success. Likely you spend time in front of a sales man to negotiate your salary. They will likely 'review' the data that gleamed from your interview(s). They are feeding your insecurities before they ask the tough question. If they do not have this guy they believe you will accept anything. Challenge this assumption you will likely get some time with the person who really is calling the shots and she will respect you a little more for negotiating.

Later in your career they will try to preface this with asking for a Salary history. This is a game of poker and they don't need to know your hand. If asked about Salary history remark that you consider that information proprietary and suggest a number significantly higher than what you are expecting. They certainly will not let you know the rate they bill customers before hiring you on.

Try to gather information about their likely rates before hand. Always know what the mean rates are for your market for the position your going for. Also maintain the ability to say no eventually. Even if your heart set on a dream job it helps to have a number of interviews lined up in close proximity. Even if it is a battle ship gray position that you have zero desire in accepting you will become better at negotiating when you have said no even if it is, "not in a million years no." If they bid higher than you are expecting you can work up from there almost always.

College gave me zero .NET skills

Confession time. I interviewed and landed my first .NET Dev gig having read many IT books but only one .NET book. (The latest edition) I could talk about running for National SkillsUSA Secretary and losing, competing Computer Maintenance at the national level, and myriad of other things that show intangible skills. You need to sell your potential. Its about showing passion.

It is also about being truthful about what you don't know. The hiring company will likely give some time to a Senior Dev who knows all the secret handshakes in the technology they are interviewing in. She will ask you questions you likely do not know the answers to. The goal is not to ace the questions but display honesty and more relevantly creativity under pressure.

Unlike me during my first recruitment experience you may be a well read student of the technology at hand for your first gig. Knowing your strengths and weaknesses and being practiced in giving an elevator pitch for a few of them is invaluable. Being new to the career yet polished is sometimes more useful then being jaded and experienced its all about valuing the right things. Perfection is not your weakness and it will differentiate you. At least in my book.

Saturday, May 17, 2014

.NET Framework: Building a generalized WCF DataContractSerializer

I am working on sharing some samples as a common framework through a blog series. I begin this series with this post about using Window Communication Foundation's (WCF) default serializer the DataContractSerializer outside of WCF. On Legacy projects you may still be using ASMX web service or some other technology and want to start migrating serialization to a format that will allow you to easily upgrade to WCF.

WCF is a way to do web services in .NET since .NET Framework 3.0. The sample in this post will work with all versions of WCF.

Unit Testing

I find Unit Tests a great way to share assumptions, document usage, and learn someone's coding style. In the sample I provided a sample usage of XmlDataContractSerializer in the test named SerializeToXmlString_BasicUseCaseWorks. Yes I do not have an Assert but as a side not this unit test does test that the Serialization happens without exception. 

As MSTest like most unit testing frameworks fails a test if an exception is thrown. I use MSTest because I am not doing anything that requires a particular unit testing framework. Feel free to use the one of your choice. I am not espousing its use over others.

[TestMethod]
        public void SerializeToXmlString_BasicUseCaseWorks()
        {
            var strategy = new XmlDataContractSerializer<ContactDto>();
            var data = CreateSampleData(); 
            var xml = strategy.SerializeToXmlString(data, true);
        }
 I share with you some of my favorite places using the Contact Data Transport Object (DTO) class ContactDto. The CreateSampleData mimics a Repository method, creating a collection of some of my favorite places statically although you could imagine it hitting a data store of some type.
private ContactDto CreateSampleData()
        {
            var data = new ContactDto();
            data.Email = "foreachdev@gmail.com";
            data.FullName = "Joshua Kincaid";
            data.AddressCollection.AddRange(new[]{
             new AddressDto(){
                 Line1="Admissions",
                 Line2="1 Old Dominion Way",
                 City="Norfolk",
                 ProvinceState="Virginia",
                 PostalCode="23529",
                 PreferenceOrder=5
             },
             new AddressDto(){
                 Line1="Handsome Biscuit",
                 Line2="2511 Colonial Ave",
                 City="Norfolk",
                 ProvinceState="Virginia",
                 PostalCode="23517",
                 PreferenceOrder=1
             },
             new AddressDto()
             {
                 Line1="OTTO",
                 Line2="1 5th Ave",
                 City="Manhattan",
                 ProvinceState="New York",
                 PostalCode="10003",
                 PreferenceOrder=0
             }
            });
            return data;
        }
XmlDataContractSerializer uses a base class to allow us to easily use an IOC Container to change out serializers with a config change.
public class XmlDataContractSerializer<T> : XmlSerializer<T, DataContractSerializerAdapter<T>> { }

The Rest of the Code 

XmlSerializer exposes the ISerializer interface for dependency injection purposes. You could have a IXmlSerializer or include a parameter for format if that is your preference.
using System;
using System.IO;
using System.Text;
using System.Xml;

namespace Jrf.Core
{
    /// <summary>
    /// A Serializer component for working with POCOs that has DataContract and DataMember classes. 
    /// </summary>
    public class XmlSerializer<T, U> : ISerializer<T> where U : ISerializer<T>, new()
    {
        private const string _XmlDeclaration = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
        /// <summary>
        /// Serializes class with DataContract and DataMember attributs to Xml using an in memory stream then reads it to a string.
        /// </summary>
        /// <typeparam name="T">Type to serialize.</typeparam>
        /// <param name="dataObject">The object to serialize.</param>
        /// <returns>String containing xml form of the POCO.</returns>
        public string SerializeToXmlString(T dataObject, bool includeDeclaration = false)
        {
            var output = new StringBuilder();
            var stream = new MemoryStream();
            var reader = new StreamReader(stream);
            try
            {
                Serialize(dataObject, stream);
                if (includeDeclaration)
                {
                    output.Append(_XmlDeclaration);
                    output.Append(Environment.NewLine);
                }
                output.Append(reader.ReadToEnd());
            }
            finally
            {
                //Avoids multiple dispose calls. (See FXCOP CA2202)
                if (reader != null)
                {
                    reader.Dispose();
                }
            }
            return output.ToString();
        }
        /// <summary>
        /// Serializes class with DataContract and DataMember attributs to XmlDocument using an in memory stream.
        /// </summary>
        /// <typeparam name="T">Type to serialize.</typeparam>
        /// <param name="dataObject">The object to serialize.</param>
        /// <returns>XmlDocument.</returns>
        public XmlDocument SerializeToXmlDocument(T dataObject, bool includeDeclaration = false)
        {
            var doc = new XmlDocument();
            using (var stream = new MemoryStream())
            {
                Serialize(dataObject, stream);
                doc.Load(stream);
                if (includeDeclaration)
                {
                    var root = doc.DocumentElement;
                    var dec = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
                    doc.InsertBefore(dec, root);
                }
            }
            return doc;
        }
        /// <summary>
        /// Creates and runs the serializer.
        /// </summary>
        /// <typeparam name="T">Type of Object to serialize.</typeparam>
        /// <param name="dataObject">Object to serialize.</param>
        /// <param name="stream">Stream to dump the serilization to.</param>
        public void Serialize(T dataObject, Stream stream)
        {
            var serializer = new U();
            serializer.Serialize(dataObject, stream);
            stream.Position = 0;
        }
    }
}
Finally, we have the simple DataContractSerializer strategy.
using System.IO;
using System.Runtime.Serialization;

namespace Jrf.Core
{
    /// <summary>
    /// Provides Serializer Services via the DataContract Serializer.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class DataContractSerializerAdapter<T> : ISerializer<T>
    {
        /// <summary>
        ///  Serializer method.
        /// </summary>
        /// <typeparam name="T">Type of object to be serialized.</typeparam>
        /// <param name="input">Object to be serialized.</param>
        /// <param name="output">Xml stream.</param>
        public void Serialize(T input, Stream output)
        {
            var serializer = new DataContractSerializer(typeof(T));
            serializer.WriteObject(output, input);
        }
    }
}

Wrapping up

 I will upload my code to Github as I continue this series. In the mean time, if I forgot any of the code in the walk through, please let me know.