Tag Archives: Musings

Idempotence

From Wikipedia:

Idempotence (/ˌaɪdɨmˈpoʊtəns/ eye-dəm-poh-təns) is the property of certain operations in mathematics and computer science, that can be applied multiple times without changing the result beyond the initial application.

About a month ago, I came up with a great example of idempotence which I want to share if anybody has confusion about what it means exactly, or has to explain it to someone outside of the realm of mathematics or computer science, like customer stakeholders.

It came to me when I was doing dishes one night. I had left a baby food jar on the counter waiting for my wife to get back down to the kitchen area since I didn’t know if it had been cleaned over at the in-laws or not. When she got back to the kitchen, after I asked if it had been washed, she gave me the perfect example of idempotence:

If you aren’t sure if it has been washed or not, just wash it; it won’t hurt anything if you wash it again.

–My wife

So when you are trying to explain idempotence to someone, feel free to use this example found in every day life.

I hope you find this useful.

–Proctor

XMLisp?

I had a twisted thought about a potential future thought experiment of using XML and Lisp style languages.

Having used Lisp a very little bit back in college for one semester, and read more about it in Structure and Interpretation of Computer Programs, I started looking into Clojure recently. I did a session of CodeRetreat last year in it, and was hearing more about it this year at SCNA so I started to read up on it more and play a little bit with the language.

Tie that in with that I recently was transferred to a new group at work that is doing some SOA (Service Oriented Architecture) work. Something triggered when I thought about the XML payloads being sent between the SOA Web Services and how that tied into what I am reading about Lisp and Clojure.

In other languages we think about serializing command objects into XML and back and send those messages between Services as a message payload. What made me think was that XML is a tree structure as well as the code in a Lisp type language.

What if we did something like Javascript and JSON? What if we convert the Lisp structure to XML and back, and then we can execute this Lisp structure data as Lisp code? With XML we can then also apply transforms and convert one message/command into another message/command, which would allow one message to be sent and transformed into multiple messages to be received by inserting messaging splitters and transformers. This is also not worrying about things like the security of the evaluation of the Lisp data as code since this something to think about as a thought experiment.

I don’t know if this is a novel idea, or if someone else has already tried it, but to me it seems like an interesting thing to think about and mull over.

TDD: Clicker Training for Developers?

I started thinking about some of the bigger names in the developer community and how polarizing they can be due to their hard line positions on topics.  One of the topics that came to mind was Test Driven Development, and how the advocates of it almost always have a strict stance on the correct ways to approach it.  Outside-in or inside-out.  Only one assertion per test or assert one logical concept.  Mocks vs stubs. State vs behavior. TDD or BDD, or is there is really even a difference.

My wife pet-sits, and as she is cooking, so she likes to watch shows which cover training pets, similiar to how one might listen to podcasts as they drive to work.  I will occasionally over-hear, or catch parts of these shows myself, usually while helping her in the kitchen. I also recently read Switch: How to Change When Change is Hard, by Chip and Dan Heath which has a section discussing the importance of reinforcing positive behavior when trying to encourage change and establish habits.  Thinking about the hard-liners and TDD, I realized Kent Beck created the perfect “training clicker” for developers.  Whether this was intentional or not at the time will be something I leave for him to answer.

To train by positive reinforcement, one has to capture the desired behavior and immediately reward it.  When one test drives their code they are encouraged to run their test after each change to see if their change works.  As unit tests are supposed to be fast, this gives the user immediate feedback to know if what they did worked or did not.

The majority of the test runners use either one of two words depending on the result of the test: success or failure.  These two words are very emotionally charged.  Combine this with the fact that they are usually printed in all caps and followed by a number of exclamation points results in output like:
SUCCESS!!!
or
FAILURE!!!

Can’t you just see the emotions getting charged.

Add on to this a graphical user interface for the test runner, or even add ons which change the console text color depending on the end state of the test runs, which use the colors green and red for successes and failures respectively, and you get even more emotional resonance.  You have now gone from the above results to something along the lines of
SUCCESS!!!
or
FAILURE!!!

How is that for evoking an emotional response? I believe I have even heard Kent Beck talking about the thrill he sees in seeing the status bar turn green.

Also, the proponents of TDD encourage small units of work.  The reason being, when you work in minimal units of change you know pretty much exactly what caused the test to fail.  There ends up being a hidden effect to this though.  When you work in small units between test runs, that behavior is now getting reinforced even more frequently, and engraining that behavior more deeply.  Do this enough and that behavior will eventually turn into a habit. And our self-serving egos love to rationalize why our habits are the right thing to be doing, lest we allow ourselves to realize we might be acting wrongly.

And I do not think this just applies to those that are strong proponents for TDD.  Do we ever consider that someone who is a strong opponent may have been negatively reinforced by TDD?  Might they have tried on their own with no guidance and gotten frequent feedback of failures?  Maybe they tried at the wrong level of abstraction, or on a codebase that was not designed with testability in mind. Maybe the test runner just kept giving them negative reinforcement on what they were doing until they decided that TDD is a waste of time.

I am putting this idea out there not to cast judgement against TDD, as it is a practice that I believe has a large amount of value to it, and would love to get good at, but as a something to think about.  Maybe this will help the each side see why the other side might feel they way they do about TDD.

I would love to know your thoughts on this.