Are there any "best" or at least "common" practices to handle allowances in OpenSCAD code? I'm designing a few mechanisms with OpenSCAD, and one of the parameters that need adjustment between printers/filaments is allowances between pieces that need to be assembled together (for example, if I want a "5&nbsp;mm diameter pin" to fasten two pieces together, how much larger than 5&nbsp;mm will the holes / how much smaller than 5&nbsp;mm will the pin need to be).

Currently I approach the problem by setting a global variable allowance and manually using it in the code, something like:

module pin(radius) {
    cylinder(r = radius + allowance)
}

module hole(radius) {
    cylinder(r = radius - allowance)
}


I have no real world experience with design though, so I wonder if there are common or coding best practices to account for allowances when designing parts like for example:


specific modules to be used,
conventional names for variables
specific techniques to be used (scaling? vectors?)
conventions (like only use tolerances on the fastener, not the fastened object)
...?


To clarify: I'm not looking on advice on how to plan the dimensions of my designs.  Rather, I am looking for advice on how to organise the OpenSCAD code generating them.
It helps to understand the different aspects of dimensions, so you can use the terminology correctly.  This will help you define your variables in OpenSCAD with correct names.  (Tolerance is the wrong term to use.)  And once you have correct names, you'll understand how to specify the dimensions in OpenSCAD.


Tolerance is the amount of random deviation or variation permitted for a given dimension.
Allowance is a planned difference between a nominal or reference value and an exact value.  
Clearance is the intentional space between two parts.
Interference is the intentional overlap between two parts. 


Two other terms 


Accuracy is the maximum dimensional variation between parts.  A machine cannot produce parts with a tighter tolerance than its accuracy.
Precision is the size of the steps your machine is capable of. It is often confused with accuracy.


In your case you need to define the allowance in order to create the clearance you desire.

To design your 5&nbsp;mm pin and 5&nbsp;mm hole, you need to understand your machine's accuracy.  The printer could print the pin larger than 5&nbsp;mm or smaller than 5&nbsp;mm.  Or it could print the hole larger than 5&nbsp;mm or smaller than 5&nbsp;mm.  You'll need to print some pins and holes and measure the differences between what you defined and what you printed.  The difference between the largest and smallest measurements you take is your machine's accuracy.  And be sure to check the accuracy in your X, Y, and Z dimensions; your printer might have a difference between them that would impact the roundness of the parts.  

Let's say that your printer's measured accuracy is &plusmn;&nbsp;0.2&nbsp;mm.

Then, we move to clearance.  What is the minimum gap between parts you are looking for, and what is the maximum you can accept?

Let's say you want a clearance of at least 0.2&nbsp;mm between the pin and hole, but no more than 1.0&nbsp;mm.  Since your accuracy is &plusmn; 0.2&nbsp;mm, your pin will be 5.0&nbsp;&plusmn;&nbsp;0.2&nbsp;mm, so the hole must therefore be 5.6&nbsp;mm&nbsp;&plusmn;&nbsp;0.2&nbsp;mm.  The minimum tolerance condition would be an minimum sized hole (5.4&nbsp;mm) and a maximum sized pin (5.2&nbsp;mm); the maximum tolerance would be a maximum sized hole (5.8&nbsp;mm) and a minimum sized pin (4.8&nbsp;mm).

Note that a clearance of 1.0&nbsp;mm might be too sloppy for your application.  You might think to tighten the tolerances to 0.05&nbsp;mm in order to reduce the clearance.  But if your printer can't produce a part that meets your specified tolerances, you would need to find a different way to manufacture or finish the parts.