Uncle Bob Martin Profile picture
Software Craftsman
15 subscribers
Apr 7, 2023 12 tweets 2 min read
On: “preferring composition to inheritance”.

I first saw this recommendation in the mid 90s in the Design Patterns book (or possibly in the materials that surrounded it). I believe it was espoused most vocally by John Vlissides.

🧵 First we need to remember that this was during a period when the implications of inheritance were not well understood. Inheritance was a relatively new language feature that the vast majority of programmers had no experience with.
Nov 22, 2022 6 tweets 1 min read
I encountered this thread recently. Usually I ignore statements like this; but not this time. …🧵 The author’s primary point is that all the design patterns in the GOF book can be replaced with functional programming techniques like first class functions and function composition.
Sep 7, 2022 4 tweets 1 min read
That political divisions have entered the software community is one of the saddest things I have experienced in my long and storied career. That programmers who once respected each other professionally have now become unwilling, or socially unable, to display that respect due to a difference of political opinion is a disease that causes great harm to our industry and society.
Mar 20, 2021 6 tweets 1 min read
There are some threads I’ve been following that suggest that the best design approach is just simplicity. I think that’s fine. Designs should be simple. But what exactly is simplicity? You may find Rich Hickey’s talk illuminating.

The short answer is: Simplicity is not easy. It takes time and thought to make something simple. And it takes something else. It takes principles.
Sep 21, 2020 5 tweets 1 min read
When is inheritance preferable to composition?

First we need to recognize that inheritance is just a special form of composition. Derived classes are composed of their base classes.

However, the coupling of derived to base is much tighter than composite to component. The reason for this tight coupling is that inheritance is intimately tied to implementation whereas a component can be abstracted. The derived class IS an instance of the base class. The composite is not an instance of the component.
Jun 11, 2020 7 tweets 1 min read
Years ago I was a student of Jiu Jitsu. As we learned and gained belt ranks, we also passed through three different fundamental areas of technique. Shodan, Nidan, and Sandan. Each of these techniques spawned dozens of maneuvers, each of which had to be mastered. Once the entire set was mastered, then the student could graduate to the next fundamental technique.
Jun 11, 2020 5 tweets 1 min read
Social distancing, masks, sanitation, and general precaution are still necessary. As businesses open back up and we begin to go out and engage more with each other, the virus will increase its spread. We see this in Phoenix right now. Several counties in California, and LA in particular have been experiencing steady growth for quite some time.
Feb 22, 2020 9 tweets 2 min read
Are objects more about behavior or data? From the outside looking in the data are hidden and the behaviors are exposed. We see inputs transformed into outputs; but see none of the data sequestered within; nor do we know where or how that data are stored. Are database tables more about behavior or data? They are simple data structures. From the outside looking in the data are exposed and no behavior is visible or even implied.
Jan 13, 2020 5 tweets 1 min read
I have one major gripe about clojure. Lazy evaluation, as powerful and elegant as it is, can be a debugging nightmare. Code that looks entirely correct can fail for obscure and puzzling reasons; if you don’t understand the deep underlying mechanisms. Lazy evaluation can change the order in which you _think_ things are done. If you have any time dependent side effects this ordering issue can be confounding.
Oct 23, 2019 11 tweets 2 min read
My recent tweet about the “cancel culture” elicited the response I expected. In that tweet I neither attacked nor defended any individual. Rather, I called out a behavior that in my opinion is toxic. Specifically the twitter “pile-on”. Generally speaking I think decorum demands that we call out bad behaviors and opinions, and avoid pointing the finger at particular individuals. Discussions are better than accusations.
Aug 5, 2019 4 tweets 1 min read
We use the term “unit” test to describe the tests we write while using TDD. But that name is unfortunate because it has no good definition. We don’t know what a unit really is.

The tests we write in TDD are written by programmers and for programmers. For this reason they are sometimes called programmer tests.

@GeePawHill has called them microtests. This is a good name because TDD tests are usually very small and cover a tiny scope.

But each of these names has flaws.
Aug 4, 2019 8 tweets 1 min read
Accounting involves the separation and partitioning of accounts and transactions in order to reduce the coupling between and increase the cohesion within those accounts. This is a highly creative discipline that depends upon systems thinking. Accountants fill those accounts with minute details, each necessary, each different, each a part of a much larger whole. The management of all that detail is a daunting task requiring intense discipline.
Jun 9, 2019 13 tweets 2 min read
Imagine a system written in Eiffel with perfect use of ‘design by contract’ so that every function is surrounded by preconditions and postconditions. All arguments are checked, and all return values are checked. Imagine this is true for every pathway through the system. Imagine that the system is entirely closed within ‘design by contract’. Every output is checked. Every input is checked.
Jun 7, 2019 8 tweets 2 min read
The Halting Problem:

It is common for folks to toss off “the Halting Problem” as a kind of informal way of saying that algorithms cannot be proven to be correct. But this is a misunderstanding. Indeed, Dijkstra showed that it was possible to prove a large class of algorithms correct. That class of algorithms did not employ uncontainable GOTOs; but instead transferred control through the common structures of sequence, selection, and iteration.
Jun 5, 2019 4 tweets 1 min read
When I do TDD in Clojure I like to use the clojure/spec library. This gives me the illusion of static type checking in a dynamically typed language. Of course this means that I am writing more tests than I would have to write if I were using static typing. However, as the modules in the system approach maturity, and all their behavioral tests are passing, the spec tests become relatively useless. They can be disabled without losing any test coverage.
Jun 4, 2019 9 tweets 2 min read
Software is more like science than mathematics. Mathematical expressions are provable, scientific theories are merely demonstrable. Math is deductive. Science is empirical.

Software is empirical. We demonstrate, but do not prove, correctness. Static typing is an attempt to make software more mathematical. Type correctness is deductive and provable. However, type correctness does not imply behavioral correctness. Even when fully type correct the behavior must be demonstrated empirically.
Sep 28, 2018 5 tweets 1 min read
I do not hate Donald Trump. I do not love Donald Trump. If that is a problem for you, you should unfollow me now. I support the good things that Donald Trump has done. I resist the bad things that Donald Trump has done. As an honorable and decent human being I think Barack Obama is Donald Trump’s superior; in just about every way. As ceremonial leader of the country, I think Obama was much better than Trump. As chief executive I think Trump has been far superior to Obama.
Aug 3, 2018 14 tweets 3 min read
I spent the last few days fixing bugs in, and refactoring, a relatively small function that added a new feature to an existing system. It was a horror scene. The previous programmer (who released the code and then quit) had not thought the problem through very carefully. So there were a number of logical holes that were found by customers within hours of the initial release.

As I examined the code I saw that there were no tests anywhere. There was no way for me to probe the behavior of the code without using the GUI.
Jun 30, 2018 10 tweets 2 min read
@eyydontatme Again, thank you for the considered response. Responses like that are much better than fire and forget tweets. I’m not going to address the media’s use of Nazi-ism here. I’ve beaten that horse to death. The immigration issue is both simple and complicated. The simple part is that people, and especially, children are suffering. It’s horrific. You made that case very well.
Jun 30, 2018 6 tweets 1 min read
What can we learn from the latest fracas?

1. There are small number of people who are so polarized on their positions that they are willing to destroy you if you make a statement that is not perfectly aligned with their views. 2. These people will be loud, insistent, and utterly irrational. They will make the most absurd claims and scream them as absolute truths. Their goal is to create a moral blockade. A gale of lies and misdirections in order to keep all opposing views at bay.
Jun 23, 2018 5 tweets 1 min read
Programs are made up of Dijkstra’s three structures: Sequence, Selection, and Iteration. Each of these is based upon jumps. Sequential statements jump from the end of the first to be beginning of the second. Selection statements (ifs) jump to the code selected by the predicate and then to the statement after the selection. Loops jump from the end of the loop back to the predicate; and then to the statement after the loop.