Writing Open Source Plugins

Posted by David Estes on May 19, 2014

Filed under Grails, Open Source

Writing plugins for your favorite framework, or language, can be a very enjoyable and rewarding experience. There are so many open source projects out in the world now. Wether you're writing plugins for Rails, Grails, or even PHP, there are tons of examples and guides on how to make them. But how do you make a plugin that everyone wants to use? How do you support your plugin without it consuming your time? How do you encourage outside contributors to aid in your endeavor? All of these are great questions that can come with multiple answers. There are, however, a few key factors that every developer should follow to help them pursue these goals.

Elegance In Simplicity

Keeping your code clean and simple is imperitive in making a quality plugin. This key factor affects almost all of the questions asked earlier. Some plugins decide to accompish a large sum of issues in one swoop. This is problematic for the user and, in the long run, the developer who made the plugin. When a plugin becomes bloated, it becomes more difficult to test and maintain. This means, as your userbase grows, more issues get reported, and more time is spent by you (the developer) maintaining the project. Bloated plugins also discourage outside contributions. The more difficult your plugin is to understand, the more frustrated a potential contributor becomes. A large plugin can also become more susceptible to breaking as its dependencies are updated.

Write beautiful code. Some of you may think that sounds crazy, or there is no such thing, but trust me; This is definitely a thing. Writing nice code can be different with each respective language or framework being targeted (In the case of PHP, there is definitely a hurdle ;) ). Keep your classes and functions short. Don't script out a glorious thousand line function that accomplishes some level of black magic that noone can understand later. Instead, split this method into several smaller, reusable pieces of code. Methods should be well named and short ( try to keep it under 15 lines ). Make those method names long and obvious. If your method requires a comment above to explain its purpose, most of the time, that means you need a better function name. Not only is your code easier to read, it's also easier to test! Testing is paramount to maintaining a stable plugin with low upkeep.

Minimize Dependence

One common issue that I see crop up in plugins, time and time again, Is a dependency breaking the plugin. In some cases the dependency in question, is so small and minor, that it seems silly to be a dependency. As you go off to write your awesome project, stop and think about a dependency that you may want to add to your project. What does it bring to your project? Is it something that could be easily implemented internally? If not, how stable is this dependency historically? Is it actively being supported and developed? Are there alternative options? If you ask yourself these questions and keep your external dependencies to a minimum, you have set yourself up for a plugin that can better tolerate outside package updates out of your control.

Seek Feedback

Don't be afraid to ask for community feedback. See what the audience thinks of your plugin. Give them an early rough cut preview to play with and make suggestions. Take to twitter, irc, mailing lists, or wherever the community is to tell them about your project and ask for feedback. You might get some really good ideas as you progress which can give the plugin that extra edge needed for wide adoption.

Support your users.

Supporting yout userbase in a timely and helpful manner is extremely important. If a github issue is raised, try to resolve it as soon as possible. Not only will this make the reporter happy you resolved their issue. It will also give them reason to tell others about your project and its active support. If a feature is requested, sometimes its best to say no. The last thing we want is scope creep. Encourage discussion in the feature. Why is it important? Could it be implemented differently, or in a better way. Do this before typing a line of code. You will find, this keeps the project focused on key features and leaves the minor ones for later.

Following these tips, should help guide anyone looking to make a quality open source plugin. These rules not only apply to plugins, but really any open source project looking to encourage growth. Good luck and happy coding!