SlideShare a Scribd company logo
Seven Ineffective Coding
Habits of Many Java
Programmers
@KevlinHenney
Seven Ineffective Coding Habits of Many Java Programmers
Seven Ineffective Coding Habits of Many Java Programmers
It turns out that style matters in
programming for the same
reason that it matters in writing.
It makes for better reading.
Douglas Crockford
JavaScript: The Good Parts
Seven Ineffective Coding Habits of Many Java Programmers
Noisy Code
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.
http://en.wikipedia.org/wiki/Signal_to_noise_ratio
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
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
public class RecentlyUsedList
{
private List<String> items;
public RecentlyUsedList()
{
items = new ArrayList<String>();
}
public void add(String newItem)
{
if (items.contains(newItem))
{
int position = items.indexOf(newItem);
String existingItem = items.get(position);
items.remove(position);
items.add(0, existingItem);
}
else
{
items.add(0, newItem);
}
}
public int size()
{
int result = items.size();
return result;
}
public String get(int index)
{
int position = 0;
for (String item : items)
{
if (position == index)
return item;
++position;
}
throw new IndexOutOfBoundsException();
}
}
public class RecentlyUsedList
{
private List<String> items = new ArrayList<String>();
public void add(String newItem)
{
items.remove(newItem);
items.add(newItem);
}
public int size()
{
return items.size();
}
public String get(int index)
{
return items.get(size() - index – 1);
}
}
public class RecentlyUsedList
{
private List<String> items;
public RecentlyUsedList()
{
items = new ArrayList<String>();
}
public void add(String newItem)
{
if (items.contains(newItem))
{
int position = items.indexOf(newItem);
String existingItem = items.get(position);
items.remove(position);
items.add(0, existingItem);
}
else
{
items.add(0, newItem);
}
}
public int size()
{
int result = items.size();
return result;
}
public String get(int index)
{
int position = 0;
for (String item : items)
{
if (position == index)
return item;
++position;
}
throw new IndexOutOfBoundsException();
}
}
Seven Ineffective Coding Habits of Many Java Programmers
Seven Ineffective Coding Habits of Many Java Programmers
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"
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"
A common fallacy is to assume authors
of incomprehensible code will somehow
be able to express themselves lucidly
and clearly in comments.
Kevlin Henney
https://twitter.com/KevlinHenney/status/381021802941906944
Seven Ineffective Coding Habits of Many Java Programmers
Unsustainable Spacing
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
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
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?
The way many programmers lay out their code
Column 80
The way people read
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 ∙ http://www.visualmess.com/
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 ∙ http://www.visualmess.com/
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 ∙ http://www.visualmess.com/
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)
int doNotFormat = likeThis(someArgumentOrExpression,
anotherArgumentOrExpression);
int insteadFormat =
somethingLikeThis(
someArgumentOrExpression,
anotherArgumentOrExpression);
int orFormat = somethingLikeThis(
someArgumentOrExpression,
anotherArgumentOrExpression);
int asItIs = unstable(someArgumentOrExpression,
anotherArgumentOrExpression);
int butThisIs =
stable(
someArgumentOrExpression,
anotherArgumentOrExpression);
int andThisIs = stable(
someArgumentOrExpression,
anotherArgumentOrExpression);
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();
}
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();
}
XXXXXX XXXXXXXXXX XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX
XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXX
XX XXXXXXXXXXXXX XXXXXXXXXXX
XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXX XXXXXXXXXXXXX
XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXX
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();
}
XXXXXX XXXXXXXXXX XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX
XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXX
XX XXXXXXXXXXXXX XXXXXXXXXXX
XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXX XXXXXXXXXXXXX
XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXX
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();
}
XXXXXX XXXXXXXXXX XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX
XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXX
XX XXXXXXXXXXXXX XXXXXXXXXXX
XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXX XXXXXXXXXXXXX
XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXX
class AttributedBody extends Body
implements Attributed
{
AttributedImpl attrImpl = new AttributedImpl();
...
}
public static String quotedString(
String from, char start, char end)
{
int startPos = from.indexOf(start);
int endPos = from.lastIndexOf(end);
if (startPos == -1) // no start found
return null;
else if (endPos == -1) // no end found
return from.substring(startPos);
else // both start and end found
return from.substring(startPos, endPos + 1);
}
public void replaceValue(String name, Object newValue)
throws NoSuchAttributeException
{
Attr attr = find(name); // lookup the attr
if (attr == null) // it isn't found
throw new NoSuchAttributeException(name, this);
attr.valueOf(newValue);
}
Seven Ineffective Coding Habits of Many Java Programmers
Seven Ineffective Coding Habits of Many Java Programmers
Lego Naming
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.
http://en.wikipedia.org/wiki/Agglutination
pneumonoultramicroscopicsilicovolcanoconiosis
Rindfleischetikettierungsüberwachungsaufgabenübertragungsgesetz
fylkestrafikksikkerhetsutvalgssekretariatslederfunksjonene
Seven Ineffective Coding Habits of Many Java Programmers
Proxy
validate
Service
Value
get
create
Manager
check
Controller
set
Factory
Object
doenable
process
disable
Exception
add
remove
public interface BookEntity ...
public interface BookEntityFactory ...
public interface ISBNValidator ...
public interface CatalogueRepository ...
public interface CatalogueRepositoryProvider ...
public abstract class AbstractBookEntity
implements BookEntity
public class BookEntityImpl
extends BookEntity ...
public class BookEntityFactoryImpl
implements BookEntityFactory ...
public class ISBNValidatorImpl
implements ISBNValidator ...
public class CatalogueRepositoryImpl
implements CatalogueRepository ...
public class CatalogueRepositoryProviderImpl
implements CatalogueRepositoryProvider ...
public interface Book ...
public final class ISBN ...
public interface Catalogue ...
public class DescriptionOfCatalogueImplementation
implements Catalogue ...
public interface ConditionChecker
{
boolean checkCondition();
}
public interface Condition
{
boolean isTrue();
}
public Connection createConnection(Provider...)
throws ConnectionFailureException
...
public Connection connectTo(Provider...)
throws ConnectionFailure
...
Omit needless words.
William Strunk and E B White
The Elements of Style
Seven Ineffective Coding Habits of Many Java Programmers
Underabstraction
http://fragmental.tw/2009/04/29/tag-clouds-see-how-noisy-your-code-is/
http://fragmental.tw/2009/04/29/tag-clouds-see-how-noisy-your-code-is/
if (portfolioIdsByTraderId.get(trader.getId())
.containsKey(portfolio.getId()))
{
...
}
Dan North, "Code in the Language of the Domain"
97 Things Every Programmer Should Know
if (trader.canView(portfolio))
{
...
}
Dan North, "Code in the Language of the Domain"
97 Things Every Programmer Should Know
parser.processNodes(text, false);
Gregor Hohpe, "Convenience Is Not an -ility"
97 Things Every Programmer Should Know
If you have a procedure with
ten parameters, you probably
missed some.
Alan Perlis
Seven Ineffective Coding Habits of Many Java Programmers
Unencapsulated State
encapsulate enclose (something) in or as if in a capsule.
 express the essential feature of (someone or something)
succinctly.
 enclose (a message or signal) in a set of codes which
allow use by or transfer through different computer
systems or networks.
 provide an interface for (a piece of software or hardware)
to allow or simplify access for the user.
The New Oxford Dictionary of English
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,
while a cord affords pulling.
http://en.wikipedia.org/wiki/Affordance
public class RecentlyUsedList
{
private List<String> items = new ArrayList<String>();
public List<String> getList()
{
return items;
}
public void add(String newItem)
{
if(newItem == null)
throw new IllegalArgumentException();
items.remove(newItem);
items.add(0, newItem);
}
...
}
public class RecentlyUsedList
{
private List<String> items = new ArrayList<String>();
public List<String> getList()
{
return items;
}
public void add(String newItem)
{
if(newItem == null)
throw new IllegalArgumentException();
items.remove(newItem);
items.add(0, newItem);
}
...
}
Don't ever invite a
vampire into your
house, you silly boy.
It renders you
powerless.
public class RecentlyUsedList
{
private List<String> items = new ArrayList<String>();
public int isEmpty()
{
return items.isEmpty()
}
public int size()
{
return items.size();
}
public String get(int index)
{
return items.get(index);
}
public void add(String newItem)
{
if(newItem == null)
throw new IllegalArgumentException();
items.remove(newItem);
items.add(0, newItem);
}
...
}
public class RecentlyUsedList
{
private List<String> items = new ArrayList<String>();
public int isEmpty()
{
return items.isEmpty()
}
public int size()
{
return items.size();
}
public String get(int index)
{
return items.get(index);
}
public void add(String newItem)
{
if(newItem == null)
throw new IllegalArgumentException();
items.remove(newItem);
items.add(0, newItem);
}
...
}
public class RecentlyUsedList
{
private List<String> items = new ArrayList<String>();
public int isEmpty()
{
return items.isEmpty()
}
public int size()
{
return items.size();
}
public String get(int index)
{
return items.get(size() – index - 1);
}
public void add(String newItem)
{
if(newItem == null)
throw new IllegalArgumentException();
items.remove(newItem);
items.add(newItem);
}
...
}
Seven Ineffective Coding Habits of Many Java Programmers
Do not use
new in
constructors.?
It’s OK to use
new in
constructors.
Do not use
throw in
constructors.?
It’s OK to use
throw in
constructors.
Seven Ineffective Coding Habits of Many Java Programmers
Getters and Setters
Seven Ineffective Coding Habits of Many Java Programmers
Seven Ineffective Coding Habits of Many Java Programmers
Seven Ineffective Coding Habits of Many Java Programmers
Seven Ineffective Coding Habits of Many Java Programmers
public final class Date implements ...
{
...
public int getYear() ...
public int getMonth() ...
public int getDayInMonth() ...
public void setYear(int newYear) ...
public void setMonth(int newMonth) ...
public void setDayInMonth(int newDayInMonth) ...
...
}
public final class Date implements ...
{
...
public int getYear() ...
public int getMonth() ...
public int getWeekInYear() ...
public int getDayInYear() ...
public int getDayInMonth() ...
public int getDayInWeek() ...
public void setYear(int newYear) ...
public void setMonth(int newMonth) ...
public void setWeekInYear(int newWeek) ...
public void setDayInYear(int newDayInYear) ...
public void setDayInMonth(int newDayInMonth) ...
public void setDayInWeek(int newDayInWeek) ...
...
}
When it is not
necessary to
change, it is
necessary not to
change.
Lucius Cary
public final class Date implements ...
{
...
public int getYear() ...
public int getMonth() ...
public int getWeekInYear() ...
public int getDayInYear() ...
public int getDayInMonth() ...
public int getDayInWeek() ...
...
}
public final class Date implements ...
{
...
public int year() ...
public int month() ...
public int weekInYear() ...
public int dayInYear() ...
public int dayInMonth() ...
public int dayInWeek() ...
...
}
public final class Date implements ...
{
...
public int year() ...
public Month month() ...
public int weekInYear() ...
public int dayInYear() ...
public int dayInMonth() ...
public DayInWeek dayInWeek() ...
...
}
Some people, when confronted with a
problem, think, "I know, I'll use threads,"
and then two they hav erpoblesms.
Ned Batchelder
https://twitter.com/#!/nedbat/status/194873829825327104
Mutable
Immutable
Unshared Shared
Unshared mutable
data needs no
synchronisation
Unshared immutable
data needs no
synchronisation
Shared mutable
data needs
synchronisation
Shared immutable
data needs no
synchronisation
Synchronisation
Quadrant
Seven Ineffective Coding Habits of Many Java Programmers
Uncohesive Tests
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?"
Seven Ineffective Coding Habits of Many Java Programmers
public class RecentlyUsedList
{
...
public RecentlyUsedList() ...
public boolean isEmpty() ...
public int size() ...
public String get(int index) ...
public void add(String newItem) ...
...
}
public class RecentlyUsedListTest
{
@Test
public void testConstructor() ...
@Test
public void testIsEmpty() ...
@Test
public void testSize() ...
@Test
public void testGet() ...
@Test
public void testAdd() ...
...
}
public class RecentlyUsedList_spec
{
public static class A_new_list
{
@Test public void is_empty() 
}
public static class An_empty_list
{
@Test public void retains_a_single_addition() 
@Test public void retains_unique_additions_in_stack_order() 
}
public static 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() 
}
public static class Any_list
{
@Test public void rejects_addition_of_null_items() 
@Test public void rejects_indexing_past_its_end() 
@Test public void rejects_negative_indexing() 
}
}
public class RecentlyUsedList_spec
{
public static class A_new_list
{
@Test public void is_empty() 
}
public static class An_empty_list
{
@Test public void retains_a_single_addition() 
@Test public void retains_unique_additions_in_stack_order() 
}
public static 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() 
}
public static class Any_list
{
@Test public void rejects_addition_of_null_items() 
@Test public void rejects_indexing_past_its_end() 
@Test public void rejects_negative_indexing() 
}
}
A test case should
be just that: it
should correspond
to a single case.
Style is the art of
getting yourself out
of the way, not
putting yourself in it.
David Hare

More Related Content

Similar to Seven Ineffective Coding Habits of Many Java Programmers

Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many Programmers
Kevlin Henney
 
Design Patterns: Back to Basics
Design Patterns: Back to BasicsDesign Patterns: Back to Basics
Design Patterns: Back to Basics
Paulo Gandra de Sousa
 
The Role Of Ontology In Modern Expert Systems Dallas 2008
The Role Of Ontology In Modern Expert Systems   Dallas   2008The Role Of Ontology In Modern Expert Systems   Dallas   2008
The Role Of Ontology In Modern Expert Systems Dallas 2008
Jason Morris
 
KevlinHenney_PuttingThereIntoArchitecture
KevlinHenney_PuttingThereIntoArchitectureKevlinHenney_PuttingThereIntoArchitecture
KevlinHenney_PuttingThereIntoArchitecture
Kostas Mavridis
 
Experiments in Reasoning
Experiments in ReasoningExperiments in Reasoning
Experiments in Reasoning
Aslam Khan
 
Turning Development Outside-In
Turning Development Outside-InTurning Development Outside-In
Turning Development Outside-In
Kevlin Henney
 
Clean Code 2
Clean Code 2Clean Code 2
Clean Code 2
Fredrik Wendt
 
Object? You Keep Using that Word
Object? You Keep Using that WordObject? You Keep Using that Word
Object? You Keep Using that Word
Kevlin Henney
 
Value Objects
Value ObjectsValue Objects
Value Objects
barryosull
 
Using binary classifiers
Using binary classifiersUsing binary classifiers
Using binary classifiers
butest
 
Designing Testable Software
Designing Testable SoftwareDesigning Testable Software
Designing Testable Software
Omegapoint Academy
 
Dcn 20170823 yjy
Dcn 20170823 yjyDcn 20170823 yjy
Dcn 20170823 yjy
재연 윤
 
Using Topological Data Analysis on your BigData
Using Topological Data Analysis on your BigDataUsing Topological Data Analysis on your BigData
Using Topological Data Analysis on your BigData
AnalyticsWeek
 
Computational decision making
Computational decision makingComputational decision making
Computational decision making
Boris Adryan
 
The Art of Identifying Vulnerabilities - CascadiaFest 2015
The Art of Identifying Vulnerabilities  - CascadiaFest 2015The Art of Identifying Vulnerabilities  - CascadiaFest 2015
The Art of Identifying Vulnerabilities - CascadiaFest 2015
Adam Baldwin
 
What's next in Julia
What's next in JuliaWhat's next in Julia
What's next in Julia
Jiahao Chen
 
A well-typed program never goes wrong
A well-typed program never goes wrongA well-typed program never goes wrong
A well-typed program never goes wrong
Julien Wetterwald
 
2013 - Andrei Zmievski: Machine learning para datos
2013 - Andrei Zmievski: Machine learning para datos2013 - Andrei Zmievski: Machine learning para datos
2013 - Andrei Zmievski: Machine learning para datos
PHP Conference Argentina
 
Running Head Discussion Board .docx
Running Head Discussion Board                                  .docxRunning Head Discussion Board                                  .docx
Running Head Discussion Board .docx
jeanettehully
 
Maintainable code
Maintainable codeMaintainable code
Maintainable code
RiverGlide
 

Similar to Seven Ineffective Coding Habits of Many Java Programmers (20)

Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many Programmers
 
Design Patterns: Back to Basics
Design Patterns: Back to BasicsDesign Patterns: Back to Basics
Design Patterns: Back to Basics
 
The Role Of Ontology In Modern Expert Systems Dallas 2008
The Role Of Ontology In Modern Expert Systems   Dallas   2008The Role Of Ontology In Modern Expert Systems   Dallas   2008
The Role Of Ontology In Modern Expert Systems Dallas 2008
 
KevlinHenney_PuttingThereIntoArchitecture
KevlinHenney_PuttingThereIntoArchitectureKevlinHenney_PuttingThereIntoArchitecture
KevlinHenney_PuttingThereIntoArchitecture
 
Experiments in Reasoning
Experiments in ReasoningExperiments in Reasoning
Experiments in Reasoning
 
Turning Development Outside-In
Turning Development Outside-InTurning Development Outside-In
Turning Development Outside-In
 
Clean Code 2
Clean Code 2Clean Code 2
Clean Code 2
 
Object? You Keep Using that Word
Object? You Keep Using that WordObject? You Keep Using that Word
Object? You Keep Using that Word
 
Value Objects
Value ObjectsValue Objects
Value Objects
 
Using binary classifiers
Using binary classifiersUsing binary classifiers
Using binary classifiers
 
Designing Testable Software
Designing Testable SoftwareDesigning Testable Software
Designing Testable Software
 
Dcn 20170823 yjy
Dcn 20170823 yjyDcn 20170823 yjy
Dcn 20170823 yjy
 
Using Topological Data Analysis on your BigData
Using Topological Data Analysis on your BigDataUsing Topological Data Analysis on your BigData
Using Topological Data Analysis on your BigData
 
Computational decision making
Computational decision makingComputational decision making
Computational decision making
 
The Art of Identifying Vulnerabilities - CascadiaFest 2015
The Art of Identifying Vulnerabilities  - CascadiaFest 2015The Art of Identifying Vulnerabilities  - CascadiaFest 2015
The Art of Identifying Vulnerabilities - CascadiaFest 2015
 
What's next in Julia
What's next in JuliaWhat's next in Julia
What's next in Julia
 
A well-typed program never goes wrong
A well-typed program never goes wrongA well-typed program never goes wrong
A well-typed program never goes wrong
 
2013 - Andrei Zmievski: Machine learning para datos
2013 - Andrei Zmievski: Machine learning para datos2013 - Andrei Zmievski: Machine learning para datos
2013 - Andrei Zmievski: Machine learning para datos
 
Running Head Discussion Board .docx
Running Head Discussion Board                                  .docxRunning Head Discussion Board                                  .docx
Running Head Discussion Board .docx
 
Maintainable code
Maintainable codeMaintainable code
Maintainable code
 

More from Kevlin Henney

Program with GUTs
Program with GUTsProgram with GUTs
Program with GUTs
Kevlin Henney
 
The Case for Technical Excellence
The Case for Technical ExcellenceThe Case for Technical Excellence
The Case for Technical Excellence
Kevlin Henney
 
Empirical Development
Empirical DevelopmentEmpirical Development
Empirical Development
Kevlin Henney
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
Kevlin Henney
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
Kevlin Henney
 
Solid Deconstruction
Solid DeconstructionSolid Deconstruction
Solid Deconstruction
Kevlin Henney
 
Get Kata
Get KataGet Kata
Get Kata
Kevlin Henney
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went Away
Kevlin Henney
 
Structure and Interpretation of Test Cases
Structure and Interpretation of Test CasesStructure and Interpretation of Test Cases
Structure and Interpretation of Test Cases
Kevlin Henney
 
Agility ≠ Speed
Agility ≠ SpeedAgility ≠ Speed
Agility ≠ Speed
Kevlin Henney
 
Refactoring to Immutability
Refactoring to ImmutabilityRefactoring to Immutability
Refactoring to Immutability
Kevlin Henney
 
Old Is the New New
Old Is the New NewOld Is the New New
Old Is the New New
Kevlin Henney
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Kevlin Henney
 
Code as Risk
Code as RiskCode as Risk
Code as Risk
Kevlin Henney
 
Software Is Details
Software Is DetailsSoftware Is Details
Software Is Details
Kevlin Henney
 
Game of Sprints
Game of SprintsGame of Sprints
Game of Sprints
Kevlin Henney
 
Good Code
Good CodeGood Code
Good Code
Kevlin Henney
 
The Error of Our Ways
The Error of Our WaysThe Error of Our Ways
The Error of Our Ways
Kevlin Henney
 
SOLID Deconstruction
SOLID DeconstructionSOLID Deconstruction
SOLID Deconstruction
Kevlin Henney
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
Kevlin Henney
 

More from Kevlin Henney (20)

Program with GUTs
Program with GUTsProgram with GUTs
Program with GUTs
 
The Case for Technical Excellence
The Case for Technical ExcellenceThe Case for Technical Excellence
The Case for Technical Excellence
 
Empirical Development
Empirical DevelopmentEmpirical Development
Empirical Development
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Solid Deconstruction
Solid DeconstructionSolid Deconstruction
Solid Deconstruction
 
Get Kata
Get KataGet Kata
Get Kata
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went Away
 
Structure and Interpretation of Test Cases
Structure and Interpretation of Test CasesStructure and Interpretation of Test Cases
Structure and Interpretation of Test Cases
 
Agility ≠ Speed
Agility ≠ SpeedAgility ≠ Speed
Agility ≠ Speed
 
Refactoring to Immutability
Refactoring to ImmutabilityRefactoring to Immutability
Refactoring to Immutability
 
Old Is the New New
Old Is the New NewOld Is the New New
Old Is the New New
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
 
Code as Risk
Code as RiskCode as Risk
Code as Risk
 
Software Is Details
Software Is DetailsSoftware Is Details
Software Is Details
 
Game of Sprints
Game of SprintsGame of Sprints
Game of Sprints
 
Good Code
Good CodeGood Code
Good Code
 
The Error of Our Ways
The Error of Our WaysThe Error of Our Ways
The Error of Our Ways
 
SOLID Deconstruction
SOLID DeconstructionSOLID Deconstruction
SOLID Deconstruction
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
 

Recently uploaded

Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
dream girl
 
A Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdf
A Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdfA Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdf
A Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdf
kalichargn70th171
 
B.Sc. Computer Science Department PPT 2024
B.Sc. Computer Science Department PPT 2024B.Sc. Computer Science Department PPT 2024
B.Sc. Computer Science Department PPT 2024
vmsdeptcom
 
Celebrity Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Servic...
Celebrity Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Servic...Celebrity Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Servic...
Celebrity Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Servic...
45unexpected
 
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
bhumivarma35300
 
02. Ruby Basic slides - Ruby Core Teaching
02. Ruby Basic slides - Ruby Core Teaching02. Ruby Basic slides - Ruby Core Teaching
02. Ruby Basic slides - Ruby Core Teaching
quanhoangd129
 
Old Tools, New Tricks: Unleashing the Power of Time-Tested Testing Tools
Old Tools, New Tricks: Unleashing the Power of Time-Tested Testing ToolsOld Tools, New Tricks: Unleashing the Power of Time-Tested Testing Tools
Old Tools, New Tricks: Unleashing the Power of Time-Tested Testing Tools
Benjamin Bischoff
 
Applitools Autonomous 2.0 Sneak Peek.pdf
Applitools Autonomous 2.0 Sneak Peek.pdfApplitools Autonomous 2.0 Sneak Peek.pdf
Applitools Autonomous 2.0 Sneak Peek.pdf
Applitools
 
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
OnePlan Solutions
 
TEQnation 2024: Sustainable Software: May the Green Code Be with You
TEQnation 2024: Sustainable Software: May the Green Code Be with YouTEQnation 2024: Sustainable Software: May the Green Code Be with You
TEQnation 2024: Sustainable Software: May the Green Code Be with You
marcofolio
 
How To Fill Timesheet in TaskSprint: Quick Guide 2024
How To Fill Timesheet in TaskSprint: Quick Guide 2024How To Fill Timesheet in TaskSprint: Quick Guide 2024
How To Fill Timesheet in TaskSprint: Quick Guide 2024
TaskSprint | Employee Efficiency Software
 
01. Ruby Introduction - Ruby Core Teaching
01. Ruby Introduction - Ruby Core Teaching01. Ruby Introduction - Ruby Core Teaching
01. Ruby Introduction - Ruby Core Teaching
quanhoangd129
 
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
jealousviolet
 
Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...
Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...
Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...
norina2645
 
Predicting Test Results without Execution (FSE 2024)
Predicting Test Results without Execution (FSE 2024)Predicting Test Results without Execution (FSE 2024)
Predicting Test Results without Execution (FSE 2024)
andrehoraa
 
Hotel Management Software Development Company
Hotel Management Software Development CompanyHotel Management Software Development Company
Hotel Management Software Development Company
XongoLab Technologies LLP
 
ERP Software Solutions Provider in Coimbatore
ERP Software Solutions Provider in CoimbatoreERP Software Solutions Provider in Coimbatore
ERP Software Solutions Provider in Coimbatore
Nextskill Technologies
 
Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...
Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...
Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...
rachitkumar09887
 
Fantastic Design Patterns and Where to use them No Notes.pdf
Fantastic Design Patterns and Where to use them No Notes.pdfFantastic Design Patterns and Where to use them No Notes.pdf
Fantastic Design Patterns and Where to use them No Notes.pdf
6m9p7qnjj8
 
🚂🚘 Premium Girls Call Ranchi 🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
🚂🚘 Premium Girls Call Ranchi  🛵🚡000XX00000 💃 Choose Best And Top Girl Service...🚂🚘 Premium Girls Call Ranchi  🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
🚂🚘 Premium Girls Call Ranchi 🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
bahubalikumar09988
 

Recently uploaded (20)

Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
 
A Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdf
A Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdfA Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdf
A Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdf
 
B.Sc. Computer Science Department PPT 2024
B.Sc. Computer Science Department PPT 2024B.Sc. Computer Science Department PPT 2024
B.Sc. Computer Science Department PPT 2024
 
Celebrity Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Servic...
Celebrity Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Servic...Celebrity Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Servic...
Celebrity Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Servic...
 
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
 
02. Ruby Basic slides - Ruby Core Teaching
02. Ruby Basic slides - Ruby Core Teaching02. Ruby Basic slides - Ruby Core Teaching
02. Ruby Basic slides - Ruby Core Teaching
 
Old Tools, New Tricks: Unleashing the Power of Time-Tested Testing Tools
Old Tools, New Tricks: Unleashing the Power of Time-Tested Testing ToolsOld Tools, New Tricks: Unleashing the Power of Time-Tested Testing Tools
Old Tools, New Tricks: Unleashing the Power of Time-Tested Testing Tools
 
Applitools Autonomous 2.0 Sneak Peek.pdf
Applitools Autonomous 2.0 Sneak Peek.pdfApplitools Autonomous 2.0 Sneak Peek.pdf
Applitools Autonomous 2.0 Sneak Peek.pdf
 
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
 
TEQnation 2024: Sustainable Software: May the Green Code Be with You
TEQnation 2024: Sustainable Software: May the Green Code Be with YouTEQnation 2024: Sustainable Software: May the Green Code Be with You
TEQnation 2024: Sustainable Software: May the Green Code Be with You
 
How To Fill Timesheet in TaskSprint: Quick Guide 2024
How To Fill Timesheet in TaskSprint: Quick Guide 2024How To Fill Timesheet in TaskSprint: Quick Guide 2024
How To Fill Timesheet in TaskSprint: Quick Guide 2024
 
01. Ruby Introduction - Ruby Core Teaching
01. Ruby Introduction - Ruby Core Teaching01. Ruby Introduction - Ruby Core Teaching
01. Ruby Introduction - Ruby Core Teaching
 
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
 
Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...
Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...
Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...
 
Predicting Test Results without Execution (FSE 2024)
Predicting Test Results without Execution (FSE 2024)Predicting Test Results without Execution (FSE 2024)
Predicting Test Results without Execution (FSE 2024)
 
Hotel Management Software Development Company
Hotel Management Software Development CompanyHotel Management Software Development Company
Hotel Management Software Development Company
 
ERP Software Solutions Provider in Coimbatore
ERP Software Solutions Provider in CoimbatoreERP Software Solutions Provider in Coimbatore
ERP Software Solutions Provider in Coimbatore
 
Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...
Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...
Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...
 
Fantastic Design Patterns and Where to use them No Notes.pdf
Fantastic Design Patterns and Where to use them No Notes.pdfFantastic Design Patterns and Where to use them No Notes.pdf
Fantastic Design Patterns and Where to use them No Notes.pdf
 
🚂🚘 Premium Girls Call Ranchi 🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
🚂🚘 Premium Girls Call Ranchi  🛵🚡000XX00000 💃 Choose Best And Top Girl Service...🚂🚘 Premium Girls Call Ranchi  🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
🚂🚘 Premium Girls Call Ranchi 🛵🚡000XX00000 💃 Choose Best And Top Girl Service...
 

Seven Ineffective Coding Habits of Many Java Programmers

  • 1. Seven Ineffective Coding Habits of Many Java Programmers @KevlinHenney
  • 4. It turns out that style matters in programming for the same reason that it matters in writing. It makes for better reading. Douglas Crockford JavaScript: The Good Parts
  • 7. 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. http://en.wikipedia.org/wiki/Signal_to_noise_ratio
  • 8. 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
  • 9. 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
  • 10. public class RecentlyUsedList { private List<String> items; public RecentlyUsedList() { items = new ArrayList<String>(); } public void add(String newItem) { if (items.contains(newItem)) { int position = items.indexOf(newItem); String existingItem = items.get(position); items.remove(position); items.add(0, existingItem); } else { items.add(0, newItem); } } public int size() { int result = items.size(); return result; } public String get(int index) { int position = 0; for (String item : items) { if (position == index) return item; ++position; } throw new IndexOutOfBoundsException(); } }
  • 11. public class RecentlyUsedList { private List<String> items = new ArrayList<String>(); public void add(String newItem) { items.remove(newItem); items.add(newItem); } public int size() { return items.size(); } public String get(int index) { return items.get(size() - index – 1); } } public class RecentlyUsedList { private List<String> items; public RecentlyUsedList() { items = new ArrayList<String>(); } public void add(String newItem) { if (items.contains(newItem)) { int position = items.indexOf(newItem); String existingItem = items.get(position); items.remove(position); items.add(0, existingItem); } else { items.add(0, newItem); } } public int size() { int result = items.size(); return result; } public String get(int index) { int position = 0; for (String item : items) { if (position == index) return item; ++position; } throw new IndexOutOfBoundsException(); } }
  • 14. 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"
  • 15. 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"
  • 16. A common fallacy is to assume authors of incomprehensible code will somehow be able to express themselves lucidly and clearly in comments. Kevlin Henney https://twitter.com/KevlinHenney/status/381021802941906944
  • 19. 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
  • 20. 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
  • 21. 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?
  • 22. The way many programmers lay out their code Column 80
  • 24. 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 ∙ http://www.visualmess.com/
  • 25. 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 ∙ http://www.visualmess.com/
  • 26. 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 ∙ http://www.visualmess.com/
  • 27. 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)
  • 28. int doNotFormat = likeThis(someArgumentOrExpression, anotherArgumentOrExpression); int insteadFormat = somethingLikeThis( someArgumentOrExpression, anotherArgumentOrExpression); int orFormat = somethingLikeThis( someArgumentOrExpression, anotherArgumentOrExpression);
  • 29. int asItIs = unstable(someArgumentOrExpression, anotherArgumentOrExpression); int butThisIs = stable( someArgumentOrExpression, anotherArgumentOrExpression); int andThisIs = stable( someArgumentOrExpression, anotherArgumentOrExpression);
  • 30. 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(); }
  • 31. 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(); }
  • 32. XXXXXX XXXXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXX XX XXXXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXX
  • 33. 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(); }
  • 34. XXXXXX XXXXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXX XX XXXXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXX
  • 35. 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(); }
  • 36. XXXXXX XXXXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXX XX XXXXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXX XXXXXXXXXXXX
  • 37. class AttributedBody extends Body implements Attributed { AttributedImpl attrImpl = new AttributedImpl(); ... }
  • 38. public static String quotedString( String from, char start, char end) { int startPos = from.indexOf(start); int endPos = from.lastIndexOf(end); if (startPos == -1) // no start found return null; else if (endPos == -1) // no end found return from.substring(startPos); else // both start and end found return from.substring(startPos, endPos + 1); }
  • 39. public void replaceValue(String name, Object newValue) throws NoSuchAttributeException { Attr attr = find(name); // lookup the attr if (attr == null) // it isn't found throw new NoSuchAttributeException(name, this); attr.valueOf(newValue); }
  • 43. 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. http://en.wikipedia.org/wiki/Agglutination
  • 47. public interface BookEntity ... public interface BookEntityFactory ... public interface ISBNValidator ... public interface CatalogueRepository ... public interface CatalogueRepositoryProvider ... public abstract class AbstractBookEntity implements BookEntity public class BookEntityImpl extends BookEntity ... public class BookEntityFactoryImpl implements BookEntityFactory ... public class ISBNValidatorImpl implements ISBNValidator ... public class CatalogueRepositoryImpl implements CatalogueRepository ... public class CatalogueRepositoryProviderImpl implements CatalogueRepositoryProvider ...
  • 48. public interface Book ... public final class ISBN ... public interface Catalogue ... public class DescriptionOfCatalogueImplementation implements Catalogue ...
  • 53. Omit needless words. William Strunk and E B White The Elements of Style
  • 58. if (portfolioIdsByTraderId.get(trader.getId()) .containsKey(portfolio.getId())) { ... } Dan North, "Code in the Language of the Domain" 97 Things Every Programmer Should Know
  • 59. if (trader.canView(portfolio)) { ... } Dan North, "Code in the Language of the Domain" 97 Things Every Programmer Should Know
  • 60. parser.processNodes(text, false); Gregor Hohpe, "Convenience Is Not an -ility" 97 Things Every Programmer Should Know
  • 61. If you have a procedure with ten parameters, you probably missed some. Alan Perlis
  • 64. encapsulate enclose (something) in or as if in a capsule.  express the essential feature of (someone or something) succinctly.  enclose (a message or signal) in a set of codes which allow use by or transfer through different computer systems or networks.  provide an interface for (a piece of software or hardware) to allow or simplify access for the user. The New Oxford Dictionary of English
  • 65. 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, while a cord affords pulling. http://en.wikipedia.org/wiki/Affordance
  • 66. public class RecentlyUsedList { private List<String> items = new ArrayList<String>(); public List<String> getList() { return items; } public void add(String newItem) { if(newItem == null) throw new IllegalArgumentException(); items.remove(newItem); items.add(0, newItem); } ... }
  • 67. public class RecentlyUsedList { private List<String> items = new ArrayList<String>(); public List<String> getList() { return items; } public void add(String newItem) { if(newItem == null) throw new IllegalArgumentException(); items.remove(newItem); items.add(0, newItem); } ... }
  • 68. Don't ever invite a vampire into your house, you silly boy. It renders you powerless.
  • 69. public class RecentlyUsedList { private List<String> items = new ArrayList<String>(); public int isEmpty() { return items.isEmpty() } public int size() { return items.size(); } public String get(int index) { return items.get(index); } public void add(String newItem) { if(newItem == null) throw new IllegalArgumentException(); items.remove(newItem); items.add(0, newItem); } ... }
  • 70. public class RecentlyUsedList { private List<String> items = new ArrayList<String>(); public int isEmpty() { return items.isEmpty() } public int size() { return items.size(); } public String get(int index) { return items.get(index); } public void add(String newItem) { if(newItem == null) throw new IllegalArgumentException(); items.remove(newItem); items.add(0, newItem); } ... }
  • 71. public class RecentlyUsedList { private List<String> items = new ArrayList<String>(); public int isEmpty() { return items.isEmpty() } public int size() { return items.size(); } public String get(int index) { return items.get(size() – index - 1); } public void add(String newItem) { if(newItem == null) throw new IllegalArgumentException(); items.remove(newItem); items.add(newItem); } ... }
  • 73. Do not use new in constructors.?
  • 74. It’s OK to use new in constructors.
  • 75. Do not use throw in constructors.?
  • 76. It’s OK to use throw in constructors.
  • 83. public final class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getDayInMonth() ... public void setYear(int newYear) ... public void setMonth(int newMonth) ... public void setDayInMonth(int newDayInMonth) ... ... }
  • 84. public final class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getWeekInYear() ... public int getDayInYear() ... public int getDayInMonth() ... public int getDayInWeek() ... public void setYear(int newYear) ... public void setMonth(int newMonth) ... public void setWeekInYear(int newWeek) ... public void setDayInYear(int newDayInYear) ... public void setDayInMonth(int newDayInMonth) ... public void setDayInWeek(int newDayInWeek) ... ... }
  • 85. When it is not necessary to change, it is necessary not to change. Lucius Cary
  • 86. public final class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getWeekInYear() ... public int getDayInYear() ... public int getDayInMonth() ... public int getDayInWeek() ... ... }
  • 87. public final class Date implements ... { ... public int year() ... public int month() ... public int weekInYear() ... public int dayInYear() ... public int dayInMonth() ... public int dayInWeek() ... ... }
  • 88. public final class Date implements ... { ... public int year() ... public Month month() ... public int weekInYear() ... public int dayInYear() ... public int dayInMonth() ... public DayInWeek dayInWeek() ... ... }
  • 89. Some people, when confronted with a problem, think, "I know, I'll use threads," and then two they hav erpoblesms. Ned Batchelder https://twitter.com/#!/nedbat/status/194873829825327104
  • 90. Mutable Immutable Unshared Shared Unshared mutable data needs no synchronisation Unshared immutable data needs no synchronisation Shared mutable data needs synchronisation Shared immutable data needs no synchronisation Synchronisation Quadrant
  • 93. 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?"
  • 95. public class RecentlyUsedList { ... public RecentlyUsedList() ... public boolean isEmpty() ... public int size() ... public String get(int index) ... public void add(String newItem) ... ... }
  • 96. public class RecentlyUsedListTest { @Test public void testConstructor() ... @Test public void testIsEmpty() ... @Test public void testSize() ... @Test public void testGet() ... @Test public void testAdd() ... ... }
  • 97. public class RecentlyUsedList_spec { public static class A_new_list { @Test public void is_empty()  } public static class An_empty_list { @Test public void retains_a_single_addition()  @Test public void retains_unique_additions_in_stack_order()  } public static 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()  } public static class Any_list { @Test public void rejects_addition_of_null_items()  @Test public void rejects_indexing_past_its_end()  @Test public void rejects_negative_indexing()  } }
  • 98. public class RecentlyUsedList_spec { public static class A_new_list { @Test public void is_empty()  } public static class An_empty_list { @Test public void retains_a_single_addition()  @Test public void retains_unique_additions_in_stack_order()  } public static 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()  } public static class Any_list { @Test public void rejects_addition_of_null_items()  @Test public void rejects_indexing_past_its_end()  @Test public void rejects_negative_indexing()  } }
  • 99. A test case should be just that: it should correspond to a single case.
  • 100. Style is the art of getting yourself out of the way, not putting yourself in it. David Hare