Background
Software Engineering is a team activity where every individual is playing a vital role. Most successful software projects are granted for team players and not individual efforts. Purpose of this article is to familiarize developers involved to keep few things in mind while they are developing the product. It will help you in the project as well as improve your team abilities for future. We will focus on developers to agree on a standard and follow it through the software development.
Standards
Following list describes areas or things that we need to take care of while developing softwares.
1. XML Comments
Always use XML comments for each major block of code. We don’t focus to write comment on every line of program. But only on the major block of code like if you are developing a class, then first add comment with class. Secondly add comments on the public methods or members of class. An example of this is as
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
///<summary> /// Connect to database through MySQL Connector Provider /// and perform data manipulation operations ///</summary> public class DBConnection { MySqlConnection connection = null; MySqlCommandcmd = null; MySqlDataAdapter da = null; DataSet ds = null; ///<summary> /// default constructor ///</summary> public DBConnection() { connection = new MySqlConnection(); } ///<summary> /// open connection ///</summary> ///<returns></returns> private bool OpenConnection() { try { connection.ConnectionString = AppSettings.DB_CONNECTION_STRING; connection.Open(); returnt rue; } catch (Exception ex) { return false; } } } |
2. Avoid Using Constants or Magic Numbers
Avoid using constants or magic numbers in the program. For constants define Enums there and use them. See below example.
1 2 3 4 5 6 7 8 |
Public enum Reports { COMPLAINT_PRIORITIES = 1, COMPLAINT_STATUS = 2, COMPLAINT_TYPE = 3, DEPARTMENT_AND_COMPLAINTS = 4, SYSTEM_USERS = 5 } |
Here rather than using constants you can use enum throughout the program.
3. Use Configuration Manager
Never use/access configuration files settings directly or you can say use of configuration manager on the forms or pages you develop is not good practice. For thisyou can add a class “AppSettings”. In this class you can define your own constants and populate them from the configuration file. See below snap code for this.
1 2 3 4 5 |
Public static class AppSettings { Public static string DB_CONNECTION_STRING = ConfigurationManager.ConnectionStrings["dbConnectionString"].ToString(); Public static string APP_REPORTS_PATH = ConfigurationManager.AppSettings["REPORT_PATH"].ToString(); } |
4. Constants
Make constants with upper case letter like in above example.
5. Keep Track of Warnings
Keep track of the warnings as well while developing. This will suggest you many things regarding your code. For example if you define a variable and don’t use in code, you will get a warning regarding this. By doing this you will remove un necessary code/variables from the file.
6. Use of foreach Loop
For collections try your best to use “foreach” like loops and not the traditional for or while loops.
7. Empty Strings
Empty string comparison or assignment is not appreciated through (“”), but instead use the string.Empty. You will mostly need this on clearing the form controls.
8. Exception Handling
Your code should use exception handling and give proper messages to user.
9. Use Methods
Don’t write code directly in the form control events, instead make your own functions/methods and call them from your events as required.
10. Hot Keys
Make your form controls user friendly and useable through keyboard. For this use hot keys and accelerator keys.