locked
Coding Standards RRS feed

  • Question

  • Hi,

    i am developing a windows application

     I am want to know the coding guidelines and standard in both vb.net and c#.net language

    please give me one sample code application using dto, dal, bal,ui layers and exception handling

    please guide me

    waiting for reply....................

    Thursday, April 19, 2012 1:28 PM

Answers

  • Hello,

    First off here is a thought, if you ask 10 developers for standards you will get 10 different options. Much depends on their background, were they self starters, learn to program from classes etc. Also what languages did they work with prior to VB.NET.

    From my perspective always begin by having solid requirements for projects before writing a single line of code. When coding always strive to write code that takes all measures to ensure you have the least amount of possible errors at run time and when (and they will) they do cause run time problems have a method to record them i.e. log file, email etc.

    The following link would be a good place to start for a guideline.

    http://msdn.microsoft.com/en-us/library/aa291596(v=vs.71).aspx

    Also in the IDE under options set Option Strict On, the default is Off which more likely than not lead to poorly written code. There are times when Option Strict Off may be your only option and when you need if off place that code into a code module, the first line would read Option Strict Off, all other files in your project will have Option Strict On.

    In regards to exception/error handling the following link contains the basics for dealing with unhandled exceptions.

    http://code.msdn.microsoft.com/Dealing-with-unhandled-9b933818

    When it comes to working with data there are several major methods which you should explore them all. One of them will more likely than not fill your needs but without trying (or at least reading about them) them out you will not know the good and bad of each one dependent on what you are attempting to do with your data. Lastly I feel it is wise to write your data layer outside of forms when possible so you are not tied to one UI element.

    One last thought, strive to write parts of your solution in small parts which might be breaking down parts of the solution into class or code modules or creating support projects that your main project uses. If you are just learning to code and found something in another language supported by .NET do not hesitate to add the project (meaning you have the complete source code) to your solution and don't be concerned the project is not VB.NET if it suits your needs rather than spend time attempting to convert the code to VB.NET.


    KSG

    Thursday, April 19, 2012 7:23 PM
  • Your query might be more related to software design patterns than coding standards as such.  There is some commentary here:

    http://msdn.microsoft.com/en-us/magazine/cc188707.aspx
    http://msdn.microsoft.com/en-us/magazine/cc301852.aspx

    Friday, April 20, 2012 2:49 AM

All replies

  • Hello,

    First off here is a thought, if you ask 10 developers for standards you will get 10 different options. Much depends on their background, were they self starters, learn to program from classes etc. Also what languages did they work with prior to VB.NET.

    From my perspective always begin by having solid requirements for projects before writing a single line of code. When coding always strive to write code that takes all measures to ensure you have the least amount of possible errors at run time and when (and they will) they do cause run time problems have a method to record them i.e. log file, email etc.

    The following link would be a good place to start for a guideline.

    http://msdn.microsoft.com/en-us/library/aa291596(v=vs.71).aspx

    Also in the IDE under options set Option Strict On, the default is Off which more likely than not lead to poorly written code. There are times when Option Strict Off may be your only option and when you need if off place that code into a code module, the first line would read Option Strict Off, all other files in your project will have Option Strict On.

    In regards to exception/error handling the following link contains the basics for dealing with unhandled exceptions.

    http://code.msdn.microsoft.com/Dealing-with-unhandled-9b933818

    When it comes to working with data there are several major methods which you should explore them all. One of them will more likely than not fill your needs but without trying (or at least reading about them) them out you will not know the good and bad of each one dependent on what you are attempting to do with your data. Lastly I feel it is wise to write your data layer outside of forms when possible so you are not tied to one UI element.

    One last thought, strive to write parts of your solution in small parts which might be breaking down parts of the solution into class or code modules or creating support projects that your main project uses. If you are just learning to code and found something in another language supported by .NET do not hesitate to add the project (meaning you have the complete source code) to your solution and don't be concerned the project is not VB.NET if it suits your needs rather than spend time attempting to convert the code to VB.NET.


    KSG

    Thursday, April 19, 2012 7:23 PM
  • Your query might be more related to software design patterns than coding standards as such.  There is some commentary here:

    http://msdn.microsoft.com/en-us/magazine/cc188707.aspx
    http://msdn.microsoft.com/en-us/magazine/cc301852.aspx

    Friday, April 20, 2012 2:49 AM
  • As far as design standards are concerined it is always a good idea to use the layered approach.  Most designers will agree that there should be three layers. 1) Data Access Layer, 2) Business Logic Layer 3) Presentation Layer.

    1) Data Access Layer:  Tables needed to store your data and queries or stored procedures needed to add, change, update, delete, or query the data.

    2) Business Logic Layer: Code used to execute the queries contained in the Data Access Layer as well as capturing the business rules that will cause these queries to be executed. 

    3) Presentation Layer:  Forms and related controls that will display the information to the user.

    The Presentation Layer calls the functions and procedures created in the Business Logic Layer and displays the results.

    The Business Logic Layer provides the access to the database objects made available in the Data Access Layer. 

    Using this layered approach compartmentalizes development and makes it easier to locate and correct errors.  It is however important that you finish one layer before starting work on the next.

    Wednesday, April 25, 2012 3:54 AM
  • Thank you V. Shane Curtis, Kevininstructor and  Acamar for reply,

    Mr. V. Shane Curtis can you give me the coding standard details to follow and sample code,

    in this please show me using exception handling display the error related error message

    eg: for duplicate insertion exception display the error message "Duplicate insertion not allowed "

    if data inserted "Data Saved Successfully"

    and how can we throw the exception from one layer to another layer and display the proper error message in presentation layer

    Wednesday, April 25, 2012 7:25 AM
  • Thank you V. Shane Curtis, Kevininstructor and  Acamar for reply,

    Mr. V. Shane Curtis can you give me the coding standard details to follow and sample code,

    in this please show me using exception handling display the error related error message

    eg: for duplicate insertion exception display the error message "Duplicate insertion not allowed "

    if data inserted "Data Saved Successfully"

    and how can we throw the exception from one layer to another layer and display the proper error message in presentation layer

    I'm affraid your questions go beyond the scope of the forums. Click the Learn tab at the top of this page and start following links, reading articles, and watching videos. There are many different patterns and practices to implement and choosing the most appropriate one is something that must be done on an application-by-application basis.

    You will need to spend your own time learning about the possible choices so that you can choose a set of patterns and practices that suit the application you are trying to design.  There is no one-size-fits-all, universal answer.  You must first define what your application is supposed to do and determine the kinds of information you will need to work with and perhaps store.  Then you will choose platforms to satisfy these needs.  Once that is done, you can choose a development pattern that suits the application requirements.

    For instance, the Access Layer approach which V. Shane Curtis mentioned is a traditional pattern suitable for most any application; however, modern complex applications now tend to favor an MVP (model-view-presenter) or MVC (model-view-controller) pattern instead.  And there are other possible patterns as well.

    These forums are a great place to get help with a specific question or problem.  But the learning centers need to be used for general purpose, or broad-spectrum learning.  It would be unreasonable to ask any individual contributor to try to sum up a ton of web content into a single post.  Once you know more about the patterns and practices available, you could then start a thread to ask questions about a specific pattern or practice in relation to a specific application scenario (which you would also have to describe).


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Wednesday, April 25, 2012 3:23 PM
    Moderator