1 / 38

Designing Docassemble Interviews for Maintainability

Learn how to write code that is easy to follow, speeds up development, and makes your life easier. Discover basic techniques, control flow strategies, coding style tips, interview file organization, and the benefits of object-oriented programming.

stran
Download Presentation

Designing Docassemble Interviews for Maintainability

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Designing Docassemble Interviews for Maintainability Quinten Steenhuis, Founder, Lemma Legal Consulting @QSteenhuis

  2. Why care? • Write code your future self can follow • Speed up development • Make your life easier

  3. When does it matter? • When your interview is “big enough” • You start to get frustrated with navigating around it

  4. Premature optimization is the root of all evil ” Donald Knuth

  5. 5 Basic Techniques • Manage control flow in one place • Use good coding style • Use the “right” number of interview files • Use the right editor • Use object-oriented principles

  6. “need” is considered harmful

  7. Interview Flow Control • Use one mandatory code block to control program flow • Give the code block an ID • Use only simple branching logic in the control block

  8. Use one control block • One place to look to understand program flow • Easily change the order of questions • Easily test different questions that don’t depend on earlier questions

  9. Model Interviews https://lemmalegal.com/2019/06/17/designing-docassemble-interviews-for-maintainability-start-to-finish/

  10. 2. Code with Style

  11. Using “good” coding style • Use the id tag to label questions and code • Use the variable name standards • Use comments

  12. Tag your blocks • Easy to find the question you need • Needed for Google Analytics • Aid in translation • Aid in debugging

  13. The nice thing about standards is that you have so many to choose from ” Andrew Tannenbaum

  14. Variable Name Standards • https://bit.ly/2IkW7mz (Michelle from Code for Boston) • On Slack: #structuring-code

  15. 3. Divide and Conquer

  16. Why do you need a separate interview file? • Question reuse • Translation (old style only) • Multiple simultaneous authors • Interview file is just “too long”

  17. Use the right number of interview files • Start with 1 • Separate reusable questions • Keep a skeleton interview with control flow • Keep related questions/code together, but take advantage of search

  18. 4. Get your edit on

  19. Some popular (free) editors • VS Code • Atom • Notepad++ • Emacs? ViM?

  20. Using an external editor • Plain text means you choose the editor • Better search/replace • Code completion • Split screen view

  21. 5. Objectify your life

  22. Why use Classes / OOP? • Make your code readable • Use advanced Docassemble features • Make your code more modular and reusable • Simplify your interviews • Write idiomatic code

  23. Object oriented classes • Create once and use again • Build iteratively • Hide implementation details

  24. Built-in classes to understand: • Individual • Address • Date • DAList

  25. Built-in classes are used in • send_email(), send_sms() • map_of() • Pronouns/age functions • Collective/singular tense matching

  26. Are classes easy? Truthfully, no. But it’s worth learning the basics. Start here: https://bit.ly/2wSTTVd

  27. A common pattern: DAObject and DAList Asset / AssetList Individual / Individual List 3-4 attributes, a collection, and one-two methods that count or act on the attributes (such as sum)

  28. Common Pattern #2: API query • Constructor that uses the Docassemble configuration to get an API key • A getter for each type of item retrievable by the API • A setter • Extend over time as you use more of the API

  29. Quinten Steenhuis, Lemma Legal @QSteenhuis Questions?

More Related