• Stars
    star
    1,275
  • Rank 35,564 (Top 0.8 %)
  • Language
  • Created over 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tidbits of developer best practices from around the web

Programming Best Practices Tidbits

A Collection of quotes and paraphrases for developers from around the web.

Use your own judgment in their application.


Never build Large Apps

The secret to building large apps is never build large apps. Break your applications into small pieces. Then, assemble those testable, bite-sized pieces into your big application.

โ€“ Justin Meyer, author JavaScript MVC

Source

Quality Matters

When I hear "JUST BANG OUT CODE THAT WORKS" I think of all the apps I don't use anymore because they gradually lost the ability to iterate.

โ€“ Avdi Grimm

Source

Don't Write Code

Donโ€™t write code (write new code only when everything else fails) is the single most important lesson every developer needs to learn. The amount of duplicate, crappy code (across projects) that exists today is overwhelming. In a lot of cases developers donโ€™t even bother to look around. They just want to write code.

Source

Reducing the amount of code in your product should be a goal.

"I hate code, and I want as little of it as possible in our product." โ€“ Jack Diederich

Source

Keep Lean Dependencies

The old adage "don't reinvent the wheel" doesn't apply when the wheel comes attached to a locomotive engine.

Source

Don't expect a rewrite to do better than the original

It's important to remember that when you start from scratch there is absolutely no reason to believe that you are going to do a better job than you did the first time. First of all, you probably don't even have the same programming team that worked on version one, so you don't actually have "more experience". You're just going to make most of the old mistakes again, and introduce some new problems that weren't in the original version.

โ€“ Joel Spolsky

Source

Stop Writing Classes

The signature of "this shouldn't be a class" is when the class has two methods, and one of them is the constructor. Any time you see these signs, you probably should have just written a function.

โ€“ Jack Diederich

Source

Forget new features, Just do the same stuff better.

The problem: it is too easy to lose sight of what users often care about more, which is the performance and usability of the applications and features they already use most often.

โ€“ Tim Anderson

Source

Reinvent the Wheel

Inventing your own wheels gives you a deep appreciation and understanding of how wheels work and what makes a good one.

Source

Don't do hard things, do easy things.

  • Simple is better than complex.
  • Complex is better than complicated.
  • Flat is better than nested.
  • Readability counts.
  • If the implementation is hard to explain, it's a bad idea.
  • If the implementation is easy to explain, it may be a good idea.

โ€“ The Zen of Python

Source

Shortlist cut from Jack Diederich's "Stop Writing Classes" talk

Rewriting > Refactoring

If you are changing more than 25% of a class or method, consider simply rewriting it. You will write the code more cleanly.

Refactoring > Rewriting

Common Excuses For A Software Rewrite

  1. The Code Sucks
  2. "We're So Much Smarter Now"
  3. We Picked The Wrong Platform/Language

Why Rewriting Is (Almost) Never A Good Idea

  1. It Always Takes Longer Than You Expect
  2. Markets Change
  3. Existing Customers Become Frustrated
  4. Refactoring Can Cleanup The Code
  5. You Don't Control The Rewrite, It Controls You

Source

Accept that you have no idea how this will grow

The key is to acknowledge from the start that you have no idea how this will grow. When you accept that you don't know everything, you begin to design the system defensively... You should spend most of your time thinking about interfaces rather than implementations.

โ€“ Nicholas Zakas, author "High-performance JavaScript websites"

Source

Acknowledgement to Addy Osmani

Avoid Code Smells

Source
Source

Write unit tests.

Every programmer knows they should write tests for their code. Few do. The universal response to "Why not?" is "I'm in too much of a hurry." This quickly becomes a vicious cycle- the more pressure you feel, the fewer tests you write. The fewer tests you write, the less productive you are and the less stable your code becomes. The less productive and accurate you are, the more pressure you feel. Programmers burn out from just such cycles. Breaking out requires an outside influence. We found the outside influence we needed in a simple testing framework that lets us do a little testing that makes a big difference.

Source

[Without unit tests] You're not refactoring, you're just changing shit. โ€” Hamlet D'Arcy

To write effective unit tests, you need to write testable code

Flaw #1: Constructor does Real Work

Warning Signs

  • new keyword in a constructor or at field declaration
  • Static method calls in a constructor or at field declaration
  • Anything more than field assignment in constructors
  • Object not fully initialized after the constructor finishes (watch out for initialize methods)
  • Control flow (conditional or looping logic) in a constructor
  • Code does complex object graph construction inside a constructor rather than using a factory or builder
  • Adding or using an initialization block

Flaw #2: Digging into Collaborators

Warning Signs

  • Objects are passed in but never used directly (only used to get access to other objects)
  • Law of Demeter violation: method call chain walks an object graph with more than one dot (.)
  • Suspicious names: context, environment, principal, container, or manager

Flaw #3: Brittle Global State & Singletons

Warning Signs

  • Adding or using singletons
  • Adding or using static fields or static methods
  • Adding or using static initialization blocks
  • Adding or using registries
  • Adding or using service locators

Flaw #4: Class Does Too Much

Warning Signs

  • Summing up what the class does includes the word โ€œandโ€
  • Class would be challenging for new team members to read and quickly โ€œget itโ€
  • Class has fields that are only used in some methods
  • Class has static methods that only operate on parameters

Source

Source

Test-Driven Development with Inversion of Control.

Even if you aren't testing your code, you should write testable code. IoC enables testable code. Inject test-friendly dependencies or mocks at test time, to isolate the unit-under-test.

Avoid mixing Object Creation with Application Logic

Source

Avoid creating technical debt.

"Although immature code may work fine and be completely acceptable to the customer, excess quantities will make a program unmasterable, leading to extreme specialization of programmers and finally an inflexible product. ... A little debt speeds development so long as it is paid back promptly with a rewrite ... Every minute spent on not-quite-right code counts as interest on that debt. Entire engineering organizations can be brought to a stand-still under the debt load of an unconsolidated implementation ...โ€ (Emphasis mine)

Source

Premature optimisation is the root of all evil

"Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%."

Source

Plan, Plan, Plan.

It is much cheaper to do it correctly the first time than to redo it later on. The sooner a problem is identified and fixed, the cheaper it is to do so.

"The general who wins a battle makes many calculations in his temple before the battle is fought. The general who loses a battle makes but few calculations beforehand. Thus do many calculations lead to victory, and few calculations to defeat: how much more no calculation at all! It is by attention to this point that I can foresee who is likely to win or lose."

"Plans are worthless, planning is invaluable."- Sir Winston Churchill

For this to work, everyone involved has to listen, everyone has to be open, everyone has to be responsive. Or we could keep flailing away with the fucked up attitude that โ€œit has to be this wayโ€ because the sacred project plan says itโ€™s this way. Because that really is a lot of fun, isnโ€™t it?

Programming is also Teaching your team

... a team of mediocre, inexperienced coders who work together and write for the benefit of the team has the capability to become a great team, and they can take that learning approach to create other great teams. It all comes down to whether the team sees its work as simply writing code... or writing with the goal of both code and learning" (Emphasis mine)

โ€“ Reginald Braithwaite

Source

"The most important element of successful software development is learning."

When the entire team meets a certain standard for competence, there is a very large learning surface exposed and the team is able to absorb more information.

Source

"...there are lies, damned lies, and software development estimates."

Software can only partially be designed in advance. ... requirements suffer from observation, that the act of building software causes the requirements to change. ...technical factors cannot be perfectly understood, that only the act of trying to build something with specific components will reveal all of the gotchas and who-knews associated with a chosen technology strategy. ...software design is an iterative process, starting with a best guess that is continually refined with experience. the normal case for software projects is that tasks are rarely completed exactly as estimated, but that as a project progresses, the aggregate variance from estimates falls.

Source

Nobody likes to look stupid. If youโ€™re a professional and someone puts you on the spot to answer โ€œhow long will this take?โ€ itโ€™s only human to want to provide an answer. Whether you call it professional pride or ego, itโ€™s a powerful driver. Good IT workers really donโ€™t like saying โ€œI donโ€™t know.โ€ If they say it, they probably mean it. So stop pushing for a definitive answer when one doesnโ€™t exist.Itโ€™s perfectly reasonable to want some sort of plan up front. Iโ€™m actually one of those funny types who believe up front planning is a necessity. So long as everyone understands an estimate is just that: an estimate. You learn as you go along and discover more detail. So you revise the estimate accordingly.

The mess we're in

โ€“ Joe Armstrong, author Erlang

Your architecture should resemble your domain

So what does the architecture of your application scream? When you look at the top level directory structure, and the source files in the highest level package; do they scream: health care system, or accounting system, or inventory management system? Or do they scream: rails, or spring/hibernate, or asp?

Architectures should not be supplied by frameworks. Frameworks are tools to be used, not architectures to be conformed to. If your architecture is based on frameworks, then it cannot be based on your use cases.

โ€“ Uncle Bob Martin, "Screaming Architecture"

Source

Follow the principles of X

  • Do not add new functionality unless you know of some real application that will require it.
  • It is as important to decide what a system is not as to decide what it is. Do not serve all the world's needs; rather, make the system extensible so that additional needs can be met in an upwardly compatible fashion.
  • The only thing worse than generalizing from one example is generalizing from no examples at all.
  • If a problem is not completely understood, it is probably best to provide no solution at all.
  • If you can get 90 percent of the desired effect for 10 percent of the work, use the simpler solution. (See also Worse is better.)
  • Isolate complexity as much as possible.
  • Provide mechanism rather than policy. In particular, place user interface policy in the clients' hands.

Source

Follow the principles of Unix

"This is the Unix philosophy: Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface" - Doug McIlroy, quoted in A Quarter Century of Unix [Salus]. Addison-Wesley. 1994. ISBN 0-201-54777-5.

  • Rule of Modularity: Write simple parts connected by clean interfaces.
  • Rule of Clarity: Clarity is better than cleverness.
  • Rule of Composition: Design programs to be connected to other programs.
  • Rule of Separation: Separate policy from mechanism; separate interfaces from engines.
  • Rule of Simplicity: Design for simplicity; add complexity only where you must.
  • Rule of Parsimony: Write a big program only when it is clear by demonstration that nothing else will do.
  • Rule of Transparency: Design for visibility to make inspection and debugging easier.
  • Rule of Robustness: Robustness is the child of transparency and simplicity.
  • Rule of Representation: Fold knowledge into data so program logic can be stupid and robust.
  • Rule of Least Surprise: In interface design, always do the least surprising thing.
  • Rule of Silence: When a program has nothing surprising to say, it should say nothing.
  • Rule of Repair: When you must fail, fail noisily and as soon as possible.
  • Rule of Economy: Programmer time is expensive; conserve it in preference to machine time.
  • Rule of Generation: Avoid hand-hacking; write programs to write programs when you can.
  • Rule of Optimization: Prototype before polishing. Get it working before you optimize it.
  • Rule of Diversity: Distrust all claims for โ€œone true wayโ€.
  • Rule of Extensibility: Design for the future, because it will be here sooner than you think.

โ€“ Eric S. Raymond, "The Art of Unix Programming"

Source

Bitdeli Badge

More Repositories

1

functional-javascript-workshop

A functional javascript workshop. No libraries required (i.e. no underscore), just ES5.
JavaScript
2,049
star
2

keycode

Convert between keyboard keycodes and keynames and vice versa.
JavaScript
452
star
3

columnify

Create text-based columns suitable for console output. Supports cell wrapping.
JavaScript
428
star
4

linklocal

Install local dependencies as symlinks.
JavaScript
349
star
5

npm-run

Run locally-installed node module executables.
JavaScript
183
star
6

polyfill-webcomponents

(deprecated) Browserify-compatible web-component polyfills, courtesy of Polymer
JavaScript
119
star
7

pkgfiles

Sanity check which files you are and aren't about to publish to npm
JavaScript
82
star
8

npm-which

Locate a program or locally installed node module's executable
JavaScript
78
star
9

offset

Get offset of an element within the document
JavaScript
59
star
10

wcwidth

Port of C's wcwidth() and wcswidth()
JavaScript
53
star
11

npm-path

Get a PATH containing locally installed module executables.
JavaScript
49
star
12

colornames

Map color names to HEX color values
JavaScript
45
star
13

react

Emit change events whenever object changes. Compatible with component/reactive.
JavaScript
41
star
14

sift

Fast String Distance (SIFT) Algorithm
JavaScript
40
star
15

npm3

Use npm v3 alongside your currently installed npm.
JavaScript
34
star
16

pkgcount

Produce a report on number of duplicate packages in node_modules.
JavaScript
29
star
17

scroll-position

Fire events when scrolling over dom elements
JavaScript
28
star
18

next-tick

process.nextTick for browser
JavaScript
25
star
19

robotlegs-utilities-UndoableCommand

Undoable Command Classes for Robotlegs Framework
JavaScript
24
star
20

npm-tutor

npm tutor for nodeconf 2014
JavaScript
23
star
21

saltmine

Arbitrary computation on the GPU using WebGL.
JavaScript
22
star
22

mdm-tunnel

A tunnel for getting behind NATs
JavaScript
20
star
23

cruft

Delete cruft from npm packages
JavaScript
19
star
24

nim

Command-line tool for inspecting node library objects, function implementations and listing properties โ€“ with syntax highlighting.
JavaScript
19
star
25

adventure-map

Simple exercise loader & generators for substack/adventure.
JavaScript
19
star
26

tojson-loader

WebPack Loader. Generate JSON assets at build-time.
JavaScript
18
star
27

css-path

Get CSS path to an element.
JavaScript
18
star
28

chimes

`Array.prototype` iteration methods for any iterator.
JavaScript
18
star
29

to-factory

Convert ES6 classes into factory functions so they can be called with or without new.
JavaScript
18
star
30

graphs

An intuitive data structure for graphs, implemented using ES6 data structures.
JavaScript
17
star
31

canvas-noise

Generate noise on a canvas.
JavaScript
16
star
32

serializerr

Convert Errors & Objects into an easily-serialized vanilla Object.
JavaScript
15
star
33

osi-licenses-full

All OSI-approved licenses as markdown
JavaScript
15
star
34

split-object

Work with Objects using built-in functional Array methods.
JavaScript
14
star
35

assertf

assert with printf message formatting
JavaScript
14
star
36

pkgrep

Powerful CLI tool to find, filter & format package data in node_modules.
JavaScript
13
star
37

npm-next

Wraps the latest unstable version of npm with different name so you can test alongside stable npm.
JavaScript
12
star
38

pkill

Convenience wrapper around `pkill(1)`
JavaScript
12
star
39

async-compose

Compose multiple async functions together to operate on a result.
JavaScript
11
star
40

voxel-real-physics

"Real" physics for VoxelJS with CANNON.JS
JavaScript
11
star
41

node-webhooks

easily create webhooks
JavaScript
10
star
42

scriptloader

Absurdly simple on-demand script loader.
JavaScript
10
star
43

protochain

Get the prototype chain of an object or primitive as an Array.
JavaScript
9
star
44

get

Create functions for use with map, reduce, filter, etc. that get object properties without need for anonymous wrappers.
JavaScript
9
star
45

color-convert

Convert colors between RGB, HSL & HSV.
JavaScript
9
star
46

express-koans

WIP Express 3 Koans
JavaScript
9
star
47

til

Today I learned
8
star
48

file-uploader

Programmatic multipart file uploads
JavaScript
8
star
49

enode

Easily harness the power of DNode/Upnode
JavaScript
8
star
50

beforefn

Execute a function before a function.
JavaScript
8
star
51

afterfn

Invoke a function after a function.
JavaScript
7
star
52

neuquant

NeuQuant Neural-Net Quantization Algorithm
JavaScript
7
star
53

guardfn

Conditionally execute a function
JavaScript
7
star
54

voxel-merge

Merge voxel chunks into convex volumes.
JavaScript
7
star
55

to-array

Convert an array-like object into an Array.
JavaScript
7
star
56

installed

Read all the installed packages in a folder, and produce an Array of all the data.
JavaScript
7
star
57

pkgresolve

Resolve a dependency from within the context of another package.
JavaScript
6
star
58

stitchup

Command-line stitchjs. Easily package and minify Javascript & Coffeescript CommonJS modules. Individual modules can be imported in the browser via require()
CoffeeScript
6
star
59

midi-experiment

JavaScript
6
star
60

assert

assert module ported from Node.JS for use as a component in the browser.
JavaScript
6
star
61

xpath

XPath utilities extracted from Firebug.
JavaScript
6
star
62

grunt-ember

Collate Ember templates into a single file
JavaScript
6
star
63

candlelightproject

Android IPv6 Geo-Location Based Wireless Mesh Network
Java
6
star
64

opengl-es2-docset

Dash docset for OpenGL ES 2.0 (i.e. webgl)
HTML
5
star
65

element-collection

Provide enumerable methods (find/select/filter) to collections of DOM Elements
JavaScript
5
star
66

ordered-set

A performant ES6 Set subclass that defines custom iteration order.
JavaScript
5
star
67

fnfn

Add before/after/around/guard functions to an API.
JavaScript
5
star
68

statement

A State Machine. Under Construction.
JavaScript
5
star
69

element-selector

Use mouse to select elements on the screen
JavaScript
4
star
70

npm-fresh

Keep your npm cache fresh.
JavaScript
4
star
71

cellutron

My first attempt at a game. Top down 'shooter' style. Pure AS3. Uses box2d physics, TweenMax for tweening & Flint for some particles.
ActionScript
4
star
72

npm-prev

Wraps previous stable version of npm so you can run it alongside other npm versions
JavaScript
4
star
73

candlelight

Android Mesh Network
3
star
74

silk-app-examples

Gregfroese's Silk Example Components
PHP
3
star
75

pipe-graph

Generate graphs of your streams.
JavaScript
3
star
76

overshadow-listeners

Add an event listener before existing listeners.
JavaScript
3
star
77

signalfn

Simple signalling
JavaScript
3
star
78

es5-workshop

Introduction to ES5 methods.
JavaScript
3
star
79

slow-install

An npm package that's slow to install. Slowness is configurable.
JavaScript
2
star
80

get-descriptor

Prototype-aware Object.getOwnPropertyDescriptor
JavaScript
2
star
81

eventsource-stream

Stream events to the browser as server-sent events.
JavaScript
2
star
82

bin-path

Get paths to module executables
JavaScript
2
star
83

node-xmlrpc-multicall

system.multicall for node-xmlrpc
JavaScript
2
star
84

attribute-binding

Bind to incoming data via attributes on your custom elements.
JavaScript
2
star
85

component-server

Easily serve local components as dependencies.
JavaScript
2
star
86

statemachine

A State Machine. Under Construction.
JavaScript
2
star
87

xpath2css

Convert simple xpaths to CSS selectors.
JavaScript
2
star
88

namefn

Rename a function.
JavaScript
2
star
89

lzw

LZW Encoder
JavaScript
2
star
90

component-badge

Generate component badges. WIP
JavaScript
2
star
91

backbone-events

Backbone.Events API as a component
JavaScript
2
star
92

browserify-slides

SingaporeJS 17 Feb 2014
JavaScript
2
star
93

component-dashdoc

Generate a Dash docset for published components.
JavaScript
2
star
94

tapef

Tape API with Mocha's error output. A hack.
JavaScript
2
star
95

switchstream

switch between output streams. e.g. a filter that pipes valid & invalid data to different streams
JavaScript
2
star
96

dom-support

Component to test browser feature support.
JavaScript
2
star
97

pincushion

JavaScript
2
star
98

expressions

Grab bag of template binding expressions.
JavaScript
2
star
99

overlay

Generate overlays over DOM elements.
JavaScript
2
star
100

npm-home

Chrome Extension. Redirects to a package's github page from npm.org. Simulates original behaviour of `npm home`.
JavaScript
2
star