Seven Ineffective Coding Habits of Many
|
|
- Ethan Booth
- 6 years ago
- Views:
Transcription
1 Seven Ineffective Coding Habits of Many
2
3
4
5 It turns out that style matters in programming for the same reason that it matters in writing. It makes for better reading.
6
7 Noisy Code
8 Signal-to-noise ratio (often abbreviated SNR or S/N) is a measure used in science and engineering that compares the level of a desired signal to the level of background noise. Signal-to-noise ratio is sometimes used informally to refer to the ratio of useful information to false or irrelevant data in a conversation or exchange.
9 To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them? William Shakespeare Hamlet
10 Continuing existence or cessation of existence: those are the scenarios. Is it more empowering mentally to work towards an accommodation of the downsizings and negative outcomes of adversarial circumstance, or would it be a greater enhancement of the bottom line to move forwards to a challenge to our current difficulties, and, by making a commitment to opposition, to effect their demise? Tom Burton Long Words Bother Me
11 public class RecentlyUsedList private List<string> items; public RecentlyUsedList() items = new List<string>(); public void Add(string newitem) if (items.contains(newitem)) int position = items.indexof(newitem); string existingitem = items[position]; items.removeat(position); items.insert(0, existingitem); else items.insert(0, newitem); public int Count get int size = items.count; return size; public string this[int index] get int position = 0; foreach (string item in items) if (position == index) return item; ++position; throw new ArgumentOutOfRangeException();
12 public class RecentlyUsedList private List<string> items; public RecentlyUsedList() items = new List<string>(); public void Add(string newitem) if (items.contains(newitem)) int position = items.indexof(newitem); string existingitem = list[position]; items.removeat(position); items.insert(0, existingitem); else items.insert(0, newitem); public int Count get int size = items.count; return size; public string this[int index] get int position = 0; foreach (string value in items) if (position == index) return value; ++position; throw new ArgumentOutOfRangeException(); public class RecentlyUsedList private List<string> items = new List<string>(); public void Add(string newitem) items.remove(newitem); items.add(newitem); public int Count get return items.count; public string this[int index] get return items[count - index - 1];
13
14
15 Comments A delicate matter, requiring taste and judgement. I tend to err on the side of eliminating comments, for several reasons. First, if the code is clear, and uses good type names and variable names, it should explain itself. Second, comments aren't checked by the compiler, so there is no guarantee they're right, especially after the code is modified. A misleading comment can be very confusing. Third, the issue of typography: comments clutter code. Rob Pike, "Notes on Programming in C"
16 There is a famously bad comment style: i=i+1; /* Add one to i */ and there are worse ways to do it: /********************************** * * * Add one to i * * * **********************************/ i=i+1; Don't laugh now, wait until you see it in real life. Rob Pike, "Notes on Programming in C"
17 A common fallacy is to assume authors of incomprehensible code will somehow be able to express themselves lucidly and clearly in comments. Kevlin Henney
18
19 Unsustainable Spacing
20 To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them? William Shakespeare Hamlet
21 Continuing existence or cessation of existence: those are the scenarios. Is it more empowering mentally to work towards an accommodation of the downsizings and negative outcomes of adversarial circumstance, or would it be a greater enhancement of the bottom line to move forwards to a challenge to our current difficulties, and, by making a commitment to opposition, to effect their demise? Tom Burton Long Words Bother Me
22 Continuing existence or cessation of existence: those are the more empowe to work towa accommodati downsizings outcomes of circumstance a greater enh the bottom li forwards to a our current d by making a opposition, t demise?
23 Column 80 How many programmers lay out their code
24 How people read
25 To answer the question "What is clean design?" most succinctly: a clean design is one that supports visual thinking so people can meet their informational needs with a minimum of conscious effort. Daniel Higginbotham "Clean Up Your Mess A Guide to Visual Design for Everyone"
26 You convey information by the way you arrange a design's elements in relation to each other. This information is understood immediately, if not consciously, by the people viewing your designs. Daniel Higginbotham "Clean Up Your Mess A Guide to Visual Design for Everyone"
27 This is great if the visual relationships are obvious and accurate, but if they're not, your audience is going to get confused. They'll have to examine your work carefully, going back and forth between the different parts to make sure they understand. Daniel Higginbotham "Clean Up Your Mess A Guide to Visual Design for Everyone"
28 public int hownottolayoutamethodheader(int firstargument, String secondargument) public int ensureargumentsarealignedlikethis( int firstargument, String secondargument) public int orensureargumentsaregroupedlikethis( int firstargument, String secondargument) public int butnotalignedlikethis(int firstargument, String secondargument)
29 int donotformat = likethis(someargumentorexpression, anotherargumentorexpression); int insteadformat = somethinglikethis( someargumentorexpression, anotherargumentorexpression); int orformat = somethinglikethis( someargumentorexpression, anotherargumentorexpression);
30 int asitis = unstable(someargumentorexpression, anotherargumentorexpression); int butthisis = stable( someargumentorexpression, anotherargumentorexpression); int andthisis = stable( someargumentorexpression, anotherargumentorexpression);
31 public ResultType arbitrarymethodname(firstargumenttype firs SecondArgumentType sec ThirdArgumentType thir LocalVariableType localvariable = method(firstargument, secondargument) if (localvariable.issomething(thirdargument, SOME_SHOUTY_CONSTANT)) dosomethingwith(localvariable); return localvariable.getsomething();
32 public ResultType arbitrarymethodname( FirstArgumentType firstargument, SecondArgumentType secondargument, ThirdArgumentType thirdargument) LocalVariableType localvariable = method(firstargument, secondargument); if (localvariable.issomething( thirdargument, SOME_SHOUTY_CONSTANT)) dosomething(localvariable); return localvariable.getsomething();
33 XXXXXX XXXXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXX XX XXXXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXX
34 public ResultType arbitrarymethodname( FirstArgumentType firstargument, SecondArgumentType secondargument, ThirdArgumentType thirdargument) LocalVariableType localvariable = method(firstargument, secondargument); if (localvariable.issomething( thirdargument, SOME_SHOUTY_CONSTANT)) dosomething(localvariable); return localvariable.getsomething();
35 XXXXXX XXXXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXX XX XXXXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXX
36 public ResultType arbitrarymethodname( FirstArgumentType firstargument, SecondArgumentType secondargument, ThirdArgumentType thirdargument) LocalVariableType localvariable = method(firstargument, secondargument); if (localvariable.issomething( thirdargument, SOME_SHOUTY_CONSTANT)) dosomething(localvariable); return localvariable.getsomething();
37 XXXXXX XXXXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXX XX XXXXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXX
38
39 Lego Naming
40 Agglutination is a process in linguistic morphology derivation in which complex words are formed by stringing together morphemes, each with a single grammatical or semantic meaning. Languages that use agglutination widely are called agglutinative languages.
41 pneumonoultramicroscopicsilicovolcanoconiosis fylkestrafikksikkerhetsutvalgssekretariatslederfunksjonene Rindfleischetikettierungsüberwachungsaufgabenübertragungsgesetz
42 add validate Proxy Controller Value get Exception Factory Manager set enable process create Object check disable do Service remove
43
44
45
46 People will be using the words you choose in their conversation for the next 20 years. You want to be sure you do it right. Unfortunately, many people get all formal [...]. Just calling it what it is isn't enough.
47 public interface ConditionChecker boolean checkcondition();...
48 public interface Condition boolean istrue();...
49 They have to tack on a flowery, computer science-y, impressive sounding, but ultimately meaningless word, like Object, Thing, Component, Part, Manager, Entity, or Item.
50 The simple, the punchy, the easily remembered will be far more effective in the long run than some long name that says it all, but in such a way that no one wants to say it at all.
51 AccessViolationException ArgumentOutOfRangeException ArrayTypeMismatchException BadImageFormatException CannotUnloadAppDomainException EntryPointNotFoundException IndexOutOfRangeException InvalidOperationException OverflowException
52 AccessViolation ArgumentOutOfRange ArrayTypeMismatch BadImageFormat CannotUnloadAppDomain EntryPointNotFound IndexOutOfRange InvalidOperation Overflow
53 ArgumentException ArithmeticException ContextMarshalException FieldAccessException FormatException NullReferenceException ObjectDisposedException RankException TypeAccessException
54 Argument Arithmetic ContextMarshal FieldAccess Format NullReference ObjectDisposed Rank TypeAccess
55 InvalidArgument InvalidArithmeticOperation FailedContextMarshal InvalidFieldAccess InvalidFormat NullDereferenced OperationOnDisposedObject ArrayRankMismatch InvalidTypeAccess
56 Omit needless words. William Strunk and E B White The Elements of Style
57
58 Underabstraction
59
60
61 if (portfolioidsbytraderid.get(trader.getid()).containskey(portfolio.getid()))... Dan North, "Code in the Language of the Domain" 97 Things Every Programmer Should Know
62 if (trader.canview(portfolio))... Dan North, "Code in the Language of the Domain" 97 Things Every Programmer Should Know
63 parser.processnodes(text, false); Gregor Hohpe, "Convenience Is Not an -ility" 97 Things Every Programmer Should Know
64 If you have a procedure with ten parameters, you probably missed some. Alan Perlis
65
66 Unencapsulated State
67 public class RecentlyUsedList private List<string> items = new List<string>(); public List<string> Items get return items; public void Add(string newitem) if(newitem == null) throw new ArgumentNullException(); items.remove(newitem); items.insert(0, newitem);...
68 public class RecentlyUsedList private List<string> items = new List<string>(); public List<string> Items get return items; public void Add(string newitem) if(newitem == null) throw new ArgumentNullException(); items.remove(newitem); items.insert(0, newitem);...
69 public class RecentlyUsedList private List<string> items = new List<string>(); public List<string> Items get return items; public void Add(string newitem) if(newitem == null) throw new ArgumentNullException(); items.remove(newitem); items.insert(0, newitem);... var list = new RecentlyUsedList(); list.add("hello, World!"); Console.WriteLine(list.Items.Count); list.items.add("hello, World!"); Console.WriteLine(list.Items.Count); list.items.add(null);
70 Don't ever invite a vampire into your house, you silly boy. It renders you powerless.
71 public class RecentlyUsedList private IList<string> items = new List<string>(); public int Count get return items.count; public string this[int index] get return items[index]; public void Add(string newitem) if(newitem == null) throw new ArgumentNullException(); items.remove(newitem); items.insert(0, newitem);...
72 public class RecentlyUsedList private IList<string> items = new List<string>(); public int Count get return items.count; public string this[int index] get return items[count index - 1]; public void Add(string newitem) if(newitem == null) throw new ArgumentNullException(); items.remove(newitem); items.add(newitem);...
73
74 Getters and Setters
75
76
77
78
79 public class Money implements public int getunits()... public int gethundredths()... public Currency getcurrency() public void setunits(int newunits)... public void sethundredths(int newhundredths)... public void setcurrency(currency newcurrency)......
80 public final class Money implements public int getunits()... public int gethundredths()... public Currency getcurrency()......
81 Just because you have a getter, doesn't mean you should have a setter.
82 public final class Money implements public int getunits()... public int gethundredths()... public Currency getcurrency()......
83 public final class Money implements public int units()... public int hundredths()... public Currency currency()......
84 "Get something" is an imperative with an expected side effect.
85
86 Uncohesive Tests
87 Everybody knows that TDD stands for Test Driven Development. However, people too often concentrate on the words "Test" and "Development" and don't consider what the word "Driven" really implies. For tests to drive development they must do more than just test that code performs its required functionality: they must clearly express that required functionality to the reader. That is, they must be clear specifications of the required functionality. Tests that are not written with their role as specifications in mind can be very confusing to read. Nat Pryce and Steve Freeman "Are Your Tests Really Driving Your Development?"
88 public class RecentlyUsedList... public RecentlyUsedList()... public int Count get... public string this[int index] get... public void Add(string newitem)......
89 [TestFixture] public class RecentlyUsedListTests [Test] public void TestConstructor()... [Test] public void TestCountGet()... [Test] public void TestIndexerGet()... [Test] public void TestAdd()......
90 test test test test method method method test
91 namespace RecentlyUsedList_spec [TestFixture] public class A_new_list [Test] public void Is_empty() [TestFixture] public class An_empty_list [Test] public void Retains_a_single_addition() [Test] public void Retains_unique_additions_in_stack_order() [TestFixture] public class A_non_empty_list [Test] public void Is_unchanged_when_head_item_is_readded() [Test] public void Moves_non_head_item_to_head_when_it_is_readded() [TestFixture] public class Any_list_rejects [Test] public void Addition_of_null_items() [Test] public void Indexing_past_its_end() [Test] public void Negative_indexing()
92 namespace RecentlyUsedList_spec [TestFixture] public class A_new_list [Test] public void Is_empty() [TestFixture] public class An_empty_list [Test] public void Retains_a_single_addition() [Test] public void Retains_unique_additions_in_stack_order() [TestFixture] public class A_non_empty_list [Test] public void Is_unchanged_when_head_item_is_readded() [Test] public void Moves_non_head_item_to_head_when_it_is_readded() [TestFixture] public class Any_list_rejects [Test] public void Addition_of_null_items() [Test] public void Indexing_past_its_end() [Test] public void Negative_indexing()
93 So who should you be writing the tests for? For the person trying to understand your code. Good tests act as documentation for the code they are testing. They describe how the code works. For each usage scenario, the test(s): Describe the context, starting point, or preconditions that must be satisfied Illustrate how the software is invoked Describe the expected results or postconditions to be verified Different usage scenarios will have slightly different versions of each of these. Gerard Meszaros "Write Tests for People"
94 namespace RecentlyUsedList_spec [TestFixture] public class A_new_list... [TestFixture] public class An_empty_list [Test] public void Retains_a_single_addition( [Values("London", "Bristol", "Oslo")] string addend) var items = new RecentlyUsedList(); // Given... items.add(addend); // When... Assert.AreEqual(1, items.count); // Then... Assert.AreEqual(addend, list[0]); [Test] public void Retains_unique_additions_in_stack_order() [TestFixture] public class A_non_empty_list... [TestFixture] public class Any_list_rejects...
95 One of the things that Osherove warns against is multiple asserts in unit tests. Owen Pellegrin
96 string[] itinerary =...; string[] expected = "London", "Bristol", "Oslo" ; Assert.AreEqual(expected, itinerary);
97 Assert.DoesNotThrow(() => string[] itinerary =...; string[] expected =...; ); Assert.IsNotNull(itinerary); Assert.AreEqual(3, itinerary.length); Assert.AreEqual("London", itinerary[0]); Assert.AreEqual("Bristol", itinerary[1]); Assert.AreEqual("Oslo", itinerary[2]);
98 My guideline is usually that you test one logical concept per test. You can have multiple asserts on the same object. They will usually be the same concept being tested. Roy Osherove
99 A test case should be just that: it should correspond to a single case.
100 One of the most foundational principles of good design is: Gather together those things that change for the same reason, and separate those things that change for different reasons. This principle is often known as the single responsibility principle, or SRP. In short, it says that a subsystem, module, class, or even a function, should not have more than one reason to change.
101
102 We refer to a sound line of reasoning, for example, as coherent. The thoughts fit, they go together, they relate to each other. This is exactly the characteristic of a class that makes it coherent: the pieces all seem to be related, they seem to belong together, and it would feel somewhat unnatural to pull them apart. Such a class exhibits cohesion.
103 We refer to a sound line of reasoning, for example, as coherent. The thoughts fit, they go together, they relate to each other. This is exactly the characteristic of a test that makes it coherent: the pieces all seem to be related, they seem to belong together, and it would feel somewhat unnatural to pull them apart. Such a test exhibits cohesion.
104 tests tests tests class class tests
105
106
107
108 At some level the style becomes the substance.
Seven Ineffective Coding Habits of Many
Seven Ineffective Coding Habits of Many Programmers @KevlinHenney It turns out that style matters in programming for the same reason that it matters in writing. It makes for better reading. Douglas
More informationProgramming with GUTs
Programming with GUTs @KevlinHenney kevlin@curbralan.com When you write unit tests, TDDstyle or after your development, you scrutinize, you think, and often you prevent problems without even encountering
More informationProgramming with GUTs
Programming with GUTs @KevlinHenney kevlin@curbralan.com When you write unit tests, TDDstyle or after your development, you scrutinize, you think, and often you prevent problems without even encountering
More informationenterprise, noun a project or undertaking that is especially bold, complicated or arduous readiness to engage in undertakings of difficulty, risk, danger or daring a design of which the execution is attempted
More information5 ineffective. MANY F# programmers. DON T have. coding habits
5 ineffective coding habits MANY F# programmers DON T have habit ˈhabɪt/ A settled or regular tendency or practice, especially one that is hard to give up. I m not a great programmer; I m just a good programmer
More informationSmall Is Beautiful. A talk on code as if people mattered A talk on code as if economics
Small Is Beautiful A talk on code as if people mattered A talk on code as if economics mattered @KevlinHenney Sustainable development is development that meets the needs of the present without compromising
More informationKnow Your Units TDD, DDT, POUTing and GUTs Kevlin Henney
Know Your Units TDD, DDT, POUTing and GUTs Kevlin Henney kevlin@curbralan.com Intent Clarify the practice(s) of unit testing Content Kinds of tests Testing approach Good unit tests Listening to your tests
More informationProgrammer's Dozen. Thirteen Recommendations for Reviewing, Kevlin Henney
Programmer's Dozen Thirteen Recommendations for Reviewing, Refactoring and Regaining Control of Code Kevlin Henney kevlin@curbralan.com programmer a person who writes computer programs. dozen a group or
More informationLecture Notes on Memory Layout
Lecture Notes on Memory Layout 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 11 1 Introduction In order to understand how programs work, we can consider the functions,
More information1.2 Adding Integers. Contents: Numbers on the Number Lines Adding Signed Numbers on the Number Line
1.2 Adding Integers Contents: Numbers on the Number Lines Adding Signed Numbers on the Number Line Finding Sums Mentally The Commutative Property Finding Sums using And Patterns and Rules of Adding Signed
More informationIn our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology.
Guide to and Hi everybody! In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology. This guide focuses on two of those symbols: and. These symbols represent concepts
More informationThe Stack, Free Store, and Global Namespace
Pointers This tutorial is my attempt at clarifying pointers for anyone still confused about them. Pointers are notoriously hard to grasp, so I thought I'd take a shot at explaining them. The more information
More informationGood Object- Oriented Development
Good Object- Oriented Development Kevlin Henney kevlin@curbralan.com @KevlinHenney See http://programmer.97things.oreilly.com (also http://tr.im/97tepsk and http://tinyurl.com/97tepsk) and follow @97TEPSK
More informationAXIOMS OF AN IMPERATIVE LANGUAGE PARTIAL CORRECTNESS WEAK AND STRONG CONDITIONS. THE AXIOM FOR nop
AXIOMS OF AN IMPERATIVE LANGUAGE We will use the same language, with the same abstract syntax that we used for operational semantics. However, we will only be concerned with the commands, since the language
More informationOrganizing Information. Organizing information is at the heart of information science and is important in many other
Dagobert Soergel College of Library and Information Services University of Maryland College Park, MD 20742 Organizing Information Organizing information is at the heart of information science and is important
More informationWeek - 01 Lecture - 04 Downloading and installing Python
Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 04 Downloading and
More informationFormal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5
Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5 [talking head] Formal Methods of Software Engineering means the use of mathematics as an aid to writing programs. Before we can
More informationCSE 142/143 Unofficial Commenting Guide Eric Arendt, Alyssa Harding, Melissa Winstanley
CSE 142/143 Unofficial Commenting Guide Eric Arendt, Alyssa Harding, Melissa Winstanley In Brief: What You Need to Know to Comment Methods in CSE 143 Audience o A random person you don t know who wants
More informationUpcoming Features in C# Mads Torgersen, MSFT
Upcoming Features in C# Mads Torgersen, MSFT This document describes language features currently planned for C# 6, the next version of C#. All of these are implemented and available in VS 2015 Preview.
More information6.001 Notes: Section 8.1
6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything
More informationProgram development plan
Appendix A Program development plan If you are spending a lot of time debugging, it is probably because you do not have an effective program development plan. A typical, bad program development plan goes
More informationExcerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.
Chapter 5 Using the Integers In spite of their being a rather restricted class of numbers, the integers have a lot of interesting properties and uses. Math which involves the properties of integers is
More informationSoftware Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore
Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore Lecture 04 Software Test Automation: JUnit as an example
More information10 Tips For Effective Content
10 Tips For Effective Email Content Nowadays when it comes to online marketing, and the Internet as a whole, so many people are being added to so many email lists. They're being bombarded constantly by
More informationSML Style Guide. Last Revised: 31st August 2011
SML Style Guide Last Revised: 31st August 2011 It is an old observation that the best writers sometimes disregard the rules of rhetoric. When they do so, however, the reader will usually find in the sentence
More informationTurning Development Outside
Turning Development Outside In @KevlinHenney What We Talk About When We Talk About Development @KevlinHenney What We Talk About When We Talk About Requirements @KevlinHenney Too often we push the problem
More informationCSE 331 Midterm Exam Sample Solution 2/18/15
Question 1. (10 points) (Forward reasoning) Using forward reasoning, write an assertion in each blank space indicating what is known about the program state at that point, given the precondition and the
More informationAssertions, pre/postconditions
Programming as a contract Assertions, pre/postconditions Assertions: Section 4.2 in Savitch (p. 239) Specifying what each method does q Specify it in a comment before method's header Precondition q What
More informationIt Is Possible to Do Object-Oriented Programming in Java
It Is Possible to Do Object-Oriented Programming in Java Kevlin Henney kevlin@curbralan.com @KevlinHenney The Java programming language platform provides a portable, interpreted, high-performance, simple,
More informationSection 1.1 Definitions and Properties
Section 1.1 Definitions and Properties Objectives In this section, you will learn to: To successfully complete this section, you need to understand: Abbreviate repeated addition using Exponents and Square
More informationCSE 331 Midterm Exam Sample Solution 2/13/12
Question 1. (14 points) (assertions) Using backwards reasoning, find the weakest precondition for each sequence of statements and postcondition below. Insert appropriate assertions in each blank line.
More informationEXAMINING THE CODE. 1. Examining the Design and Code 2. Formal Review: 3. Coding Standards and Guidelines: 4. Generic Code Review Checklist:
EXAMINING THE CODE CONTENTS I. Static White Box Testing II. 1. Examining the Design and Code 2. Formal Review: 3. Coding Standards and Guidelines: 4. Generic Code Review Checklist: Dynamic White Box Testing
More informationLecture Notes on Contracts
Lecture Notes on Contracts 15-122: Principles of Imperative Computation Frank Pfenning Lecture 2 August 30, 2012 1 Introduction For an overview the course goals and the mechanics and schedule of the course,
More informationCS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class
CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount
More information6.001 Notes: Section 6.1
6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of
More informationClasses and Methods גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון
Classes and Methods גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap Lectures 4 and 5 present two sides of OOP: Lecture 4 discusses the static, compile time representation of object-oriented
More informationLecture 1 Contracts : Principles of Imperative Computation (Fall 2018) Frank Pfenning
Lecture 1 Contracts 15-122: Principles of Imperative Computation (Fall 2018) Frank Pfenning In these notes we review contracts, which we use to collectively denote function contracts, loop invariants,
More informationLecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning
Lecture 1 Contracts 15-122: Principles of Imperative Computation (Spring 2018) Frank Pfenning In these notes we review contracts, which we use to collectively denote function contracts, loop invariants,
More informationFederal Plain Language Guidelines
Federal Plain Language Guidelines March 2011 Revision 1, May 2011 Table of Contents Introduction... i Revision 1 Changes... ii Table of Contents... iii I. Think about your audience... 1 a. Identify and
More information(a) (4 pts) Prove that if a and b are rational, then ab is rational. Since a and b are rational they can be written as the ratio of integers a 1
CS 70 Discrete Mathematics for CS Fall 2000 Wagner MT1 Sol Solutions to Midterm 1 1. (16 pts.) Theorems and proofs (a) (4 pts) Prove that if a and b are rational, then ab is rational. Since a and b are
More informationThe Surface Plane. Sensory Design
The Surface Plane Sensory Design The Surface Plane At the top of the five-plane model, we turn our attention to those aspects of the product our users will notice first: the sensory design. Here, content,
More informationThe Three Rules. Program. What is a Computer Program? 5/30/2018. Interpreted. Your First Program QuickStart 1. Chapter 1
The Three Rules Chapter 1 Beginnings Rule 1: Think before you program Rule 2: A program is a human-readable essay on problem solving that also executes on a computer Rule 3: The best way to improve your
More informationClasses and Methods עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מבוסס על השקפים של אותו קורס שניתן בשנים הקודמות
Classes and Methods עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מבוסס על השקפים של אותו קורס שניתן בשנים הקודמות 2 Roadmap Lectures 4 and 5 present two sides of OOP: Lecture 4 discusses the static,
More informationFor this chapter, switch languages in DrRacket to Advanced Student Language.
Chapter 30 Mutation For this chapter, switch languages in DrRacket to Advanced Student Language. 30.1 Remembering changes Suppose you wanted to keep track of a grocery shopping list. You could easily define
More informationParsing Text Input CS 005. This document is aimed at increasing your understanding of parsing text input, as well as informing you of
Parsing Text Input CS 005 Jimmy Ho Computer Science Department October 13, 1998 Brown University This document is aimed at increasing your understanding of parsing text input, as well as informing you
More information05. SINGLETON PATTERN. One of a Kind Objects
BIM492 DESIGN PATTERNS 05. SINGLETON PATTERN One of a Kind Objects Developer: What use is that? Guru: There are many objects we only need one of: thread pools, caches, dialog boxes, objects that handle
More informationTo figure this out we need a more precise understanding of how ML works
Announcements: What are the following numbers: 74/2/70/17 (2:30,2:30,3:35,7:30) PS2 due Thursday 9/20 11:59PM Guest lecture on Tuesday 9/25 o No RDZ office hours next Friday, I am on travel A brief comment
More informationClasses and Methods לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון
Classes and Methods לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון 22 Roadmap Lectures 4 and 5 present two sides of OOP: Lecture 4 discusses the static, compile time representation of object-oriented
More information(Photos and Instructions Based on Microsoft Outlook 2007, Gmail, Yahoo! Mail, and Hotmail)
Specific instructions on how to compose a professional e-mail using send and reply options, basic e-mail components, appropriate wording, content, tone, and examples of what not to do. (Photos and Instructions
More informationA PROGRAM IS A SEQUENCE of instructions that a computer can execute to
A PROGRAM IS A SEQUENCE of instructions that a computer can execute to perform some task. A simple enough idea, but for the computer to make any use of the instructions, they must be written in a form
More informationMITOCW ocw f99-lec07_300k
MITOCW ocw-18.06-f99-lec07_300k OK, here's linear algebra lecture seven. I've been talking about vector spaces and specially the null space of a matrix and the column space of a matrix. What's in those
More informationSkill 1: Multiplying Polynomials
CS103 Spring 2018 Mathematical Prerequisites Although CS103 is primarily a math class, this course does not require any higher math as a prerequisite. The most advanced level of mathematics you'll need
More informationChapter 1 Getting Started
Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different
More informationViolations of the contract are exceptions, and are usually handled by special language constructs. Design by contract
Specification and validation [L&G Ch. 9] Design patterns are a useful way to describe program structure. They provide a guide as to how a program fits together. Another dimension is the responsibilities
More information15-122: Principles of Imperative Computation (Section G)
15-122: Principles of Imperative Computation (Section G) Document 2 Solutions 0. Contracts This lecture was mainly about contracts and ensuring correctness of code. Josh Zimmerman There are 4 types of
More informationChapter Fourteen Bonus Lessons: Algorithms and Efficiency
: Algorithms and Efficiency The following lessons take a deeper look at Chapter 14 topics regarding algorithms, efficiency, and Big O measurements. They can be completed by AP students after Chapter 14.
More informationCIT 590 Homework 10 Battleship
CIT 590 Homework 10 Battleship Purposes of this assignment: To give you more experience with classes and inheritance General Idea of the Assignment Once again, this assignment is based on a game, since
More informationHardware versus software
Logic 1 Hardware versus software 2 In hardware such as chip design or architecture, designs are usually proven to be correct using proof tools In software, a program is very rarely proved correct Why?
More information6.001 Notes: Section 15.1
6.001 Notes: Section 15.1 Slide 15.1.1 Our goal over the next few lectures is to build an interpreter, which in a very basic sense is the ultimate in programming, since doing so will allow us to define
More informationObject-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007
Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007 Java We will be programming in Java in this course. Partly because it is a reasonable language, and partly because you
More informationCSE 331 Software Design & Implementation
CSE 331 Software Design & Implementation Hal Perkins Winter 2018 Module Design and General Style Guidelines UW CSE 331 Winter 2018 1 Style Use the active voice. Omit needless words. Don't patch bad code
More informationCOP 3330 Final Exam Review
COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time
More informationCS112 Lecture: Defining Instantiable Classes
CS112 Lecture: Defining Instantiable Classes Last revised 2/3/05 Objectives: 1. To describe the process of defining an instantiable class 2. To discuss public and private visibility modifiers. Materials:
More informationDenotational semantics
1 Denotational semantics 2 What we're doing today We're looking at how to reason about the effect of a program by mapping it into mathematical objects Specifically, answering the question which function
More informationGuidelines for Writing C Code
Guidelines for Writing C Code Issue 01-bugfix Martin Becker Institute for Real-Time Computer Systems (RCS) Technische Universität München becker@rcs.ei.tum.de June 9, 2014 Contents 1 Introduction 1 2 Pragmatic
More informationIn this example on 20X200, the contrast ratio between the navigation text and its background is 1.57:1.
ACCESSIBLITY COMMON DEVELOPER MISTAKES Web Council Meeting, May 11 th 2011 1. Too Low Contrast The contrast between text and background is a major contributing factor to the readability of a website. This
More informationAlgebraic Specifications
Object-Oriented Design Lecture 2 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 11, 2007 Algebraic Specifications Last time I said a word about the abstraction barrier, separating the clients from the implementors.
More informationHelping the Compiler Help You. Thomas Dy
Helping the Compiler Help You Thomas Dy Programming do { programmer.write_code(); if(lazy) { sleep(); } compile_code(); } while(compiler.has_errors()); Compiler: Me no speaky English Programmer: Compiler,
More informationGoals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1
Natural Semantics Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1 1 Natural deduction is an instance of first-order logic; that is, it is the formal
More informationMITOCW watch?v=flgjisf3l78
MITOCW watch?v=flgjisf3l78 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high-quality educational resources for free. To
More informationThe Way of the Semicolon -or- Three Things I Wish I Had Known Before I Ever Coded One Patricia Hettinger, Oakbrook Terrace, IL
The Way of the Semicolon -or- Three Things I Wish I Had Known Before I Ever Coded One Patricia Hettinger, Oakbrook Terrace, IL ABSTRACT Learning SAS or teaching it to someone else can be very difficult.
More informationTopics. Java arrays. Definition. Data Structures and Information Systems Part 1: Data Structures. Lecture 3: Arrays (1)
Topics Data Structures and Information Systems Part 1: Data Structures Michele Zito Lecture 3: Arrays (1) Data structure definition: arrays. Java arrays creation access Primitive types and reference types
More informationFramework Design Guidelines
Framework Design Guidelines Conventions, Idioms, and Patterns for Reusable.NET Libraries Krzysztof Cwalina Brad Abrams Addison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto
More informationControl Structures. Code can be purely arithmetic assignments. At some point we will need some kind of control or decision making process to occur
Control Structures Code can be purely arithmetic assignments At some point we will need some kind of control or decision making process to occur C uses the if keyword as part of it s control structure
More informationVisual Design. Simplicity, Gestalt Principles, Organization/Structure
Visual Design Simplicity, Gestalt Principles, Organization/Structure Many examples are from Universal Principles of Design, Lidwell, Holden, and Butler Why discuss visual design? You need to present the
More informationthe NXT-G programming environment
2 the NXT-G programming environment This chapter takes a close look at the NXT-G programming environment and presents a few simple programs. The NXT-G programming environment is fairly complex, with lots
More informationWrite for your audience
Comments Write for your audience Program documentation is for programmers, not end users There are two groups of programmers, and they need different kinds of documentation Some programmers need to use
More informationPrelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion
Prelim 1 CS 2110, October 1, 2015, 5:30 PM 0 1 2 3 4 5 Total Question Name True Short Testing Strings Recursion False Answer Max 1 20 36 16 15 12 100 Score Grader The exam is closed book and closed notes.
More informationString Allocation in Icon
String Allocation in Icon Ralph E. Griswold Department of Computer Science The University of Arizona Tucson, Arizona IPD277 May 12, 1996 http://www.cs.arizona.edu/icon/docs/ipd275.html Note: This report
More informationMITOCW watch?v=kz7jjltq9r4
MITOCW watch?v=kz7jjltq9r4 PROFESSOR: We're going to look at the most fundamental of all mathematical data types, namely sets, and let's begin with the definitions. So informally, a set is a collection
More informationYou ve encountered other ways of signalling errors. For example, if you lookup an unbound key in a hashtable, Java (and Scala) produce nulls:
Lecture 5 1 Required Reading Read Chapters 16 and 17 of Programming in Scala. 2 Partial Functions and Signalling Errors Many functions are not defined on all inputs. For example, if you re reading input
More informationCS 351 Design of Large Programs Programming Abstractions
CS 351 Design of Large Programs Programming Abstractions Brooke Chenoweth University of New Mexico Spring 2019 Searching for the Right Abstraction The language we speak relates to the way we think. The
More informationstatic CS106L Spring 2009 Handout #21 May 12, 2009 Introduction
CS106L Spring 2009 Handout #21 May 12, 2009 static Introduction Most of the time, you'll design classes so that any two instances of that class are independent. That is, if you have two objects one and
More informationmk-convert Contents 1 Converting to minikanren, quasimatically. 08 July 2014
mk-convert 08 July 2014 Contents 1 Converting to minikanren, quasimatically. 1 1.1 Variations on a Scheme..................... 2 1.2 Racket to minikanren, nally.................. 8 1.3 Back to the beginning......................
More informationChapter 4 Defining Classes I
Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the
More informationCS 1044 Project 5 Fall 2009
User-defined Functions and Arrays This programming assignment uses many of the ideas presented in topics 3 through 18 of the course notes, so you are advised to read those carefully. Read and follow the
More informationCOMP-202 Unit 4: Programming with Iterations
COMP-202 Unit 4: Programming with Iterations Doing the same thing again and again and again and again and again and again and again and again and again... CONTENTS: While loops Class (static) variables
More information6.170 Laboratory in Software Engineering Java Style Guide. Overview. Descriptive names. Consistent indentation and spacing. Page 1 of 5.
Page 1 of 5 6.170 Laboratory in Software Engineering Java Style Guide Contents: Overview Descriptive names Consistent indentation and spacing Informative comments Commenting code TODO comments 6.170 Javadocs
More informationRapid Software Testing Guide to Making Good Bug Reports
Rapid Software Testing Guide to Making Good Bug Reports By James Bach, Satisfice, Inc. v.1.0 Bug reporting is a very important part of testing. The bug report, whether oral or written, is the single most
More information1 of 5 3/28/2010 8:01 AM Unit Testing Notes Home Class Info Links Lectures Newsgroup Assignmen [Jump to Writing Clear Tests, What about Private Functions?] Testing The typical approach to testing code
More informationThese are notes for the third lecture; if statements and loops.
These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern
More informationThe next several pages summarize some of the best techniques to achieve these three goals.
Writing and Reviewing Documents You are required to write the following documents in this course: 1) A description of your GPS data collection and results. 2) A technical description of a data collection
More informationCSE wi Midterm Exam 2/8/18. Name UW ID #
Name UW ID # There are 11 questions worth a total of 120 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,
More informationFive Considerations for Software Architects
Five Considerations for Software Architects Kevlin Henney kevlin@curbralan.com Economy There's nothing long-winded about "Liberté, égalité, fraternité". Maurice Saatchi Continuing existence or cessation
More informationFinal Examination --- SAMPLE SOLUTIONS May
CS 134 Spring 2010 Final Examination --- SAMPLE SOLUTIONS May 19. 2010 This is a closed book exam. You have 150 minutes to complete the exam. There are 7 questions in total, and the point values for the
More informationSedgewick Specialties
Sedgewick Specialties Our textbook is apparently a follow-up on another CS1083-ish book that uses a lot of simplified libraries, to avoid overwhelming newbies with the standard Java libraries. This book
More informationCS106A Handout 28 Winter February 28, 2014 Second Practice Second CS106A Midterm
CS106A Handout 28 Winter 2013-2014 February 28, 2014 Second Practice Second CS106A Midterm This handout is intended to give you practice solving problems that are comparable in format and difficulty to
More informationPromoting Component Architectures in a Dysfunctional Organization
Promoting Component Architectures in a Dysfunctional Organization by Raj Kesarapalli Product Manager Rational Software When I first began my career as a software developer, I didn't quite understand what
More informationBit level Binaries and Generalized Comprehensions in Erlang. Per Gustafsson and Kostis Sagonas Dept of Information Technology Uppsala University
Bit level Binaries and Generalized Comprehensions in Erlang Per Gustafsson and Kostis Sagonas Dept of Information Technology Uppsala University Binaries as we know them Introduced in 1992 as a container
More informationTopic C. Communicating the Precision of Measured Numbers
Topic C. Communicating the Precision of Measured Numbers C. page 1 of 14 Topic C. Communicating the Precision of Measured Numbers This topic includes Section 1. Reporting measurements Section 2. Rounding
More information