Algorithm Programming 2 89-211 Coding Advices Bar-Ilan University 2005-2006 תשס " ו by Moshe Fresko.

Slides:



Advertisements
Similar presentations
User-Defined Functions Like short programs Can operate on their own data Can receive data from callers and return data to callers.
Advertisements

Revealing the Secrets of Self-Documenting Code Svetlin Nakov Telerik Corporation For C# Developers.
Unit 6 Assignment 2 Chris Boardley.
Internal Documentation Conventions. Kinds of comments javadoc (“doc”) comments describe the user interface: –What the classes, interfaces, fields and.
Coding Standards for Java An Introduction. Why Coding Standards are Important? Coding Standards lead to greater consistency within your code and the code.
Documentation 1 Comprehending the present – Investing in the future.
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
Design Patterns in Java Appendix D UML at a Glance Summary prepared by Kirk Scott 1.
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.
Programming Style a programs language gives you a lot of freedom how to write a program – too much? but some programming style is good goal: it must be.
Designing Classes How to write classes in a way that they are easily understandable, maintainable and reusable.
CSE1301 Computer Programming: Lecture 13 Documentation.
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.
Writing a Memorandum Business Communication and Report Writing.
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
Computer Science 240 Principles of Software Design.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Chapter 7 Designing Classes. Class Design When we are developing a piece of software, we want to design the software We don’t want to just sit down and.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Design-Making Projects Work (Chapter7) n Large Projects u Design often distinct from analysis or coding u Project takes weeks, months or years to create.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 3.0.
Computer Science 240 © Ken Rodham 2006 Principles of Software Design.
07 Coding Conventions. 2 Demonstrate Developing Local Variables Describe Separating Public and Private Members during Declaration Explore Using System.exit.
CSC204 – Programming I Lecture 4 August 28, 2002.
Quality Code academy.zariba.com 1. Lecture Content 1.Software Quality 2.Code Formatting 3.Correct Naming 4.Documentation and Comments 5.Variables, Expressions.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
Refactoring Improving the structure of existing code Refactoring1.
SE: CHAPTER 7 Writing The Program
23-Oct-15 Abstract Data Types. 2 Data types A data type is characterized by: a set of values a data representation, which is common to all these values,
Java Coding Standards and Best Practices Coding Standards Introduction: After completing this chapter, you will able to keep your code up to standards.
Best Practices. Contents Bad Practices Good Practices.
Designing Classes 2 How to write classes in a way that they are easily understandable, maintainable and reusable.
Refactoring1 Improving the structure of existing code.
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
Software Design Design is the process of applying various techniques and principles for the purpose of defining a device, a process,, or a system in sufficient.
CPS120: Introduction to Computer Science Decision Making in Programs.
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.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
CS242.  Reduce Complexity  Introduce an intermediate, understandable abstraction  Avoid code duplication  Support subclassing  Hide sequences  Hide.
Software Engineering CS3003 Lecture 4 Code bad smells and refactoring.
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
Code Conventions Tonga Institute of Higher Education.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.
Designing Classes. Software changes Software is not like a novel that is written once and then remains unchanged. Software is extended, corrected, maintained,
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Refactoring1 Improving the structure of existing code.
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
Controlling Program Flow with Decision Structures.
Principles of Programming. Achieving an Object-Oriented Design  Abstraction and Information Hiding  Object-Oriented Design  Functional Decomposition.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 6.0.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. 4 Simple Flow of Control.
Principles and examples
GC211Data Structure Lecture2 Sara Alhajjam.
Object Oriented Programming using Java - Class Instance Variables
University of Central Florida COP 3330 Object Oriented Programming
Objects First with Java
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
Improving the structure of existing code
Unit 6 Assignment 2 Chris Boardley.
Beginning Style 27-Feb-19.
CISC101 Reminders All assignments are now posted.
Business Communication and Report Writing
Controlling Program Flow
Software Development Techniques
Presentation transcript:

Algorithm Programming Coding Advices Bar-Ilan University תשס " ו by Moshe Fresko

Programming Principles A Good Program must have following traits. Readability Program will be read, by other people or even in the future by us Maintainability The problem for which the program was originally written may evolve and change over time. Reliability To assure not to introduce errors into programs. Performance Programs must perform well enough to do the task. Effectiveness Not to waste resources. In programming task to take care of the following Planning : Thinking about the programming task as a whole. Stylistic patterns : Program must look nice and readible. Design and Structuring How to structure your code to aid maintainability and safety. Safety To prevent errors.

Programming practice Starting Pair Programming (Maintainability) Better to work in pairs. Two minds are better than one. Scheduling a Task (Planning) Timing a schedule can be learned by practice. Try to estimate every task you have and learn from previous estimation inaccuracy. It is easier to estimate small tasks. So divide the task. Piecemeal Growth (Planning) Hard to write large programs in one shot. So write a working small program, and then expand it.

Programming practice Designing One Service Per Class (Structural) A program is easier to maintain when it is made up of small simple parts, so give each class one job to do. Polymorphism before Selection (Structural) Good OO programs use relatively few if-switch statements. Most decisions must be made via the polymorphism. Logical Interfaces (Maintainability) The interface should define logical services, rather then its implementation. Complete Interfaces (Design) Provide a set of public methods in your class that permits the client software to perform all legal transformations. Make sure that clients will have access to all needed aspects of this service. Example: A Stack implementation needs isEmpty() method Stack must make possible for the client to decide the response to an error Strong encapsulation (Safety) Don ’ t reveal the details of your implementation, even indirectly. Example: Don ’ t return an internal Container, unless it is immutable To return Iterator is a poor practice, especially if it has a Remove or Modify method.

Programming practice Getting Ready to Program Rewrite (Planning) Rewrite your program several times. Rewrite it at least once before you show it to anyone. Optimize for Readability (Maintainability) Make your code as clear and correct as possible, not as fast as possible. Intention Revealing Name (Maintainability) All the names in your programs (variables, parameters, classes, methods) should denote the purpose of the item they refer to.. Consistent Naming (Maintainability) Use a consistent style for naming things in your program. Public Features First (Stylistic) List the public parts of your class first, and the private parts last. Private Fields (Safety) All of your fields should be private. Provide protected accessor functions when necessary. Initialize (Safety) When you declare a field or local variable, initialize it immediately.

Programming practice Getting Ready to Program Test Everything Now (Safety) When you write any code, write a test for it as well. Assign Variables Once (Design) Once you have given a variable a value, do not change it if at all possible. The value should preferably assigned when the variable is declared. If possible make them final. Short Method (Structural) Your methods should usually be short. Break up long or complicated methods into parts. Write Method Objects when needed Comment (only) when necessary (Maintainability) Make your comments to indicate the intent of the program. i++ ; // increment i => a worthless comment i++ ; // increment the card counter => a better comment cardCounter++ ; => no comment needed Say it once (Structural) Make little pieces. Don ’ t write similar codes several times.

Programming practice Coding Indent for Structure (Stylistic) The parts of a structure should be indented from the keywords and punctuation symbols. All of the statements at the same level of the structure should be indented exactly the same amount. Don ’ t indent too much or too little. Brace All (Stylistic) Completely brace all statement parts in all structures even if it has a single expression. Braces Line Up (Structural) When writing brace symbols, if the opening and closing symbol don ’ t both fit on the same line, then make them line up exactly vertically. Use Spaces instead of Tabs (Maintainability) Some editors put spaces when pressing to Tab Consistent Capitalization (Stylistic) Capitalize consistently to show the kind of thing a name refers to. Capitalize the first letter of : Class Name, Interface Name. Never capitalize the first letter of a method name or variable name. Constant names are completely capitalized Package names are all small letters. For a name having a couple of words, capitalize the words except the first one

Programming practice Coding (Cont.) Name Your Constants (Maintainability) Name any important constant values in your program and refer to them only by name. Spell it out (Maintainability) Don ’ t abbreviate your method and variable names. Locals When Needed (Design) Use local variables when they are used to avoid duplicate computation, and otherwise avoid their use when the intent is clear without them. One statement per line (Stylistic) Write your programs so that there is only one statement on each line. Short lines (Maintainability) Keep your lines short so that it can be grasped on the screen and on the printer. Function instead of a Complex Condition Any complex condition should be written as a separate method. Use “ this. ” (Maintainability) When you refer to a field of the current object, prefix the reference with “ this. ” Local Variables Reassigned Above Their Use