Programmeerimine Delphi keskkonnas MTAT.03.214 Programmeerimine Delphi keskkonnas MTAT.03.214 Jelena Zaitseva

Slides:



Advertisements
Similar presentations
The If Then Else Statement Using JavaScript TIP The If Statement is the fundamental control structure that allows branches in the flow of control in a.
Advertisements

Variables and Powerful Names Nathan Scheck CS525 Software Engineering II Fall II 2007 – Sheldon X. Liang, Ph.D. Nathan Scheck CS525 Software Engineering.
Coding Standard: General Rules 1.Always be consistent with existing code. 2.Adopt naming conventions consistent with selected framework. 3.Use the same.
Software Engineering Table-driven methods General control issues.
Software Engineering Fundamental data types. Guidelines - numbers Avoid “magic numbers” (hard- coded values that are not self- explanatory): Changes can.
Software Engineering Variables. The data literacy test Count 1.0 if you know what the concept means. Count 0.5 if you believe you know what the concept.
Software Engineering Routine design. High quality routines Routine: individual method or procedure invocable for a single purpose.
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
DECISIONS Chapter 5. The if Statement  Action based on a conditions  If the condition is true, the body of the statement is executed if (amount
Revealing the Secrets of Self-Documenting Code Svetlin Nakov Telerik Corporation
Variables and Powerful Naming Ryan Ruzich. Naming Considerations The most important consideration in naming a variable is that the name fully and accurately.
Software Engineering Linear code Conditionals. Linear code 1.Statements that must be in a specific order. 2.Statements whose order does not matter.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Introduction to Computers and Programming Style Lecture Professor: Evan Korth New York University.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Varriables CSC 171 FALL 2001 LECTURE 2. History The abacus.
Algorithm Programming Coding Advices Bar-Ilan University תשס " ו by Moshe Fresko.
General Issues in Using Variables
The Pseudocode Programming Process Chapter 9. Summary of Steps in Building Classes and Routines.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Primitive Data Types and Operations Identifiers, Variables, and Constants Primitive Data Types Byte, short, int, long, float, double, char, boolean Casting.
1 Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
 Thursday: › Team Presentations › Risk Assessment and project plan due 11:55 pm  Friday: › Help on coding/testing  Monday: › HW 5 due, 11:55 pm.
Quality Code academy.zariba.com 1. Lecture Content 1.Software Quality 2.Code Formatting 3.Correct Naming 4.Documentation and Comments 5.Variables, Expressions.
Chapter 7: High Quality Routines By Raj Ramsaroop.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
CPS120: Introduction to Computer Science
VBScript Language. What is VBScript Based on the Visual Basic family of languages Supports object oriented features Interpreted Loosely Typed Implicitly.
Semester 1 Final Review Lesson 1.1 Variables in Algebra Evaluate the variable expression when x = x.
Internet Software Development Controlling Threads Paul J Krause.
6/3/2016 CSI Chapter 02 1 Introduction of Flow of Control There are times when you need to vary the way your program executes based on given input.
ECE122 Feb. 22, Any question on Vehicle sample code?
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
Best Practices for Variables
Using Variables Chapter Outline 2  Variable Initialization  Scope  Persistence  Using Each Variable for Single Purpose  Variable Names.
Self-Documenting Code Chapter 32. Kinds of Comments  Repeat of code  Explanation of code  Marker in code  Summary of code  Description of code’s.
1-Dec-15 Additional control structures. 2 The if-else statement The if-else statement chooses which of two statements to execute The if-else statement.
Programmeerimine Delphi keskkonnas MTAT Programmeerimine Delphi keskkonnas MTAT Jelena Zaitseva
Scientific Method Vocabulary. Scientific Method  Research Question: You see something happen and you ask “why?”  Hypothesis: An “if…then” statement.
Revealing the Secrets of Self-Documenting Code Svetlin Nakov Telerik Corporation
Program Style Chapter 22 IB103 Week 12 (part 2). Modularity: the ability to reuse code Encapsulation: hide data access directly but may use methods (the.
Conditions, Logical Expressions, and Selection Control Structures ROBERT REAVES.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
GoodOO Programming Practice in Java © Allan C. Milne v
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
© BYU 03 BA1 Page 1 ECEn 224 Boolean Algebra – Part 1.
High-Quality Routines Chapter 5-6. Review Class Quality Checklist 2.
Murach, Chapter 4. Two Data Types Value Types – Store their own data Reference Types Do not store their own data Stores a reference to an area of memory.
Swift. Introduced in 2014 Replaces Objective-C as “recommended development language” “safer, succinct, readable” Emphasizes type safety.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
CS100Lecture 21 Announcements For homework due Thursday, work alone -- do not work in pairs New class location: Olin 155 Office hour oops! Lyn: MW, 11:15-12:15.
Communicating in Code: Commenting Programming Studio Spring 2009 Note: several examples in this lecture taken from The Practice of Programming by Kernighan.
Variables Names SCMP Special Topic: Software Development
Solving systems of equations
Road Map Style Principle of proximity Naming variables if / else.
Topics The if Statement The if-else Statement Comparing Strings
© 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Fundamental Data Types
High-Quality Routines
Topics The if Statement The if-else Statement Comparing Strings
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
Java Classes and Objects 3rd Lecture
Variables Names CSC-3004 Introduction to Software Development
Chapter 09 – Part II Using Variables
JavaScript.
Coding practices For IT and Computing students 2014.
Chap 2. Identifiers, Keywords, and Types
Presentation transcript:

Programmeerimine Delphi keskkonnas MTAT Programmeerimine Delphi keskkonnas MTAT Jelena Zaitseva

Tips on naming variables

Choose variable names with care x := x - xx; xxx := fido + SalesTax(fido); x := x + LateFee(x1, x) + xxx; x := x + Interest(x1, x);

Choose variable names with care x := x - xx; xxx := fido + SalesTax(fido); x := x + LateFee(x1, x) + xxx; x := x + Interest(x1, x); Balance := Balance - LastPayment; MonthlyTotal := NewPurchases + SalesTax(NewPurchases); Balance := Balance + LateFee(CustomerID, Balance) + MonthlyTotal; Balance := Balance + Interest(CustomerID, Balance);

Choosing a name for variable Examples of good and bad names of variables: Examples of good and bad names of variables: current date: CD, CurrentData, Current, Date, TodaysDate lines per page: LinesPerPage, NumberOfLines, Lines number of people on the Olympic team: NTM, NumberOfPeopleOnTheOlympicTeam, TeamMembersCount NumberOfPeopleOnTheOlympicTeam, TeamMembersCount

Common opposites in variable names first/last first/last min/max min/max next/previous next/previous old/new old/new visible/invisible visible/invisible source/target, source/destination source/target, source/destination locked/unlocked locked/unlocked …

Naming status variables Think of a better name than flag for status variables Think of a better name than flag for status variables if (flag) then … if (IsDataReady) then … if (printFlag = 2) then … if (ReportType = rtMonthly) then … type type TReportType = (rtDaily, rtMonthly, rtAnnual); TReportType = (rtDaily, rtMonthly, rtAnnual); TSomeNewClass = class TSomeNewClass = class private private FReportType: TReportType FReportType: TReportType public public property ReportType: TReportType read FReportType; property ReportType: TReportType read FReportType; end; end;

Naming boolean variables Give boolean variables names that imply true or false. Give boolean variables names that imply true or false. if (status) then … if (DataProcessed) then … if (IsDataProcessed) then … if (IsDataProcessed) then …

Naming enumerated types Using prefix helps to ensure if members of a type belong to the same group. Using prefix helps to ensure if members of a type belong to the same group.type TSound = (sndClick, sndClack, sndClock); TSound = (sndClick, sndClack, sndClock); TMonth = (mJanuary, mFebruary, …, mDecember); TMonth = (mJanuary, mFebruary, …, mDecember); TBaseColor = (bcRed, bcGreen, bcBlue); TBaseColor = (bcRed, bcGreen, bcBlue); TFavoriteColor = (fcRed, fcPink, fcBlue); TFavoriteColor = (fcRed, fcPink, fcBlue);

Kinds of names to avoid Avoid misleading names or abbreviations Avoid misleading names or abbreviations Avoid names with similar meanings Avoid names with similar meanings Avoid names with different meanings but similar names Avoid names with different meanings but similar names Avoid numerals in names Avoid numerals in names Avoid misspelled words in names Avoid misspelled words in names Avoid the names of standard types, Avoid the names of standard types, variables, and routines Don’t differentiate variable names solely by capitalization Don’t differentiate variable names solely by capitalization Don’t use names that are totally unrelated to what the variable represent Don’t use names that are totally unrelated to what the variable represent if if=then then then := else else then := if;

Tips on writing code

Boolean variables Use boolean variables to document your code Use boolean variables to document your code Use boolean variables to simplify complicated tests Use boolean variables to simplify complicated tests if ( (ElementIndex < 0) or (MAX_ELEMENT_INDEX < elementIndex) or (MAX_ELEMENT_INDEX < elementIndex) or (ElementIndex == LastElementIndex) ) then … (ElementIndex == LastElementIndex) ) then … Finished := (ElementIndex < 0) or (MAX_ELEMENT_INDEX < elementIndex); (MAX_ELEMENT_INDEX < elementIndex); Repeated := ElementIndex == LastElementIndex; if (Finished or Repeated) then …

Enumerated types use enumerated types for readability use enumerated types for readability –if ChosenColor = 1 then –if ChosenColor = bcRed then use enumerated types for modifiability use enumerated types for modifiability use enumerated types as an alternative to boolean variables use enumerated types as an alternative to boolean variables

Constants use named constants in data declarations use named constants in data declarations avoid literals, even ‘safe’ ones avoid literals, even ‘safe’ ones for I:=1 to 12 do for I:=1 to 12 do YearProfit := YearProfit + Profit(I); YearProfit := YearProfit + Profit(I); for Month := mJanuary to mDecember do for Month := mJanuary to mDecember do YearProfit := YearProfit + Profit(Month); use named constants consistently use named constants consistently

keep variables ‘live’ for as short a time as possible keep variables ‘live’ for as short a time as possible

use only one statement per line use only one statement per line YearProfit:=0; for Month:=mJanuary to mDecember do YearProfit:=YearProfit+Profit(Month);

write self-documenting code write self-documenting code for I:=2 to GivenNumber do Numbers[I].MeetsCriteria := True; for PrimeCandidate:=2 to GivenNumber do Numbers[I].IsPrime := True;

document unclear dependencies with comments document unclear dependencies with comments –comments should say things about code that the code can’t say about itself – at the summary level (focusing on why rather than how)