The other day I got an email from WordPress saying “Your site has updated to WordPress 4.1.1”. I probably should have paid attention to it. But I assumed everything was ok. Next time I’ll check.

Today I went to check something on my blog and found it down. 500 error! If you host a site at all, you know that panic feeling you get when that happens. My blog is hosted on Azure Web Sites which is pretty cool but still makes me nervous when there are problems because it’s not a regular server that I can just log into and poke around. Plus, I am no expert with php or WordPress. In the end I was able to figure out the problem without too much trouble. Here’s what I did…

I opened up FileZilla (my ftp client of choice), connected to my server and started poking around. On the Azure Portal you can easily find the ftp address and account name used to connect. Luckily I knew the password!

On the root there is a folder LogFiles. That seemed like a good place to start.

It contained a file named php_errors.log. Again, sounds promising!

I found a lot of errors since this had been going on for a few days! Here is what it said:

PHP Fatal error:  ‘break’ operator with non-constant operand is no longer supported in D:\home\site\wwwroot\wp-content\plugins\blogml-importer\XPath.class.php on line 3773

So it seemed pretty clear what the problem was. An installed plugin (blogml-importer) was crashing my blog! But I had no idea how to fix it. I searched the web for “wordpress plugin fatal error” and found a link with the info I needed.

To disable a plugin manually without access to the WordPress admin site, just ftp in, go to the plugins folder (wp-content/plugins/) and rename the blogml-importer folder. I did it and everything worked.

Lucky for me, blogml-importer is just a plugin I used to import my content when I moved from dasBlog to WordPress. So I don’t need that anymore anyway.

Crisis averted. If you are stuck, I hope this information helps you too.

Do you know what a Tuple is? Have you ever used a Tuple in C#? Have you heard of Tuples but assumed they were some complicated language feature? Tuples are very useful and very easy to use.

A Tuple is a very easy way to create objects that have multiple properties. Sure, creating classes is pretty easy too. But sometimes you just want to pass around a few pieces of information and not create a class just for that. And yes, I know you can use a struct instead. But both of those are very permanent. Do I really need to create a new Type in my project for something so simple? Here’s an example.

Today I was writing a method that returned some XML as string. The XML was going to be combined into a larger XML document. Sort of like this:

string xml = "<OuterNode><Section1>{0}</Section1></OuterNode>";
string inner = someService.GetXml();
string.Format(xml, inner);

Pretty simple right? But then I found out that I actually needed to get 2 portions of XML and they went into two different places:

string xml = “<OuterNode><Section1>{0}</Section1><Section2>{1}</Section2></OuterNoded>”; //simplified for the example

Sure there are lots of ways to do this:

  1. I could create a second method to return the second section of XML. Sure I could. But as much as I like single responsibility, the method I am using really is the right place to return both pieces of information. You’ll have to trust me on that :)
  2. I could create a class to hold both pieces of information like the one below. But, well, I am lazy. Plus, it just feels like a lot of overhead for this.
public class XmlHolder
{
    public string FirstPart {get; set;}
    public string SecondPart{ get;set;}
}

This is a use case where a Tuple can come in handy. A Tuple is a data structure that has a specific number of arguments, each of a specific Type and in a particular order. Please don’t be mislead by the word “structure”; a Tuple is a Class, not a Struct. Here is how you create a Tuple:

var firstTuple = Tuple.Create(xmlPartOne, xmlPartTwo); //Both of those arguments are strings.

Cool huh?

To get the data out:

var foo = firstTuple.Item1;
var bar = firstTuple.Item2;

OK, cool. But not super cool. “Item1”, “Item2”??? To me that seems sort of cheesy. But keep in mind, this is not a Dynamic Type object so you can’t name the properties. So I guess “Item1”, etc, will be ok.

Using the Create() method is cool. But what exactly does it create? Here is another way to write it that gives us some more insight:

Tuple<string, string> firstTuple = Tuple.Create(xmlPartOne, xmlPartTwo);

or

Tuple<string, string> firstTuple = new Tuple<string, string>(xmlPartOne, xmlPartTwo);

Now you can see what is really going on… Generics! I love Generics.

Do you have more than two items? That’s no problem:

var foo = Tuple.Create(string1, string2, string3, string4, string5); // assume these arguments are all strings please.

Got items of different types? Easy:

var foo = Tuple.Create(someString, someInt, someDecimal, somePersonObject, someThingElse);

That last one is the same as this:

Tuple<string, int, decimal, Person, SomeThingElse> firstTuple = Tuple.Create(someString, someInt, someDecimal, somePersonObject, someThingElse);

Easy right? And of course, thanks to Generics it is strongly typed.

These guys are really easy to use. Plus unlike an anonymous object, you can pass them around. Here I have a method that takes a Tuple as an argument.

public void DoSomething(Tuple<int, string, DateTime> input)
{
    int age = input.Item1;
    string name = input.Item2;
    DateTime hireDate = input.Item3;
}

The problem with the example above is that the developer who calls the method cant really tell what arguments the method really wants. It would probably be better to do this:

public void DoSomething(int age, string Name, DateTime hireDate)

So, Tuples are classes that should be used with some caution. Not because they are “bad” but they may not be the best kind of object to pass around because, while strongly typed, the properties aren’t “strongly named”. Certainly not a great choice for a public API. I think they should really be used sparingly. Certainly great for prototyping. And good for real applications too. But as a team lead, I wouldn’t want to see my team start using Tuples in place of regular classes all over the place!

Some more information:

Tuples were introduced in .Net 4.0.

Tuples are immutable. You can’t change the value once it is defined.

Items in the Tuple can be value or reference types.

Tuples are classes, not structs so they are on the heap, not the stack. That means they are garbage collected.

You can use Create() for Tuples with 1 item to 8:

  • Create(T1); // called a singleton
  • Create(T1, T2); // called a pair
  • Create(T1, T2, T3); //called a triple
  • Create(T1, T2, T3, T4); // called a quadruple
  • Create(T1, T2, T3, T4, T5); // called a quintuple
  • Create(T1, T2, T3, T4, T5, T6); // called a sextuple
  • Create(T1, T2, T3, T4, T5, T6, T7); // called a septuple
  • Create(T1, T2, T3, T4, T5, T6, T7, T8); // called an octuple
  • Plus you can pass another Tuple in as the 8th argument to make even larger Tuples!

Check them out, I hope you will enjoy using Tuples in your code.

Now that the holidays are over it is time to get back to business. The Philly Application Lifecycle Management group has 2 great meetings scheduled.

The first is Thursday evening, Jan 22. Come hear Nik Molnar talk about tracking web performance.

The second meeting is next month on Thursday Feb. 19. For that meeting, Jess Chadwick talks about Getting the most out of NuGet.

We are really lucky to have these great speakers coming to our group. I’ve attended talks presented by both of these guys and I can assure you they will be good!

For more information about the group, please head over to Meetup.com:

 

Here are some additional details on the meetings.

Tracking Real World Web Performance

Study upon study confirms that web performance has a direct correlation to revenue, operating costs, and search engine ranking. With this in mind, we all want our applications to be faster but how do we know what bottlenecks to focus on?

Join Nik Molnar, co-founder of the open source debugging and diagnostics tool Glimpse, to learn how to leverage free and open source tools to capture your application’s live performance data, understand what the metrics mean and focus on the ones you should really care about.

This session will cover how to use free services to act as a simple lab for synthetic performance testing and how to get Real User Metrics (RUM) from the very last mile via the instrumentation API’s built into browsers. Nik will also demonstrate techniques to automate the performance feedback loop so you can ensure to always treat “fast as a feature”.

This session is suitable for any stakeholder who cares about performance. It is classified as 200 level.

 

Getting the Most out of NuGet

NuGet is far more than just a UI that makes it easy to incorporate open source projects into your applications. At the core of NuGet lies a platform that any team or organization can leverage to easily and collaboratively share assemblies, content, and even development tools… all within the comfort of your company’s LAN.

In this session we’ll go beyond the public package repository and take a look at the NuGet platform in depth to see how easy it is to create custom NuGet packages and host them in a private repository. We’ll also explore some of the other powerful things that NuGet enables you to do such as easily sharing tools and even scripting Visual Studio.

Jess Chadwick is a software developer and technologist with over fifteen years of development experience ranging from embedded devices in start-ups to enterprise-scale web farms at Fortune 500s. He is an ASPInsider and a magazine, book, and online course author, including O’Reilly’s Programming ASP.NET MVC 4 and several courses on Lynda.com. Jess is actively involved in the development community, regularly speaking at user groups and conferences as well as leading the NJDOTNET Central New Jersey .NET user group.

If you haven’t heard already, there are two new user groups starting up in the Philadelphia Area. Both are hosted on meetup.

ALM

The first is Philly Application Lifecycle Management User Group. The group’s first meeting is Thursday 2/27, 6pm at the Microsoft MTC in Malvern. The topic is “Getting the Most from Team Foundation Server 2013. And the speaker is… ME! I hope you’ll come out and help get this new group started. Here is a summary of the talk:

TFS is a powerful tool for many things including Work Item Tracking, Source Control and more. But what can you do when the standard templates just don’t fit your needs? Every team is different. Did you know that it is actually pretty easy to customize many parts of TFS to fit your team’s process? I’ve recently upgraded an entire IT department’s source control and work item tracking from TFS 2008 to TFS 2013. During the process I customized many facets of TFS. In this talk, I’ll share what I learned along the way. When we are done, you’ll be set to start getting the most from TFS.

Xamarin

The second new group is the Philly Area Xamarin Group. Their first meeting is Tuesday March 11. Looks like the first one is a meet and greet at Field House in Philadelphia. That sounds like fun.

I recently did a presentation of VS tips at the Philly.Net user group. My presentation included some tips for Visual Studio 2013 as well as some for older versions. I’ve bundled 3 related tips into one post here.

Clipboard Ring

The first tip is one that applies to past versions of Visual Studio but it always surprises me how few people know about this. When you are pasting content in Visual Studio, instead of using the traditional Ctrl + V to paste, use Ctrl + Shift + V to cycle through the clipboard ring. It is simple and easy to use. Sometimes I use Ctrl C to copy some text and when I try to paste it I hit Ctrl C again by mistake. Now I just copied a (usually) blank line into my clipboard and I can’t get back to the text I really wanted to paste. Fear not, Ctrl + Shift + V to the rescue and I can cycle back through the clipboard to the text I really wanted.

Avoid Copying Blank Lines

In the tip above, I mentioned a common scenario where I sometimes use Ctrl + C by mistake when I really want Ctrl V for “paste”. Sure the clipboard ring can help solve that problem but VS 2013 introduces a new feature. Just click on over to the options page at Tools > Options and then navigate to Text Editor > All Languages (or better yet, use Quick Launch and type in “blank lines”). You’ll see this:

image

In your case, the checkbox is probably checked. Uncheck it and you won’t have to worry about this again!

Box Selection/Column Mode

Once again, this feature has been in VS for a long time but many, many devs still don’t know about it. Everyone (right?) knows about using Ctrl + right/left arrows (or the mouse) to select text. But in the following sample, I realize that I have four variables declared as string but they should be int.

image

To fix them, I can just use Ctrl + Alt + the arrows or the mouse. But now, it is not just the left and right arrows but the up and down arrows as well.

image

And while that is selected, I can just start typing:

image

Play around with this. You can also use it to insert totally new text on all lines too.