Monday, October 31, 2022

Books I read (January - October 2022)

January
- Elemental Design Patterns, Jason McC. Smith
- Antipatterns: Refactoring Software, Architectures, and Projects in Crisis, William J. Brown, Raphael C. Malveau, Hays W. "Skip" McCormick
- The Courage of Hopelessness: Chronicles of a Year of Acting Dangerously, Slavoj Žižek
- Get Your Hands Dirty on Clean Architecture: A hands-on guide to creating clean web applications with code examples in Java, Tom Hombergs
- Strangers on a Train, Patricia Highsmith
- Brothers in Arms, Lois McMaster Bujold
- The Great Mental Models: General Thinking Concepts, Shane Parrish, Rhiannon Beaubien

February
- Invicto: Logra más, sufre menos, Marcos Vázquez
- El rumor del oleaje (潮騒), Yukio Mishima
- Mirror Dance, Lois McMaster Bujold
- Memories, Lois McMaster Bujold
- The Pride of Chanur, C.J. Cherryh
- All Systems Red, Martha Wells
- The Culture of the New Capitalism, Richard Sennett

March
- Komarr, Lois McMaster Bujold
- Universidad para asesinos (Σεμινάρια φονικής γραφής), Petros Markaris
- Sobre héroes y tumbas, Ernesto Sabato
- Continuous Delivery, Jez Humble, David Farley

April
- Java by Comparison: Become a Java Craftsman in 70 Examples, Simon Harrer, Jörg Lenhard, Linus Dietz
- A Civil Campaign, Lois McMaster Bujold
- Indistractable: How to Control Your Attention and Choose Your Life, Nir Eyal
- The Long Way to a Small, Angry Planet, Becky Chambers
- Winterfair Gifts, Lois McMaster Bujold
- Queenie, Candice Carty-Williams
- The Extraordinary and Unusual Adventures of Horatio Lyle, Catherine Webb
- The How of Happiness: A Scientific Approach to Getting the Life You Want, Sonja Lyubomirsky
- Diplomatic Immunity, Lois McMaster Bujold

May
- A Closed and Common Orbit, Becky Chambers
- Captain Vorpatril's Alliance, Lois McMaster Bujold
- The Flowers of Vashnoi, Lois McMaster Bujold
- Design Patterns Explained: A New Perspective on Object-Oriented Design, Alan Shalloway, James R. Trott
- Writing Maintainable Unit Tests, Jan Van Ryswyck
- Amongst our weapons, Ben Aaronovitch
- Cryoburn, Lois McMaster Bujold
- Gentleman Jole and The Red Queen, Lois McMaster Bujold
- Batman: Year One, Frank Miller, David Mazzucchelli

June
- Modern Software Engineering: Doing What Works to Build Better Software Faster, David Farley
- Accelerate: The Science of Lean Software and DevOps: Building and Scaling High Performing Technology Organizations, Gene Kim, Jez Humble, Nicole Forsgren
- Records of a spaceborn few, Becky Chambers
- Refactoring for Software Design Smells: Managing Technical Debt, Ganesh Samarthyam, Girish Suryanarayana, Tushar Sharma
- Free fall, Lois McMaster Bujold
- Fundamentals of Software Architecture: An Engineering Approach, Mark Richards, Neal Ford
- The Galaxy, and the Ground Within, Becky Chambers
- Technical Agile Coaching with the Samman Method, Emily Bache
- Shards of honor, Lois McMaster Bujold

July
- Barrayar, Lois McMaster Bujold
- La muerte de Ulises (Τριηµερία), Petros Markaris
- Building Evolutionary Architectures: Support Constant Change, Neal Ford, Rebecca Parsons and Patrick Kua
- Tinker Tailor Soldier Spy, John le Carré
- The calculating stars, Mary Robinette Kowal
- Design It! : Pragmatic Programmers: From Programmer to Software Architect, Michael Keeling

August
- Effective Software Testing: A developer's guide, Maurício Aniche
- Refactoring: Improving the Design of Existing Code (2nd Edition), Martin Fowler
- He, she and it, Marge Piercy
- Prefactoring, Ken Pugh
- Drive: The Surprising Truth About What Motivates Us, Daniel H. Pink
- The fated sky, Mary Robinette Kowal
- The relentless moon, Mary Robinette Kowal
- Otra vida por vivir (Μια ζωή ακόμα), Theodor Kallifatides (2nd time)
- Five Lines of Code: How and when to refactor, Christian Clausen
- The Corrosion of Character: The Personal Consequences of Work in the New Capitalism, Richard Sennett
- Refactoring Workbook, William C. Wake (2nd time)
- Verdades a la cara: Recuerdos de los años salvajes, Pablo Iglesias

September
- Ética para inversores (Ο φόνος είναι χρήμα), Petros Márkaris
- The Honourable Schoolboy, John le Carré
- Autumn Quail (السمان والخريف), Naguib Mahfouz

October
- Transitions: Making Sense of Life's Changes, William Bridges
- El jinete polaco, Antonio Muñoz Molina
- The Influential Mind: What the Brain Reveals About Our Power to Change Others, Tali Sharot
- Self-Compassion: The Proven Power of Being Kind to Yourself, Kristin Neff
- Refactoring at Scale, Maude Lemaire
- Smiley's People, John le Carré

Saturday, October 1, 2022

Books I read (January - September 2022)

January
- Elemental Design Patterns, Jason McC. Smith
- Antipatterns: Refactoring Software, Architectures, and Projects in Crisis, William J. Brown, Raphael C. Malveau, Hays W. "Skip" McCormick
- The Courage of Hopelessness: Chronicles of a Year of Acting Dangerously, Slavoj Žižek
- Get Your Hands Dirty on Clean Architecture: A hands-on guide to creating clean web applications with code examples in Java, Tom Hombergs
- Strangers on a Train, Patricia Highsmith
- Brothers in Arms, Lois McMaster Bujold
- The Great Mental Models: General Thinking Concepts, Shane Parrish, Rhiannon Beaubien

February
- Invicto: Logra más, sufre menos, Marcos Vázquez
- El rumor del oleaje (潮騒), Yukio Mishima
- Mirror Dance, Lois McMaster Bujold
- Memories, Lois McMaster Bujold
- The Pride of Chanur, C.J. Cherryh
- All Systems Red, Martha Wells
- The Culture of the New Capitalism, Richard Sennett

March
- Komarr, Lois McMaster Bujold
- Universidad para asesinos (Σεμινάρια φονικής γραφής), Petros Markaris
- Sobre héroes y tumbas, Ernesto Sabato
- Continuous Delivery, Jez Humble, David Farley

April
- Java by Comparison: Become a Java Craftsman in 70 Examples, Simon Harrer, Jörg Lenhard, Linus Dietz
- A Civil Campaign, Lois McMaster Bujold
- Indistractable: How to Control Your Attention and Choose Your Life, Nir Eyal
- The Long Way to a Small, Angry Planet, Becky Chambers
- Winterfair Gifts, Lois McMaster Bujold
- Queenie, Candice Carty-Williams
- The Extraordinary and Unusual Adventures of Horatio Lyle, Catherine Webb
- The How of Happiness: A Scientific Approach to Getting the Life You Want, Sonja Lyubomirsky
- Diplomatic Immunity, Lois McMaster Bujold

May
- A Closed and Common Orbit, Becky Chambers
- Captain Vorpatril's Alliance, Lois McMaster Bujold
- The Flowers of Vashnoi, Lois McMaster Bujold
- Design Patterns Explained: A New Perspective on Object-Oriented Design, Alan Shalloway, James R. Trott
- Writing Maintainable Unit Tests, Jan Van Ryswyck
- Amongst our weapons, Ben Aaronovitch
- Cryoburn, Lois McMaster Bujold
- Gentleman Jole and The Red Queen, Lois McMaster Bujold
- Batman: Year One, Frank Miller, David Mazzucchelli

June
- Modern Software Engineering: Doing What Works to Build Better Software Faster, David Farley
- Accelerate: The Science of Lean Software and DevOps: Building and Scaling High Performing Technology Organizations, Gene Kim, Jez Humble, Nicole Forsgren
- Records of a spaceborn few, Becky Chambers
- Refactoring for Software Design Smells: Managing Technical Debt, Ganesh Samarthyam, Girish Suryanarayana, Tushar Sharma
- Free fall, Lois McMaster Bujold
- Fundamentals of Software Architecture: An Engineering Approach, Mark Richards, Neal Ford
- The Galaxy, and the Ground Within, Becky Chambers
- Technical Agile Coaching with the Samman Method, Emily Bache
- Shards of honor, Lois McMaster Bujold

July
- Barrayar, Lois McMaster Bujold
- La muerte de Ulises (Τριηµερία), Petros Markaris
- Building Evolutionary Architectures: Support Constant Change, Neal Ford, Rebecca Parsons and Patrick Kua
- Tinker Tailor Soldier Spy, John le Carré
- The calculating stars, Mary Robinette Kowal
- Design It! : Pragmatic Programmers: From Programmer to Software Architect, Michael Keeling

August
- Effective Software Testing: A developer's guide, Maurício Aniche
- Refactoring: Improving the Design of Existing Code (2nd Edition), Martin Fowler
- He, she and it, Marge Piercy
- Prefactoring, Ken Pugh
- Drive: The Surprising Truth About What Motivates Us, Daniel H. Pink
- The fated sky, Mary Robinette Kowal
- The relentless moon, Mary Robinette Kowal
- Otra vida por vivir (Μια ζωή ακόμα), Theodor Kallifatides (2nd time)
- Five Lines of Code: How and when to refactor, Christian Clausen
- The Corrosion of Character: The Personal Consequences of Work in the New Capitalism, Richard Sennett
- Refactoring Workbook, William C. Wake (2nd time)
- Verdades a la cara: Recuerdos de los años salvajes, Pablo Iglesias

September
- Ética para inversores (Ο φόνος είναι χρήμα), Petros Márkaris
- The Honourable Schoolboy, John le Carré
- Autumn Quail (السمان والخريف), Naguib Mahfouz

Monday, August 29, 2022

Books I read (January - August 2022)

January
- Elemental Design Patterns, Jason McC. Smith
- Antipatterns: Refactoring Software, Architectures, and Projects in Crisis, William J. Brown, Raphael C. Malveau, Hays W. "Skip" McCormick
- The Courage of Hopelessness: Chronicles of a Year of Acting Dangerously, Slavoj Žižek
- Get Your Hands Dirty on Clean Architecture: A hands-on guide to creating clean web applications with code examples in Java, Tom Hombergs
- Strangers on a Train, Patricia Highsmith
- Brothers in Arms, Lois McMaster Bujold
- The Great Mental Models: General Thinking Concepts, Shane Parrish, Rhiannon Beaubien

February
- Invicto: Logra más, sufre menos, Marcos Vázquez
- El rumor del oleaje (潮騒), Yukio Mishima
- Mirror Dance, Lois McMaster Bujold
- Memories, Lois McMaster Bujold
- The Pride of Chanur, C.J. Cherryh
- All Systems Red, Martha Wells
- The Culture of the New Capitalism, Richard Sennett

March
- Komarr, Lois McMaster Bujold
- Universidad para asesinos (Σεμινάρια φονικής γραφής), Petros Markaris
- Sobre héroes y tumbas, Ernesto Sabato
- Continuous Delivery, Jez Humble, David Farley

April
- Java by Comparison: Become a Java Craftsman in 70 Examples, Simon Harrer, Jörg Lenhard, Linus Dietz
- A Civil Campaign, Lois McMaster Bujold
- Indistractable: How to Control Your Attention and Choose Your Life, Nir Eyal
- The Long Way to a Small, Angry Planet, Becky Chambers
- Winterfair Gifts, Lois McMaster Bujold
- Queenie, Candice Carty-Williams
- The Extraordinary and Unusual Adventures of Horatio Lyle, Catherine Webb
- The How of Happiness: A Scientific Approach to Getting the Life You Want, Sonja Lyubomirsky
- Diplomatic Immunity, Lois McMaster Bujold

May
- A Closed and Common Orbit, Becky Chambers
- Captain Vorpatril's Alliance, Lois McMaster Bujold
- The Flowers of Vashnoi, Lois McMaster Bujold
- Design Patterns Explained: A New Perspective on Object-Oriented Design, Alan Shalloway, James R. Trott
- Writing Maintainable Unit Tests, Jan Van Ryswyck
- Amongst our weapons, Ben Aaronovitch
- Cryoburn, Lois McMaster Bujold
- Gentleman Jole and The Red Queen, Lois McMaster Bujold
- Batman: Year One, Frank Miller, David Mazzucchelli

June
- Modern Software Engineering: Doing What Works to Build Better Software Faster, David Farley
- Accelerate: The Science of Lean Software and DevOps: Building and Scaling High Performing Technology Organizations, Gene Kim, Jez Humble, Nicole Forsgren
- Records of a spaceborn few, Becky Chambers
- Refactoring for Software Design Smells: Managing Technical Debt, Ganesh Samarthyam, Girish Suryanarayana, Tushar Sharma
- Free fall, Lois McMaster Bujold
- Fundamentals of Software Architecture: An Engineering Approach, Mark Richards, Neal Ford
- The Galaxy, and the Ground Within, Becky Chambers
- Technical Agile Coaching with the Samman Method, Emily Bache
- Shards of honor, Lois McMaster Bujold

July
- Barrayar, Lois McMaster Bujold
- La muerte de Ulises (Τριηµερία), Petros Markaris
- Building Evolutionary Architectures: Support Constant Change, Neal Ford, Rebecca Parsons and Patrick Kua
- Tinker Tailor Soldier Spy, John le Carré
- The calculating stars, Mary Robinette Kowal
- Design It! : Pragmatic Programmers: From Programmer to Software Architect, Michael Keeling

August
- Effective Software Testing: A developer's guide, Maurício Aniche
- Refactoring: Improving the Design of Existing Code (2nd Edition), Martin Fowler
- He, she and it, Marge Piercy
- Prefactoring, Ken Pugh
- Drive: The Surprising Truth About What Motivates Us, Daniel H. Pink
- The fated sky, Mary Robinette Kowal
- The relentless moon, Mary Robinette Kowal
- Otra vida por vivir (Μια ζωή ακόμα), Theodor Kallifatides (2nd time)
- Five Lines of Code: How and when to refactor, Christian Clausen
- The Corrosion of Character: The Personal Consequences of Work in the New Capitalism, Richard Sennett
- Refactoring Workbook, William C. Wake (2nd time)
- Verdades a la cara: Recuerdos de los años salvajes, Pablo Iglesias

Tuesday, August 23, 2022

Example of role tests in JavaScript with Jest

In this post we’ll show our last example applying the concept of role tests, this time in JavaScript using Jest. Have a look at our previous posts on this topic.

This example comes from a deliberate practice session we did recently with some developers from Audiense with whom we’re doing Codesai’s Practice Program in JavaScript twice a month.

Similar to what we did in our previous example of role tests in Java, we wrote the following tests to develop two different implementations of the TransactionsRepository port while solving the Bank Kata: the InMemoryTransactionsRepository and the NodePersistTransactionRepository.

These are their tests, respectively:

As what happened in our previous post, both tests contain the same test cases since both tests document and protect the contract of the same role, TransactionsRepository, which InMemoryTransactionsRepository and NodePersistTransactionRepository implement.

Again we’ll use the concept of role tests to remove that duplication, and make the contract of the role we are implementing more explicit.

Although Jest does not have something equivalent or similar to the RSpec’s shared examples functionality we used in our previous example in Ruby, we can get a very similar result by composing functions.

First, we wrote the behavesLikeATransactionRepository function. This function contains all the test cases that document the role and protect its contract, and receives as a parameter a testContext object containing methods for all the operations that will vary in the different implementations of this integration test.

Notice that in the case of Jest we are using composition, whereas we used inheritance in the case of Junit.

Then, we called the behavesLikeATransactionRepository function from the previous tests and implemented a particular version of the methods of the testContext object for each test.

This is the new code of InMemoryTransactionsRepositoryTest:

And this is the new code of NodePersistTransactionRepository after the refactoring:

This new version of the tests not only reduces duplication, but also makes explicit and protects the behaviour of the TransactionsRepository role. It also makes less error prone the process of adding a new implementation of TransactionsRepository because just by using the behavesLikeATransactionRepository function, you’d get a checklist of the behaviour you need to implement in order to ensure substitutability, i.e., to ensure the Liskov Substitution Principle is not violated.

These role tests using composition are also more readable than the Junit ones, in my opinion at least :)

Acknowledgements.

I’d like to thank Audiense’s deliberate practice group for working with us on this kata, and my colleague Rubén Díaz for co-facilitating the practice sessions with me.

Thanks to my Codesai colleagues for reading the initial drafts and giving me feedback.

References.

Example of role tests in Java with Junit

I’d like to continue with the topic of role tests that we wrote about in a previous post, by showing an example of how it can be applied in Java to reduce duplication in your tests.

This example comes from a deliberate practice session I did recently with some people from Women Tech Makers Barcelona with whom I’m doing Codesai’s Practice Program in Java twice a month.

Making additional changes to the code that resulted from solving the Bank Kata we wrote the following tests to develop two different implementations of the TransactionsRepository port: the InMemoryTransactionsRepository and the FileTransactionsRepository.

These are their tests, respectively:

As you can see both tests contain the same test cases: a_transaction_can_be_saved and transactions_can_be_retrieved but their implementations are different for each class. This makes sense because both implementations implement the same role, (see our previous post to learn how this relates to Liskov Substitution Principle).

We can make this fact more explicit by using role tests. In this case, Junit does not have something equivalent or similar to the RSpec’s shared examples functionality we used in our previous example in Ruby. Nonetheless, we can apply the Template Method pattern to write the role test, so that we remove the duplication, and more importantly make the contract we are implementing more explicit.

To do that we created an abstract class, TransactionsRepositoryRoleTest. This class contains the tests cases that document the role and protect its contract (a_transaction_can_be_saved and transactions_can_be_retrieved) and defines hooks for the operations that will vary in the different implementations of this integration test (prepareData, readAllTransactions and createRepository):

Then we made the previous tests extend TransactionsRepositoryRoleTest and implemented the hooks.

This is the new code of InMemoryTransactionsRepositoryTest:

And this is the new code of FileTransactionsRepositoryTest after the refactoring:

This new version of the tests not only reduces duplication, but also makes explicit and protects the behaviour of the TransactionsRepository role. It also makes less error prone the process of adding a new implementation of TransactionsRepository because just by extending the TransactionsRepositoryRoleTest, you’d get a checklist of the behaviour you need to implement to ensure substitutability, i.e., to ensure the Liskov Substitution Principle is not violated.

Have a look at this Jason Gorman’s repository to see another example that applies the same technique.

In a future post we’ll show how we can do the same in JavaScript using Jest.

Acknowledgements.

I’d like to thank the WTM study group, and especially Inma Navas and Laura del Toro for practising with this kata together.

Thanks to my Codesai colleagues, Inma Navas and Laura del Toro for reading the initial drafts and giving me feedback.

References.