Can You Learn to Program?

I don’t believe that everyone has the aptitude to program.

I know that might seem like a strangely bold statement, especially from someone that makes their living teaching people how to program but hear me out.

I think you can agree with me that not everyone is cut out to do everything.

I want to learn how to paint, draw and play the guitar.  I have spent countless hours learning – I have paid for lessons and I have put in a lot of effort.  But do I know how to do any of those things? No.

Why? Because I don’t have the aptitude.

What is aptitude? Aptitude can be defined as having a natural ability or a “fitness” for a task. Aptitude means that you have a competency for a certain kind of task or work. Some of us have the aptitude to be great basketball players because we were born tall.  Some of us can be great runners and participate in 5Ks every weekend because we have good stamina. Some people have the aptitude for mathematics because they were born with strong analytic skills.

So, no – everyone cannot learn how to program just like I cannot learn how to play the guitar.

So how do you know if you have the aptitude or not?

One way to find out is to take tests in areas such as Numerical Reasoning, Logic or Pattern Recognition.  These are all good skills that translate into being able to learn programming languages and concepts faster. You can find some of these tests here:

These tests can help identify whether or not you have some of the necessary skills but they should be considered the end-all voice on whether or not someone is capable of learning how to program.

Some people believe that if you are good at math that you can be a good programmer.  I am almost in this camp but I have to disagree with some of this idea. Most of the programming that you will be doing for a living revolves around business problems. Math isn’t going to help with these but it will help with foundation logic. Since most of the first programming languages were developed by mathematicians, it makes sense that a lot of the same concepts would be applied or borrowed into the concepts used in computer science.  However, being good at math is not a free pass into programming.

Are these tests and scores really going to tell you anything?

In my mind, the only way to find out if you have the aptitude for something is to try it.  Only by trying to learn something, putting in the effort and practicing it are you going to find out if this is something that you like, enjoy, and/or are good at.  Over my years of teaching I have seen all sides of this coin.  Students that want to learn programming so bad but just can’t get it.  I’ve had students that joined the class because someone told them they should and were good at it but hated actually doing it.  I’ve had students think that learning to program was going to be like playing video games and they shy away from it because “its hard” and I’ve had students come in thinking programming was going to be terribly hard and finding it was simple.

What can we learn from this?

Expectations are the common thread between all of these students. Everyone comes into programming expecting something but their expectations do not align with reality they aren’t going to get anywhere. I recommend that you put away what you think programming is going to be like, whether it is easy or hard, whether you are good at it or not and put your butt in the seat.  Do the work. Only then will you know if you can do this.

Sorting Elements in a Object-based Array

Since most C# applications are taking advantage of object-oriented practices, we often end up with arrays of objects instead of simple-types like int.

Let’s imagine, we have a class like this:

[codesyntax lang=”csharp”]

public class Employee
	public string FirstName;
	public string LastName;
	public decimal Salary;
	public int EmpType;




Then we have an application that creates arrays of Employee objects so we can store each instance of the object.  For example:

[codesyntax lang=”csharp”]

Employee[] myList = new Employee[2];


Suppose I want to sort the array by a particular field of Employee?  How could we sort this array of Employee objects by the LastName field?

There are two ways we can accomplish this – delegates and LINQ


A delegate is a special type that references a method.  You can define a parameter list and a return type just like you can in regular methods.  Through this delegate process, we can create a method that sorts the object array by comparison.

[codesyntax lang=”csharp”]

delegate(Employee emp1, Employee emp2)
	return emp1.LastName.CompareTo(emp2.LastName);


The CompareTo method is built-in to the .NET framework and compares two objects of the same type. It will return less than 0 when X < Y, zero when X = Y and greater than 0 when X > Y.


LINQ stands for Language-Integrated Query. It is a feature of the .NET framework and allows you to create queries based on simple patterns and built-in methods.   LINQ has a method OrderBy that is designed to compare and sort two elements.

[codesyntax lang=”csharp”]

var sortedArray = myList.OrderBy(emp => emp.LastName).ToList();


Either of these methods will work when you have an array of objects that need to be sorted by one or more of their elements.  Make sure to let me know if you have questions!

Number Validation Program

Its OK, especially when you are just getting started, to practice learning C# on some smaller code projects.  Don’t underestimate how much you can learn about programming in the console before you move on to more complex tasks.

For this program, we are going to validate a number that the user gives us in a console application. Here are the specifications:

Write a program in console that accepts an Integer value from the user

When you have accepted the value, determine if it is less than or equal to 10.  If so, print the statement: “This value is small”.

If its larger than 10, print the statement: “This value is large”.

If the user enters a number greater than 100, print the statement: “This value is too big!” but don’t print either of the previous statements

Hint: Remember to use Convert.ToInt32 when accepting the integer value from the Console.ReadLine() statement so you can store the incoming value into an integer variable.

Try it out on your own and see if you can get it working. If you get stuck, check the answer below.

[codesyntax lang=”csharp” lines_start=”1″ title=”Solution” blockstate=”collapsed”]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NumberValidation
    class NumberValidationProgram
        static void Main(string[] args)
            //print a welcome statement
            Console.WriteLine("Welcome to the number validation program");
            Console.WriteLine("Please enter a number");

            //accept the number from the console
            int number = Convert.ToInt32(Console.ReadLine());

            //check the number against the validation rules
            if(number <= 10)
                Console.WriteLine("This value is small");
            else if(number > 10 && number <= 100)
                Console.WriteLine("This value is large");
            else if(number > 100)
                Console.WriteLine("This value is too big!");


Understanding Object Oriented Programming

What is Object Oriented Programming?

Quite often I get a question or see a question posted online along the lines of: “What is this thing called OOP?”, “What is so special about it?”, “Why should I use it?” or “How do I use it?”. The person asking this type of question usually has experience of non-OO programming and wants to know the benefits of making the switch. Unfortunately most of the replies I have seen have been long on words but short on substance or example.  The main reason for this is that some of the explanations about OO are rather vague and can be interpreted in several ways, and if something is open to interpretation it is also open to a great deal of misinterpretation.  Hopefully this article will help clear up the confusion and give you a better idea of what Object Oriented Programming is.

What is Object Oriented Programming?

Object Oriented Programming is programming which is oriented around objects, thus taking advantage of Encapsulation, Polymorphism, and Inheritance to increase code reuse and decrease code maintenance.  Here are some examples between object oriented programming and non-object oriented programming.  Don’t let the big words scare you – these are easy concepts to learn.

What is an Object Oriented language?

A computer language is an Object Oriented language if it provides support for the following:

  • Class: A class is a blueprint, or prototype, that defines the variables and the methods common to all objects of a certain kind.
  • Object: An instance of a class. A class must be instantiated into an object before it can be used in the software. More than one instance of the same class can be in existence at any one time.
  • Encapsulation: The act of placing data and the operations that perform on that data in the same class. The class then becomes the ‘capsule’ or container for the data and operations.
  • Inheritance: The reuse of base classes (superclasses) to form derived classes (subclasses). Methods and properties defined in the superclass are automatically shared by any subclass.
  • Polymorphism: Same interface, different implementation. The ability to substitute one class for another. This means that different classes may contain the same method names, but the result which is returned by each method will be different as the code behind each method (the implementation) is different in each class.

A class defines (encapsulates) both the properties (data) of an entity and the methods (functions) which may act upon those properties. Neither properties nor methods which can be applied to that entity should exist outside of that class definition.


Different Definitions

A method is defined as a self-contained block of code. Each method name must be unique within the application.  This is the name we use when we want to call upon this block of code to perform its job.

Public string DisplayName(string name)



                return name;


A little bit of a breakdown:

  • Public is an access modifier, it tells us what parts of the program are going to have access to this method and which one do not.
  • String tells us about the data type of the information the method will return when it is done performing its job. In this case, we can see that the data type of the variable “name” is a string and since that is what we are returning, we have to indicate that here.
  • DisplayName is the name of the method so we know what it is called when we want to use it.
  • The parameter list follows in the parenthesis. Methods do not have to have parameters but they sometimes need outside information brought in so they can perform their job. We can provide any number of parameters needed in a comma separated list.

A class method is defined within the boundaries of a class definition. Each class name “MyClass” must be unique within the application. Each class may contain any number of functions (also known as “methods”), and the function name “DisplayName” must be unique within the class but need not be unique within the application.

Public class MyClass


                Public string DisplayName(string name)



                                Return name;




Accessing them is Different

It is important to note that neither a method nor a class can be accessed until an instance of the class object has been created. Calling a method is very straightforward:

String result = DisplayName(“Sara”);

Calling a class method is not so straightforward. First it is necessary to create an instance of the class (an object), then to access the function (method) name through the object. The object name must be unique within the application.

//create an instance of the object

MyClass myObj = new MyClass();

//now I can call a method from inside of MyClass

String result = myObj.DisplayName(“Sara”);


State Maintenance can be Tricky

A method by default does not have state: each time that it is called it is treated as a fresh invocation and not a continuation of any previous invocation. An object does have state; each time an object’s method is called it acts upon the object’s state as it was after the previous method call. It is possible for both a regular method and a class method to use local variables, and they both operate in the same way. This means that the local variables do not exist outside the scope of the function or class method, and any values placed in them do not persist between each instance. It is possible for a method to remember values between each time it is called by declaring a variable as static, as in the following example:

Public int Count()


                Static int count = 0;


                Return count;



Each time this method is called it will return a value that is one greater than the previous call. Without the keyword static it would always return the value ’1′. Class variables which need to persist outside of a method are declared at class level, as follows:

Public class Calculator


                //define class variables

                Int someValue;

                //setup properties for class variables

                Public int SomeValue


                                Get { return someValue;}

                                Set {somevalue = value;}


                //setup a method that Adds the value

                Public int Add (int number)


                                SomeValue += value;


//setup a method that Subtracts the value

Public int Subtract (int number)


                                SomeValue -= value;




Properties are used to handle the way the data moves in the class when we want to access class-member variables.  Using the Get we can access the value of a variable and through the Set we can change the value of the variable. This helps us control access to the information in the variable and to be able to perform validation and other checks before the value is changed.



Many people use the terms “object oriented” or “OO Programming” sometimes out of context.  These terms are slippery and we must be careful that we intend what they truly mean.  There are only three features which really differentiate an Object Oriented language from a non-OO language, and these are Encapsulation, Inheritance and Polymorphism.  If it doesn’t have these three key ideas then it isn’t object-oriented.  OO doesn’t necessarily mean that you will get code that is high reusability and low maintainability that is up to the quality of the code and the experience of the developer, however if you are using object oriented techniques; you are moving in the right direction.


Why project based learning?

Project based learning is one of the most powerful things that can be used to help people new to programming understand the concepts that they need to be successful.  I think one of the biggest failings that programming teachers have is that they teaching programming from an objective-based approach.

Loops, Arrays, Events, etc…all of these things are taught in a “silo” and not integrated together to show the student how they connect to other structures. Teachers want students to show mastery a particular topic such as If Statements, but don’t show how If Statements can be used in various ways.  We’re not showing the student the whole picture and with programming, the whole picture is important to see how the problem is being solved.

So what is project based learning?

Project Based Learning is a teaching method in which students gain knowledge and skills by working for an extended period of time to investigate and respond to a complex question, problem, or challenge. This is taught using a few principals:

Significant Content – At its core, the project is focused on teaching students important knowledge and skills, derived from standards and key concepts at the heart of academic subjects.

In-Depth Inquiry – Students are engaged in an extended, rigorous process of asking questions, using resources, and developing answers.

Driving Question – Project work is focused by an open-ended question that students understand and find intriguing, which captures their task or frames their exploration.

Critique and Revision – The project includes processes for students to give and receive feedback on the quality of their work, leading them to make revisions or conduct further inquiry.

Public Audience – Students present their work to other people, beyond their classmates and teacher.

Sounds simple right?

So in programming we need to give students the whole picture so they can be prepared for the in-depth study that will take place.  We need to focus on letting them drive the process and choose a topic that they find interesting.  We have to be presenting our students with timely feedback and critique and we need to encourage students to show their work to a wider audience.

Project based learning has been widely used in education for years but it appears to be a foreign concept in programming education.  This is one of the basic foundational ideas that I used to found C# Learning so that students can learn programming from this more focused approach that helps point the student down the path of real learning and not just memorization or frustration.


Working with Programming Teams

You can’t have great software without a great team, and most software teams behave like dysfunctional families. –Jim McCarthy

Let’s face it.  Today, most software is not developed and written by one person but is a product of a team effort.  Learning to work with other developers is a difficult step for some people.  The key to a good software development team is not only understanding how people work together but the understanding that software teams go through phases of development.  Just like the above quote, each member of your team may be in a different development phase, causing dysfunctional communication and problems.  If you understand the phases that teams are going through, as well as why things are happening the way they are, you stand a greater chance of surviving the process.

Project teams go through 5 phases with different feelings, responses and responsibilities at each level.  Here is a breakdown:

Phase 1: Forming

During the forming phase team members are just getting to know each other, the project and are optimistic about the work ahead.  They often have high expectations regarding the work and the team experience.  Team members can also experience some anxiety regarding their ability to do the work and fit in with the team.  In this phase team member often ask many questions that stem from the excitement and anxiety they are feeling.

During this phase, teams should be working on setting up their structure, setting goals, and defining roles.  Teams need a clear mission and need to define their expectations about their project and the processes they will use.  It is during this phase that trust begins to build between team members.

Phase 2: Storming

Much like “storming the castle” the team will begin this phase with vigor that can quickly turn sour.  As the team begins to move towards accomplishing their goals, the team members may be finding that the project or their teammates do not live up to their earlier expectations and excitement.  This can cause problems with your team in which feelings of frustration and anger begin to surface.  Due to this frustration, team meetings can erupt into conflict as disagreements about goals, expectations and responsibilities are aired.

Phase 3: Norming

The norming phase should bring an end to the conflict seen in the storming phase and team members should begin to resolve their differences.  If the team’s conflict in the storming phase allowed for team members to feel like they can express their opinions and ideas without criticism, your team will be in a better place now, with increase feelings of trust and comfort.  Team members will feel accepted by the other members as they begin to see how everyone’s ideas come together to form the final product.  Teams that had a rough storming phase will have to find their equilibrium before they can get to the norming phase and move on.

Phase 4: Performing

In the performing phase, team members often feel confident about the project’s progress, the team and their contribution.  They are now familiar with each other’s strengths and weaknesses and they are able to see the team as a whole entity.  At this stage, team members can often prevent or solve problems and conflict internally as part of the team’s process.  Members are also more willing to assist other and take on new responsibilities as needed.

Phase 5: Transforming

The transforming phase is a termination phase.  During this phase the team members may be splitting up to move on to other teams or the project may enter a “shipped” state where a maintenance team will continue to do other tasks.  During this phase, team members may experience several feelings such as anxiety because they are uncertain of where their new assignment may be and sadness because they do not want the team and their new relationships to come to an end.  Members should also feel a sense of accomplishment or satisfaction since their work was successful and their goals have been met.

Understanding the phases of team development can help you navigate your way through a team software development project.  It also helps if you understand what to expect as your project moves through developmental phases to help you integrate better with your teammates and be a more productive member.


Debugging doesn’t have to be difficult

One of the most challenging things for a new developer to learn is how to debug their code.  It seems that sometimes, problems can seem impossible to find or fix.  For new developers, this process can be overwhelming and lead to needless frustration.  In this article, I will talk about problem-solving as well as the art of debugging so that you can become more familiar with the practice of finding bugs in your code and fixing problems.

When new developers are first learning how to code, it is not uncommon for them to stumble upon an error that leaves them completely befuddled and without working code.  Instead of just crying “my code doesn’t work!” developers must begin to dissect the problem and find the proper approach to fixing it.  There is (or should be) a methodical set of steps to debugging instead of just making random changes hoping you’ll hit upon the solution.  To provide a straightforward approach to debugging, you should focus on the following key elements:

  • Reproducibility – Often a bug is found and reported without a clear way of reproducing the error.  Being able to recreate the circumstances that cause a bug is the first step towards finding its location in your code.  A bug that appears through a precise set of steps is easy to solve, where a bug that seems random or intermittent can be harder to track down.  Though the process of cause and effect deduction, you are most likely going to be able to find and fix a bug easily if you can reproduce it.


  • Reduction – Reduction is the process through which you reduce a problem to its essence.  What is the smallest path to the bug?  The simpler the path, the easier it can be to track it down.  If you have a large amount of data it can provide a big blockade to tracking down a problem, therefore you may need to cut the file in half as you narrow down the problem, throwing the other half out until you determine if the problem exists in this set or not.  If not, begin working on the other data set until the problem can be found.


  •  Deduction – Using deduction we can find the general path through the program, the components that the data interacts with on our way to the problem area.  Is the data getting damaged on its way to the component where the failure occurs?  What is the difference between data that doesn’t work and data that does?  You want to narrow down the field of possibilities by forming and eliminating hypotheses.


  • Experimentation – Just like how scientists create experiments to try to prove a hypothesis, you will need to experiment with your data and input to see if your bug disappears.  Using your logic skills and powers of deductive reasoning you can create a set of theories about the possible problem and set up experiments to test those theories.  If you are correct, then your changes will most likely tell you where the problem is.


  • Experience – There is no substitute to experience; it’s not something you can get in a classroom.  To become a better programming you must write code, make mistakes and learn how to fix those mistakes.  Experience can help in debugging because you will grow in your ability to execute the previous four elements and you may have seen this particular problem before in another program and will know how to fix it.  You also learn more about how different systems work and can lend that experience to this particular problem you are on now.  When in doubt, borrow experience from another programmer for the same reasons as above.  Getting a different perspective on the problem can also help lead you to the problem area.


  •  Tenacity – Programmers are going to make mistakes, especially new ones.  You must begin with the attitude that you will mess up and that you will be able to fix the problems that you have created.  Do not give up no matter how long it takes to find the problem and correct it.  Each time you solve a problem you will become more confident in your programming skills and you will become a much better programmer from the experience you gained fixing those bugs.


These elements are not in any particular order and you may use some or all in fixing each problem with your code.  One thing to remember is that once you have found and fixed the bug that is not the end of the learning experience.  You should also understand why the bug was occurring and how your solution has fixed it.  The key to learning is to understand and only by understanding what we are doing in our code will we be able to use this experience in the future.  This is especially true if we found a solution online that works, but we don’t truly know what it is doing.

In the end, debugging can be one of the most difficult and frustrating parts of programming.  How you approach problems and your attitude will make a big difference.  Most programmers approach problems as a challenge that must be overcome and they enjoy the interesting aspects of research and problem solving.  This way, they can attack problem with confidence, knowing they will eventually solve it.  A good programmer can distinguish themselves by learning to take the right attitude and become a tenacious problem solver.  I hope this has helped provide you with a strategy to follow that will increase your confidence as you find and correct your bugs.


Why does programming have to be hard?

I can remember the first day I stepped onto the campus where I would get my first college degree.

There was so much intimidation – how do I know what to do?  So much fear – what if I can’t do this?

I didn’t know what I wanted to do with my life or what I wanted to be when I grew up but I did know that if I didn’t go to school I was going to be delivering pizza (what I was currently doing) for the rest of my life.

As I walked into the Student Services department and met with the advisor I was assigned, she asked me a question – “What do you like to do?”. I didn’t really have anything I liked to do.

“Well” she said, “What do you like to do for fun?”.

“Computers are fun” I told her. I meant it when I said it but looking back now, I didn’t mean it.  “The Internet is fun” is what I should’ve said.  “Playing games on the computer is fun” would’ve been the honest answer.

“Great!” she says brightly, “We have a program in computers, let’s get you a schedule.”My journey into programming started that easy.  I was on my way!  Programmers make a lot of money, right?  There is a high demand for jobs, right?  This is going to be great!

I had no idea what I was walking into in my first programming class.  

An older gentleman was standing at the front.  He introduces himself as the instructor and starts to pass out papers.  “This is just a little test” he tells the class.

“A test!” my brain screams.  On the first day?

The instructor explains that its just a knowledge test to see what we already know.

My head is spinning because I can’t answer any of these questions.  Am I supposed to already know some of this stuff?  I thought this was an introductory class.

At the end, the instructor collects the test and we never heard about them again.  I can only image the insight that he learned from looking over the frantic and scared answers of a class that was already feeling inferior on the first day.

Looking back at this memory helps me remember what I am doing as a teacher in programming.  Programming inherently comes with three problems:

1 – The portrayal of our industry by the media is a lie.  I can (and will) write a whole post on this topic later.

2 – Students don’t like math and think programming has a lot of math

3 – Students think programming is going to be as fun as playing games on the computer

All of these are ideas that we are going to have to overcome to be better programming students and what teachers have to overcome to learn how to teach programming better. What do you think? I would love to hear about how you got started in this field or what your first day in class was like.