Developer Discussion – SmartThings Developer Best Practices
Posted in : Developer Discussions on by : Tim
Here’s a look back at the developer Discussion from July 13, 2016.
We talk about SmartThings development best practices and how to make your SmartThings development as successful as possible. Here is a preview of some of the practices we talk about.
Code should be readable
Code is executed by machines, but read by humans. Readability can be subjective, but there are some general guidelines that should be followed:
Don’t repeat yourself
Follow the DRY principle (don’t repeat yourself).
Don’t copy/paste code blocks – pull common code out into a shared utility method.
Methods should serve a single purpose
Methods should serve a single purpose, and be concise. If a method definition doesn’t fit on a standard computer screen, it’s way too big.
Look for opportunities to split out code into utility methods. For example, parsing a large HTTP response inline can bloat a method; instead, split out the parsing into a method that can then be called. This facilitates easier understanding of the code, and promotes better separation of concerns.