Communicating in Code: Naming Programming Studio Spring 2009.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

Coding Standard: General Rules 1.Always be consistent with existing code. 2.Adopt naming conventions consistent with selected framework. 3.Use the same.
Chapter 2: Modularization
 Lex helps to specify lexical analyzers by specifying regular expression  i/p notation for lex tool is lex language and the tool itself is refered to.
Communicating in Code: Layout and Style Programming Studio Spring 2009 Note: several examples in this lecture taken from The Practice of Programming by.
Documentation 1 Comprehending the present – Investing in the future.
COSC 120 Computer Programming
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 2: Your First Program.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
15-Jun-15 Beginning Style. 2 Be consistent! Most times, you will enter an ongoing project, with established style rules Follow them even if you don’t.
Style Rules II: Names and Naming. Overview Today we will discuss: –Reasons for naming conventions –Rules for naming variables, classes, and methods.
CS1061: C Programming Lecture 23: Review; Examination Details A. O’Riordan, 2005.
1 Introduction to Software Engineering Lecture 42 – Communication Skills.
A simple C++ program /* * This program prints the phrase "Hello world!" * on the screen */ #include using namespace std; int main () { cout
Naming Programming Studio Spring 2008 Lecture 2. Purpose of Coding.
26-Jun-15 Beginning Style. 2 Be consistent! Most times, you will enter an ongoing project, with established style rules Follow them even if you don’t.
Chapter 2: Introduction to C++.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Dobrin / Keller / Weisser : Technical Communication in the Twenty-First Century. © 2008 Pearson Education. Upper Saddle River, NJ, All Rights Reserved.
General Issues in Using Variables
110-D1 Variables, Constants and Calculations(1) Chapter 3: we are familiar with VB IDE (building a form…) to make our applications more powerful, we need.
Group practice in problem design and problem solving
Code as Communication Programming Studio Spring 2015.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Slides by Evan Gallagher Fundamental Data Types 09/09/13.
Programming Logic and Design Sixth Edition Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs.
Communicating in Code: Naming Programming Studio Spring 2013.
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
Programming Style and Documentation Objective(s) F To become familiar with Java Style and Documentation Guidelines.
1 Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
1 CM 220: College Composition II Unit 9 Seminar P RESENTING YOUR BIG IDEA TO THE W ORLD.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
Procedures and Functions Computing Module 1. What is modular programming? Most programs written for companies will have thousands of lines of code. Most.
Chapter 7: High Quality Routines By Raj Ramsaroop.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
CPS120: Introduction to Computer Science
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Info.Design © Writing for the Web Workshop Crafting Usable Content.
Functions, Procedures, and Abstraction Dr. José M. Reyes Álamo.
Program style. Global area Place comment s at beginning of the program: 1.purpose 2.author 3.the date the program was written 4.the data and description.
Working With Objects Tonga Institute of Higher Education.
CS242.  Reduce Complexity  Introduce an intermediate, understandable abstraction  Avoid code duplication  Support subclassing  Hide sequences  Hide.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Guidelines for a Language- Independent Convention Identify global variables –Use g_prefix –Exp: g_RunningTotal Identify module variables –Use m_prefix.
C++ Basics L KEDIGH. Objectives 1. basic components of a c++ program using proper terminology and programming conventions adopted for this class. 2. List.
C++ Basics L KEDIGH. Objectives 1. basic components of a c++ program using proper terminology and programming conventions adopted for this class. 2. List.
Working With Objects Tonga Institute of Higher Education.
INT213-Week-2 Working with Variables. What is variable
Technical Communication A Practical Approach Chapter 14: Web Pages and Writing for the Web William Sanborn Pfeiffer Kaye Adkins.
CPS120: Introduction to Computer Science Variables and Constants.
Review of HTML and CSS A (very) brief review of some key fundamentals to be aware of in IT-238.
Programming for Interactivity Professor Bill Tomlinson Tuesday & Wednesday 6:00-7:50pm Fall 2005.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
Today… Style, Cont. – Naming Things! Methods and Functions Aside - Python Help System Punctuation Winter 2016CISC101 - Prof. McLeod1.
1 Functions Part 1 Prototypes Arguments Overloading Return values.
Dani Vainstein1 VBScript Session 8. Dani Vainstein2 What we learn last session? VBScript procedures. Sub procedures. Function Procedures. Getting data.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
1 January 31, Documenting Software William Cohen NCSU CSC 591W January 31, 2008.
Bill Tucker Austin Community College COSC 1315
Communicating in Code: Naming
Tonga Institute of Higher Education
Beginning Style 27-Feb-19.
Chapter 2: Introduction to C++.
Symbol Table 薛智文 (textbook ch#2.7 and 6.5) 薛智文 96 Spring.
EECE.2160 ECE Application Programming
Chapter 2 Primitive Data Types and Operations
Communicating in Code: Naming
Presentation transcript:

Communicating in Code: Naming Programming Studio Spring 2009

What’s the Purpose of Coding?

To give the computer instructions?

What’s the Purpose of Coding? To give the computer instructions

What’s the Purpose of Coding? To give the computer instructions To demonstrate your skill?

What’s the Purpose of Coding? To give the computer instructions To demonstrate your skill

What’s the Purpose of Coding? To give the computer instructions To demonstrate your skill An effective way to express ideas of what you want the computer to do

What’s the Purpose of Coding? An effective way to express ideas of what you want the computer to do Communication! –To the computer –To yourself (later on) –To others

What about Documentation? External documentation is very useful, but has its own problems –Can be out of date/inconsistent with program –Maintained separately (multiple files) –Often for a different audience developer vs. user Clearly written code can be more important than well-written documentation of that code

Communicating in Code Choosing good names Including appropriate comments Following good layout and style These are all critical to documentation, and with good naming, commenting, and layout, other documentation may be unnecessary!

Names We assign names throughout a program Give identity Imply behavior/purpose Provide recognition

What gets named? Variables Functions Types/classes Namespaces Macros Source Files

Choosing Names Sometimes there are naming conventions –If you work at a company that has an agreed convention, follow it! But, there are several “wise” ideas to consider when choosing names.

Naming Considerations Be sure it’s not a reserved name (Duh!) Sometimes it’s easy to forget… 1.Make it informative 2.Keep it concise 3.Make it memorable 4.Make it pronounceable

Informative Names The amount of information a name needs depends on its scope – understand it when seen Use descriptive names for globals, short names for locals Large routines/loops need more descriptive names s = 0; for (WhichGroup=0; WhichGroup<num; WhichGroup++) { s += G[WhichGroup].n(); }

Informative Names The amount of information a name needs depends on its scope – understand it when seen Use descriptive names for globals, short names for locals Large routines/loops need more descriptive names nAnimals = 0; for (i=0; i<NumAnimalGroups; i++) { nAnimals += AnimalGroup[i].NumberInGroup(); }

Descriptive Names Names should convey what it represents or does, unless obvious from context Describe everything a routine does –Print() vs. PrintAndCloseFile() Avoid meaningless or vague names –HandleData(), PerformAction(), etc.

Descriptive Names Procedures: Active names –Verb followed by noun –AnotherStudent(s) vs. AddStudent(s) Functions different: give return value –GetNumStudents() vs. numStudents() Booleans: Be clear what is returned –checkEOF vs. isEOF

Consistent Names Key: Be Consistent! –nKids, numKids, num_kids, NumKids, nkids, Number_Kids, numberofkids –Write1stObject(), WriteSecondObject(), write_third_object() –averageSalary vs. salaryMinimum Use related names for related operations –OpenFile(): CloseFile() vs. fclose() –open/close, first/last, old/new, min/max, etc.

Name Length Tradeoff between description and visual space Moderate-length names tend to be best –8-20 characters If a glance at the code seems like it has lots of short or lots of long names, use caution! Scope plays a role Rarely-used functions might be longer

Other Random Naming Considerations Beware of “temp” variables Be careful of reusing variable names Be careful of overloading names Avoid intentional misspellings Consider pronunciation

Conventions Lots of conventions out there Conventions help convey information away from its definition Very useful for larger groups/programs Examples: –Globals have initial capital letters –Constants are in ALL CAPS –Etc.

Common Naming Conventions Beginning/ending with a p if a pointer Starting with n for a number i, j are integer indices s is a string, c or ch are characters

Hungarian Naming Convention Base types: –wnWindow –scrScreen Region –fonFont –chCharacter –paParagraph Eg: wnMain, scrUserWorkspace

Hungarian Naming Convention Prefixes –aarray –ccount –ddifference between two variables –eelement of array –gglobal variable –hhandle –iindex into array e.g. iwnUserView = index into array of windows giving user views