Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
7 ineffective
coding
habits
MANY
F#
programmers
DON’T
have
BuildStuff ‘14
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
with great habits.”
- Kent Beck
Noisy Code
Visual Dishonesty
Lego Naming
Underabstraction
Unencapsulated State
Getters and Setters
Uncohesive Tests
@theburningmonk
does the language I use
make a difference?
“Programming languages
have a devious influence:
they shape our thinking
habits.”
- Edsger W. Dijkstra
Noisy Code
@theburningmonk
@theburningmonk
@theburningmonk
every LOC is a cost
@theburningmonk
more code
more chance for bugs
@theburningmonk
more code
more engineers
@theburningmonk
@theburningmonk
You should do whatever possible to increase the
productivity of individual programmers in terms of
the exp...
@theburningmonk
You should do whatever possible to increase the
productivity of individual programmers in terms of
the exp...
does the language I use
make a difference?
@theburningmonk
@theburningmonk
source http://bit.ly/1oBHHh1
@theburningmonk
source http://bit.ly/1oBHHh1
@theburningmonk
source http://bit.ly/1oBHHh1
@theburningmonk
source http://bit.ly/1oBHHh1
@theburningmonk
source http://bit.ly/1oBHHh1
@theburningmonk
source http://bit.ly/1oBHHh1
@theburningmonk
source http://bit.ly/1oBHHh1
@theburningmonk
Recap
@theburningmonk
no { }
no nulls
fewer syntactic noise
@theburningmonk
fewer code
fewer noise
@theburningmonk
fewer noise
higher SNR
@theburningmonk
fewer code
more productivity
- Dan North
“Lead time to someone saying
thank you is the only reputation
metric that matters.”
Visual
Dishonesty
“…a clean design is one that
supports visual thinking so
people can meet their
informational needs with a
minimum of consc...
@theburningmonk
public void MyCleverMethod(
int firstArg,
string secondArg)
signifies hierarchy
“You convey information by the way you
arrange a design’s elements in relation to
each other. This information is understo...
“This is great if the visual relationships are
obvious and accurate, but if they’re not,
your audience is going to get con...
@theburningmonk
Whilst talking with an ex-colleague, a question came up on how to implement the Stable Marriage
problem us...
@theburningmonk
Whilst talking with an ex-colleague, a question came up on how to implement the Stable Marriage
problem us...
@theburningmonk
how we read CODE
public void DoSomething(int x, int y)
{
Foo(y,
Bar(x,
Zoo(Monkey())));
}
see also http://...
@theburningmonk
how we read CODE
public void DoSomething(int x, int y)
{
Foo(y,
Bar(x,
Zoo(Monkey())));
}
2.bottom-to-top
...
@theburningmonk
Whilst talking with an ex-colleague, a question came up on
how to implement the Stable Marriage problem us...
@theburningmonk
|>
see also http://bit.ly/1KN8cd0
@theburningmonk
how we read CODE
let drawCircle x y radius =
circle radius
|> filled (rgb 150 170 150)
|> alpha 0.5
|> move...
@theburningmonk
how we read CODE
let drawCircle x y radius =
circle radius
|> filled (rgb 150 170 150)
|> alpha 0.5
|> move...
@theburningmonk
{}
@theburningmonk
public ResultType MyCleverMethod(
int firstArg,
string secondArg,
string thirdArg) {
var localVar =
Anothe...
@theburningmonk
XXXXXX XXXXXXXXXX XXXXXXXXXXXXXX
XXX XXXXXXXX
XXXXXX XXXXXXXXX
XXXXXX XXXXXXXX
XXX XXXXXXXX
XXXXXXXXXXXXXX...
@theburningmonk
public ResultType MyCleverMethod(
int firstArg,
string secondArg,
string thirdArg) {
var localVar =
Anothe...
“This is great if the visual relationships are
obvious and accurate, but if they’re not,
your audience is going to get con...
@theburningmonk
public ResultType MyCleverMethod(
int firstArg,
string secondArg,
string thirdArg)
{
var localVar =
Anothe...
@theburningmonk
XXXXXX XXXXXXXXXX XXXXXXXXXXXXXX
XXX XXXXXXXX
XXXXXX XXXXXXXXX
XXXXXX XXXXXXXX
XXX XXXXXXXX
XXXXXXXXXXXXXX...
- Douglas Crockford
“It turns out that style
matters in programming for
the same reason that it
matters in writing.
It mak...
@theburningmonk
two competing rules for
structuring code in
C-style languages
@theburningmonk
Compiler
{ }
Human
{ } + whitespace
@theburningmonk
what if…?
@theburningmonk
Compiler
whitespace
Human
whitespace
@theburningmonk
xxx
{
}
xxx {
}
no
braces no
problem
@theburningmonk
There should be one - and preferably only
one - obvious way to do it.
- the Zen of Python
@theburningmonk
let myCleverFunction x y z =
let localVar = anotherCleverFunction x y
if localVar.IsSomething(z, MY_CONSTA...
@theburningmonk
XXX XXXXXXXXXXXXXXXX X X X
XXX XXXXXXXX XXXXXXXXXXXXXXXXXXXX X X
XX XXXXXXXX XXXXXXXXXXX X XXXXXXXXXX XXXX...
@theburningmonk
You should do whatever possible to increase the
productivity of individual programmers in terms of
the exp...
@theburningmonk
Recap
@theburningmonk
|>
@theburningmonk
one way to describe
hierarchy
Lego Naming
@theburningmonk
naming is HARD
- Phil Karlton
“There are only two hard things
in Computer Science: cache
invalidation and naming things.”
- Mike Mahemoff
“Names are the one and only
tool you have to explain what a
variable does in every place it
appears, witho...
@theburningmonk
Lego Naming
Gluing common words together in an
attempt to create meaning.
@theburningmonk
Strategy
Process
Create
Add
Controller
Factory
Proxy
Object
Exception
Enable
Do
Disable
Service
Remove
Che...
@theburningmonk
see http://methodnamer.com
@theburningmonk
this is not naming
@theburningmonk
this is not naming
this is labelling
@theburningmonk
@theburningmonk
@theburningmonk
naming is HARD
@theburningmonk
anonymous functions
aka lambdas
@theburningmonk
fewer things to name
@theburningmonk
words
|> Array.map (fun x -> x.Count)
|> Array.reduce (+)
@theburningmonk
smaller scope
shorter names
@theburningmonk
@theburningmonk
http://bit.ly/1ZpAByu
When x, y, and z are
great variable names
@theburningmonk
"The length of a name should be related to the
length of the scope. You can use very short
variable names ...
@theburningmonk
object expressions
@theburningmonk
enterpriseCrew.OrderBy(
(fun c -> c.Current),
{ new IComparer<Occupation> with
member this.Compare(x, y) =...
@theburningmonk
enterpriseCrew.OrderBy(
(fun c -> c.Current),
{ new IComparer<Occupation> with
member this.Compare(x, y) =...
@theburningmonk
fewer things to name
@theburningmonk
tuples + pattern matching
@theburningmonk
tuples + pattern matching
fewer abstractions
@theburningmonk
tuples + pattern matching
fewer abstractions
fewer things to name
@theburningmonk
words
|> Seq.groupBy id
|> Seq.map (fun (word, gr) ->
word, Seq.length gr)
|> Seq.iter (fun (word, len) ->...
@theburningmonk
words
|> Seq.groupBy id
|> Seq.map (fun (word, gr) ->
word, Seq.length gr)
|> Seq.iter (fun (word, len) ->...
@theburningmonk
words
|> Seq.groupBy id
|> Seq.map (fun (word, gr) ->
word, Seq.length gr)
|> Seq.iter (fun (word, len) ->...
@theburningmonk
words
|> Seq.groupBy id
|> Seq.map (fun (word, gr) ->
word, Seq.length gr)
|> Seq.iter (fun (word, len) ->...
@theburningmonk
Lego Naming can also be
the symptom of a failure to
identify the right level of
abstractions.
@theburningmonk
the RIGHT level of
abstraction might be
smaller than “object”
@theburningmonk
public interface ConditionChecker
{
bool CheckCondition();
}
@theburningmonk
public interface Condition
{
bool IsTrue();
}
@theburningmonk
@theburningmonk
type Condition = unit -> bool
source https://vimeo.com/113588389
@theburningmonk
ClassNotFoundException
IllegalArgumentException
IndexOutOfBoundsException
NoSuchMethodException
Unsupporte...
@theburningmonk
ClassNotFound
IllegalArgument
IndexOutOfBounds
NoSuchMethod
UnsupportedOperation
@theburningmonk
ArithmeticException
ArrayStoreException
ClassCastException
InstantiationException
NullPointerException
Sec...
@theburningmonk
IntegerDivisionByZero
IllegalArrayElementType
CastToNonSubclass
ClassCannotBeInstantiated
NullDereferenced...
@theburningmonk
lightweight exception syntax
@theburningmonk
open System
open System.IO
exception InsufficientBytes
@theburningmonk
open System
open System.IO
exception InsufficientBytes
what could this type represent?
@theburningmonk
Recap
@theburningmonk
F# < > silver bullet
@theburningmonk
anonymous functions
fewer things to name
@theburningmonk
short names
@theburningmonk
tuple + pattern matching
fewer things to name
@theburningmonk
no abstraction is too small
@theburningmonk
lightweight exception syntax
Underabstraction
@theburningmonk
@theburningmonk
public Result DoSomething(
int a,
string b,
string c,
string d,
DateTime e,
DateTime f,
string g,
MyEnum h)
“If you have a procedure
with ten parameters, you
probably missed some.”
- Alan Perlis
source https://vimeo.com/97507575
@theburningmonk
lightweight syntax for
types and hierarchies
@theburningmonk
record
@theburningmonk
type Employee =
{
FirstName : string
Surname : string
Salary : int<Pound>
}
@theburningmonk
type Employee =
{
FirstName : string
Surname : string
Salary : int<Pound>
}
immutable by default
@theburningmonk
let promote emp raise =
{
emp with Salary <- emp.Salary + raise
}
@theburningmonk
mutable state
complects
value and time
@theburningmonk
type Employee =
{
FirstName : string
Surname : string
Salary : int<Pound>
}
unit-of-measure
@theburningmonk
[<Measure>]
type Pound
e.g. 42<Pound>
153<Pound>
10<Meter> / 2<Second> = 5<Meter/Second>
10<Meter> * 2<Second> = 20<Meter Second>
10<Meter> + 10<Meter> = 20<Meter>
10<Mete...
10<Meter> / 2<Second> = 5<Meter/Second>
10<Meter> * 2<Second> = 20<Meter Second>
10<Meter> + 10<Meter> = 20<Meter>
10<Mete...
@theburningmonk
discriminated
unions
@theburningmonk
type PaymentMethod =
| Cash
| Cheque of ChequeNumber
| Card of CardType * CardNumber
Unencapsulated
State
@theburningmonk
@theburningmonk
public class RecentlyUsedList
{
private List<string> items = new List<string>();
public List<string> Items...
@theburningmonk
immutability
@theburningmonk
type RecentlyUsedList (?items) =
let items = defaultArg items [ ]
member this.Items = Array.ofList items
m...
@theburningmonk
Affordance
an affordance is a quality of an object, or
an environment, which allows an individual
to perfo...
source https://www.youtube.com/watch?v=aAb7hSCtvGw
@theburningmonk
your abstractions should
afford right behaviour,
whilst make it impossible
to do the wrong thing
@theburningmonk
“Make illegal states unrepresentable”
- Yaron Minsky
@theburningmonk
discriminated
unions
@theburningmonk
type PaymentMethod =
| Cash
| Cheque of ChequeNumber
| Card of CardType * CardNumber
finite, closed set of...
closed hierarchy
no Nulls
@theburningmonk
match paymentMethod with
| Cash -> …
| Cheque chequeNum -> …
| Card (cardType, cardNum) -> …
@theburningmonk
Recap
@theburningmonk
immutability
@theburningmonk
make illegal state
unrepresentable
Getters and
Setters
“When it’s not necessary to change,
it’s necessary to not change.”
- Lucius Cary
“Now we have shortcuts to do the
wrong thing.
We used to have type lots to do the
wrong thing, not anymore.”
- Kevlin Henn...
@theburningmonk
immutability by default
@theburningmonk
type Person =
{
Name : string
Age : int
}
@theburningmonk
type Person =
{
mutable Name : string
mutable Age : int
}
@theburningmonk
immutability
Uncohesive
Tests
@theburningmonk
MethodA
MethodB
When_…Then_… ()
When_…Then_… ()
When_…Then_… ()
When_…Then_… ()
When_…Then_… ()
When_…Then...
@theburningmonk
MethodA
MethodB
MethodC
FeatureA
FeatureB
@theburningmonk
complexities & potential
bugs in the way methods
work together
@theburningmonk
…especially when states
are concerned
@theburningmonk
Test Driven Development
“For tests to drive development they
must do more than just test that code
performs its required functionality: they
must ...
@theburningmonk
@theburningmonk
how many tests?
@theburningmonk
every test has a cost
@theburningmonk
did we cover all the
edge cases?
@theburningmonk
Property-Based Testing
(with FsCheck)
@theburningmonk
List.rev
reverse + reverse = original
length of list is invariant
append + reverse = reverse + prepend
@theburningmonk
List.rev
property : reverse + reverse = original
let ``reverse + reverse = original`` rev aList =
aList |>...
@theburningmonk
List.rev
property : length of list is invariant
let ``length of list is invariant`` rev aList =
List.lengt...
@theburningmonk
List.rev
property : append + reverse = reverse + prepend
let ``append + reverse = reverse + prepend`` rev ...
@theburningmonk
Check.Verbose (``append + reverse = reverse + prepend``
List.rev)
//
0: ‘005' []
1: false ["N "]
2: “" [fa...
@theburningmonk
shrinking
@theburningmonk
Check.Quick (``append + reverse = reverse + prepend`` id)
// Falsifiable, after 2 tests (4 shrinks) (StdGe...
@theburningmonk
let computers do the
grunt work
source : http://bit.ly/1kEpEso
@theburningmonk
Types vs Tests
@theburningmonk
all bugs
@theburningmonk
unknown
known
@theburningmonk
tests
types
@theburningmonk
tests
types
@theburningmonk
unit-testing
distr. systems
system-testing
@theburningmonk
Jepsenproperty-based
unit-testing system-testing
distr. systems
@theburningmonk
Jepsenproperty-based
unit-testing
types as proof TLA+
distr. systems
system-testing
Noisy Code
Visual Dishonesty
Lego Naming
Underabstraction
Unencapsulated State
Getters and Setters
Uncohesive Tests
“Practice does not make perfect.
Only perfect practice makes perfect.”
- Vince Lombardi
“Perfection is not attainable. But if we
chase perfection, we can catch excellence.”
- Vince Lombardi
“Programming languages
have a devious influence:
they shape our thinking
habits.”
- Edsger W. Dijkstra
“One of the most disastrous
thing we can learn is the first
programming language, even
if it's a good programming
language....
“I’m not a great programmer;
I’m just a good programmer
with great habits.”
- Kent Beck
@theburningmonk
what about ineffective
coding habits SOME F#/FP
programmers DO have?
@theburningmonk
@theburningmonk
people are too puritanical about purity
…premature optimization
is the root of all evil. Yet
we should not pass up
our opportunities in that
critical 3%
- Donald ...
@theburningmonk
F# Map vs .Net array vs Dictionary
@theburningmonk
@theburningmonk
Explicit is better than implicit.
- the Zen of Python
@theburningmonk
Simple is better than Complex.
Complex is better than Complicated.
- the Zen of Python
@theburningmonk
Special cases aren't special enough to
break the rules.
- the Zen of Python
@theburningmonk
Special cases aren't special enough to
break the rules.
Although practicality beats purity.
- the Zen of P...
@theburningmonk
If the implementation is hard to explain,
it's a bad idea.
- the Zen of Python
@theburningmonk
@theburningmonk
theburningmonk.com
github.com/theburningmonk
@theburningmonk
is hiring :-)
http://tech.just-eat.com/jobs
@theburningmonk IntegerDivisionByZero IllegalArrayElementType CastToNonSubclass ClassCannotBeInstantiated
@theburningmonk IntegerDivisionByZero IllegalArrayElementType CastToNonSubclass ClassCannotBeInstantiated
@theburningmonk IntegerDivisionByZero IllegalArrayElementType CastToNonSubclass ClassCannotBeInstantiated
Prochain SlideShare
Chargement dans…5
×

@theburningmonk IntegerDivisionByZero IllegalArrayElementType CastToNonSubclass ClassCannotBeInstantiated 7 ineffective coding habits many F# programmers don't have

304 955 vues

Publié le

@theburningmonk
IntegerDivisionByZero
IllegalArrayElementType
CastToNonSubclass
ClassCannotBeInstantiated
NullDereferenced
SecurityViolation

Publié dans : Ingénierie, Technologie
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... Download Full doc Ebook here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... Download PDF EBOOK here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... Download Full doc Ebook here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... Download PDF EBOOK here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... Download Full doc Ebook here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... Download PDF EBOOK here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/tthk4c7 } ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • +++++++++++++++++++++++++++++++Ebook pdf/fb2 == Copy link to Download https://ebooksfreede.com/load/7_ineffective_coding_habits_many_F#_programmers_don't_have.pdf +++++++++++++++++++++++
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • +++++++++++++++++++++++++++++++Ebook pdf/fb2 == Copy link to Download https://ebooksfreede.com/load/7_ineffective_coding_habits_many_F#_programmers_don't_have.pdf +++++++++++++++++++++++
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici

×