Video: code generation with Sprouts & TextMate

Sprouts & TextMate code gen from Stray on Vimeo.

Recently a few people, including Troy (@troygilbert) and Paul Robertson (@probertson) have been asking about my workflow with TextMate and Sprouts.

So I screencapped an example of where I really feel like they are giving me a power-up. I’m sure you can do this level of code generation in many other IDEs, but the ease with which you can do it with Sprouts+TextMate makes it hard to resist.

The usecase shown here is an air app that controls a whole bunch of inter-related data. All data types need to be loaded, some also need to be edited and saved/deleted.

In version 1 of this app – built a few years ago – the specifics of each loading/saving/deleting process were implemented through switches and conditionals. I came to hate this system.

In this version, each data type has a strong event type that goes with it – AccountDataEvent, UserDataEvent, GroupDataEvent etc. I have some simple base classes that capture the common processes of moving the data between the app and the server, but the differing logics are wired up using the CommandMap instead.

I know from my version 1 experience that actually these data types each require something a little special. The upside of this approach is that I’ve got a small, digestible, chunk of code in each specific class. They’re isolated from each other’s changes. I can develop and test them and know that they won’t get messed up by the next type I add.  The code is written to the concrete types so I’m doing very little casting.

The downside – in many peoples eyes – is that saving and deleting alone require an extra 7 classes and 7 test cases.

And that’s where the power of Sprouts generators really comes in…

About the Author

I'm an actionscript programmer living and working in a tiny village in the Yorkshire Dales, UK. I used to be a TV reporter, but my inner (and often outer) geek won. I also write stuff. Most recently Head First 2D Geometry.

Visit Stray's Website

Share the post

Delicious It Digg this! Stumble this! Share on Reddit Share on Buzz Share on FriendFeed