img by Coba

How to Become a Good C# Programmer, Part 4

This is Part 4 in my series on How to Become a Good C# Developer. You can find Part 1 at here, Part 2 (Steps 1 and 2) here, and Part 3 (Steps 3 and 4) here. If you need to reference the full list of steps to take to be a good C# programmer, you can find those here.

Step 5: Implement your project while you are reading/taking the class

Don't wait - get started quickly. I don't expect that you'll have the knowledge to begin until you are a few chapters in at the earliest though so don't just start with no knowledge; wait until you have enough knowledge of C# OOAD to intelligently start. Generally OOAD is covered pretty early on in any compendium on a .NET Framework-based language so that shouldn't be a problem.

Start with the GUI

This probably goes against the grain of much conventional programming advice but hey - it's my "system" therefore I can tell you what I think works best for most people. I find that if I start with the visual elements, I can visualize/think of the rest of the application much easier. It gives me a frame of reference if you will and allows me to quit thinking in utter abstract terms and lets me to hone in on accomplishing specific things (like what happens when a user clicks the Submit button).

Don't get too fancy here - start with the first screen that the user will see; it is okay to add fancy items like splash screens and product icons if you wish. The key thing here is not to get so bogged down in the architecture that you have to re-do too much work later on (called refactoring).

How to Design a GUI

While everyone has their own way of doing this, let me offer a suggested system for designing your first GUI:

  1. Start with a pen and paper and write up what it should look like - where the icons and buttons go
  2. Continuing with pen and paper, write up what menu items should be
  3. Once finalized, move to a graphics editor and create a mockup. You can use fancy tools like Photoshop or Illustrator if you have the budget or free tools like to create your mockup.
    • Although graphic mockups are not a necessity, I find them helpful. Others find tools like Balsamiq or MockupScreens more helpful. To each his own!
  4. Once you have the mockup, now it's back to the Visual Studio to create it! Use your book/class for reference on how to accomplish this.

Tip #1: It's okay to skip ahead/around in your book/class (from Step 3) to the section that talks about how to create GUI elements!

After completing the GUI design, you will have a pretty application (if you did the graphic design well) that doesn't do anything.

After the GUI, Start with Events

The next thing you want to do is start "wiring up" the buttons and menu items. This is where your programming skills will begin to develop. GUI drag-and-drop at this stage of your career is often nothing more than drawing the mockup graphics/items onto the editor (at least it's that way in Visual Studio). You can't mess up and you can't do it wrong - if you do mess up, just delete it and drag-and-drop another item onto the surface. The actual work is done when you decide what happens:

  • When something loads or unloads (i.e. appears on the screen and leaves the screen)
  • When a user clicks a button or menu item
  • When the user clicks Maximize, Minimize, or closes the application

As a C# developer, you'll spend much if not most of your time determining what happens when an event occurs. Go ahead and get your events in place - you can add the actual functionality later on.

After completing this step, your application will respond to events (i.e. clicks) but won't perform any work.

After the Main Events, Do Your Class Design

The reason I advocate pushing this step until after you have both the main GUI elements and main events in place is that, if you start with the class design and then do the GUI + events, inevitably you find how screwed up your class design was and you have to rip it out and start over! It will happen even by delaying the OOAD until this point but the chance is that it will happen less. Later on in your career you may opt to start with OOAD/class design but, for now, it's just easier to start with the GUI, then determine the events you need, and finally to determine the OOAD.

After completing this step, your application will still respond to events (i.e. clicks) but won't perform any work since you've only design the classes, not implemented them.

After the Class Design, Implement Method Stubs

Method stubs are a way for you to "kind of" get your program working. When you create in this manner, you will go ahead and create your objects along with the methods and properties for each. What you won't do, however, is to finalize the method/property code; you'll put a stub in place instead. Think of a method stub as a placeholder for work to be done in the future. In most cases, you won't have the necessary knowledge to write each method/property yet so go ahead and create the stub as a placeholder.

Tip #2: Use exceptions to help you remember what is a method stub and what has been implemented

Tip #3: Use comments in your code to tell Visual Studio that this is a TODO list item: // TODO: This is a method stub! 

After the Method Stubs, Write the Pseudocode

Learning to write pseudocode is a critical skill. Pseudocode is how you write, in a programming language-like format, the "how" of what your method/property will do. I've seen very complex pseucode examples and I've seen bullet points on a piece of paper serve the same function. To me, it doesn't matter - use whatever helps you understand the goal of the method/property. I've found many times that, in writing the pseudocode, that my logic was completely backwards and that I needed to rethink how the application worked. That's awesome because it means that I didn't have to spend a ton of time refactoring the application!

After the Pseudocode, Write It Up!

Now more procrastinating - get to work programming!

Next up

Let's take a look at Part 5! Of course, you are welcome to go ahead and dive into my C# training class online at any time!

Article Index:

  • Part 1 - Overview of a System for Becoming a Good C# Programmer
  • Part 2 - Steps 1 and 2: Picking a Language and Picking a Pet Project
  • Part 3 - Steps 3 and 4: Picking a Book or Class to Get Started
  • Part 4 - Step 5: Implementing Your Pet Project
  • Part 5 - Step 6: Minimizing the Trough of Disillusionment
  • Part 6 - Steps 7 and 8: Finish your Book/Class and Start a New One
  • Part 7 - Steps 9 and 10: Begin Answering Questions and Pick a New Project
  • Part 8 - Steps 11 and 12: Review more apps and Start Contributing!
  • Part 9 - Steps 13 and 14: Write a few articles and the Bonus Step
  • Part 10 - Next Steps and What Does It Take to Be a Great C# Programmer?
scott whigham
grant moyle
chad weaver