Common Coding Defects.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
The New User Interface MEDITECH Training & Education.
Chapter 3 – Designing your web pages Dr. Stephanos Mavromoustakos.
Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design.
© by Pearson Education, Inc. All Rights Reserved.
Using KompoZer -- a web editor A collection of video tutorials
IV. “Regular” Web Pages: HTML A Web Accessibility Primer: Usability for Everyone Office of Web Communications.
Microsoft Office © Copyright William Rowan Objective By the end of this you will have being given a brief introduction to: Microsoft Word Microsoft.
Creating a Web Page HTML, FrontPage, Word, Composer.
Copyright 2007, Information Builders. Slide 1 Maintain & JavaScript: Two Great Tools that Work Great Together Mark Derwin and Mark Rawls Information Builders.
Copyright © Texas Education Agency, All rights reserved. 1 Web Technologies Website Development with Dreamweaver.
Web Design-Lecture2-QN-2003 Web Design Microsoft FrontPage®
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
Website Development with Dreamweaver
Chapter 2 - More Controls More controls – Text boxes - used for user input – Frames - containers to group items – check boxes - user select an option -
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
IReport Demo Spring 2008 OEDSA Conference. Report Properties.
Body and Heading Tags and their Attributes. Attribute Name DefinitionValues backgroundIndicates the background image of the Web page. Ex. Filename(path.
Some Thoughts On PROTOTYPE Form Design. You may place prompt over or to the left of the data-entry field; select one and be consistent. Name Tom PromptResponse.
Double –Click on the Netscape Icon on your desktop The following are a series of steps to help you get started with Netscape Composer.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Web and Multimedia Development Copyright © Genetic Computer School 2007WM LESSON OVERVIEW  Use of Tables  Creating Tables  Try It – 1  Creating.
Hamilton Software Products The Measure of Excellence Customized dialog.
Chapter 10 Creating a Template for an Online Form Microsoft Word 2013.
1 Customizing Forms and Writing QuickBooks Letters Lesson 15.
Microsoft Visual Basic 2010 CHAPTER FOUR Variables and Arithmetic Operations.
WEB TESTING
The New User Interface MEDITECH Training & Education.
4. Search button should work only if there is a key word.
ASP.NET Programming with C# and SQL Server First Edition
Word Lesson 1 STUDY GUIDE.
Microsoft Word Basics.
Unit 9.1 Learning Objectives Data Access in Code
Office tool for creating tables and charts
Microsoft Access 2007 – Level 2
Web Development & Design Foundations with HTML5
Accessibility with Lectora Inspire 16
Creating an Account on Wikieducator
Microsoft Word 2010.
Variables and Arithmetic Operations
3.01 Apply Controls Associated With Visual Studio Form
Computer Programming I
Unit 8.2 How data can be used Accessing Data in Views
Creating Tables in a Web Site Using an External Style Sheet
CHAPTER FIVE Decision Structures.
3.01 Apply Controls Associated With Visual Studio Form
Microsoft Access Illustrated
Using Procedures and Exception Handling
Unit 9.2 Database access from code Database Cycle Review
Web Programming– UFCFB Lecture 17
Customization
DreamWeaver CS4.
CHAPTER FIVE Decision Structures.
Web Systems Development (CSC-215)
Variables and Arithmetic Operations
Question 1: What key on the keyboard is used to create a proportional shape? Control Key Tab Key Shift Key Delete Key.
MODULE 7 Microsoft Access 2010
WEB PROGRAMMING JavaScript.
Tutorial 6 Creating Dynamic Pages
In Class Programming BIS1523 – Lecture 11.
Word offers a number of features to help you streamline the formatting of documents. In this chapter, you will learn how to use predesigned building blocks.
Objectives At the end of this session, students will be able to:
CMSC 202 Exceptions 2nd Lecture.
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Guidelines for Microsoft® Office 2013
Web Programming and Design
CMSC 202 Exceptions 2nd Lecture.
Web Programming and Design
Presentation transcript:

Common Coding Defects

Agenda Baby defects Web Applications Common Defects

Baby Defects (1) Do not string concatenated in loop, use StringBuffer instead //Wrong example: String stNumber = ""; for(i=0; i<100; i++) { stNumber = stNumber + i; } // Correct one StringBuffer stBuf = new StringBuffer(); for(i=0; i<100; i++) { stNumber.append(i); }       String stNumber = stBuf.toString();

Baby Defects (2) Do not get size of array in for statements condition // Wrong example: for(i=0; i<arrTemp.size(); i++) { // do smt here } // Correct answer: int intSize = arrTemp.size(); f or(i=0; i<intSize; i++) { // do smt here }

Baby Defects (3) // Wrong example: : if(stVariable.equals(“”)){ } Compare a string with a constant, always call equals function from constant to avoid null pointer exception error. // Wrong example: : if(stVariable.equals(“”)){ // do smt here } // Correct answer: int intSize = arrTemp.size(); if(“”.equals(stVariable){ // do smt here }

Baby Defects (4) // Wrong : for(i=0; i<intSize; i++){ } Avoid select from database to check for existing of values in a loop, this will increase system performance. // Wrong : for(i=0; i<intSize; i++){ // select database to check here } // Select database, put to a HastTable object or List object. Remember Hastable object do not allow duplicate value : for(i=0; i<intSize; i++){ // select the HastTable to check here }

Baby Defects (5) // Wrong : for(i=0; i<intSize; i++){ } Do not create object in loop. // Wrong : for(i=0; i<intSize; i++){ TableRow objTable = (TableRow) vtResult.getElementAt(i); // do smt here } // Correct: TableRow objTable = null; for(i=0; i<intSize; i++){ objTable = (TableRow) vtResult.getElementAt(i); // do smt here }

Baby Defects (6) // Wrong: Use toString() function instead of typecast. // Wrong: String stTemp = x==y ? “” : objABC.toString(); // Correct: String stTemp = x==y ? “” : (String)objABC;

Baby Defects (7) // Wrong: String stTemp = Integer.toString(i); Redundant typecast // Wrong: String stTemp = Integer.toString(i); // Correct: String stTemp = “” + i;

Baby Defects (7) // Wrong: Check for null before use objects to avoid null pointer exception // Wrong: String stAction = request.getAttribute("stAction").toString(); // Correct: String stAction = request.getAttribute("stAction")==null ? "" :request.getAttribute("stAction");

Baby defects (8) SQL Injection (1) Lack of checking for null value(1) public bool IsValidLogin(string userName, string password) { SqlConnection con = null; SqlCommand cmd = null; bool result = false; try { con = new SqlConnection(DB_CONNECTION); con.Open(); string cmdtext = string.Format("SELECT * FROM [Users] WHERE [Account]='{0}' AND [Password]='{1}' “, userName, password); cmd = new SqlCommand(cmdtext); cmd.Connection = con; cmd.CommandType = CommandType.Text; result= cmd.ExecuteReader().HasRows; cmd.Dispose(); con.Dispose(); return result; } catch (SqlException) {return false;} } SQL Injection (1) Lack of checking for null value(1) SQL Performance Issue !!(2) Memory leak !! (2)

parameters as the same time Baby Defects(9) Combine function calling and passing parameters as the same time Assign value of the called function to a temp variable instead of pass it directly to the calling function, for example, instead of: a = func1(func2(func3, func4)); you can use three temp variables: b=func(3); c=func(4); d=fun2(b,c); a=fun1(d); When you use the temp variable, the code are clearly, and you can avoid the long line same as: strReturn = objDoc.SelectNodes(objNode.Attributes(objAttr.ChildNodes.Item(0).ToString()));

Baby defects (10) Hardcode constant -Give a fixed value when you format data, for example: dgrView.PageSize = 10; -Fixed error message in code strErr = "Error message here"; -The problem occurs when you should change these values. If you put them in the constant file, you need change only one time, if you fixed them, you'll be find and change anywhere you have the fix value

Baby defects (11) Method can not be tested public void aMethod( object arg) { try { \\ CODE BLOCK HERE } catch (Exception) { \\ DO NOTHING

Web Applications Common Defects Alignment of fields, texts Description - The texts are not vertically left or right aligned. - The fields are not vertically left and right aligned. - All text should be left-justified - All numeric fields are right-justified Cause There is no GUI template Preventive action Use CSS Style Sheet and GUI template

Web Applications Common Defects Layouts in all pages Description All windows and dialog boxes don't have a consistent look and feel. Following items are not the same: - Font of text - Color and Background - Header and footer - Size of Logo - Date format Cause There is no GUI template Preventive action Use CSS Style Sheet and GUI template

Web Applications Common Defects Symbol for mandatory fields Description There is no symbol for mandatory fields to remind users. Cause Coding careless Preventive action Use template

Web Applications Common Defects The buttons don't have the same height and distances Description The height of buttons and the distances between them in a page and in all pages are not the same Cause Graphic design No GUI template Preventive action Use CSS Style Sheet and GUI template

Web Applications Common Defects Data in combo box, list box Description Data in combo box/ list box is not sorted Cause Coding careless Preventive action Use checklist

Web Applications Common Defects Different browses Description The layout in all required browses is not correctly (e.g. in Netscape, the alignment, the distances, positions of images … are not correct as in IE) Cause Non compatibility between IE , FireFox and Netscape… Preventive action - Use CSS Style Sheet - Should clarify earlier when we get the requirement from the customer - Simple pages should be used more frequently

Web Applications Common Defects Cannot move between fields by using Tab key and Shift +Tab keys Description Users cannot use Tab key to move to next enterable fields and Shift + Tab keys to previous enterable fields. Cause Not set Tab index Preventive action Set Tab index

Web Applications Common Defects Cursor location Description - The cursor is not located in the first enterable field when the screen is opened. - After an error message occurs, the focus does not return to the error field. Cause Not focus on load Preventive action Set focus

Web Applications Common Defects Images with links have blue borders Description Should hide the color of border of the image. Cause Coding Preventive action Set border properties = 0

Web Applications Common Defects Incorrect links or the link does not work Description The links are not correctly. After clicking the links, error page or wrong page is displayed. Cause Coding Preventive action - Use tool to test broken links - Use global variables to control - Directly links need to be coded by experienced developers

Web Applications Common Defects Using mouse and keyboard Description In general, everything can be done using both the mouse and the keyboard. Cause Not set focus Preventive action Set focus

Web Applications Common Defects Error by input HTML tags, character ' Description Should prevent errors when user inputs HTML tags or character ' in text fields. HTML tags can destroy the layout. Cause Careless, un-experienced coding Preventive action Use HTML Encode, URL Encode and SQL Encode

Web Applications Common Defects Start date is greater than End date Description The logic of date is not checked, user can type Start date greater than End date, or From date is greater than To date… Cause Careless, un-experienced coding Preventive action Use checklist

Web Applications Common Defects Users can return to Web application after logout Description - Users can back to previous page after logout by clicking "Back" button in Toolbars. - When users logout, they cannot back to web application, and must input username and password again to login Cause Un-experienced coding Preventive action - Set cache of page = 0 - Re-set session variables - Check session to assure that it is still active at the beginning of the page.

Web Applications Common Defects Multiple users Description The application does not support many concurrent users as required. Cause Design/Coding Preventive action - Close connection immediately - Optimize design, code - Use tool to test

References Refer Commons defects in attach folder

Q & A