<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 http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@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" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">I was trying out the approach of the first answer here (<a href="https://stackoverflow.com/questions/6745183/erlang-extended-gen-server">https://stackoverflow.com/questions/6745183/erlang-extended-gen-server</a>). In this approach, the
extension behaviour get first crack at all of the gen_server messages and then forwards the user-module-specific stuff to the user module’s gen_server implementation.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Basically I have written a bunch of (tested/working) TCP client/server interaction code as a gen_server and have a bunch of other modules that add specific functionality on top but require the same TCP handshaking. My idea was to wrap
my working stuff as a behaviour but I can’t yet decide if I want to expose all of gen_server to my user modules or customize the interface. Right now I have opted for generality and am experimenting with exposing everything but we shall see... I am in that
awkward place where I am working out my architecture while also trying to learn Erlang best practices; fun times.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Brett<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> Fernando Benavides <elbrujohalcon@gmail.com> <br>
<b>Sent:</b> Tuesday, February 23, 2021 9:26 AM<br>
<b>To:</b> Brett Hemes <brhemes@mmm.com><br>
<b>Cc:</b> erlang-questions@erlang.org<br>
<b>Subject:</b> [EXTERNAL] Re: Specifying callbacks for behaviours extending gen_server<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">What if you only specify your own callbacks and let your implementors use...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">-behavior(your behavior).<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">-behavior(gen_server).<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Tue, 23 Feb 2021 at 16:15 Brett Hemes <<a href="mailto:brhemes@mmm.com">brhemes@mmm.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">I am designing a behaviour that extends gen_server and thus I want all of gen_server’s callback specification in addition to some additional ones on top as part of the extension.
In the past I have favored using the `-callback` attribute as recommended in the documentation but then I saw someone recommend the following when extending gen_server<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">> behaviour_info(Type) -> gen_server:behaviour_info(Type).<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">I tried combining the two approaches but such is not allowed (which makes sense). I believe my options are to append my callbacks to gen_server’s list using `behaviour_info` or
to copy gen_server’s callback specifications from the OTP source. Copy-pasting code just feels wrong... how bad is it to use `behaviour_info` over `-callback`? And am I taking the right approach?<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Thanks,<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Brett<o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
</div>
<p class="MsoNormal">-- <o:p></o:p></p>
<div>
<p class="MsoNormal">Sent from Gmail Mobile by Brujo Benavides<o:p></o:p></p>
</div>
</div>
</body>
</html>