Random techie babbling...

FDT – Templates are your friend!

Jason Nussbaum suggests on his blog the use of a standard naming convention in all your get and set functions to save you a few seconds thinking time. This is all good, but how about taking it one step further by ensuring you always use standard names while also saving some typing? If you’re using FDT I just might be able to help…

A nifty feature of FDT that not many people seem to know about is Templates. Templates allow you to easily insert and customise chunks of code, anything from one line to whole classes, in a few keystrokes. Being a lazy git at heart I have a lot of love for this feature, and use it often. The best thing is you can also easily make your own Templates to automate your regular tasks, and in this post I’ll show you to add a simple Template to write a pair of ‘get’ & ‘set’ data access functions in a record time…


Getting Stuck In
If you don’t know already, FDT comes with a set of Templates built in. To see one in action, create a new class and hit CTRL+A, type ‘sing’ and hit CTRL+SPACE…. BAM, an entire singleton class ready for your use, how cool?! Some other good ones to try out are ‘fore’ and ‘fori’, you can also just hit CTRL+SPACE on it’s own to pick from a list (the entries with a little page by them are Templates)

Modding the Templates
To view the existing templates and add your own, you have to go to the slightly burried property panel under Window->Preferences->FDT->Editor->Templates

prefs.jpg

You can click around to take a look at the ones already there to get an idea of how they work. Basically they are much like most template engines, with a bunch of boiler-plate text and some variables to be replaced, in this case enclosed in ‘${‘ & ‘}’, e.g. ${cursor}, ${user} etc. To see the standard predefined variables you can insert hit the ‘insert variable’ button for a list. Alternatively you can add your own vars and these will be requested from the user when the template is run.

By now you’ve probably got a good idea of how to make your own template functions (it’s not too hard once you’ve found where to do it!), so before you get bored of reading me ramble on and go off to watch youTube, here’s some code…

//get & set ${param}
public function get ${param}() : ${type} { return _${param}; }
public function set ${param}( value:${type} ) { _${param} = value; }

Just hit ‘New’, enter ‘getset’ as the name and past the above into the ‘pattern’ box then OK.

If you now type ‘getset’ and hit CTRL+SPACE you should just need to enter the variable name and type and job done.

Another nice side effect of this is it assumes (and kind of enforces) the use of an underscore prefix on all private local members, although you can of course change that in the template if you want.

So there you go, get & set functions in record time thanks to the mighty Templates. I use this at least half a dozen times a day when coding, saving myself whole seconds in the process, and although I can’t guarantee your productivity breakthroughs will be as astounding I encourage you to give it a try :)

Feel free to add any of your own handy templates to the comments.

vpxl pricecheap vpxlviagra vs cialisorder viagra cialis onlinelevitra professionallevitra professional onlinelevitracheap levitracialis jelly onlinecialis jellycialis soft tabscialis softcialis super active pricecheap cialis super activediscount generic cialischeap generic cialisorder cialis professionalbuy cialis professionalorder cialiscialischeap brand viagrabuy brand viagraorder viagra jellyviagra jelly priceviagra softbuy viagra soft tabsviagra super active priceviagra super activeorder generic viagrageneric viagra onlineviagra professional onlinecheap viagra professionalviagraviagra onlinerevatio onlinebuy revatioorder brand viagrabuy brand viagraorder cialis super activecialis super active onlinecheap female viagrabuy female viagraorder vpxlbuy vpxlcheap levitra professionallevitra professional onlineorder levitrabuy levitracheap cialis soft tabsbuy cialis soft tabsorder viagra soft tabsbuy viagra soft tabsviagra super active onlinecheap viagra super activeorder generic cialisgeneric cialis onlinecheap generic viagrabuy generic viagracheap cialis professionalcialis professional onlinecheap viagra professionalviagra professional onlineorder cialiscialis onlineorder viagrabuy viagracialis viagra mastercard acceptedbuy cialis australiatadalafil cialisbuy 10 mg cialiscialis sale overnight shippingcialis safe secure online shoppingcialis mail ordercialis free consultationcialis best price buy onlinecialis anti impotencebetter more effective cialis or viagraindian cialis pillshow to buy cialis onlinebuy cialis without credit cardbuy cialis visa worldwide deliverybuy viagra cheap fedexwhat is viagraorder viagra canadabuy taladafil viagraviagra mail order ukviagra low pricemail order viagrabuying viagrabuy cheapest viagra onlinebuy cheap viagra online ukviagra best prices fda approvedgeneric viagra money ordergeneric viagra mail orderexpress delivery viagradiscount viagra sales onlinediscount viagra pill salediscount viagra cialisbuy viagra internetbuy viagra in stoke on trentorder viagra reliable drugstoreorder viagra phonediscount revatiorevatiobuy female viagrafemale viagracompare viagra cialisviagra prescriptioncheap vpxlbuy vpxlorder levitra professionalbuy levitra professionalpurchase levitralevitra pricelevitra onlineorder cialis jellybuy cialis jellycialis soft tabscialis softorder cialis super activebuy cialis super activediscount generic cialischeap generic cialischeap cialis professionalcialis professional onlineorder brand cialisbrand cialis onlinebuy cialis prescriptioncialis pricecialisorder brand viagrabrand viagracheap viagra jellyviagra jelly priceorder viagra soft tabsbuy viagra soft tabsorder viagra super activeviagra super activegeneric viagrageneric viagra onlineviagra professional onlinebuy viagra professionalbuy viagra prescriptionviagra priceviagra onlinediscount revatiocheap revatiofemale viagra onlineorder female viagraviagra cialisviagra cialis shippingvpxl pricevpxlorder levitra professionalcheap levitra professionallevitra free shippingbuy levitracheap levitracialis jelly pricecialis jellycialis soft tabscialis soft tabs onlinecialis super active onlinecialis super activegeneric cialis onlinebuy generic cialisorder cialis professionalcialis professional pricecialis free shippingcialis onlinecialisdiscount brand viagrabrand viagra onlineorder viagra jellyviagra jellyorder viagra soft tabsbuy viagra soft tabsviagra super active priceviagra super activegeneric viagrabuy generic viagraorder viagra professionalcheap viagra professionalviagra free shippingviagra priceviagra onlinediscount revatiorevatio onlinefemale viagra onlinefemale viagratake viagra cialis togetherviagra cialis free deliverycheap vpxlvpxllevitra professional pricebuy levitra professionalpurchase levitraorder levitralevitra onlineorder cialis jelly
0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

2 Comments

Got something to say? Feel free, I want to hear from you! Leave a Comment

  1. Liam says:

    Right you are. I’ve done exactly the same thing for a while now.
    Another handing FDT tip and general piece of lovliness is the use of Event Metadata.
    If your class dispatches an event, then at the top of the class between the imports and the class declaration you add metadata for each event
    [Event("onDataParsed")] for example
    then whenever you reference an instance of the class and type myInstance.addEventListener you can control+space after the opening bracket and lo and behold all the events are there. This means you don’t have to remember, or open up the class to refresh your memory of the event type string, without a nasty static variable string for no reason. Every little helps

  2. Heidi says:

    This is a terrific feature in Eclipse, but what about users of Flex 2 Builder? There is currently no access to the built-in class templates, but is it possible to use the kind of templates you mention here without going back to plain Eclipse?

Leave a Comment

Let us know your thoughts on this post but remember to place nicely folks!