In this lesson we won’t add new functionality to the Paint Pot app. Instead, we will revise the code, leaving the app’s behavior unchanged. This process is called refactoring and programmers do this to improve the quality of their code in various ways -- e.g., to simplify its design, make it easier to read and easier to maintain.
In this case we will introduce the concept of a programmer-defined procedure that will help reduce the complexity of our code and make it easier to read and maintain. This is an example of procedural abstraction, a very important concept and practice in programming.
- To continue learning how to navigate the App Inventor online programming platform.
- To introduce the concept of a programmer-defined procedure.Learn to solve simple programming problems
Refactoring to Improve Code
Open App Inventor with the Paint Pot Refactor template in a separate tab and follow along with the video tutorial. After the project opens, use the Save As option to rename your project PaintPotWithProcedure
Adding Comments to Code
An important feature of every programming language, including App Inventor, is the ability to add comments to the code. A comment is a non-executable block of text that can be added to a program to provide clarification and documentation of the code. Adding comments to one’s code is a standard practice that programmers employ to help others (and themselves) understand their code.
In App Inventor, each non-collapsed block comes with the capability of having a comment added to it. To access this capability you must right-click on the block and choose the Add Comment option. This will add a small comment-icon, a blue circle with a question mark, to the block.
Good Commenting Practices
A good practice to follow is to provide comments in the following situations:
- To document every procedure that you define
- To clarify a complex algorithm that isn’t clearly obvious