No More Writing Getters and Setters in Flex

by Tom Mullaly on September 17, 2007

eokyere blog has one of the best Flex productivity tips I have seen in quite a while; if you are a Flex developer trust me, you don’t want to miss this. I build AS3 components all day, and spend way too much time manually typing getter and setter methods.  Using the Dash plugin for Eclipse and eokyere’s productivity with with dash in eclipse, you’ll never write another getter and setter again!

Dash is a plugin for Eclipse that contains Eclipse Monkey  which is a dynamic scripting tool to automate of routine programming tasks. Monkey scripts are little Javascript programs using either the Eclipse APIs or custom Monkey DOMs.

Adobe Flex Builder

Be Sociable, Share!

{ 8 comments }

Barney Boisvert

Why, pray tell, would you ever write a getter/setter in Flex that you didn’t have to hand code? The whole point of implicit getters and setters is that you can gain the benefits of getters and setters WITHOUT HAVING TO WRITE THEM.

Campbell

I got me a swanky logitec G15 keyboard that has macros. and have a whole macro bank for as3. Just highlight the private var and hit M3. very cool if you get into the groove using them.

Tony Fendall

Barney has a good point. If you only need to get and set the variable then just make it public. You only need to create getters and setters when the behaviour is more complicated, and thus can’t be generated.

In reality developers spend less than 10% of their time actually writing code (most is spent on design and debugging), so anything that only saves you 20-30 charecters at a time doesn’t really make much difference to your development cycle.

Jim

With most getters/setters I write, I many times have to check bounds or values on the setter and/or calling commitProperties(). So for consistency I write getters and setters as a convention.

Maybe I am missing something, but when reading and learning how to write components, the books I have read make use of getters/setters extensively. Also looking at the conventions used in the Flex SDK, the Adobe engineers seem to use getters and setters everywhere (so can they be all that bad).

As for saving the typing – sure it doesn’t save much time, but typing them is just a plain old pain in the ass.

Bjorn

Flex dev is full of repetitive coding. Getters/Setters the no. 1 culprit.
I’ll try any tool that provides code automation in Eclipse.

Tony Fendall

Something which largely refutes my previous comment:
In AS3 you can override a getter and setter, but you can’t override a property. In this case then, it’s a good idea to use getters and setters in components which are likely to be extended in the future

Nathanael de Jager

Using getters can also help you avoid having your variables set before the instance of your class is fully created.

Frank

Wow. Awesome stuff. Auto generating getters and setters is definitely a huge help. Sure you only need them in complex situations, but the fact that the mundane part gets auto-gen’ed is very nice.

Comments on this entry are closed.

Previous post:

Next post: