A podcast about development and design.
We do our best to be code-agnostic but we talk a lot about Rails, JavaScript, React, React Native, design, business and startups.
php/*
A podcast about development and design.
We do our best to be code-agnostic but we talk a lot about Rails, JavaScript, React, React Native, design, business and startups.
Copyright: © ¯_(ツ)_/¯
A weekly podcast about programming, development, and design through the lens of amazing books, chapter-by-chapter.
The view is an interpretation of the model. It doesn't need to be graphical. The controller is more of a coordination mechanism, and doesn't have to be related to any sort of input device.
JP: Use blackboards to coordinate disparate facts and agents, while maintaining independence and isolation among participants
John: The blackboard style of programming removes the need for so many interfaces, making for a more elegant and consistent system.
John: "Feed" concept
Seriously... just look how cool this is.
defmodule MyList do
def flatten([ [sub_head | sub_tail] | tail]) do
flatten(sub_head) ++ flatten(sub_tail) ++ flatten(tail)
end
def flatten([ head | tail]) do
flatten(head) ++ flatten(tail)
end
def flatten([]), do: []
def flatten(head), do: [head]
end
IO.inspect MyList.flatten [ 1, [ 2, 3, [ 4 ] ], 5, [ [ [ [ 6 ] ] ] ] ]
# [1, 2, 3, 4, 5, 6]
John: Welcome to Iteration: A weekly podcast about programming, development, and design through the lens of amazing books, chapter-by-chapter.
Quick update: Sketch Color Spaces
Today we'll be going through Chapter 5, "Bend or Break" - where we talk about writing flexible code. This is especially important for software engineers in a profession where things are constantly changing. (insert joke about JavaScript frameworks). We will largely focus on different ways we can decouple our code!
Life doesn't stand still. Neither can the code that we write. In order to keep up with today's near-frantic pace of change, we need to make every effort to write code that's as loose—as flexible—as possible.
Organize code into modules and limit interaction between them. If one module gets compromised and has to be replaced, the other modules should be able to carry on.
Avoid coupling by writing shy code and applying the law of Demeter
What is shy?
selection.getRecorder().getLocation().getTimeZone()Implement technology choices for an application as configuration options, not through integration or engineering
Program for the general case, and put the specifics outside the compiled code base
valid_send_daysExploit the concurrency in your user's workflow
This example was really good so I'm copying it from the book:
making a pina colada
1 open blender
2 open pina colada mix
3 put mix in blender
4 measure 1/2 cup white rum
5 pour in rum
6 add 2 cups of ice
7 close blender
8 liquefy for 2 mins
9 open blender
10 get glasses
11 get pink umbrellas
12 serve pina coladas
Think about how imperative this is. First do this... then do this...
BUT, think about what you can do concurrently: 1, 2, 4, 10, 11. These can happen all at the same time and up front. Next, 3, 5, and 6 can happen concurrently afterwards. These would be big optimizations
“Pragmatic Programmers code in defenses against their own mistakes.”
John: To me this means testing and never assuming the user is wrong.
https://github.com/egonSchiele/contracts.ruby
"You can think of contracts as assert on steroids"
This says that double expects a number and returns a number. Here's the full code:
require 'contracts'
class Example
include Contracts::Core
include Contracts::Builtin
Contract Num => Num
def double(x)
x * 2
end
end
puts Example.new.double("oops")
be strict in what you will accept before you begin, and promise as little as possible in return. Remember, if your contract indicates that you'll accept anything and promise the world in return, then you've got a lot of code to write!
What is a "correct" program?
“What is a correct program? One that does no more and no less than it claims to do. Documenting and verifying that claim is the heart of Design by Contract”
“It's much easier to find and diagnose the problem by crashing early, at the site of the problem.”
John: In ruby using rescue to aggressively just pushes the problem up. Not crashing but not working properly.
When your code discovers that something that was something to be impossible just happened, your program is no longer viable
A dead program normally does a lot less damage than a crippled one
"This application will never be used abroad, so why internationalize it?"
Let's not practice this kind of self-deception, particularly when coding
John: Write tests prove it won’t be used in a certain way.
try...catch - ask yourself: "will this code still run if I remove all of the exception handlers". if the answer is, "no" then maybe exceptions are being used in nonexceptional circumstancesJohn: Error and an exception are two different things. Very loosely: one is based on incorrect inputs the other is an error in a process.
Programs that use exceptions as part of their normal processing suffer from all the readability and maintainability problems of classic spaghetti code. These programs break encapsulation routines and their callers are more tighlting coupled via exception handling
John: Garbage collection. We are lucky as most major frameworks do garbage collection for us.
John: I currently have this problem with action-cable web-socket connections. I am opening them and not managing the closing of these connections well. So it’s leading to performance issues.
Email sending: make sure it delivered. Handle the exception, finish what you started!
Stubs/doubles vs mocks
Stub is simple fake object. It just makes sure test runs smoothly.
Mock is smarter stub. You verify Your test passes through it.
Good stack exchange link on this
JP: "what does your program think is going on": DON'T BLAME EXTERNAL FACTORS FIRST. It's probably your code haha!
John: why, when faced with a "surprising" failure, you must realize that one or more of your assumptions is wrong.
JP: "routine" code isn't infallible! did you test all of the edge cases?
I really like the debugging checklist so here it is:
John: Duplicate the problem in tests.
examples of text manipulation:
JP: Funny enough, Hunt and Thomas like using Ruby (and Perl) to quickly hack short scripts
John: I want to push more into this - Just barely experimenting with self-creating API docs. Even just things like in ruby: writing a rake task to pull out all your custom objects and methods to start docs and get a clear picture has been helpful for me.
passive vs active code generators
passive = run once to produce a result
active = run every time you need a result. results are then thrown away
JP: meta programming? code gen doesnt have to be meta
John: Refactoring methods to "Find common resources" based on "Model" name - Reducess code significantly.
Every craftsman starts his or her journey with a basic set of good quality tools
Discussion: What are your tools?
Tools become conduits from the craftsman's brain to the finished product - they have become extensions of his or her hands
Always be on the lookout for better ways of doing things
JP: plain text doesn't become obsolete - as opposed to binary. this seems obvious. this is mostly about readability
JP: you can do everything in the shell that you do using the GUI: launch apps, browsers; search files; touch, mkdir, rm -rf. basically i need to get better at this. touch newfile.rb is faster than right click > new file > newfile.rb > carriage return
JP: fuck IDE's, VIM all the way, baby!!! I no longer rely on auto complete and it's amazing. The editor is an extension to your hand
JP: the front end devs at my job don't check their files into git and it blows my mind.
JP: "it doesn't really matter whether the bug is your fault or someone else's. it is still your problem". suck it up!
JP: don't waste energy denying that a bug is possible. clearly, it is. just breathe
Picks
JP: I love doing this during "exploration" - careful not to use prototypes in prod 👀
John: prototype vs tracer bullet - Expectations: Remind them that you can build a great prototype of a new car out of balsa wood and duct tape, but you wouldn't try to drive it in rush-hour traffic! - Localhost with ngrok
JP: Remember to focus on domain problems and not petty implementation details
John: Let your code be english! - Let it reflect the way your team talks. execute_email_delivery_protical vs send_email
JP: Be deliberate and keep track... wording is key (i.e. specificity)
John: Reality - scope is a Moving target - Tracer code and testing helps make sure estimates are well thought out. Charge to estimate / mockup.
JP: Keep an open line of communication about expectations for scheduling
John: What to say when you are asked for an estimate "I'll get back to you" - Scope can be revised. Not just timeline.
Overview = combine ideas and processes
This chapter is truly about a "pragmatic" approach to development
Duplicated code arises differently:
we call these the "four i's"
"shortcuts make for long delays"
number 4 is a result of large teams - not having a --- dare I say --- a ubiquitous language
you need good communication to quell number 4
READ DOCS
Tip: Lean on code and programmatically generated things to prevent repeating yourself.
TWO OR MORE THINGS are orthogonal if changes in one do not affect any of the others
i.e. database code will be orthogonal to the UI. you can change the interface without affecting the database
driving stick shift is not orthogonal
helicopter controls are not orthogonal
bottom line: non-orthogonal systems are hard to maintain
You get two major benefits if you write orthogonal systems: increased productivity and reduced risk.
ways orthogonality can be applied to your work
if i dramatically change the requirements behind a particular function, how many modules are affected?
Toolkits and Libraries
Testing
An orthogonally designed and implemented system is easier to test. Because the interactions between the system's components are formalized and limited, more of the system testing can be performed at the individual module level. This is good news, because module level (or unit) testing is considerably easier to specify and perform than integration testing.
Reversability
Nothing is more dangerous than an idea if it's the only one you have.
Writing more orthogonal code allows you to more easily reverse changess or eb and flow with the needs of the project.
Bottom line: orthognality is about reduction of interdependency among system components
instead of carving decisions in stone, think of them mroe as being written in the sand at the beach. A big wave can come along and wipe them out at any time.
when firing a machine gun in the dark, you either:
Tracer ammunition (tracers) are bullets or cannon caliber projectiles that are built with a small pyrotechnic charge in their base. Ignited by the burning powder, the pyrotechnic composition burns very brightly, making the projectile visible to the naked eye. This enables the shooter to follow the projectile trajectory to make aiming corrections.
tracer code is not disposable. you write it for keeps. it contains all the error checking, structuring, documentation, and self-checking that any piece of production code has. it simply is not fully functional
Welcome to Iteration: a weekly podcast about programing, development and design through the lens of amazing books, chapter-by-chapter
by Andy Hunt and Dave Thomas
This book will help you become a better programmer
this book was written in freaking 1999! I was 7.
programming is a craft
"as a programmer, you are part listener, part advisor, part interpreter, and part dictator. you try to capture elusive requirements and find a way of expressing them so that a mere machine can do them justice. you try to document your work so that others can understand it, and you try to engineer your work so that others can build on it. What's more, you try to do all this against the relentless ticking of the project clock. you work small miracle every day"
"you shouldn't be welded to any particular technology, but have a broad enough background and experience base to allow you to choose good solutions in particular situations"
What makes a pragmatic programmer
Tips
"We who cut mere stones must always be envisioning cathedrals."
"great lawns need small amounts of daily care, and so do great programmers."
"1% better every day. 365% bettere every year"
Challenge
hmmmmm.... really gets you thinking
Software entropy - aka Broken window theory - aka software rot
This is a great metaphor:
One broken window, left unrepaired for any substantial length of time, instills in the inhabitants of the building a sense of abandonment - ... so another window gets broken. People start littering. graffiti appears.
"The three soldiers returning home from war were hungry. When they saw the village ahead their spirits lifted—they were sure the villagers would give them a meal. But when they got there, they found the doors locked and the windows closed. After many years of war, the villagers were short of food, and hoarded what they had. Undeterred, the soldiers boiled a pot of water and carefully placed three stones into it. The amazed villagers came out to watch. "This is stone soup," the soldiers explained.
"Is that all you put in it?" asked the villagers. "Absolutely—although some say it tastes even better with a few carrots...." A villager ran off, returning in no time with a basket of carrots from his hoard. A couple of minutes later, the villagers again asked "Is that it?" "Well," said the soldiers, "a couple of potatoes give it body." Off ran another villager."
(don't be the frog who gets boiled gradually)
There will always be tradeoffs. When to ship?
Great software today is often preferable to perfect software tomorrow. If you give your users something to play with early, their feedback will often lead you to a better eventual solution.
Challenges
GOALS - I LOVE this section.
It doesn't matter whether you ever use any of these technologies on a project, or even whether you put them on your resume. The process of learning will expand your thinking, opening you to new possibilities and new ways of doing things.
Don't get swayed by media hype. I'm looking at you create-react-app!
create-react-app is the best configuration free react setup. someone challenged me and said it's just the best marketedHaving the best ideas, the finest code, or the most pragmatic thinking is ultimately sterile unless you can communicate with other people. A good idea is an orphan without effective communication
these are great soft skills!