Utah Open Source Conference 2012


Install Telnet.exe from the command line

I have a previous post about installing telnet.exe in windows 7, however, I explain how to do it using the UI. You may need to install telnet.exe from the command line.

To install telnet.exe on Windows 7 from the command line, run this command:

C:\Windows\system32>dism.exe /online /Enable-Feature:TelnetClient

Yes, it is that easy. Of course, you may think about using ssh these days as telnet just isn’t that secure.


Unit Test Stub Code Generator for Covering Arrays

Download Unit Test Stub Code Generator for Covering Arrays

The software can be downloaded here. Sorry, there is not an installer yet.

Installing Unit Test Stub Code Generator for Covering Arrays

  1. Copy the folder “Unit Test Stub Code Generator for Covering Arrays 1.0″ to anywhere on a Windows computer.
  2. Copy the Config directory to %ProgramData%\UnitTestGenerator. You will likely have to create that directory manually first.

That is it.

Try these sample method signatures.

public void MyFunction(string inString, bool inBool)

public void MyFunction(string inString, int inInt, bool inBool)

public void MyFunction(Person inPerson, string inString, int inInt)
{
    // Do some stuf
}

Return to C# Unit Test Tutorial


NUnit Project and Item Templates for Visual Studio

Here is an NUnit Project Template for Visual Studio.

  1. Download this template: NUnit Project
  2. Place this zip file into the %USERPROFILE%\Documents\Visual Studio 2010\Templates\ProjectTemplates\Visual C#.
  3. Create a new Visual Studio Project and choose NUnit Project from the list of C# projects.

Here is an NUnit Item Template for Visual Studio.

  1. Download this template: NUnit Test
  2. Place this zip file into the %USERPROFILE%\Documents\Visual Studio 2010\Templates\ItemTemplates\Visual C#.
  3. Add a new item to an NUnit Project and choose NUnit Test from the list of C# items.

My C# Coding Guidelines

Everyone has their own style guide and mine has just grown naturally. I didn’t used to do all of these so many of my early posts don’t follow these formats exactly, but I now very much prefer these coding styles.

Also, it annoys me to no end when someone calls there style good and another style bad. I will do no such thing. I will mark the styles as “My style” and “Not my style”. Just because it is “No my style” doesn’t mean it isn’t a good style for you.

Some basic guidelines

  • Follow the rules of grammar whenever possible.
  • Make code as self-documenting as possible.
  • Make code easy to copy and paste.

Indentation

Use four spaces tabs when tabbing. Remember this, scrolling up and down is easier than scrolling side to side.

Do not tab brackets but tab code inside brackets.

My Style

for (i = 0; i < 10; i++)
{
    DoSomething();
}

Not my style

for (i = 0; i < 10; i++)
    {
        DoSomething();
    }

Whitespace

Add spaces after commas in method parameters but don’t space around the parenthesis.
My style

public void DoSomething(string inString, bool inValue)
{
   string a = "a";
   string b = "b";
   SomeWork(a, b);
}

Not my style

public void DoSomething ( string inString, bool inValue )
{
   string a = "a";
   string b = "b";
   SomeWork( a, b );
}

No space when declaring an array.

My Style

string[] myArray = new string[] {"String1", "String2"};

Not my style

string [] myArray = new string [] {"String1", "String2"};

Curly Brackets

Always put the curly brackets on the next line. Why? Think of the brackets as left-most column. The opening bracket should be directly above the closing bracket, in the left-most column. Or think of the brackets as a section you want to isolate from everything else. The brackets (start section) should never share a line. You should be able to easily highlight all the lines in the bracketed section and not include any code outside the brackets.

My Style

for (i = 0; i < 10; i++)
{
    if (SomeBoolCheck())
    {
        DoSomething();
    }
}

Not my style

for (i = 0; i < 10; i++) {
    if (SomeBoolCheck()) {
        DoSomething();
    }
}

Again, in every instance where you use a curly bracket, put it on the next line.

if

Almost always use brackets even if it is only one line.

My Style

if (SomeBoolCheck())
{
    DoSomething();
}

Not my style

if (SomeBoolCheck())
    DoSomething();

The only time I use a one line if statement is when it really is only one line. And when I do this, I always have an empty line afterwards.

My Style

public void DoSomething(object inParam)
{
    if (inParam == null) return;

    DoSomething();
}

Not my style

public void DoSomething(object inParam)
{
    if (inParam == null)
        return;
    DoSomething();
}

Variable names

Member variables or fields

All public variables are in camel case with the first letter uppercase. I feel that having the first letter lowercase is distracting in most instances.

My style

public string FirstName;
public string LastName;

All private member variables start with an underscore and are in camel case with the first letter uppercase.

My style

private string _FirstName;
private string _LastName;

Not my style

private string _firstName;
private string _lastName;

Properties

I don’t really differentiate public or private properties, as I rarely have private properties and in the rare instances where I do, I don’t change the syntax in any way. Also, I always have a space between properties.

My style

public string FirstName {get; set;}

public string LastName {get; set;}

Always use an autoproperty unless you have at least one line of code to add to the get or set.

A Property that must have a manual backing field should have the backing field right under the property. Why, because if you think about it, it is part of the property and if you copy it (or just copy the contents on the lines with and within the brackets), the backing property should come along with the copy and paste.

My Style

public string FirstName
{
    get { return _FirstName; }
    set
    {
        _FirstName = value;
        NotifyPropertyChanged("FirstName");
    }
} private string _FirstName;

Not my style

private string _FirstName;

// .... more code

public string FirstName
{
    get { return _FirstName; }
    set
    {
        _FirstName = value;
        NotifyPropertyChanged("FirstName");
    }
}

Note: In my example, I am using a property for a ViewModel in the MVVM format. I would really prefer the following syntax. Someday, I will figure out how to do this without including 3rd party software.

[NotifyPropertyChanged]
public string FirstName {get; set;}

[NotifyPropertyChanged]
public string LastName {get; set;}

Methods

Naming

Methods should be named very clearly based on what they do. Length is not a problem due to intellisense. For example, imaging you want to have a function that eats a cookie. You would name it as follows. Also, I don’t do anything different for public verses private (or protected or internal) methods. They are all camel case with the first letter uppercase.

public void EatACookie()
{
    // ... code to eat a cookie
}

Parameters

All parameters in functions are in lowercamel case. Remember, having the first letter of a name be lowercase is distracting to me. However, I get by this by and mark the variable with the preposition “in”. In rare cases where I use a ref or an out for a parameter, I use those prepositions where “in” would be.

This also adds an additional benefit of marking the parameter variables differently than internal variables.

My style

public void EatACookie(Cookie inCookie)
{
    // ... code to eat a cookie
}

Not my style

public void EatACookie(Cookie cookie)
{
    // ... code to eat a cookie
}

Variables declared in a method

I basically just go all lowercase using the same name as the object when possible, or the most self documenting variable name as possible.

public void EatACookie(Cookie inCookie)
{
    Mouth mouth = new Mouth()
    mouth.Teeth.Chew(inCookie, 27);
    mouth.Swallow();
}

However, if the word needs camel case, I often add a short tag in front similar to method parameters only I usually use “loc” or “tmp” to mark them as local or temporary variables. Again, I use the same name as the object when possible, or the most self documenting variable name as possible.

My style

public void EatACookie(Cookie inCookie)
{
    CookieMonster tmpCookieMonster = new CookieMonster ()
    tmpCookieMonster.EatCookie(inCookie);
}

Final remarks

I am sure I have more styles I use, and I will add them as I go.


Using FreeBSD inside a controlled network – A required HTTP Proxy and No FTP

Inside a controlled network, it is a little harder to use FreeBSD. The simple things become hard, such as running “portsnap fetch extract” or running “make install” on a port.

In a certain network, I am experiencing certain security settings that I must make FreeBSD work around:

  1. An HTTP proxy is required to access external sites
  2. No FTP access.

Working with a required HTTP proxy on FreeBSD

You cannot bypass the proxy. Most ports are blocked with HTTP/HTTPS forced through the proxy. Even worse, DNS only responds for internal addresses  and the proxy handles the external sites, so your local box never actually resolves names to IP addresses and the browser only works because the proxy makes it work.

Setting a global proxy on FreeBSD

You can configure FreeBSD to use a proxy. You can set a global proxy, sort of. It looks like you can set a global proxy per shell. However, not all apps respect that proxy.

csh/tcsh

To add a global proxy to any csh or tcsh shell, add the following line to this file: /etc/csh.cshrc

setenv HTTP_PROXY http://ProxyNameOrIp:8080

sh

To add a global proxy to any sh shell, add the following lines to this file: /etc/profile

HTTP_PROXY=http://ProxyNameOrIp:8080
export HTTP_PROXY

Now that you have made these settings, your proxy should be working and any tool that uses HTTP/HTTPS, such as fetch, portsnap, make fetch, etc., should now properly use the proxy to access the internet.

fetch and tools that use it (ports, portsnap, etc…)

Any HTTP source should now work. Both ports and portsnap and other such FreeBSD tools use fetch so as soon as the environment variable is set, fetch and any tool that uses it will work.

Tools that don’t use fetch (Subversion, etc…)

Other tools, such as subversion, may not support the HTTP_PROXY environment variable and must be manually configured. For Subversion, I couldn’t find a global setting, instead it was a user setting. The file in your home directory. It usually exists by default but contains only comments. The following is the minimal lines you need.

[global]
http-proxy-host = ProxyNameOrIP
http-proxy-port = 8080

Working with no FTP access on FreeBSD

This problem is easy to get around. Always use HTTP or HTTPS. FreeBSD has usually made it that simple as all the common tools that use FTP seem to have HTTP options as well.

Ports

Most ports have an HTTP site as a backup download location. The best case, you run make install and it just finds an HTTP site and downloads the port for you. In the worst case, you may have to manually edit the Makefile and add an http source.

Portsnap uses http by default.


Decoupling settings from /etc/rc.conf in FreeBSD

The rc.conf file can have a lot of settings that quite important. In fact, I would say it has so many settings that it often gets very bloated. Have you ever made a huge mistake and wiped out the rc.conf when it is huge and full of many settings. Or have you ever had a system crash that wiped out the rc.conf? I have! A large rc.conf can be difficult to recover without a backup. On a production server, I will have such a backup but in my lab and on my PC-BSD desktop, I don’t.

My personal experiences of erasing the rc.conf are silly but they happened. Feel free to laugh but I have been using FreeBSD since 2001 (11 years as of the writing of this post) and each of these happened in lab environments or on my personal laptop where I was less careful and none of them ever happened on a production server.

  1. I accidentally ran a command that wiped it because I used > which overwrites the file, instead of >>, which appends to the file.
    $ sudo echo ‘someapp_enable=”yes”‘ > /etc/rc.conf
  2. PC-BSD wireless settings are written to the /etc/rc.conf file and once while managing my wireless settings, the system crashed, rebooted, and my /etc/rc.conf was empty.
  3. I once was going to delete the hosts file and add a new one and I am so used to typing /etc/rc.conf that I typed that instead of /etc/hosts. Oops!
    $ rm -f /etc/rc.conf
  4. While writing a script to update a setting in /etc/rc.conf, my script wiped it. Maybe the reason was similar to #1, maybe it was different, I don’t remember.

How to store settings in separate files on FreeBSD

If you do a quick read of the man 5 rc.conf, it will tell you that you can put setting in rc.conf, rc.conf.local, or in any filename residing in a folder called /etc/rc.conf.d and all these files can store settings.

Moving all your settings to rc.conf.local just moves the problem I described above, it doesn’t actually fix it, so I am not going to use that solution. However, using a separate file per setting in the /etc/rc.conf.d directory is quite a great idea.

Step 1 – Create the /etc/rc.conf.d directory

  1. Create a /etc/rc.conf.d directory:
    # sudo mkdir /etc/rc.conf.d

Step 2 – Create a file to hold a setting

Example 1 – Hostname

  1. Create a file in /etc/rc.conf.d and name it hostname.
  2. Add the hostname=”SystemName.domain.tld” setting to the file.

Note: You can do both steps at the same time with one command:

# sudo echo ‘hostname=”SystemName.domain.tld”‘ > /etc/rc.conf.d/hostname

Example 2 – SSH

  1. Create a file in /etc/rc.conf.d and name it ssh.
  2. Add the sshd_enable=”YES” setting to the file.

Note: You can do both steps at the same time with one command:

# sudo echo ‘sshd_enable=”YES”"‘ > /etc/rc.conf.d/ssh

Example 3 – Default Gateway

Yes, on FreeBSD the default route setting is called defaultrouter, not gateway or defaultroute as one would expect.

  1. Create a file in /etc/rc.conf.d and name it defaultrouter, or if you want to name it gateway or defaultroute.
  2. Add the defaultrouter=”192.168.0.1″ setting to the file.

Note: You can do both steps at the same time with one command:

# sudo echo ‘defaultrouter=”192.168.0.1″‘ > /etc/rc.conf.d/defaultroute

Conclusion

If you use the /etc/rc.conf.d file, then if you ever accidentally overwrite a file, it is not that hard to deal with because every setting is decoupled in its own file. You only lose one setting.

From now on, in my posts, I will tell likely suggest adding settings using a separate file in /etc/rc.conf.d.


MSVCR100.dll Download or MSVCP100.dll Download

In a previous post, Avoiding the MSVCR100.dll, MSVCP100D.dll, or MSVCR100D.dll is missing error, I explain what the MSVCR100.dll is and how to solve problems with it.

Many have asked for an MSVCR100.dll download. Turns out that Visual Studio has a redistributable folder that contains these dlls. So I zipped it up and I am redistributing it.

Here it is:

Download MSVCR100.dll and MSVCP100.dll


Monitoring the uptime of your blog

So my blog was down and I didn’t know. The mysql server and CPanel were down, actually.

I decided I should set up a monitoring service so I set out to find one.

I found this article:

http://mashable.com/2010/04/09/free-uptime-monitoring/

This was the first one on the list and it will monitor up to 50 sites for free  every 5 minutes and try to send you email or texts if your site is down.

http://www.uptimerobot.com

Google pulled this site up and while it only monitors one site for free and only at 30 or 60 minute intervals, it seems to have some statistics for you.

http://www.siteuptime.com/

 


Developer Training Tracking Checklist

This is to cover development related training, (so no Human Resources (HR) training is listed here).

Why training does not occur

The industry is full of companies that do not invest in training for their developers. There are many reasons training does occur and for every company these reasons may be slightly different.  Here are some that seem prevalent.

  1. There is an assumption that developers do not need training.
  2. They assume developers train themselves.
  3. They cannot afford training.
  4. They haven’t even thought about it.

Of course, many software development companies provide excellent training, so this article may not apply to them.

Why you should train your developers

Training is extremely important and this article exists so that if you are in a software company that is failing to train your developers, your development department can take steps to improve this.

To make correct decisions

Many software development companies fail in many areas. Training will not guarantee success in these failed areas, but it will increase your odds of success significantly. Often developers are treated as experts and analysts for tools and processes to perform their jobs. Developers often get to choose their source control tool, 3rd party libraries, the branching strategy, and more. Unfortunately, most developers are not trained System Analysts so they do not actually have an expertise in how to locate multiple products that feel a need, research which is best, and choose the one that is best for the company. Instead, the choice is often made because it is the first tool or process the developer found or already knew about that works for their very narrow need at the moment.

If your developers are well-versed in a topic and know the options and the pros and cons of each option, they are more likely to make correct choices for your company.  Ask yourself and your team about your current tools and processes. Is your development department just using these tools and processes because they are the most common, or because a skilled analyst determined that process fit your business?

When you hire a new employee, or when you implement a training program among existing employees, it is difficult to know where a developer stands in regards to training. If you want to find out where a developer is at, and help them move to the next level, you need a tracking system.

To grow as a developer

You may find that developer grow at a fast rate their first few years. But then, this growth may stop. A developer’s skills may stagnate. They know enough to do their job so they don’t continue to learn.  This is a problem because new technology always comes out and new tools are released to aid in their job.

To maximize productivity

A trained developer should produce code faster and with higher quality.

Software Development is always improving and something that may take a day today, might take 30 seconds and one line of code a year from now due to either a new tool or a new library.

To improve quality

There are a lot of bugs per lines of code and training, especially on quality topics such as design patterns and unit testing, can really improve the quality of a product.

How to track a developer’s training

I designed a simple tracking system. I made a list of topics (which are by no means complete) and subtopics. I gave each sub topic three levels to show continued growth.

The following is a spreadsheet version of the simple Developer Tracking System I created.

As a Google Doc: Developer Training Tracking Checklist
As Excel: Developer Training Tracking Checklist
As Excel (inverted) Developer Training Tracking Checklist – Inverted

Basically, the items that you should train on are as follows:

Training Topic Sub Topic Level
Development Tools IDE Level 1
Level 2
Level 3
IDE Plugins Level 1
Level 2
Level 3
Other Tools Level 1
Level 2
Level 3
Your company’s product Product 1 Level 1
Level 2
Level 3
Product 2 Level 1
Level 2
Level 3
Source Management Tool (TFS, GIT, SVN) Level 1
Level 2
Level 3
Branching Strategy Level 1
Level 2
Level 3
Development Language (C++, .NET, Java, PHP, etc…) Style Guides Level 1
Level 2
Level 3
Best Practices Level 1
Level 2
Level 3
Design Patterns Level 1
Level 2
Level 3
Advanced Language Level 1
Level 2
Level 3
Language Libriaries Log4Net Level 1
Level 2
Level 3
Unity Level 1
Level 2
Level 3
Unit Test Test Framework (Nunit) Level 1
Level 2
Level 3
Unit Test Best Practices Level 1
Level 2
Level 3
Libs (SystemWrapper) Level 1
Level 2
Level 3
Localization Localization Procedure Level 1
Level 2
Level 3
Build Building Locally System Level 1
Level 2
Level 3
Nightly Build System Level 1
Level 2
Level 3
Continuous Integration Level 1
Level 2
Level 3

Here is the key:

Key or Legend

Training Topic = A broad general development topic. Example: Source Management
Sub Topic = A more specific development topic. Examples: Source Control Tool, Chosen Branching Strategy
Level 1 = Often over the shoulder training of a new hire. A basic overview that is enough to get them working. For example, what are the basics for using TFS. 1-4 hours. All level 1 trainings should be provided within the first three months or at first use. Level 1 can be marked off without training if the employee demonstrates they are already at a higher level.
Level 2 = Usually in a formal training or an online training. A more in-depth overview of the sub topic. 8+ hours. All level 2 trainings should be complete by the end of year 1. Level 2 can be marked off without training if the employee demonstrates they are already at a higher level.
Level 3 = Expert level training. This could come from combining a few trainings, such as one or more Text Books, Online Research. 24+ hours. Level 3 trainings take time. The should begin after the first year of employment (unless a job requires it occurs earlier) and one or two should be completed each quarter. If an employee thinks they are already at a level 3, they should create a portfolio of information describing why they are at level 3 and present to a peer group of four or more individuals. If at least three of the four agree, then Level 3 is passed.

Training Types

FT = Formal Training. Hopefully in a classroom by a technical trainer.
OR = Online Research. Employee reads blogs and articles about the subject and indicate the articles and blogs read.
OT = Online Training. A formal training delivered online.
TB = Text Book. A book about the subject. Indicate which book. Also, the book should be read by multiple developers who should meet every other week to discuss the topics in the book.
ST = Shoulder Training. A person trains from over the shoulder. You may want to track who provided the training.

Hopefully if you are a VP of Engineering or CTO of a development company, you can take this and implement this in your environment.