State machines are a powerful way to organize code. They are, after all, one of the fundamental models of computation. That’s pretty good. A well designed state machine can make a complicated problem clear, and easy to understand.
Chris, on the other hand, found this one.
<span class="hljs-keyword">static</span> {
sM.put(tk(NONE, NONE, invite), sp(PENDING, INVITED)); <span class="hljs-comment">// t1</span>
sM.put(tk(REJECTED, REJECTED, invite), sp(PENDING, INVITED)); <span class="hljs-comment">// t2</span>
sM.put(tk(PENDING, IGNORED, invite), sp(PENDING, INVITED)); <span class="hljs-comment">// t3</span>
sM.put(tk(PENDING, INVITED, cancel), sp(NONE, NONE)); <span class="hljs-comment">// t4</span>
sM.put(tk(PENDING, IGNORED, cancel), sp(NONE, NONE)); <span class="hljs-comment">// t5</span>
sM.put(tk(PENDING, BLOCKED, cancel), sp(NONE, BLOCKED)); <span class="hljs-comment">// t6</span>
sM.put(tk(INVITED, PENDING, accept), sp(ACCEPTED, ACCEPTED)); <span class="hljs-comment">// t7</span>
sM.put(tk(INVITED, PENDING, reject), sp(REJECTED, REJECTED)); <span class="hljs-comment">// t8</span>
sM.put(tk(INVITED, PENDING, ignore), sp(IGNORED, PENDING)); <span class="hljs-comment">// t9</span>
sM.put(tk(INVITED, PENDING, block), sp(BLOCKED, PENDING)); <span class="hljs-comment">// t10</span>
sM.put(tk(ACCEPTED, ACCEPTED, remove), sp(NONE, NONE)); <span class="hljs-comment">// t11</span>
sM.put(tk(REJECTED, REJECTED, remove), sp(NONE, NONE)); <span class="hljs-comment">// t12</span>
sM.put(tk(IGNORED, PENDING, remove), sp(NONE, NONE)); <span class="hljs-comment">// t13</span>
sM.put(tk(PENDING, IGNORED, remove), sp(NONE, NONE)); <span class="hljs-comment">// t14</span>
sM.put(tk(BLOCKED, PENDING, remove), sp(NONE, NONE)); <span class="hljs-comment">// t15</span>
sM.put(tk(PENDING, BLOCKED, remove), sp(NONE, BLOCKED)); <span class="hljs-comment">// t16</span>
sM.put(tk(NONE, BLOCKED, invite), sp(PENDING, BLOCKED)); <span class="hljs-comment">// t17</span>
sM.put(tk(IGNORED, PENDING, invite), sp(PENDING, INVITED)); <span class="hljs-comment">// t19</span>
sM.put(tk(INVITED, PENDING, invite), sp(ACCEPTED, ACCEPTED)); <span class="hljs-comment">// t20</span>
sM.put(tk(NONE, NONE, remove), sp(NONE, NONE)); <span class="hljs-comment">// t21</span>
sM.put(tk(NONE, BLOCKED, remove), sp(NONE, BLOCKED)); <span class="hljs-comment">// t22</span>
sM.put(tk(BLOCKED, NONE, remove), sp(NONE, NONE)); <span class="hljs-comment">// t23</span>
}
Honestly, I only know this is a state machine because Chris told me. I could hazard a guess base on the variable name sM
. The comments certainly don’t help. Numbering lines isn’t exactly what I want comments for. I don’t know what tk
or sp
are actually doing.
So yes, this is an unreadable blob that I don’t understand, which is always bad. But do you know what elevates this one step above that? If you note the third parameter to the tk
function- invite
, cancel
, accept
, etc? Those are constants. So are INVITED
, PENDING
, ACCEPTED
.
While I am not fond of using the structure of a variable name to denote its role, “caps means const” is a very well accepted standard. A standard that they’re using sometimes, but not all the time, and just looking at this makes me grind my teeth.

BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!
Source: Read MoreÂ