Friday, January 28, 2022

Avoiding the Deadly Quadrant

I saw a video (opens in a new window) recently which illustrated an important concept in a very elegant way. 



This is important, because in 3/4 of this diagram, your code is inherently safe to run in a multi-threaded environment.  There are no synchronization blocks required, there is no need for complicated gatekeeping.  And yet, somehow a lot of code winds up with mutable data and synchronization headaches.

Applying just a few functional programming principles to your work can go a long way.  Parameters should generally be considered inviolate, use return properly and don't try modifying your inputs directly.  Prefer constants to variables. 

When you kick off a process, you really don't want it randomly reaching out and modifying some kind of global state.  If it REALLY needs to send messages home, give it a tool to do so, such as a callback function it can use for that purpose.

New Directions

 I've been learning lately.

I mean, I have been learning a lot.  Some of it is completely new, some of it is just fresh perspective on old ideas.

This is undoubtedly the natural consequence of being put in charge of developing a green-field project (can you believe it?!?) using both familiar and unfamiliar technologies.  It's a mobile app.  It's an API.  It's a cloud native, event driven...  work in progress.  As a consequence, I run into unexpected things all the time.  I also get to see up close what works and doesn't, as my client is flexible enough to let us experiment with features.

I think I need to record this stuff for anyone who might be interested.  I'm not saying that I will be giving up on discussions of OOP principles, but I will also be expanding my reach.

There was no single trigger for this, but the past year or so has helped me to understand a few new tools and concepts.  I'm still working out others, as I have been all along.  But now I'm going to write it down here.

I hope it proves useful.


JD