tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Tapestry > Developer Bible
Date Sat, 26 Jan 2013 21:36:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/12/_/styles/combined.css?spaceKey=TAPESTRY&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/TAPESTRY/Developer+Bible">Developer
Bible</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~bobharner">Bob
Harner</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        Added links to idea-settings.jar and tapestry-indent-eclipse.xml<br />
    </div>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >It&#39;s a free license for all
committers and it&#39;s just better. Yes, the first few days can be an unpleasant fumble
because everything is almost, but not quite, familiar.  Pretty soon you&#39;ll love IDEA
and recognize that Eclipse has been bending you over and doing unspeakable things. <br>
<br></td></tr>
            <tr><td class="diff-changed-lines" >There are shared code formatting
settings in <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">_&lt;support/idea-settings.jar_&gt;.</span>
<span class="diff-added-words"style="background-color: #dfd;">the [support directory|https://git-wip-us.apache.org/repos/asf?p=tapestry-5.git;a=tree;f=support]
(idea-settings.jar).</span>  This will prevent unexpected conflicts due to formatting.
<br></td></tr>
            <tr><td class="diff-unchanged" > <br>h3. Eclipse <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >Howard uses this ... because he can&#39;t
manage to switch IDEs constantly (he uses Eclipse for training). Lately its gotten better.
<br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">As
with IntelliJ, there are shared code formatting settings for Eclipse in the [support directory|https://git-wip-us.apache.org/repos/asf?p=tapestry-5.git;a=tree;f=support]
(tapestry-indent-eclipse.xml). <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h2. Copyrights <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <div class='navmenu' style='float:right; background:#eee; margin:3px; padding:3px'><table
class="tableview" width="100%">
            <tr><th style="padding: 3px 3px 3px 0px">Related Articles</th></tr>
                        <tr>
            <td>
                                 <span class="icon icon-page" title=Page>Page:</span>
                         <a href="/confluence/display/TAPESTRY/Confluence+Site+Setup">Confluence
Site Setup</a>
        
                                            </td>
        </tr>
                <tr>
            <td>
                                 <span class="icon icon-page" title=Page>Page:</span>
                         <a href="/confluence/display/TAPESTRY/Developer+Bible">Developer
Bible</a>
        
                                            </td>
        </tr>
                <tr>
            <td>
                                 <span class="icon icon-page" title=Page>Page:</span>
                         <a href="/confluence/display/TAPESTRY/Release+Process">Release
Process</a>
        
                                            </td>
        </tr>
                <tr>
            <td>
                                 <span class="icon icon-page" title=Page>Page:</span>
                         <a href="/confluence/display/TAPESTRY/Version+Numbers">Version
Numbers</a>
        
                                            </td>
        </tr>
                <tr>
            <td>
                                 <span class="icon icon-page" title=Page>Page:</span>
                         <a href="/confluence/display/TAPESTRY/Developer+Information">Developer
Information</a>
        
                                            </td>
        </tr>
                <tr>
            <td>
                                 <span class="icon icon-page" title=Page>Page:</span>
                         <a href="/confluence/display/TAPESTRY/Building+Tapestry+from+Source">Building
Tapestry from Source</a>
        
                                            </td>
        </tr>
            </table>
</div> 

<p>This is a semi-random outpouring of thoughts related to being a Tapestry committer.</p>

<h2><a name="DeveloperBible-IDEChoices"></a>IDE Choices</h2>

<h3><a name="DeveloperBible-IntelliJ"></a>IntelliJ</h3>

<p>It's a free license for all committers and it's just better. Yes, the first few days
can be an unpleasant fumble because everything is almost, but not quite, familiar.  Pretty
soon you'll love IDEA and recognize that Eclipse has been bending you over and doing unspeakable
things.</p>

<p>There are shared code formatting settings in the <a href="https://git-wip-us.apache.org/repos/asf?p=tapestry-5.git;a=tree;f=support"
class="external-link" rel="nofollow">support directory</a> (idea-settings.jar). 
This will prevent unexpected conflicts due to formatting.</p>

<h3><a name="DeveloperBible-Eclipse"></a>Eclipse</h3>

<p>Howard uses this ... because he can't manage to switch IDEs constantly (he uses Eclipse
for training). Lately its gotten better.</p>

<p>As with IntelliJ, there are shared code formatting settings for Eclipse in the <a
href="https://git-wip-us.apache.org/repos/asf?p=tapestry-5.git;a=tree;f=support" class="external-link"
rel="nofollow">support directory</a> (tapestry-indent-eclipse.xml).</p>

<h2><a name="DeveloperBible-Copyrights"></a>Copyrights</h2>

<p>All source files should have the ASF copyright comment on top, except where such
a comment would interfere with its behavior.  For example, component template files omit the
comment.</p>

<p>As you make changes to files, update the copyright to add the current year to the
list.  The goal is that the copyright notice includes the year in which files change.  When
creating a new file, don't back date the copyright year ... start with the current year. 
Try not to change the copyright year on files that haven't actually changed.</p>

<p>IntelliJ has a great comparison view: Cmd-9 to see the local changes, the Cmd-D to
see the differences. You can whip through the changes (using Cmd-forward arrow) and make sure
copyrights are up to date as you review the changes prior to a commit.</p>

<h2><a name="DeveloperBible-CommitMessages"></a>Commit Messages</h2>

<p>Always provide a commit message.  Howard generally tries to work off the JIRA, so
his commit message is often:</p>

<blockquote><p>TAP5-1234: Make the Foo Widget more Ajax-tastic!</p></blockquote>

<p>It is <em>very important</em> to include the JIRA issue id in the commit.
 This is used in many places: JIRA links issues to the SVN commits for that issue (very handy
for seeing what changed as part of a bug fix).  The Hudson CI server does as well, and will
actually link SVN commits to issues after succesfully building.</p>

<h2><a name="DeveloperBible-JIRAProcedures"></a>JIRA Procedures</h2>

<p>All Tapestry committers should be registerred with JIRA and part of the tapestry-developers
JIRA group.</p>

<p>Every committer is invited to look at the list of <a href="https://issues.apache.org/jira/secure/IssueNavigator.jspa?mode=hide&amp;requestId=12317068"
class="external-link" rel="nofollow">'Review for closing'</a> issues and review them
as it contains probably outdated or no more valid issues.</p>

<p>There's also a list of all <a href="https://issues.apache.org/jira/secure/IssueNavigator.jspa?mode=hide&amp;requestId=12316792"
class="external-link" rel="nofollow">Open</a> issue about the project.</p>

<p>Ideally, we would always work top priortity to low priority.  Howard sometimes jump
out of order, if there's something cool to work on that fits in an available time slot.  Alternately,
you are always allowed to change the priority of a bug before or as you work it.</p>

<p>As a general rule issues which are "<em>Invalid</em>" or "<em>Won't</em>
<em>Fix</em>" shouldn't have a "<em>Fix</em> <em>version</em>".</p>

<h3><a name="DeveloperBible-Startingwork"></a>Starting work  </h3>

<p>When you start to work on an issue, make sure it is <em>assigned to you</em>
and use the <em>start progress</em> option.</p>

<p>Add comments about the state of the fix, or the challenges in creating a fix.  This
often spurs the Issue's adder to<br/>
provide more details.</p>

<p>Update the issue description to make it more legible and more precise if needed,
i.e., "NPE in CheckUpdates" might become "NullPointerException when checking for updates to
files that have been deleted".  Verbose is good.</p>

<h3><a name="DeveloperBible-Closingbugs"></a>Closing bugs  </h3>

<p>Is it a bug fix without tests?  <b>No.</b> A good plan is to write a
test that fails then work the code until the test passes. Often code works in a unit test
but fails unexpectedly in an integration test. As the G-Man says <em>"Expect unforeseen
consequences"</em>.</p>

<p>When you check in a fix, you should <b>close</b> the issue and make sure
the <b>fix release</b> is correct.</p>

<p>We're playing fast and loose &#8211; a better procedure would be to mark the
bug resolved and verify the fix before closing it.  That's ok, we have a community to double
check our work <img class="emoticon" src="/confluence/images/icons/emoticons/smile.gif"
height="20" width="20" align="absmiddle" alt="" border="0"/>.</p>

<p>For anything non-trivial, wait for the Hudson CI server to build.  It catches a lot
of things ... such as files that were not added to SVN.  And even IntelliJ has a bit of trouble
with wildly refactored code. Hudson will catch all that.</p>

<h3><a name="DeveloperBible-Invalidissuesandduplicates"></a>Invalid issues
and duplicates</h3>

<p>Always provide comments about why_ an issue is invalid (<em>"A Ruby implementation
of Tapestry is out of scope for the project."</em>), or at least, a link to the duplicate
issues.</p>

<p>Consider writing new tests to prove that an issue is not valid and then leave the
tests in place &#8211; then close the bug as invalid.</p>

<p>Close the issue but <em>make sure the fix release is blank</em>.  Otherwise,
the issue <em>will be listed in the release notes</em>, which we don't want.</p>

<h2><a name="DeveloperBible-Publicvs.Private%2FInternal"></a>Public vs.
Private/Internal</h2>

<p>This is a real big deal.  As long as code is in the internal package, we have a high
degree of carte-blanche to change it.  As soon as code is public, we become handcuffed to
backwards compatibility.</p>

<p><em>Interfaces are public, implementations are private</em>.  You can
see this is the bulk of the code, where org.apache.tapestry5.services is almost all interfaces
and the implementations are in org.apache.tapestry5.internal.services.</p>

<p>Many more services have both the interface and the implementation in org.apache.tapestry5.internal.services.</p>

<p>We absolutely <em>do not</em> want to make Page or ComponentPageElement
public.  You will often see public service facades that take a page name as a method parameter,
and convert it to a page instance before invoking methods on internal services.</p>

<h2><a name="DeveloperBible-EvolvingComponents"></a>Evolving Components</h2>

<p>We do not have a specific plan for this yet. Future Tapestry 5 will add features
to allow clean renames of parameters, and a way to deprecated and eventually remove components.</p>

<h2><a name="DeveloperBible-EvolvingInterfaces"></a>Evolving Interfaces</h2>

<p>Tapestry uses interfaces quite extensively.</p>

<p>Interfaces fall into two categories: service interfaces called by user code, and
interfaces implemented by user code.</p>

<p>Internal interfaces may be changed at any time. That's why so much is kept internal.</p>

<h3><a name="DeveloperBible-ServiceInterfaces"></a>Service Interfaces</h3>

<p>New methods may be added if absolutely necessary, but this should be avoided if at
all possible. Don't forget the <tt>@since</tt> Javadoc annotation.</p>

<p>Consider having a stable public facade service whose implementation calls into one
or more internal service.</p>

<h3><a name="DeveloperBible-UserInterfaces"></a>User Interfaces</h3>

<p>These should be frozen, no changes once released.  Failure to do so causes <em>non-backwards
compatible upgrade problems</em>; that is, classes that implement the (old) interface
are suddenly invalid, missing methods from the (new) interface.</p>

<p>Consider introducing a new interface that extends the old one and adds new methods.
 Make sure you support both.</p>

<p>You can see this with ServiceDef and ServiceDef2 (which extends ServiceDef).  Yes
this can be a bit ugly.</p>

<p>Howard uses utility methods that convert from ServiceDef to ServiceDef2, adding a
wrapper implementation around a ServiceDef instance if necessary:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  <span class="code-keyword">public</span> <span class="code-keyword">static</span>
ServiceDef2 toServiceDef2(<span class="code-keyword">final</span> ServiceDef sd)
  {
    <span class="code-keyword">if</span> (sd <span class="code-keyword">instanceof</span>
ServiceDef2)
        <span class="code-keyword">return</span> (ServiceDef2) sd;

    <span class="code-keyword">return</span> <span class="code-keyword">new</span>
ServiceDef2()
    {
        <span class="code-keyword">public</span> <span class="code-object">boolean</span>
isPreventDecoration()
        {
            <span class="code-keyword">return</span> <span class="code-keyword">false</span>;
        }

        <span class="code-keyword">public</span> ObjectCreator createServiceCreator(ServiceBuilderResources
resources)
        {
            <span class="code-keyword">return</span> sd.createServiceCreator(resources);
        }

        . . .
    };
  }
</pre>
</div></div>

<h2><a name="DeveloperBible-Useof@since"></a>Use of @since</h2>

<p>When adding new classes or interface, or adding new methods to existing types, add
an @since Javadoc comment.</p>

<p>Use the complete version number of the release in which the type or method was added:
i.e., <em>@since 5.1.0.3</em>.</p>

<h2><a name="DeveloperBible-CodeStyle"></a>Code Style</h2>

<p>Yes, at one time Howard used leading underscores for field names. He has since changed
my mind, but this unfortunately infected other people; please try to make your code blend
in when modifying existing source.</p>

<p>Long ago, Tapestry (3) code used the regrettable "leading-I-on-interfaces" style.
 Don't do that.  Everything's an interface.</p>

<p>Howard prefers braces on a new line (and thus, open braces lined up with close braces),
so that's what the default code formatting is set up for. It's okay to omit braces for trivial
if statements, such as <tt>if (!test) return;</tt>.  </p>

<p>Use a lot of vertical whitespace to break methods into logical sections.</p>

<p>We're coding Java, not Pascal; it's better to have a few checks early on with quick
returns or exceptions than have ten-levels deep block nesting just so a method can have a
single return statement. In other words, <em>else considered harmful</em>. Low
code complexity is better, more readable, more maintainable code.</p>

<p>Don't bother alphabetizing things, because the IDE lets you jump around easily.</p>

<p><em>Final is the new private.</em>  Final fields are great for multi-threaded
code.  Especially when creating service implementations with dependencies, store those dependencies
into final fields. Once we're all running on 100 core workstations, you'll thank me.  Seriously,
Java's memory model is seriously twisted stuff, and assigning to a non-final field from a
constructor opens up a tiny window of non-thread safety.</p>

<h2><a name="DeveloperBible-Comments"></a>Comments</h2>

<p>Comments are overwhelmingly important.  Try to capture the <em>why</em>
of a class or method.   Add lots of links, to code that will be invoked by the method, to
related methods or classes, and so forth. For instance, you may often have an annotation,
a worker class for the annotation, and a related service all cross-linked.</p>

<p>Comment the <em>interfaces</em> and don't get worked up on the <em>implementations</em>.
 Javadoc does a perfectly good job of copying interface comments to implementations, so this
falls under the <em>Don't Repeat Yourself</em> guideline.</p>

<p>Be very careful about documenting what methods can accept null, and what methods
may return null.  Generally speaking, people will assume that null is not allowed for parameters,
and method will never return null, unless it is explicitly documented that null is allowed
(or potentially returned).</p>

<h2><a name="DeveloperBible-Documentation"></a>Documentation</h2>

<p>Try and keep the documentation up-to date as you make changes; it is <em>much</em>
harder to do so later.  This is now much easier using the Confluence wiki (you're reading
the result <img class="emoticon" src="/confluence/images/icons/emoticons/smile.gif" height="20"
width="20" align="absmiddle" alt="" border="0"/>).</p>

<p>Documentation is the <em>#1 criticism</em> of Tapestry!</p>

<h2><a name="DeveloperBible-ClassandMethodNamingConventions"></a>Class and
Method Naming Conventions</h2>

<p>Naming things is hard.  Names that make sense to one person won't to another.</p>

<p>That being said, Howard has tried to be somewhat consistent with naming.  Not perfectly.</p>

<h3><a name="DeveloperBible-Factory%2CCreator"></a>Factory, Creator</h3>

<p>A factory class creates new objects. Methods will often be prefixed with "create"
or "new".  Don't expect a Factory to cache anything, it just creates new things.</p>

<h3><a name="DeveloperBible-Source"></a>Source</h3>

<p>A source is a level up from a Factory.  It <em>may</em> combine multiple
factories together. It <em>usually</em> will cache the result.  Method are often
prefixed with "get".</p>

<h3><a name="DeveloperBible-Findvs.Get"></a>Find vs. Get</h3>

<p>For methods:  A "find" prefix indicates that a non-match is valid and null may be
returned. A "get" prefix indicates that a non-match is invalid and an exception will be thrown
in that case (and null will never be returned).</p>

<h3><a name="DeveloperBible-Contribution"></a>Contribution</h3>

<p>A data object usually associated with a Tapestry IoC service's configuration.</p>

<h3><a name="DeveloperBible-Filter"></a>Filter</h3>

<p>Part of a pipeline, where there's an associated main interface, and the Filter wraps
around that main interface.  Each main interface method is duplicated in the Filter, with
an extra parameter used to chain the interface.</p>

<h3><a name="DeveloperBible-Manager"></a>Manager</h3>

<p>Often a wrapper around a service configuration, it provides access to the contributed
values (possibly after some transformation).</p>

<h3><a name="DeveloperBible-To"></a>To</h3>

<p>A method prefix that indicates a conversion or coersion from one type to another.
 I.e., <tt>toUserPresentable()</tt>.</p>

<h3><a name="DeveloperBible-Worker"></a>Worker</h3>

<p>An object that peforms a specific job.  Workers will be stateless, but will be passed
a stateful object to perform some operation upon.</p>

<h3><a name="DeveloperBible-Builder"></a>Builder</h3>

<p>An object whose job is to create other objects, typically in the context of creating
a core service implementation for a Tapestry IoC service (such as PipelineBuilder or ChainBuilder).</p>

<h3><a name="DeveloperBible-Support"></a>Support</h3>

<p>An object that provides supporting operations to other objects; this is a kind of
"loose aggregation".</p>

<h3><a name="DeveloperBible-Parameters"></a>Parameters</h3>

<p>A data object that holds a number of related values that would otherwise be separate
parameter values to a method. This tends to streamline code (especially when using a Filter
interface) and allows the parameters to be evolved without changing the method signature.</p>

<h3><a name="DeveloperBible-Strategy"></a>Strategy</h3>

<p>An object that "plugs into" some other code, allowing certain decisions to be deferred
to the Strategy. Often a Strategy is selected based on the type of some object being operated
upon.</p>

<h3><a name="DeveloperBible-Context"></a>Context</h3>

<p>Captures some stateful information that may be passed around between stateless services.</p>

<h3><a name="DeveloperBible-Constants"></a>Constants</h3>

<p>A non-instantiable class that contains public static fields that are referenced in
multiple places.</p>

<h3><a name="DeveloperBible-Hub"></a>Hub</h3>

<p>An object that allows listeners to be registered. Often includes a method prefixed
with "trigger" that will send notifications to listeners.</p>

<h2><a name="DeveloperBible-Implement%7B%7BtoString%28%29%7D%7D"></a>Implement
<tt>toString()</tt></h2>

<p>Objects that are exposed to user code should generally implement a meaningful toString()
method. And that method should be tested.</p>

<h2><a name="DeveloperBible-Subclassing"></a>Subclassing</h2>

<p>You'll notice there isn't a lot of inheritance in Tapestry.  Given the function of
the IoC container, it is much more common to use some variation of <em>aggregation</em>
rather than <em>inheritance</em>.</p>

<p>Where subclassing exists, the guideline for constructor parameters is:  the subclass
should include all the constructor parameters of the superclass, in the same positions.  Thus
subclass constructor parameters are appended to the list of super-class constructor parameters.</p>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/TAPESTRY/Developer+Bible">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=23339445&revisedVersion=10&originalVersion=9">View
Changes</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message