Tag: Csharp

Self-Documenting Code: The Approach

Posted by

by Misty S Bledsoe

Document your code consistently to improve the lifespan of the code. Photo courtesy of ardelfin/Morguefile.com

Beginning programmers are taught during their coursework to get into good programming habits. One of them is to do everything in your power to have what is called “Self-Documenting Code.” Some things that can be helpful are to remember:

  1. Comment Everything. Begin every section with comments that begin with commenting slashes “//” at the beginning of every module or the end of each module significant ending point of functions and modules. For multiple line comments you want to begin and end with “/*” and “*/”.
  2. Consistently choose meaningful variable names. For example, name a color variable “colorBlue” and not something like “color1” etc… The first choice reads better and tells other programmers what the variable means and what its purpose is.
  3. Keep naming conventions consistent. Decide what naming conventions you will use and stick to it throughout the entire program. For example, name your variables using all lowercase then uppercase with each additional word or start all variables with uppercase. Sometimes the languages you choose will determine the casing rules for you.

No matter what kind of project you work on, keep in mind if stay consistent on your comment practices, variable and naming conventions it will keep your code as self-documenting as possible. It will also be easier to read and to maintain over the long haul. 

How to Change the Name of the Application File when Programming in C#

Posted by

by Misty S Bledsoe

Changing the default file name of your program is not difficult.//Photo courtesty of ppdigital/Morguefile.com

Changing the default application file name when working on a project in C# gives the code more readability and increases the cohesiveness of the overall program. For example, if you leave the default program name as “program.cs” it can apply to just about can C# application. Instead, if the name of your program is “Time Clock,” consider renaming the program name “Timeclock.cs.”

  1. Open VisualStudio.NET. You’ll see the starting page. Open a new project.
  2. When the new project opens the blank screen, click on the “Solution Explorer” tab. If you do not see this tab, go up to “View” in the menu choices and click on it. Navigate to “Solution Explorer” to have it appear in the workspace.
  3. Click on the file “program.cs.” Click on the Properties tab. If you do not see the properties tab, go up to “View” in the menu choices and click on it. Navigate to “Properties” and click on it.
  4. Scroll down to the “File name” field and change the file name to match your project name and leave the “.cs” after it. Hit enter when you are finished.