At BuildStuff'14, Kevlin Henney presented an excellent talk titled "Seven ineffective coding habits of many programmers". As an attendee that day and someone who has exhibited many of these habits over the years, I came to realize that using F# has cured me of many of these ineffective habits! In this talk I'll share my thoughts on how the use of F# and functional programming techniques can help form and nurture good habits and give you the perfect practice you need to make perfect.
17. @theburningmonk
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. @theburningmonk
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.
35. “…a clean design is one that
supports visual thinking so
people can meet their
informational needs with a
minimum of conscious effort.”
- Daniel Higginbotham (www.visualmess.com)
37. “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 (www.visualmess.com)
38. “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 (www.visualmess.com)
39. @theburningmonk
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…
how we read ENGLISH
see also http://bit.ly/1KN8cd0
40. @theburningmonk
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…
2.top-to-bottom
1.left-to-right
how we read ENGLISH
see also http://bit.ly/1KN8cd0
41. @theburningmonk
how we read CODE
public void DoSomething(int x, int y)
{
Foo(y,
Bar(x,
Zoo(Monkey())));
}
see also http://bit.ly/1KN8cd0
42. @theburningmonk
how we read CODE
public void DoSomething(int x, int y)
{
Foo(y,
Bar(x,
Zoo(Monkey())));
}
2.bottom-to-top
1.right-to-left
see also http://bit.ly/1KN8cd0
43. @theburningmonk
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…
2.top-to-bottom
1.left-to-right
how we read ENGLISH
public void DoSomething(int x, int y)
{
Foo(y,
Bar(x,
Zoo(Monkey())));
}
2.top-to-bottom
1.right-to-left
how we read CODE
see also http://bit.ly/1KN8cd0
45. @theburningmonk
how we read CODE
let drawCircle x y radius =
circle radius
|> filled (rgb 150 170 150)
|> alpha 0.5
|> move (x, y)
see also http://bit.ly/1KN8cd0
46. @theburningmonk
how we read CODE
let drawCircle x y radius =
circle radius
|> filled (rgb 150 170 150)
|> alpha 0.5
|> move (x, y)
2.top-to-bottom
1.left-to-right
see also http://bit.ly/1KN8cd0
50. @theburningmonk
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();
}
51. “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.”
52. @theburningmonk
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();
}
61. @theburningmonk
let myCleverFunction x y z =
let localVar = anotherCleverFunction x y
if localVar.IsSomething(z, MY_CONSTANT) then
doSomething localVar
localVar.GetSomething()
62. @theburningmonk
XXX XXXXXXXXXXXXXXXX X X X
XXX XXXXXXXX XXXXXXXXXXXXXXXXXXXX X X
XX XXXXXXXX XXXXXXXXXXX X XXXXXXXXXX XXXX
XXXXXXXXXXX XXXXXXXX
XXXXXXXX XXXXXXXXXXXX
63. @theburningmonk
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.
69. - Phil Karlton
“There are only two hard things
in Computer Science: cache
invalidation and naming things.”
70. - Mike Mahemoff
“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.”
86. @theburningmonk
"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
140. @theburningmonk
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
141. @theburningmonk
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.
166. “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 specification of the
required functionality.”
- Nat Pryce & Steve Freeman
174. @theburningmonk
List.rev
property : length of list is invariant
let ``length of list is invariant`` rev aList =
List.length (rev aList) = List.length aList
Check.Quick (``length of list is invariant`` List.rev)
// Ok, passed 100 tests.