5 ineffective. MANY F# programmers. DON T have. coding habits

Size: px
Start display at page:

Download "5 ineffective. MANY F# programmers. DON T have. coding habits"

Transcription

1 5 ineffective coding habits MANY F# programmers DON T have

2 habit ˈhabɪt/ A settled or regular tendency or practice, especially one that is hard to give up.

3 I m not a great programmer; I m just a good programmer with great habits. - Kent Beck

4 Noisy Code Visual Dishonesty Lego Naming Underabstraction Unencapsulated State Getters and Setters Uncohesive Tests

5 does the language I use make a difference?

6 Programming languages have a devious influence: they shape our thinking habits. - Edsger W. Dijkstra

7 Noisy Code

8

9

10

11 every LOC is a cost

12 more code more chance for bugs

13 more code longer time-to-comprehension

14 more code more engineers

15

16 You should do whatever possible to increase the productivity of individual programmers in terms of the expressive power of the code they write. Less code to do the same thing (and possibly better). Less programmers to hire. Less organizational communication costs.

17 You should do whatever possible to increase the productivity of individual programmers in terms of the expressive power of the code they write. Less code to do the same thing (and possibly better). Less programmers to hire. Less organizational communication costs.

18 does the language I use make a difference?

19

20 source

21 source

22 source

23 source

24 source

25 source

26 source

27 Visual Dishonesty

28 a clean design is one that supports visual thinking so people can meet their informational needs with a minimum of conscious effort. - Daniel Higginbotham (

29 public void MyCleverMethod( int firstarg, string secondarg) signifies hierarchy

30 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 (

31 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 (

32 how we read ENGLISH Whilst talking with an ex-colleague, a question came up on how to implement the Stable Marriage problem using a message passing approach. Naturally, I wanted to answer that question with Erlang! Let s first dissect the problem and decide what processes we need and how they need to interact with one another. The stable marriage problem is commonly stated as: Given n men and n women, where each person has ranked all members of the opposite sex with a unique number between 1 and n in order of preference, marry the men and women together such that there are no two people of opposite sex who would both rather have each other than their current partners. If there are no such people, all the marriages are stable. (It is assumed that the participants are binary gendered and that marriages are not same-sex). From the problem description, we can see that we need: * a module for man * a module for woman * a module for orchestrating the experiment In terms of interaction between the different modules, I imagined something along the lines of see also

33 how we read ENGLISH Whilst talking with an ex-colleague, a question came up on how to implement the Stable Marriage problem using a message passing approach. Naturally, I wanted to answer that question with Erlang! 1.left-to-right Let s first dissect the problem and decide what processes we need and how they need to interact with one another. The stable marriage problem is commonly stated as: Given n men and n women, where each person has ranked all members of the opposite sex with a unique number between 1 and n in order of preference, marry the men and women together such that there are no two people of opposite sex who would both rather have each other than their current partners. If there are no such people, all the marriages are stable. (It is assumed that the participants are binary gendered and that marriages are not same-sex). From the problem description, we can see that we need: * a module for man * a module for woman * a module for orchestrating the experiment In terms of interaction between the different modules, I imagined something along the lines of 2. top-to-bottom see also

34 how we read CODE public void DoSomething(int x, int y) { Foo(y, Bar(x, Zoo(Monkey()))); } see also

35 how we read CODE public void DoSomething(int x, int y) { } 2. bottom-to-top Foo(y, Bar(x, Zoo(Monkey()))); 1.right-to-left see also

36 Whilst talking with an ex-colleague, a question came up on how to implement the Stable Marriage problem using a message passing 1.left-to-right approach. Naturally, I wanted to answer that question with Erlang! Let s first dissect the problem and decide what processes we need and how they need to interact with one another. 2. top-to-bottom The stable marriage problem is commonly stated as: Given n men and n women, where each person has ranked all members of the opposite sex with a unique number between 1 and n in order of preference, marry the men and women together such that there are no two people of opposite sex who would both rather have each other than their current partners. If there are no such people, all the marriages are stable. (It is assumed that the participants are binary gendered and that marriages are not same-sex). From the problem description, we can see that we need: * a module for man * a module for woman * a module for orchestrating the experiment In terms of interaction between the different modules, I imagined something along the lines of how we read ENGLISH 2. top-to-bottom how we read CODE public void DoSomething(int x, int y) { Foo(y, Bar(x, Zoo(Monkey()))); } 1.right-to-left see also

37 > see also

38 how we read CODE let drawcircle x y radius = circle radius > filled (rgb ) > alpha 0.5 > move (x, y) see also

39 how we read CODE 1.left-to-right let drawcircle x y radius = circle radius > filled (rgb ) > alpha 0.5 > move (x, y) 2. top-to-bottom see also

40 {}

41 public ResultType MyCleverMethod( int firstarg, string secondarg, string thirdarg) { var localvar = AnotherCleverMethod(firstArg, secondarg); if (localvar.issomething( thirdarg, MY_CONSTANT)) { DoSomething(localVar); } return localvar.getsomething(); }

42 XXXXXX XXXXXXXXXX XXXXXXXXXXXXXX XXX XXXXXXXX XXXXXX XXXXXXXXX XXXXXX XXXXXXXX XXX XXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXX XXXXXXXXX XX XXXXXXXX XXXXXXXXXXX XXXXXXXX XXXXXXXXXX XXXXXXXXXXX XXXXXXXX XXXXXX XXXXXXXX XXXXXXXXXXXX

43 public ResultType MyCleverMethod( int firstarg, string secondarg, string thirdarg) { var localvar = AnotherCleverMethod(firstArg, secondarg); if (localvar.issomething( thirdarg, MY_CONSTANT)) { DoSomething(localVar); } return localvar.getsomething(); }

44 public ResultType MyCleverMethod( int firstarg, string secondarg, string thirdarg) { var localvar = AnotherCleverMethod(firstArg, secondarg); if (localvar.issomething( thirdarg, MY_CONSTANT)) { DoSomething(localVar); } return localvar.getsomething(); }

45 XXXXXX XXXXXXXXXX XXXXXXXXXXXXXX XXX XXXXXXXX XXXXXX XXXXXXXXX XXXXXX XXXXXXXX XXX XXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXX XXXXXXXXX XX XXXXXXXX XXXXXXXXXXX XXXXXXXX XXXXXXXXXX XXXXXXXXXXX XXXXXXXX XXXXXX XXXXXXXX XXXXXXXXXXXX

46 It turns out that style matters in programming for the same reason that it matters in writing. It makes for better reading. - Douglas Crockford

47 two competing rules for structuring code in C-style languages

48 Compiler Human { } { } + whitespace

49 what if?

50 Compiler Human whitespace whitespace

51 xxx { } xxx { } no braces no problem

52 There should be one - and preferably only one - obvious way to do it. - the Zen of Python

53 let mycleverfunction x y z = let localvar = anothercleverfunction x y if localvar.issomething(z, MY_CONSTANT) then dosomething localvar localvar.getsomething()

54 XXX XXXXXXXXXXXXXXXX X X X XXX XXXXXXXX XXXXXXXXXXXXXXXXXXXX X X XX XXXXXXXX XXXXXXXXXXX X XXXXXXXXXX XXXX XXXXXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXXXXXX

55 You should do whatever possible to increase the productivity of individual programmers in terms of the expressive power of the code they write. Less code to do the same thing (and possibly better). Less programmers to hire. Less organizational communication costs.

56 Lego Naming

57 naming is HARD

58 There are only two hard things in Computer Science: cache invalidation and naming things. - Phil Karlton

59 Names are the one and only tool you have to explain what a variable does in every place it appears, without having to scatter comments everywhere. - Mike Mahemoff

60 Lego Naming Gluing common words together in an attempt to create meaning.

61 Remove Strategy Controller Proxy Factory Object Exception Do Check Enable Create Service Process Add Disable Set Update Get Validate

62 see

63 this is not naming

64 this is not naming this is labelling

65

66

67

68 naming is HARD

69 anonymous functions aka lambdas

70 fewer things to name

71 words > Array.map (fun x -> x.count) > Array.reduce (+)

72 smaller scope shorter names

73

74 "The length of a name should be related to the length of the scope. You can use very short variable names for tiny scopes, but for big scopes you should use longer names. Variable names like i and j are just fine if their scope is five lines long." - Robert C. Martin

75 tuples + pattern matching fewer abstractions fewer things to name

76 words > Seq.groupBy id > Seq.map (fun (word, gr) -> word, Seq.length gr) > Seq.iter (fun (word, len) -> printfn %s - %d word len)

77 words > Seq.groupBy id > Seq.map (fun (word, gr) -> word, Seq.length gr) > Seq.iter (fun (word, len) -> printfn %s - %d word len)

78 words > Seq.groupBy id > Seq.map (fun (word, gr) -> word, Seq.length gr) > Seq.iter (fun (word, len) -> printfn %s - %d word len)

79 words > Seq.groupBy id > Seq.map (fun (word, gr) -> word, Seq.length gr) > Seq.iter (fun (word, len) -> printfn %s - %d word len)

80 Lego Naming can also be the symptom of a failure to identify the right level of abstractions.

81 the RIGHT level of abstraction might be smaller than object

82 public interface ConditionChecker { bool CheckCondition(); }

83 public interface Condition { bool IsTrue(); }

84

85 type Condition = unit -> bool

86 source

87 ClassNotFoundException IllegalArgumentException IndexOutOfBoundsException NoSuchMethodException UnsupportedOperationException

88 ClassNotFound IllegalArgument IndexOutOfBounds NoSuchMethod UnsupportedOperation

89 ArithmeticException ArrayStoreException ClassCastException InstantiationException NullPointerException SecurityException

90 IntegerDivisionByZero IllegalArrayElementType CastToNonSubclass ClassCannotBeInstantiated NullDereferenced SecurityViolation

91 lightweight exception syntax

92 open System open System.IO exception InsufficientBytes

93 open System open System.IO exception InsufficientBytes what could this type represent?

94 Underabstraction

95

96

97 public Result DoSomething( int a, string b, string c, string d, DateTime e, DateTime f, string g, MyEnum h)

98 If you have a procedure with ten parameters, you probably missed some. - Alan Perlis

99 source

100 lightweight syntax for types and hierarchies

101 record

102 type Employee = { FirstName : string Surname : string Salary : int<pound> }

103 type Employee = { FirstName : string Surname : string Salary : int<pound> } immutable by default

104 let promote emp raise = let newsalary = emp.salary + raise { emp with Salary <- newsalary }

105 mutable state complects value and time

106 type Employee = { FirstName : string Surname : string Salary : int<pound> } unit-of-measure

107 [<Measure>] type Pound e.g. 42<Pound> 153<Pound>

108 10<Meter> / 2<Second> = 5<Meter/Second> 10<Meter> * 2<Second> = 20<Meter Second> 10<Meter> + 10<Meter> = 20<Meter> 10<Meter> * 10 = 100<Meter> 10<Meter> * 10<Meter> = 100<Meter 2 > 10<Meter> + 2<Second> // error 10<Meter> + 2 // error

109 10<Meter> / 2<Second> = 5<Meter/Second> 10<Meter> * 2<Second> = 20<Meter Second> 10<Meter> + 10<Meter> = 20<Meter> 10<Meter> * 10 = 100<Meter> 10<Meter> * 10<Meter> = 100<Meter 2 > 10<Meter> + 2<Second> // error 10<Meter> + 2 // error

110 discriminated unions

111 type PaymentMethod = Cash Cheque of ChequeNumber Card of CardType * CardNumber

112 Unencapsulated State

113

114

115 public class RecentlyUsedList { private List<string> items = new List<string>(); public List<string> Items { get { return items; } } }

116 immutability

117 type RecentlyUsedList (?items) = let items = defaultarg items [ ] member this.items = Array.ofList items member this.count = List.length items member this.add newitem = newitem::(items > List.filter ((<>) newitem)) > RecentlyUsedList

118 Affordance an affordance is a quality of an object, or an environment, which allows an individual to perform an action. For example, a knob affords twisting, and perhaps pushing, whilst a cord affords pulling.

119 source

120 your abstractions should afford right behaviour, whilst make it impossible to do the wrong thing

121 Make illegal states unrepresentable - Yaron Minsky

122 discriminated unions

123 type PaymentMethod = Cash Cheque of ChequeNumber Card of CardType * CardNumber finite, closed set of valid states ONLY

124 closed hierarchy

125 no Nulls

126 match paymentmethod with Cash -> Cheque chequenum -> Card (cardtype, cardnum) ->

127 Noisy Code Visual Dishonesty Lego Naming Underabstraction Unencapsulated State Getters and Setters Uncohesive Tests

128 Practice does not make perfect. Only perfect practice makes perfect. - Vince Lombardi

129 Perfection is not attainable. But if we chase perfection, we can catch excellence. - Vince Lombardi

130 Programming languages have a devious influence: they shape our thinking habits. - Edsger W. Dijkstra

131 One of the most disastrous thing we can learn is the first programming language, even if it's a good programming language. - Alan Kay

132 I m not a great programmer; I m just a good programmer with great habits. - Kent Beck

133 Explicit is better than implicit. - the Zen of Python

134 Simple is better than Complex. Complex is better than Complicated. - the Zen of Python

135 Special cases aren't special enough to break the rules. - the Zen of Python

136 Special cases aren't special enough to break the rules. Although practicality beats purity. - the Zen of Python

137 If the implementation is hard to explain, it's a bad idea. - the Zen of Python

138

139 Thu 12 October :30 21:30 BST Space Ape Games 100 New Oxford Street London WC1A 1HB

140 @theburningmonk theburningmonk.com github.com/theburningmonk

Seven Ineffective Coding Habits of Many

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 information

Seven Ineffective Coding Habits of Many

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. Noisy Code

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

CSE 143. More ArrayIntList; pre/post; exceptions; debugging. Computer Programming II. CSE 143: Computer Programming II

CSE 143. More ArrayIntList; pre/post; exceptions; debugging. Computer Programming II. CSE 143: Computer Programming II Adam Blank Lecture 3 Autumn 201 CSE 143 CSE 143: Computer Programming II More ArrayIntList; pre/post; exceptions; debugging Computer Programming II Drawings 1 Drawings 2 Drawings 3 Drawings 4 Drawings

More information

Adam Blank Lecture 3 Autumn 2016 CSE 143. Computer Programming II

Adam Blank Lecture 3 Autumn 2016 CSE 143. Computer Programming II Adam Blank Lecture 3 Autumn 2016 CSE 143 Computer Programming II CSE 143: Computer Programming II More ArrayIntList; pre/post; exceptions; debugging Drawings 1 Drawings 2 Drawings 3 Drawings 4 Drawings

More information

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong:

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong: Exception Handling Run-time errors The exception concept Throwing exceptions Handling exceptions Declaring exceptions Creating your own exception Ariel Shamir 1 Run-time Errors Sometimes when the computer

More information

AIMS Embedded Systems Programming MT 2017

AIMS Embedded Systems Programming MT 2017 AIMS Embedded Systems Programming MT 2017 Object-Oriented Programming with C++ Daniel Kroening University of Oxford, Computer Science Department Version 1.0, 2014 Outline Classes and Objects Constructors

More information

Exception Handling. Run-time Errors. Methods Failure. Sometimes when the computer tries to execute a statement something goes wrong:

Exception Handling. Run-time Errors. Methods Failure. Sometimes when the computer tries to execute a statement something goes wrong: Exception Handling Run-time errors The exception concept Throwing exceptions Handling exceptions Declaring exceptions Creating your own exception 22 November 2007 Ariel Shamir 1 Run-time Errors Sometimes

More information

Packaging and labelling

Packaging and labelling QRDvet template, opportunities for reduced label text and multi-lingual labels, recent examples EMA/IFAH-Europe Info Day 2014 Presented by: Jóhann M. Lenharðsson CVMP member (IS) An agency of the European

More information

Designing Robust Classes

Designing Robust Classes Designing Robust Classes Learning Goals You must be able to:! specify a robust data abstraction! implement a robust class! design robust software! use Java exceptions Specifications and Implementations

More information

Upcoming Features in C# Mads Torgersen, MSFT

Upcoming 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 information

Chapter 2 - Control Structures

Chapter 2 - Control Structures Chapter 2 - Control Structures 1 Outline 2.1 Introduction 2.2 Algorithms 2.3 Pseudocode 2.4 Control Structures 2.5 if Selection Structure 2.6 if/else Selection Structure 2.7 while Repetition Structure

More information

Bit 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 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 information

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures Dan Grossman Fall 2014 Hi! I m not Hal J I love this stuff and have taught

More information

Working with Objects. Overview. This chapter covers. ! Overview! Properties and Fields! Initialization! Constructors! Assignment

Working with Objects. Overview. This chapter covers. ! Overview! Properties and Fields! Initialization! Constructors! Assignment 4 Working with Objects 41 This chapter covers! Overview! Properties and Fields! Initialization! Constructors! Assignment Overview When you look around yourself, in your office; your city; or even the world,

More information

CS 142 Style Guide Grading and Details

CS 142 Style Guide Grading and Details CS 142 Style Guide Grading and Details In the English language, there are many different ways to convey a message or idea: some ways are acceptable, whereas others are not. Similarly, there are acceptable

More information

Type Conversion. and. Statements

Type Conversion. and. Statements and Statements Type conversion changing a value from one type to another Void Integral Floating Point Derived Boolean Character Integer Real Imaginary Complex no fractional part fractional part 2 tj Suppose

More information

CIS192: Python Programming

CIS192: Python Programming CIS192: Python Programming Introduction Harry Smith University of Pennsylvania January 18, 2017 Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 1 / 34 Outline 1 Logistics Rooms

More information

MATH 104B OCTAL, BINARY, AND HEXADECIMALS NUMBERS

MATH 104B OCTAL, BINARY, AND HEXADECIMALS NUMBERS MATH 104B OCTAL, BINARY, AND HEXADECIMALS NUMBERS A: Review: Decimal or Base Ten Numbers When we see a number like 2,578 we know the 2 counts for more than the 7, even though 7 is a larger number than

More information

Unit 5: More on Classes/Objects Notes

Unit 5: More on Classes/Objects Notes Unit 5: More on Classes/Objects Notes AP CS A The Difference between Primitive and Object/Reference Data Types First, remember the definition of a variable. A variable is a. So, an obvious question is:

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Writing usable APIs in practice. ACCU 2012 Conference, Oxford, UK Giovanni

Writing usable APIs in practice. ACCU 2012 Conference, Oxford, UK Giovanni Writing usable APIs in practice ACCU 2012 Conference, Oxford, UK Giovanni Asproni gasproni@asprotunity.com @gasproni 1 Summary API definition Two assumptions Why bother with usability Some techniques to

More information

Module 10: Imperative Programming, Modularization, and The Future

Module 10: Imperative Programming, Modularization, and The Future Module 10: Imperative Programming, Modularization, and The Future If you have not already, make sure you Read How to Design Programs Sections 18. 1 CS 115 Module 10: Imperative Programming, Modularization,

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

Topics Covered Thus Far CMSC 330: Organization of Programming Languages

Topics Covered Thus Far CMSC 330: Organization of Programming Languages Topics Covered Thus Far CMSC 330: Organization of Programming Languages Names & Binding, Type Systems Programming languages Ruby Ocaml Lambda calculus Syntax specification Regular expressions Context free

More information

Introduction to Programming Style

Introduction to Programming Style Introduction to Programming Style Thaddeus Aid The IT Learning Programme The University of Oxford, UK 30 July, 2013 Abstract Programming style is the part of the program that the human reads and the compiler

More information

CS 11 Haskell track: lecture 1

CS 11 Haskell track: lecture 1 CS 11 Haskell track: lecture 1 This week: Introduction/motivation/pep talk Basics of Haskell Prerequisite Knowledge of basic functional programming e.g. Scheme, Ocaml, Erlang CS 1, CS 4 "permission of

More information

Comp 11 Lectures. Mike Shah. June 26, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57

Comp 11 Lectures. Mike Shah. June 26, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57 Comp 11 Lectures Mike Shah Tufts University June 26, 2017 Mike Shah (Tufts University) Comp 11 Lectures June 26, 2017 1 / 57 Please do not distribute or host these slides without prior permission. Mike

More information

Google Hangout is a great platform for collaborating with colleagues and partners. This TechsmARTs session will begin with a few examples/case

Google Hangout is a great platform for collaborating with colleagues and partners. This TechsmARTs session will begin with a few examples/case Google Hangout is a great platform for collaborating with colleagues and partners. This TechsmARTs session will begin with a few examples/case studies of how artists and arts and culture organizations

More information

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Closures Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming t ::= x x. t t t Call-by-value big-step Operational Semantics terms variable v ::= values abstraction x.

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

SD314 Outils pour le Big Data

SD314 Outils pour le Big Data Institut Supérieur de l Aéronautique et de l Espace SD314 Outils pour le Big Data Functional programming in Python Christophe Garion DISC ISAE Christophe Garion SD314 Outils pour le Big Data 1/ 35 License

More information

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Closures Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Summary 1. Predictive Parsing 2. Large Step Operational Semantics (Natural) 3. Small Step Operational Semantics

More information

Basic Object-Oriented Concepts. 5-Oct-17

Basic Object-Oriented Concepts. 5-Oct-17 Basic Object-Oriented Concepts 5-Oct-17 Concept: An object has behaviors In old style programming, you had: data, which was completely passive functions, which could manipulate any data An object contains

More information

CSE 143. Programming is... Principles of Programming and Software Engineering. The Software Lifecycle. Software Lifecycle in HW

CSE 143. Programming is... Principles of Programming and Software Engineering. The Software Lifecycle. Software Lifecycle in HW Principles of Programming and Software Engineering Textbook: hapter 1 ++ Programming Style Guide on the web) Programming is......just the beginning! Building good software is hard Why? And what does "good"

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques () Lecture 12 February 7, 2018 Partiality, Sequencing, Records Chapters 12, 13 Midterm 1 This Friday in class Review session Tonight, 6 7:30 PM DRLB A1 Announcements

More information

CS 220: Introduction to Parallel Computing. Arrays. Lecture 4

CS 220: Introduction to Parallel Computing. Arrays. Lecture 4 CS 220: Introduction to Parallel Computing Arrays Lecture 4 Note: Windows I updated the VM image on the website It now includes: Sublime text Gitkraken (a nice git GUI) And the git command line tools 1/30/18

More information

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 2 Date:

More information

CS 3 Introduction to Software Engineering. 3: Exceptions

CS 3 Introduction to Software Engineering. 3: Exceptions CS 3 Introduction to Software Engineering 3: Exceptions Questions? 2 Objectives Last Time: Procedural Abstraction This Time: Procedural Abstraction II Focus on Exceptions. Starting Next Time: Data Abstraction

More information

OCaml Data CMSC 330: Organization of Programming Languages. User Defined Types. Variation: Shapes in Java

OCaml Data CMSC 330: Organization of Programming Languages. User Defined Types. Variation: Shapes in Java OCaml Data : Organization of Programming Languages OCaml 4 Data Types & Modules So far, we ve seen the following kinds of data Basic types (int, float, char, string) Lists Ø One kind of data structure

More information

QUIZ. What is wrong with this code that uses default arguments?

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

Exceptions. CSC207 Winter 2017

Exceptions. CSC207 Winter 2017 Exceptions CSC207 Winter 2017 What are exceptions? In Java, an exception is an object. Exceptions represent exceptional conditions: unusual, strange, disturbing. These conditions deserve exceptional treatment:

More information

Kurt Schmidt. November 13, 2017

Kurt Schmidt. November 13, 2017 ,, Dept. of Computer Science, Drexel University November 13, 2017 These notes are intended for students familiar with C++ Originally from Bruce Char & Vera Zaychik , Java is Object-Oriented, in Java is

More information

CS108, Stanford Handout #3. HW1 CodeCamp

CS108, Stanford Handout #3. HW1 CodeCamp CS108, Stanford Handout #3 Fall, 2008-09 Osvaldo Jiménez HW1 CodeCamp Thanks to Nick Parlante for much of this handout For this first homework, you will run through a series of small coding problems to

More information

CIS 45, The Introduction. What is a database? What is data? What is information?

CIS 45, The Introduction. What is a database? What is data? What is information? CIS 45, The Introduction I have traveled the length and breadth of this country and talked with the best people, and I can assure you that data processing is a fad that won t last out the year. The editor

More information

CHAPTER ONE. The Writing Process COPYRIGHTED MATERIAL

CHAPTER ONE. The Writing Process COPYRIGHTED MATERIAL CHAPTER ONE The Writing Process Successful communication is three-tiered: visual, verbal, and written. All firms, but particularly design firms, give considerable thought to the visual image and design

More information

Data Structure and Programming Languages

Data Structure and Programming Languages 204700 Data Structure and Programming Languages Jakarin Chawachat From: http://ocw.mit.edu/courses/electrical-engineering-and-computerscience/6-092-introduction-to-programming-in-java-january-iap-2010/index.htm

More information

LECTURE 1. Getting Started with Python

LECTURE 1. Getting Started with Python LECTURE 1 Getting Started with Python ABOUT PYTHON Development started in the 1980 s by Guido van Rossum. Only became popular in the last decade or so. Python 2.x currently dominates, but Python 3.x is

More information

Discrete Mathematics and Probability Theory Summer 2016 Dinh, Psomas, and Ye HW 2

Discrete Mathematics and Probability Theory Summer 2016 Dinh, Psomas, and Ye HW 2 CS 70 Discrete Mathematics and Probability Theory Summer 2016 Dinh, Psomas, and Ye HW 2 Due Tuesday July 5 at 1:59PM 1. (8 points: 3/5) Hit or miss For each of the claims and proofs below, state whether

More information

The Three Rules. Program. What is a Computer Program? 5/30/2018. Interpreted. Your First Program QuickStart 1. Chapter 1

The 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 information

What s different about Factor?

What s different about Factor? Harshal Lehri What s different about Factor? Factor is a concatenative programming language - A program can be viewed as a series of functions applied on data Factor is a stack oriented program - Data

More information

AP Computer Science A: Java Programming

AP Computer Science A: Java Programming AP Computer Science A: Java Programming Zheng-Liang Lu Department of Computer Science & Information Engineering National Taiwan University APcomSci 297 Spring 2018 Class Information Instructor: Zheng-Liang

More information

MPLAB X Debugging Techniques

MPLAB X Debugging Techniques TLS0102-001 MPLAB X Debugging Techniques The Debugging Process Author: Rob Ostapiuk, Stu Chandler Microchip Technology Objectives! Describe a generic process for debugging a program! Describe at a high

More information

COMP200 EXCEPTIONS. OOP using Java, based on slides by Shayan Javed

COMP200 EXCEPTIONS. OOP using Java, based on slides by Shayan Javed 1 1 COMP200 EXCEPTIONS OOP using Java, based on slides by Shayan Javed Exception Handling 2 3 Errors Syntax Errors Logic Errors Runtime Errors 4 Syntax Errors Arise because language rules weren t followed.

More information

Topic 7: Algebraic Data Types

Topic 7: Algebraic Data Types Topic 7: Algebraic Data Types 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 5.5, 5.7, 5.8, 5.10, 5.11, 5.12, 5.14 14.4, 14.5, 14.6 14.9, 14.11,

More information

It is written in plain language: no jargon, nor formality. Information gets across faster when it s written in words that our users actually use.

It is written in plain language: no jargon, nor formality. Information gets across faster when it s written in words that our users actually use. Web Style Guide A style guide for use for writing on Tufts Library Websites and LibGuides. Contents: 1. Web style guides for online content 2. LibGuides 2-specific style guide 3. Tisch s website-specific

More information

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5 C++ Data Types Contents 1 Simple C++ Data Types 2 2 Quick Note About Representations 3 3 Numeric Types 4 3.1 Integers (whole numbers)............................................ 4 3.2 Decimal Numbers.................................................

More information

CSE 331 Midterm Exam Sample Solution 2/18/15

CSE 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 information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing

More information

About Me Sushant Bhatia, From India/Malawi, Work at Citation Technologies Inc, an Environmental Health & Safety company with Compliance

About Me Sushant Bhatia, From India/Malawi, Work at Citation Technologies Inc, an Environmental Health & Safety company with Compliance About Me Sushant Bhatia, From India/Malawi, Work at Citation Technologies Inc, an Environmental Health & Safety company with Compliance Why I chose to do this talk No one else was doing functional programming.

More information

Types, Values, Variables & Assignment. EECS 211 Winter 2018

Types, Values, Variables & Assignment. EECS 211 Winter 2018 Types, Values, Variables & Assignment EECS 211 Winter 2018 2 Road map Strings and string I/O Integers and integer I/O Types and objects * Type safety * Not as in object orientation we ll get to that much

More information

Exceptions. What exceptional things might our programs run in to?

Exceptions. What exceptional things might our programs run in to? Exceptions What exceptional things might our programs run in to? Exceptions do occur Whenever we deal with programs, we deal with computers and users. Whenever we deal with computers, we know things don

More information

Reasoning About Imperative Programs. COS 441 Slides 10

Reasoning About Imperative Programs. COS 441 Slides 10 Reasoning About Imperative Programs COS 441 Slides 10 The last few weeks Agenda reasoning about functional programming It s very simple and very uniform: substitution of equal expressions for equal expressions

More information

CSCI 261 Computer Science II

CSCI 261 Computer Science II CSCI 261 Computer Science II Department of Mathematics and Computer Science Lecture 2 Exception Handling New Topic: Exceptions in Java You should now be familiar with: Advanced object-oriented design -

More information

1 Decorators. 2 Descriptors. 3 Static Variables. 4 Anonymous Classes. Sandeep Sadanandan (TU, Munich) Python For Fine Programmers July 13, / 19

1 Decorators. 2 Descriptors. 3 Static Variables. 4 Anonymous Classes. Sandeep Sadanandan (TU, Munich) Python For Fine Programmers July 13, / 19 1 Decorators 2 Descriptors 3 Static Variables 4 Anonymous Classes Sandeep Sadanandan (TU, Munich) Python For Fine Programmers July 13, 2009 1 / 19 Decorator Pattern In object-oriented programming, the

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 04: Exception Handling MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Creating Classes 2 Introduction Exception Handling Common Exceptions Exceptions with Methods Assertions and

More information

Try and Error. Python debugging and beautification

Try and Error. Python debugging and beautification Try and Error Python debugging and beautification What happens when something goes wrong Catching exceptions In order to handle errors, you can set up exception handling blocks in your code. The keywords

More information

Visual Programming. Lecture 3: Loops, Arrays. Mahmoud El-Gayyar

Visual Programming. Lecture 3: Loops, Arrays. Mahmoud El-Gayyar Visual Programming Lecture 3: Loops, Arrays Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Frequent issues / Review Good Programming Style Loops Arrays Outline Combining Loops and Arrays 2 Frequent issues /

More information

Index COPYRIGHTED MATERIAL

Index COPYRIGHTED MATERIAL Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes

More information

Software Engineering Testing and Debugging Testing

Software Engineering Testing and Debugging Testing Software Engineering Testing and Debugging Testing Prof. Dr. Peter Thiemann Universitt Freiburg 08.06.2011 Recap Testing detect the presence of bugs by observing failures Debugging find the bug causing

More information

Mutable Data Types. Prof. Clarkson Fall A New Despair Mutability Strikes Back Return of Imperative Programming

Mutable Data Types. Prof. Clarkson Fall A New Despair Mutability Strikes Back Return of Imperative Programming Mutable Data Types A New Despair Mutability Strikes Back Return of Imperative Programming Prof. Clarkson Fall 2017 Today s music: The Imperial March from the soundtrack to Star Wars, Episode V: The Empire

More information

Refactoring Without Ropes

Refactoring Without Ropes Refactoring Without Ropes Roger Orr OR/2 Limited The term 'refactoring' has become popular in recent years; but how do we do it safely in actual practice? Refactoring... Improving the design of existing

More information

Test Driven Development. Software Engineering, DVGC18 Faculty of Economic Sciences, Communication and IT Tobias Pulls and Eivind Nordby

Test Driven Development. Software Engineering, DVGC18 Faculty of Economic Sciences, Communication and IT Tobias Pulls and Eivind Nordby Test Driven Development Faculty of Economic Sciences, Communication and IT 2010-09-03 Tobias Pulls and Principle Use Executable Specifications Test Driven Development (TDD) xunit Behaviour Driven Development

More information

Have the students look at the editor on their computers. Refer to overhead projector as necessary.

Have the students look at the editor on their computers. Refer to overhead projector as necessary. Intro to Programming (Time 15 minutes) Open the programming tool of your choice: If you ve installed, DrRacket, double-click the application to launch it. If you are using the online-tool, click here to

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques () Lecture 20 February 28, 2018 Transition to Java Announcements HW05: GUI programming Due: THURSDAY!! at 11:59:59pm Lots of TA office hours today Thursday See Piazza

More information

Assignment #1 Simple C++

Assignment #1 Simple C++ Eric Roberts Handout #5 CS 106B January 7, 2015 Assignment #1 Simple C++ Due: Friday, January 16 Part 1. Get Qt Creator working Parts of this handout were written by Julie Zelenski. Your first task is

More information

Lecture 12: Abstraction Functions

Lecture 12: Abstraction Functions Lecture 12: Abstraction Functions 12.1 Context What you ll learn: How to read, write, and use abstraction functions to describe the relationship between the abstract values of a type and its representation.

More information

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information

CSE 131 Introduction to Computer Science Fall Exam II

CSE 131 Introduction to Computer Science Fall Exam II CSE 131 Introduction to Computer Science Fall 2017 Given: 9 November 2017 Exam II Due: End of session This exam is closed-book, closed-notes, no electronic devices allowed. The exception is the sage page

More information

Classes and Methods לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Classes 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

Program Planning, Data Comparisons, Strings

Program Planning, Data Comparisons, Strings Program Planning, Data Comparisons, Strings Program Planning Data Comparisons Strings Reading for this class: Dawson, Chapter 3 (p. 80 to end) and 4 Program Planning When you write your first programs,

More information

CSC207H: Software Design. Exceptions. CSC207 Winter 2018

CSC207H: Software Design. Exceptions. CSC207 Winter 2018 Exceptions CSC207 Winter 2018 1 What are exceptions? Exceptions represent exceptional conditions: unusual, strange, disturbing. These conditions deserve exceptional treatment: not the usual go-tothe-next-step,

More information

Comments are almost like C++

Comments are almost like C++ UMBC CMSC 331 Java Comments are almost like C++ The javadoc program generates HTML API documentation from the javadoc style comments in your code. /* This kind of comment can span multiple lines */ //

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Introduction to Object-Oriented Programming Objects and classes Abstract Data Types (ADT). Encapsulation OOP: Introduction 1 Pure Object-Oriented Languages Five rules [Source: Alan Kay]: Everything in

More information

Section we will not cover section 2.11 feel free to read it on your own

Section we will not cover section 2.11 feel free to read it on your own Operators Class 5 Section 2.11 we will not cover section 2.11 feel free to read it on your own Data Types Data Type A data type is a set of values and a set of operations defined on those values. in class

More information

BBM 102 Introduction to Programming II Spring Exceptions

BBM 102 Introduction to Programming II Spring Exceptions BBM 102 Introduction to Programming II Spring 2018 Exceptions 1 Today What is an exception? What is exception handling? Keywords of exception handling try catch finally Throwing exceptions throw Custom

More information

Recursion Examples. Factorial Recursive: Factorial Iterative: #include <iostream> using namespace std; long fact(long n) { if (n == 1) return 1;

Recursion Examples. Factorial Recursive: Factorial Iterative: #include <iostream> using namespace std; long fact(long n) { if (n == 1) return 1; Recursion Examples Factorial Recursive: long fact(long n) if (n == 1) return 1; return n*fact(n-1); int main() long n; cout > n; cout

More information

Programming Languages. Streams Wrapup, Memoization, Type Systems, and Some Monty Python

Programming Languages. Streams Wrapup, Memoization, Type Systems, and Some Monty Python Programming Languages Streams Wrapup, Memoization, Type Systems, and Some Monty Python Quick Review of Constructing Streams Usually two ways to construct a stream. Method 1: Use a function that takes a(n)

More information

CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L

CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L 2 0 1 5 Introduction Now we ll talk about ways of thinking about design Guidelines for trials in trial and errors Major Design Heuristics

More information

APS105. Modularity. C pre-defined functions 11/5/2013. Functions. Functions (and Pointers) main. Modularity. Math functions. Benefits of modularity:

APS105. Modularity. C pre-defined functions 11/5/2013. Functions. Functions (and Pointers) main. Modularity. Math functions. Benefits of modularity: APS105 Functions (and Pointers) Functions Tetbook Chapter5 1 2 Modularity Modularity Break a program into manageable parts (modules) Modules interoperate with each other Benefits of modularity: Divide-and-conquer:

More information

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

More information

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018 CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018 Typical workflow concrete syntax (string) "(fn x => x + x) 4" Parsing Possible errors / warnings

More information

CS/ENGRD 2110 SPRING 2018

CS/ENGRD 2110 SPRING 2018 CS/ENGRD 2110 SPRING 2018 Lecture 7: Interfaces and http://courses.cs.cornell.edu/cs2110 1 2 St Valentine s Day! It's Valentines Day, and so fine! Good wishes to you I consign.* But since you're my students,

More information

CSE 142/143 Unofficial Commenting Guide Eric Arendt, Alyssa Harding, Melissa Winstanley

CSE 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 information

CS 360: Programming Languages Lecture 12: More Haskell

CS 360: Programming Languages Lecture 12: More Haskell CS 360: Programming Languages Lecture 12: More Haskell Geoffrey Mainland Drexel University Adapted from Brent Yorgey s course Introduction to Haskell. Section 1 Administrivia Administrivia Homework 5 due

More information

Programming Lecture 3

Programming Lecture 3 Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

More information

For this chapter, switch languages in DrRacket to Advanced Student Language.

For 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 information

Lecture 21: The Many Hats of Scala: OOP 10:00 AM, Mar 14, 2018

Lecture 21: The Many Hats of Scala: OOP 10:00 AM, Mar 14, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 21: The Many Hats of Scala: OOP 10:00 AM, Mar 14, 2018 Contents 1 Mutation in the Doghouse 1 1.1 Aside: Access Modifiers..................................

More information

Introduction. Exceptions: An OO Way for Handling Errors. Common Runtime Errors. Error Handling. Without Error Handling Example 1

Introduction. Exceptions: An OO Way for Handling Errors. Common Runtime Errors. Error Handling. Without Error Handling Example 1 Exceptions: An OO Way for Handling Errors Introduction Rarely does a program runs successfully at its very first attempt. It is common to make mistakes while developing as well as typing a program. Such

More information

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Writing a Simple Java Program Intro to Variables Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch

More information