Wednesday, June 8, 2011

convention followed in making website

convention followed in making website

HTML (Design) Related
1) Fix max length of each control
2) Always define styles in style sheets. In worst case, define style at top of page.
3) Try to categorize the style sheets like general sections and page wise sections.
4) Check page layout and design in IE and Firefox.
5) Check and warn for important cookies or Javascript or Popup if blocked.
6) Put meaningful Page titles for each screen in hierarchy.
7) Use padding to maintain gap between controls, don’t put spaces.
8) Page Design layout should have a main table (1Row X 1Column) with height & width as 100%, and inner table within this table (of fixed width if required). Main table should have all content within it to be center aligned.
9) The applications should be designed to be displayed on “1024 X 768” screen resolution.
10) The page margins should be set to zero otherwise a default value is taken.
11) Always try to avoid horizontal scrollbar in a page.
12) Use Application path defined in web.config for page redirection.
13) Preload images on page.
14) Specify cell spacing and cell padding wherever required otherwise default value is considered.
15) Decide between using pixel width or % width as both have different looks at different resolution.
16) <span> tag does not work in Firefox. Use <div> instead.
17) Comment HTML code wherever possible.
18) Ensure that target page name in URL is entered as Case Sensitive (for Linux Servers).
19) Use relative path to refer a location, never use physical path.
20) CSS Class Names should be descriptive and use camel case e.g. tableWidth.
21) CSS Classes specific for tags should have Tag Name in the class name.
22) CSS classes specific for elements should have Element ID in the class name.
23) All files name must be different (e.g Pa ge name and class name must be different)

Javascript Related
1) Check Script Code in IE and Firefox.
2) Put validator to check <, > or ‘(if not expected, if required). This helps prevent SQL injection.
3) Comment your code for every 10~15 lines explaining the logic performed.
4) For functions add comment to explain its arguments, return type & purpose (short but explanatory).
5) Every function should contain the credentials of the creator/ modifier.
6) Use Regular Expressions to validate controls (Java script/ server side) if needed.
7) Always enclose Javascript with HTML comments i.e. within the html comments () tag.
8) Using AJAX, if something is processed in background, show an indication (e.g. loading image).
9) When using parseInt always use the base as 10 (i.e. parseInt(,10)).
10) Create a js file for common functions used within the application.
11) When storing value in a javascript variable always check for a new line character and replace it with “
” or “\n”.


Database Related
1) Use Stored procedures (if possible) as they are precompiled.
2) No hard deletion wherever possible – Instead maintain a status field.
3) Use Transactions – commit, rollback - when executing a bunch of queries together.
4) For each record in database maintain: Creation time - GMT (GetUTCDate()) & status(deleted).
5) Do not use * in select statement. Always specify field names.
6) Don't use cursors if the same logic can be achieved by using SELECT, UPDATE or DELETE.
7) Don't do SELECT max(ID) from Master when inserting in a Detail table. Use one of SCOPE_IDENTITY, IDENT_CURRENT, and @@IDENTITY.
8) Try to use “where” condition instead of “join” to filter out records.
9) Use sub queries wherever possible instead of a single select by joining more number of tables.
10) Always append the Project abbreviation as prefix of Table Name.
11) Stored procedure names should explain the task performed (e.g. CustomerGetByID).
12) Try to make single stored procedure for both Insert & Update for each table.
13) Always ensure that SQL Keywords are in capital e.g. SELECT FirstName FROM Contacts.
14) Comment each Stored Procedure - functionality performed, Created by, Created on, updated by, updated on, reason of updating.
15) Data type and length of fields should be logical (i.e. related with the task).

.NET (Code & Design) Related – Basics
1) The Project should be linked to VSS Database from Day 1.
2) Always put your signature on the code you had worked on (name, date).
3) Follow naming conventions for naming all the controls, global & local variables.
4) For functions add comment to explain its arguments, return type & task performed (short but explanatory).
5) Every function should contain the credentials of the creator/ modifier (Created by, Created on, updated by, updated on, reason of updating).
6) Create generalized functions for code reuse. Try to modularize the code as much as possible.
7) Always backup your project and database at regular intervals.
8) Use data link layer for communicating with the database server (DAL).
9) Always check for DBNull/NULL values (try to check from database by using ISNULL()).
10) Try to create common parts as User Control.
11) Try not to code based on presumed values. Try to consider scenarios where value may differ.
12) Do not refer elements of dataset by index number, always use name of field.
13) Use relative path to refer a location, never use physical path.
14) Maintain the release version number of application before deploying or releasing.
15) Server trips should be minimized.
16) Keep in mind the upper limit of the data type when using Convert functions.
17) Use Enum and constants wherever required for defining True, False etc.
18) Analyze the pros and cons of Server.Transfer and Server.Execute before using them.
19) Use case instead of if else ladder.
20) Check tab order of the page before release.
21) Always close database connections after usage.
22) Use #region to group related pieces of code together.
23) Always watch for unexpected values.
24) Comment your code for every 10~15 lines explaining the logic performed.
25) At application start up, do "self check" and ensure all required files and dependencies are available in the expected locations.
26) Check for database connection at start up, if required.
27) When fetching record from table, check the datatable contains at least one row before using it.
28) Use the AssemblyInfo file to provide assembly information.
29) If database connection, socket, I/O stream is opened, always close them in the finally block.
30) Use StringBuilder class instead of String when manipulating string objects.
31) Make the code modular, break large system into small blocks.
32) Convert strings to lower/upper case before comparing if case insensitive matching is needed.
33) Never hardcode path in code. Get the application path programmatically and use relative path or from Web.Config.
34) Always try to avoid exceptions by checking all the error conditions programmatically.
35) Decide a standard way of page to page data transfer. It can be done using Session, Querystring, Previouspagetype or HttpContext (if it is appropriate).
36) For simple data binding use DataReader. It is faster then DataSet , DataTable or DataView.
37) Use classes for Insertion/updation in database. Keep Property name same as database field (BAL).
38) On inserting value in a String type column always replace single quote with two single quotes.
39) Try to make the code very simple
40) Simplicity, organizing code properly, good design makes code more reliable and bug free.
41) Always maintain the code formatted and indented (to make it more readable).

Error & Exception Handling
42) All the code should be written inside a try catch finally block.
43) Don’t use try-catch-finally constructs inside hot-spots (i.e. loops and such) if it can be avoided.
44) Never do a 'catch exception and do nothing'.
45) Handle Exceptions and keep a log track in database.
46) When re-throwing an exception, use throw statement without specifying the original exception.
47) Error messages must be user understandable format and should be consistent.
48) All errors must be displayed in a common place in all forms.
49) Error messages, in addition to telling what is wrong, should also tell what the user should do.
50) Try to use the specific exception error handlers instead of generalized ones.

Session, Viewstate, Application and Querystring Variables
51) Usage of Session and Application variables should be minimal.
52) Store Session value in a variable at page load and use the variable across the page.
53) Check for Session timeout on each page load and redirect as required.
54) Sensitive information stored in viewstate should be always encrypted.
55) Store information in Viewstate only when required.
56) Sensitive information passed to any page through Querystring should be encrypted.
57) For storing large data use session instead of viewstate.
58) Clear all the session variables which are not required further.

Configuration Settings
59) Connection string should be defined in web.config.
60) Define culture (eg. EN-GB for Great Britain) of the application (if required).
61) Define Application path in web.config for page redirection (if required).

Classes & Methods
62) Make the member variables “private” instead of public/protected. Expose public/protected Properties to access them.
63) The event handler should call another method to perform the required action.
64) Avoid passing too many parameters to a method.
65) If method has more than 5 parameters, try to define a class or structure.
66) If a method returns a collection, return an empty collection instead of null, if there is no data.
67) Method name should describe its functionality. Do not use mis-leading names.
68) A method should do only one job. Don’t combine more than one job even if jobs are very small.
69) If we pass the values to the class from outside make property for that.

.NET (Code & Design) Related – Advanced

70) All the error messages displayed to the end user should come from a Xml file.
71) Do not hardcode strings. Use resource files.


Naming Conventions
1) Follow the below stated naming convention:
Pascal Casing – For defining Class names, Method names, Namespace, Property
- First character of each word is Uppercase and rest characters are lower case.
Example: BackColor
Camel Casing – For variable names and method parameters - First character of each word, except the first word is Uppercase and rest characters are lower case.
Example: backColorPattern
2) Use descriptive words to name variables. Do not use abbreviations.
Example: strAddress instead of strAddr
3) Never use variable names like i, n. Use meaningful names - intIndex, intCounter.
4) Do not use underscores (_) for local variable names.
5) Do not use variable names that resemble keywords.
6) Prefix boolean properties and methods with “is” or similar prefixes – isDeleted, IsNumber().
7) All control’s should be named with the related prefix followed by column name in the database.



Please Note: Each and every Class, Function, Modules, Stored Procuredures should contain the following credentials at the top:
/*
Created By –
Created On –
Updated By –
Updated On –
Reason for Updating –
*/

Also adds comments at the top explaining the arguments, return type & task performed.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.