No More Writing Getters and Setters in Flex

eokyere blog has one of the best Flex productivity tips I have seen in quite a while.  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

8 Responses to “No More Writing Getters and Setters in Flex”

  1. Barney Boisvert said on September 17th, 2007 at 11:10 am

    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.

  2. Campbell said on September 17th, 2007 at 2:29 pm

    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.

  3. Tony Fendall said on September 17th, 2007 at 2:43 pm

    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.

  4. Jim said on September 17th, 2007 at 3:29 pm

    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.

  5. Bjorn said on September 17th, 2007 at 4:45 pm

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

  6. Tony Fendall said on September 18th, 2007 at 2:31 pm

    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

  7. Nathanael de Jager said on October 1st, 2007 at 9:53 am

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

  8. Frank said on May 9th, 2008 at 3:06 pm

    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.