<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;}
span.c
{mso-style-name:c;}
span.p
{mso-style-name:p;}
span.ni
{mso-style-name:ni;}
span.n
{mso-style-name:n;}
span.nv
{mso-style-name:nv;}
span.o
{mso-style-name:o;}
span.k
{mso-style-name:k;}
span.nl
{mso-style-name:nl;}
span.nf
{mso-style-name:nf;}
span.EmailStyle28
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Since no-one else stepped into the breach, I’ll make a case.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>In my view, the –spec is a contract, which (1) is usually written before the implementation as part of your design; and (2) as such, it serves as documentation regarding your intent and usage.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>In this case, programmers calling the function should be prepared for both an <i>ok</i> return value and an <i>error</i>. Without the –spec, the programmer does not know this and may just do a match on {_, State} and then not notice any errors when the function changes. On the other side, when a maintainer comes along later wishing to modify this function, he understands (1) the function’s intent, and (2) how to signal errors. He can make whatever changes he wishes to effect new functionality so long as he obeys that contract.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Cheers,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>DBM<o:p></o:p></span></p></div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> erlang-questions-bounces@erlang.org [mailto:erlang-questions-bounces@erlang.org] <b>On Behalf Of </b>Steve Davis<br><b>Sent:</b> Tuesday, September 25, 2012 19:38<br><b>To:</b> Erlang-Questions Questions<br><b>Subject:</b> [erlang-questions] Spec is diabolical IMHO<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div id=LC71><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><rant><o:p></o:p></span></pre></div><div id=LC71><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'>Can someone who knows better explain how this evil child of -spec:<o:p></o:p></span></pre></div><div id=LC71><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><o:p> </o:p></span></pre></div><div id=LC71><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span class=c><i><span style='font-size:9.0pt;font-family:Consolas;color:#999988;border:none windowtext 1.0pt;padding:0in'>%% @doc The gen_server code_change/3 callback, called when performing</span></i></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><o:p></o:p></span></pre></div><div id=LC72><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span class=c><i><span style='font-size:9.0pt;font-family:Consolas;color:#999988;border:none windowtext 1.0pt;padding:0in'>%% a hot code upgrade on the server. Currently unused.</span></i></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><o:p></o:p></span></pre></div><div id=LC73><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span class=p><span style='font-size:9.0pt;font-family:Consolas;color:#333333;border:none windowtext 1.0pt;padding:0in'>-</span></span><span class=ni><span style='font-size:9.0pt;font-family:Consolas;color:purple;border:none windowtext 1.0pt;padding:0in'>spec</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> <span class=n><span style='border:none windowtext 1.0pt;padding:0in'>code_change</span></span><span class=p><span style='border:none windowtext 1.0pt;padding:0in'>(</span></span></span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>OldVsn</span></span><span class=p><span style='font-size:9.0pt;font-family:Consolas;color:#333333;border:none windowtext 1.0pt;padding:0in'>,</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> </span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>State</span></span><span class=p><span style='font-size:9.0pt;font-family:Consolas;color:#333333;border:none windowtext 1.0pt;padding:0in'>,</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> </span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>Extra</span></span><span class=p><span style='font-size:9.0pt;font-family:Consolas;color:#333333;border:none windowtext 1.0pt;padding:0in'>)</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> <span class=o><b><span style='border:none windowtext 1.0pt;padding:0in'>-></span></b></span> <span class=p><span style='border:none windowtext 1.0pt;padding:0in'>{</span></span><span class=n><span style='border:none windowtext 1.0pt;padding:0in'>ok</span></span><span class=p><span style='border:none windowtext 1.0pt;padding:0in'>,</span></span> </span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>State</span></span><span class=p><span style='font-size:9.0pt;font-family:Consolas;color:#333333;border:none windowtext 1.0pt;padding:0in'>}</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> <span class=p><span style='border:none windowtext 1.0pt;padding:0in'>|</span></span> <span class=p><span style='border:none windowtext 1.0pt;padding:0in'>{</span></span><span class=n><span style='border:none windowtext 1.0pt;padding:0in'>error</span></span><span class=p><span style='border:none windowtext 1.0pt;padding:0in'>,</span></span> </span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>Reason</span></span><span class=p><span style='font-size:9.0pt;font-family:Consolas;color:#333333;border:none windowtext 1.0pt;padding:0in'>}</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><o:p></o:p></span></pre></div><div id=LC74><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> <span class=k><b><span style='border:none windowtext 1.0pt;padding:0in'>when</span></b></span><o:p></o:p></span></pre></div><div id=LC75><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> </span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>OldVsn</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> <span class=p><span style='border:none windowtext 1.0pt;padding:0in'>::</span></span> </span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>Vsn</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> <span class=p><span style='border:none windowtext 1.0pt;padding:0in'>|</span></span> <span class=p><span style='border:none windowtext 1.0pt;padding:0in'>{</span></span><span class=n><span style='border:none windowtext 1.0pt;padding:0in'>down</span></span><span class=p><span style='border:none windowtext 1.0pt;padding:0in'>,</span></span> </span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>Vsn</span></span><span class=p><span style='font-size:9.0pt;font-family:Consolas;color:#333333;border:none windowtext 1.0pt;padding:0in'>},</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><o:p></o:p></span></pre></div><div id=LC76><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> </span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>Vsn</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> <span class=p><span style='border:none windowtext 1.0pt;padding:0in'>::</span></span> <span class=n><span style='border:none windowtext 1.0pt;padding:0in'>term</span></span><span class=p><span style='border:none windowtext 1.0pt;padding:0in'>(),</span></span><o:p></o:p></span></pre></div><div id=LC77><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> </span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>State</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> <span class=p><span style='border:none windowtext 1.0pt;padding:0in'>::</span></span> <span class=nl><span style='border:none windowtext 1.0pt;padding:0in'>#state</span></span><span class=p><span style='border:none windowtext 1.0pt;padding:0in'>{},</span></span><o:p></o:p></span></pre></div><div id=LC78><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> </span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>Extra</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> <span class=p><span style='border:none windowtext 1.0pt;padding:0in'>::</span></span> <span class=n><span style='border:none windowtext 1.0pt;padding:0in'>term</span></span><span class=p><span style='border:none windowtext 1.0pt;padding:0in'>(),</span></span><o:p></o:p></span></pre></div><div id=LC79><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> </span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>Reason</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> <span class=p><span style='border:none windowtext 1.0pt;padding:0in'>::</span></span> <span class=n><span style='border:none windowtext 1.0pt;padding:0in'>term</span></span><span class=p><span style='border:none windowtext 1.0pt;padding:0in'>().</span></span><o:p></o:p></span></pre></div><div id=LC80><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span class=nf><b><span style='font-size:9.0pt;font-family:Consolas;color:#990000;border:none windowtext 1.0pt;padding:0in'>code_change</span></b></span><span class=p><span style='font-size:9.0pt;font-family:Consolas;color:#333333;border:none windowtext 1.0pt;padding:0in'>(_</span></span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>OldVsn</span></span><span class=p><span style='font-size:9.0pt;font-family:Consolas;color:#333333;border:none windowtext 1.0pt;padding:0in'>,</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> </span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>State</span></span><span class=p><span style='font-size:9.0pt;font-family:Consolas;color:#333333;border:none windowtext 1.0pt;padding:0in'>,</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> <span class=p><span style='border:none windowtext 1.0pt;padding:0in'>_</span></span></span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>Extra</span></span><span class=p><span style='font-size:9.0pt;font-family:Consolas;color:#333333;border:none windowtext 1.0pt;padding:0in'>)</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'> <span class=o><b><span style='border:none windowtext 1.0pt;padding:0in'>-></span></b></span> <span class=p><span style='border:none windowtext 1.0pt;padding:0in'>{</span></span><span class=n><span style='border:none windowtext 1.0pt;padding:0in'>ok</span></span><span class=p><span style='border:none windowtext 1.0pt;padding:0in'>,</span></span> </span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>State</span></span><span class=p><span style='font-size:9.0pt;font-family:Consolas;color:#333333;border:none windowtext 1.0pt;padding:0in'>}.</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><o:p></o:p></span></pre></div><div id=LC80><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><o:p> </o:p></span></pre></div><div id=LC80><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span class=p><span style='font-size:9.0pt;font-family:Consolas;color:#333333;border:none windowtext 1.0pt;padding:0in'>...is not a total waste of too many talented people's time over the more transparent:</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><o:p></o:p></span></pre></div><div id=LC80><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><o:p> </o:p></span></pre></div><div id=LC80><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span class=p><span style='font-size:9.0pt;font-family:Consolas;color:#333333;border:none windowtext 1.0pt;padding:0in'>code_change(_</span></span><span class=nv><span style='font-size:9.0pt;font-family:Consolas;color:teal;border:none windowtext 1.0pt;padding:0in'>OldVsn</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'>, State = #state{}, _Extra) -> {ok, State}.<o:p></o:p></span></pre></div><div id=LC80><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><o:p> </o:p></span></pre></div><div id=LC80><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'>...or is spec just a diabolical case of over-engineering that is at once both incredibly onerous and bug-prone justified in the cause of the weaknesses of some ill-designed test tool?<o:p></o:p></span></pre></div><div id=LC80><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><o:p> </o:p></span></pre></div><div id=LC80><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'>My gut reaction is that if you feel that you NEED TO DO TDD style testing, you should take the time parse the source and not bloat it beyond readability by inflicting conventions on the development of the source that will simply distract and so *cause* the bugs you think that you are testing for.<o:p></o:p></span></pre></div><div id=LC80><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><o:p> </o:p></span></pre></div><div id=LC80><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'>A better use of developer time would be to enforce documentation of the intention of the function.<o:p></o:p></span></pre></div><div id=LC80><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><o:p> </o:p></span></pre></div><div id=LC80><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span class=p><span style='font-size:9.0pt;font-family:Consolas;color:#333333;border:none windowtext 1.0pt;padding:0in'></rant></span></span><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><o:p></o:p></span></pre></div><div id=LC80><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'>/s<o:p></o:p></span></pre></div><div id=LC80><pre style='line-height:12.0pt;background:white;vertical-align:baseline'><span style='font-size:9.0pt;font-family:Consolas;color:#333333'><o:p> </o:p></span></pre></div><div><p class=MsoNormal><o:p> </o:p></p></div></div></div></body></html>