02 Mar

Why You Should Give a Lightning Talk

I previously posted that I had appointed myself Community-Booster, and so I now see it as my job to convince you to give a lightning talk at your local user group.  I could start by listing the benefits to you, or to the benefits to the user group, but I don’t think the for most people the fear of things going poorly outweigh the potential benefits.  So let’s focus on your fears.

  • “I have nothing interesting to present” – This is very unlikely to be true. You spend every day working with code, there is at least one concept that with a bit of preparation you talk about for 15 minutes.
  • “I have nothing original to present” – This one is very likely to be true, but it doesn’t matter. You don’t need an original idea, you just need your take on an idea. I didn’t discover the techniques I used in my Cross Platform Development talk, I collected a bunch of different techniques that others have shared through documentation, blog posts and even other presentations and compiled them into a larger talk. I presented the Repository Pattern in a lightning talk and I sure didn’t come up with on my own.
  • “I’m not a good public speaker” – This could be true, but it doesn’t mean you can’t become a decent or good public speaker and the only way to improve is to get out there an speak.  What better place to do that than in a room filled with people who tend to not be great public speakers, they’ll will be a forgiving bunch.

The positives break down into two categories

  • Makes you more hirable – If you submit a resume and somewhere on there it says that you spoke about X technology at your local user group that should pique the hiring manager’s interest even if they don’t use that technology. It shows that you take an interest in improving yourself. It shows that you know or researched a topic enough to be able to present it.  It also shows that you can communicate, which is something that can be hard to show on a resume. Most importantly it shows that you’re willing to share your knowledge, that you’re willing to spend your time and energy to help others become better developers.
  • Improves your developer Community – Every lightning talk I’ve ever heard helped me in some way. It’s not that I’ve been able to apply the knowledge immediately, but I’ve taken what I’ve learned and filed it away for future use. Even the design patterns talks were helpful, I’ve read books on design patterns and have implemented a fair number of them, but having someone step through one is still educational.  Most importantly, you might inspire someone else to speak.

I’m not going to lie, becoming more hirable was my primary motive for blogging and speaking when I started.  Now I’m focused more on improving the community. I learn so much from other people’s contributions through blog posts, answering questions on forums and speaking at user groups that I feel obligated to give back to that community. The more of us who give back, the better we all become.

23 Feb

Null Conditional Operator

There are a bunch of cool features coming in C#6, but the one I’m looking forward to the most is the Null Conditional Operator.  Developers write a lot of code to check if a value is null.  Sometimes it creates a deep and ugly nest of if statements.  Let’s say you are trying to find a customer’s primary contact’s city, it might look like this:

string primaryContactCity;
if (customer.PrimaryContact != null)
{
    if (customer.PrimaryContact.Address != null)
    {
        primaryContactCity = customer.PrimaryContact.Address.City;
    }
}

Or maybe you prefer less nesting and instead use a longer if statement:

string primaryContactCity;
if (customer.PrimaryContact != null && customer.PrimaryContact.Address != null)
{
    primaryContactCity = customer.PrimaryContact.Address.City;
}

With the new Null Conditional Operator you can just put ?. in place of the .. If the value to the left of the ?. is null it returns null otherwise it returns the property to the right. These two bits of code return the same thing:

Address primaryContactAddress;
if (customer.PrimaryContact != null)
{
    primaryContactAddress = null;
}
else
{
    primaryContactAddress = customer.PrimaryContact.Address;
}
Person primaryContactAddress = customer?.primaryContact.Address;

So the deep nest from above can be re-written as:

string primaryContact = customer?.primaryContact?.Address?.City;

It starts to get some real power when you use it in combination with the Null Coalescing Operator ?? In the following code we return the City as ‘Unknown’ if the PrimaryContact is null, or if the Address is null, or the City is null.

string primaryContactCity = customer.primaryContact?.Address?.City ?? "Unknown";
17 Feb

Community-Booster

A little over a year ago our local .Net User Group shut down (Maine Bytes).  The guy who had been running it for 10+ years decided he didn’t want to continue the work, and rather than find someone to fill his shoes he just shut it down (if you want to hear a rant ask me what I think about that decision).

Maine Bytes seemed to encourage passive attendance, not participation.  I’m not sure if was intentional or if it was the space (rows of tables facing the speaker) or just a vibe the group developed, but I frequently went and rarely talked with anyone.  They usually had a seasoned speaker come in from out of the area and the group (myself included) began to expect that. The one time the group held a “member lightning talk” night, I think it came as a surprise, and I’m ashamed to admit I was a little put off, that we had inexperienced speakers.

When Casco Bay .Net User Group filled the gap, their second meeting was a “member lightning talk” night.  At my co-worker’s urging (he is one of the organizers) I presented a gave a quick talk on Automated UI Testing with Selenium.  I really enjoyed speaking, but I also really enjoyed the other lightning talks.  They were compact and informative.

That night was enough to encourage me to speak at Boston Code Camp, then Vermont Code Camp as well as a few more CBNUG lightning talk nights. I’ve really enjoyed each of these events for their own reasons, but Vermont Code Camp really stirred something in me.

Two things happened the week of Vermont Code Camp that changed the way I look at our user group.
1. Russ Fustino spoke to our group about Xamarin Forms, which was a great, but at the end he said “Where are we all going to get a beer?” The question wasn’t “does anyone want to get a beer?”, the assumption was that we were all going to the bar and he wanted to know where. This was the first time we went for drinks after any user group meeting I’d ever been to, and it really broke the ice for the group.

2. I went to Vermont Code Camp. At first I was excited to see how many names I recognized as seasoned speakers I’d seen at bigger conferences or recognized from Twitter. But what really impressed me was the quantity and quality of speaker from Vermont.  It made me realize that these speakers probably got their starts at their local user group (VTdotNet).

Those two things made me realize we had a lot of work to do in Portland around building a better user group and more importantly a better community.  I realized I (and the group as a whole) needed to look forward to lightning talk nights. It’s on these nights when a first time speaker gets up and fumbles through a rushed presentation of a small idea that our user group truly grows. And it’s after the “official” meeting when we reconvene at the local pub that our community grows in other equally important ways.

Because of that revelation I have decided to appoint myself Community Booster.  I am going to do my best to encourage involvement at every level.  I’m going to encourage people to attend the user group meetings, to come out with us after, to speak at the lightning talks, to submit talks to both CBNUG and code camps. This isn’t an area I have much experience in, and I’m sure I’ll make some mistakes along the way, but I feel like the community I want to have in my local area needs someone (or multiple people) to really embrace this role.

03 Feb

Don’t Be Late for Scrum

We all know the importance of being on time for meetings, and since scrum is designed to be a short meeting, if you’re 5 minutes late for scrum you can miss a third to half of it.

I’m a morning person, so I find myself most focused and most productive before lunch.  That often means that when scrum rolls around at 9:30 I can be totally lost in thought with no concept of time.  In other words I have a tendency towards running late. 
The obvious thing to do is to set a reminder, but I usually run my sound through my headphones so if I’m not wearing them there’s a good chance that reminder is just going to pop up and not be seen.  When I worked in an office I’d see the other developers moving out of the corner of my eye and realize what time it was, no problem.

Since I’ve been working from home we’ve been having scrum over Skype.  Our leader starts a group call and thanks to Skype’s ability to ring through the speakers while using my headset for communication I was never late.
image

That worked great, but we recently moved our scrums to a Google Hangout.  On the plus side, we’re all doing video (not sure why we didn’t with Skype) and having a blast with Google Effects.  The downside of course is that we need to “dial-in” to every day.

I realized immediately that this left me with the potential to be late or even miss scrum, here’s the solution I came up with.  I’m using Task Schedule that is built into Windows to launch Chrome and navigate to our Scrum hangout.  Just create a Basic Task, set the schedule, choose Launch a Program for Action.  Select the path to your favorite browser for the Program, and put the URL in the Add arguments field.
image

Now every morning when scrum starts Chrome opens a new tab and brings up the Scrum hangout.  All I need to do is click the “Join” button.

13 Jan

New Years Resolutions 2015

This is my annual post where I publicly declare a few goals for the coming year.  Next year around this time I will take a look back to see how I did.  Looking back at last year I noticed that some of my resolutions didn’t have objective measurements, so I’m trying to include those this year.

Speak More

They say you really learn something when teaching it, and I can speaking forced me to deeply learn the topics I was presenting.  I really enjoyed speaking at my local .Net user’s group as well as Boston Code Camp and Vermont Code Camp.  I’m going to submit sessions to all both code camps, my local user group and at least 2 larger conferences.  All I can do is submit, the decision about whether I speak is out of my hands.

Blog More Consistently

Last year I resolved to blog more, which I did, but I had long stretches without any new posts.  This year I’ve been receiving John Sonmez‘s email course on building a blog.  It’s been an excellent course, and I would highly recommend signing up.    One of the steps in the course is to commit to a blogging schedule.  I’m committing to 2 posts per month.  A much more objective goal than I had last year.  Don’t be surprised if you see 2 posts on the last day of every month :)

Finish My Side Project

A friend and I have been working on a rental property management web application for a while now.  We both started new jobs in the middle of it and we’re both burnt out to the point that we were close to ditching it.  We are down to a handful of tough bugs and a few minor features we want to implement before releasing.  We’ve been on a hiatus for a month now, I’m thinking I’ll take another month hiatus before picking it back up, but I will release it by May 1, 2015 with bugs and missing features if I have to.

Personal Goals

Lose Weight – As I said last year, this one is a bit cliche for a New Year’s resolution, and last year wasn’t a grand success.  I only lost 5 of the 40 I figured I needed to lose.  This year I’m going to target losing 20 of the remaining 35.  I’ll tackle the rest in 2016.

Finish House Projects – I have projects that I started basically as soon as I bought this house 5+ years ago that still haven’t been completed.  These are things I can do myself and I have been loath to hire them out.  I’m either going to do them myself or hire them out this year:

  • Fix the hole in the kitchen ceiling
  • Sheetrock the attic
  • Finish the trim on the second floor
  • Remove the unused oil tank in the basement
  • Paint the house
13 Jan

New Years Resolutions 2014 – Retrospective

It’s time for my annual resolutions blog post, but first I wanted to do a little retrospective to see how I did on last year’s resolutions.

Blog More – I did blogged more, but not as much as I had hoped.  Posts were still less than once per month.

Find more ways to share knowledge – My talk at my local user group went well enough that I submitted and gave talks at the June Boston Code Camp, the Vermont Code Camp, and November Boston Code Camp.  I really enjoyed it, and I’m definitely going to continue.  I tried submitting talks to some bigger conferences but was not accepted.  I’ll keep trying.

X Networking – I got off to a good start, checking in with some people I hadn’t spoken to in a while to see what they were up to, but I didn’t continue it and I didn’t really do anything to expand my network aside from chatting with some people at the code camps.

 Going to Bed Earlier – I mostly nailed this one.

X Lose weight – I did shed 5 pounds, and if I didn’t change anything I think I’d lose another 5 this next year.

So I was 3 for 5 last year.  I would list the year as a success overall.  I made progress, and I’m still heading in the right direction.

28 Oct

Sharing Code with Dependency Injection

This is a multipart series on how to share code between .Net platforms.  All the examples will be showing how to share between Windows 8 Store applications and Windows Phone 8 application, but the techniques are useful for sharing code between any .Net/Xamarin platforms.

  1. Linked Files
  2. Conditional Compilation
  3. Partial Classes
  4. Inheritance
  5. Dependency Injection

What is Dependency Injection?

Dependency Injection is a form of inversion of control where the consumer of a service passes some of the objects on which that service is dependent to the service, rather than having the service create them.

How do I do it?

In this case we’re not going to use a Dependency Injection framework, we’re going to use what I call “the poor mans dependency injection”.  I’m doing it this way to keep it simple and this could still work well with a framework.

First we’re going to create a Portable Class Library and in that library we’re going to define an interface for our data storage methods

public interface IMyStorage
{
    void Save(string key, object value);
    object Get(string key);
}

The we’re going to move our MainePageViewModel class to that library.  We need to modify that class to accept an IMyStorage in it’s constructor, then use that object to get and save it’s data.

public class MainPageViewModel : INotifyPropertyChanged
{
    private IMyStorage _myStorage;
    public MainPageViewModel(IMyStorage myStorage)
    {
        _myStorage = myStorage;
    }

    private string _helloMessage = "Hello World";
    public string HelloMessage
    {
        get { return _helloMessage; }
        set
        {
                
            if (_helloMessage != value)
            {
                _helloMessage = value;
                RaisePropertyChanged("HelloMessage");
            }
        }
    }

    private string _name = "";
    public string Name
    {
        get { return _name; }
        set
        {
            if (_name != value)
            {
                _name = value;
                RaisePropertyChanged("Name");
            }
        }
    }

    public ICommand SaveAction { get { return new RelayCommand(() => Save()); } }

    public ICommand LoadAction { get { return new RelayCommand(() => Load()); } }

    private void Load()
    {
        object name = null;

        name = _myStorage.Get("Name");

        if (name != null)
        {
            HelloMessage = "Load " + name.ToString();
        }
    }

    private void Save()
    {
        _myStorage.Save("Name", Name);

        HelloMessage = "Save " + Name;
    }

    private void RaisePropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}

In the platform specific projects we need to add a reference to the PCL and create a class that implements IMyStorage. Windows Phone specific code below

class MyStorage : IMyStorage
{
    public void Save(string key, object value)
    {
        if (IsolatedStorageSettings.ApplicationSettings.Contains(key))
        {
            IsolatedStorageSettings.ApplicationSettings[key] = value;
        }
        else
        {
            IsolatedStorageSettings.ApplicationSettings.Add(key, value);
        }
    }

    public object Get(string key)
    {
        if (IsolatedStorageSettings.ApplicationSettings.Contains(key))
        {
            return IsolatedStorageSettings.ApplicationSettings[key];
        }
        return null;
    }
}

Then in the MainPage.xaml.cs where we are setting the page’s datacontext to the MainPageViewModel, we need to make sure we’re passing a new instance of the MyStorage class (this is the actual Dependency Injection, poor man’s style)

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
    this.DataContext = new MainPageViewModel(new MyStorage());
}
14 Oct

Sharing Code with Inheritance

This is a multipart series on how to share code between .Net platforms.  All the examples will be showing how to share between Windows 8 Store applications and Windows Phone 8 application, but the techniques are useful for sharing code between any .Net/Xamarin platforms.

  1. Linked Files
  2. Conditional Compilation
  3. Partial Classes
  4. Inheritance
  5. Dependency Injection

What is Inheritance?

I’m just going to go ahead and assume you understand inheritance, but I’m keeping this section to stay with the theme from the other posts in this series.

How do I do it?

To share code in this way we’re going to create an abstract class MainViewModelBase with an abstract method defined for the place where we’re going to do our platform specific coding.  We can share that class between projects either through file linking or creating a Portable Class Library

abstract class MainPageViewModelBase : INotifyPropertyChanged
{
    protected abstract void Load();
    protected abstract void Save();

    //The rest of the common code would go here
    private string _helloMessage = "Hello World";
    public string HelloMessage
    {
        get { return _helloMessage; }
        set
        {
            if (_helloMessage != value)
            {
                _helloMessage = value;
                RaisePropertyChanged("HelloMessage");
            }
        }
    }

    private string _name = "";
    public string Name
    {
        get { return _name; }
        set
        {
            if (_name != value)
            {
                _name = value;
                RaisePropertyChanged("Name");
            }
        }
    }

    public ICommand SaveAction { get { return new RelayCommand(() => Save()); } }

    public ICommand LoadAction { get { return new RelayCommand(() => Load()); } }

    

    private void RaisePropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;        
}

Then we’re going to inherit from that class in each of our projects.  Here’s what the code for the Windows Phone project looks like

class MainPageViewModel : MainPageViewModelBase
{
    protected override void Load()
    {
        object name = null;
        if (IsolatedStorageSettings.ApplicationSettings.Contains("Name"))
        {
            name = IsolatedStorageSettings.ApplicationSettings["Name"];
        }
        if (name != null)
        {
            HelloMessage = "Hello " + name.ToString();
        }
    }

    protected override void Save()
    {
        if (IsolatedStorageSettings.ApplicationSettings.Contains("Name"))
        {
            IsolatedStorageSettings.ApplicationSettings["Name"] = Name;
        }
        else
        {
            IsolatedStorageSettings.ApplicationSettings.Add("Name", Name);
        }
        HelloMessage = "Hello " + Name;
    }
}
01 Oct

Sharing Code with Partial Classes

This is a multipart series on how to share code between .Net platforms.  All the examples will be showing how to share between Windows 8 Store applications and Windows Phone 8 application, but the techniques are useful for sharing code between any .Net/Xamarin platforms.

  1. Linked Files
  2. Conditional Compilation
  3. Partial Classes
  4. Inheritance
  5. Dependency Injection

What are Partial Classes?

Partial Classes are a way to split a class up into multiple files. It is frequently used when one part of your class is generated code and another part is written by hand.  In this case we’ll use partial classes to separate code that is shared between platforms and code that is platform specific.

How do I do it?

First you would need to use linked files to share the code between your projects. Then you need to change the class declaration to include the keyword partial.

partial class MainPageViewModel

Then you create a new files in each of your projects.  In this example we’ll create MainPageViewModel.WP8.cs and MainPageViewModel.W8.cs.  The WP8 file would be created in the Windows Phone project and the W8 file would be created in the Window 8 project.  We then need to include that same class declaration in those files.

Then we just move the methods with platform specific code into those platform specific partial classes.

The WP8 file would look like this:

partial class MainPageViewModel
{
    private void Load()
    {
        object name = null;
        if (IsolatedStorageSettings.ApplicationSettings.Contains("Name"))
        {
            name = IsolatedStorageSettings.ApplicationSettings["Name"];
        }
        if (name != null)
        {
            HelloMessage = "Load " + name.ToString();
        }
    }
}

The W8 file would look like this:

partial class MainPageViewModel
{
    private void Load()
    {
        object name = null;
        if (ApplicationData.Current.LocalSettings.Values.ContainsKey("Name"))
        {
            name = ApplicationData.Current.LocalSettings.Values["Name"];
        }

        if (name != null)
        {
            HelloMessage = "Hello " + name.ToString();
        }
    }
}
27 Aug

Sharing Code with Conditional Compilation

This is a multipart series on how to share code between .Net platforms.  All the examples will be showing how to share between Windows 8 Store applications and Windows Phone 8 application, but the techniques are useful for sharing code between any .Net/Xamarin platforms.

  1. Linked Files
  2. Conditional Compilation
  3. Partial Classes
  4. Inheritance
  5. Dependency Injection

What is Conditional Compilation?

Conditional Compilation tells the compiler to selectively compile code.  Many developers use these to run certain code only while in debug that they don’t want to run in production.

#if DEBUG
    //do some stuff
#endif

How do I do it?

The first step would be to link a file between two projects.  Then you can either use an existing Conditional Compilation Symbol or create your own.  For example Windows Phone 8 defines SILVERLIGHT and WINDOWS_PHONE as Conditional Compilation Symbols.  You see see what symbols have been defined by your project and even add your own by going to the Build tab in Project Properties.
CompilerDirective

To use the Conditional Compilation Symbols you just use the #if statement.  For example if you are using a namespace exists in Windows Phone, but doesn’t exist in Windows 8 you could do this:

#if WINDOWS_PHONE
using System.IO.IsolatedStorage;
#else
using Windows.Storage;
#endif

The System.IO.IsolatedStorage using statement will only be compiled in the Windows Phone projects.  The Windows.Storage using statement will be compiled in all other projects.