« [Tip] Mac manual startup of server | Main | [Tip] PostgreSQL sequences in Servoy »
April 18, 2005
[Tutorial] Organization: naming conventions
by David Workman
Data Mosaic, Inc.
Not since the days when 80% of the world's code resided in COBOL has there been a better tool for writing spaghetti code than Servoy. What?!? How can this happen with an advanced development tool such as Servoy?
If you are like me, developing your first Servoy solution was a struggle of organization. Where did I put that method? What did I name that method? What does this method supposed to do? How much of the code in this method can I copy to paste into my new method? Do I make this a global method or a form method? How do I pass parameters again? Oops, I want to rename 302 forms to be consistent, now what?
Organization is the key to Servoy happiness. In this series of mini-tutorials, I'll let you in on the things that I have learned to do over the past couple of years to be happy in Servoy land. To kick us off, a few thoughts on....
Naming conventions
I use the underscore naming convention for methods, field names, forms, objects, value lists, relationships, etc. Typical method names are "REC_delete", "NAV_next" and "PRINT_report_a". Typical form names are "lvl0_invoice", "lvl1_invoice_form", "lvl1_invoice_list" and "lvl2_invoice_items". Typical object names on a form are "btn_shipping", "fld_shipping" and "bn_chart". Field names in the database backend follow a similar pattern. I don't do anything special with relationship names -- I find the default names do the job nicely.
For variables in methods I use the lower-upper case naming system. "formName", "elementName" and "fieldTrigger" are examples. One addition I like to use is denoting array types in the naming convention like this:
var formNamesARY = new Array;
The advantage to using the two naming systems is that it is easy to tell what is a local variable and what is a named object or field in methods:
name_value = "David Workman"; //value assigned to a field
nameValue = "David Workman"; //value assigned to a local variable
The trick with naming is to use the most generic word of the name first and get successively more specific with the following words. This groups similar items in the various lists (method editor, forms list, value list list, etc).
With forms, I denote the "level" at which the form resides with the first word. "lvl0_invoice" means that this is a parent form based on the table "invoice" and can contain many sub forms. It cannot be a sub form to another form. "lvl1_invoice_list" would be a form that is a list based on the invoice table and located on a tab panel of form "lvl0_invoice". If you use a lot of tab panels (and tab panels within tab panels), this will save your life once your solution reaches forms numbering in the hundreds.
Make sure to start with a naming convention because changing your system mid-stride is not much fun since all the code in your methods is name dependent. However, it can be done using the global search and replace that the method editor has had for a while now. Back in 1.0 days, once you named something, that was it!
The root of organizing your Servoy solution lies in how well you implement your naming conventions so definitely get this area figured out. If you don't, you are bound for a world of hurt.
[Please share your thoughts and ideas in the comment section on this subject. I still haven't made it out of the experimentation stage with naming conventions.]
| Posted by David Workman on April 18, 2005 at 10:56 AM in Tutorials | Permalink
Comments
Hi David
Agree need for organisation having succeeded in comprehensively breaking an early solution when I used "FM-think" to rename a bunch of layouts. My layout naming slightly different but I think achieves the same aim:
contacts_ main form (underscore keeps it top of contacts section)
contacts_t_summary top level tab
contacts_t_documents top level tab
contacts_t_documents_t_list tab on documents
contacts_documentnew_pop 'form-in-dialog' popup for new doc
Had restricted my field and variable names to a mere 3-4 "systems" - but the ideas in your article has probably increased that by 50% !!
Regards
Graham Greensall
Worxinfo Ltd
Posted by: Graham Greensall | Apr 19, 2005 9:04:32 AM
I really think it would be great if Servoy was able to do the changes for me automatically, like Filemaker. If I change a form name then Servoy would update all occurences of the form in any method. This should be the same for method name changes too. This is one of the biggest advantages Filemaker has over all other development environments.
Sadly I know that Servoy development team would have to rewrite Servoy to take advantage of such a feature.
But I can dream.
Posted by: Raymanj | Apr 19, 2005 10:05:24 PM
I use a variation on this naming technique for forms and elements. I name my ELEMENTS on a form like:
btn_ = button
fld_ = field
tab_ = tabpanel
port_ = portal
lbl_ = label
bean_ = javabean
For FORMS I use:
dlg_ = forms used in dialogs
tab_ = forms used in tabpanels
lst_ = forms in list view
tbl_ = forms in table view
frm_ = forms in form view (or for data entry)
_DEV_ = temporary forms used in development
I hope this helps.
Also - I have a comment to Raymanj's posting about Servoy changing the object names automatically: I agree that it would be a cool thing to have. However, the amount of work to do this one feature has to be balanced with other featurs. Perhaps Servoy WILL rename all occurances of objects in the future - we'll just have to wait and see.
Also - don't forget that it's FileMaker's proprietary database structure and proprietary file format that allows them to do that. I challenge you to find ANY other non-FileMaker product that does that for you. :-)
Posted by: Bob Cusick | May 2, 2005 12:33:46 PM