Pseudocode Encoding Process

Source: Internet
Author: User

Reference books: Code Daquan Second Edition

Steps for creating classes and subprograms

The general process for creating a class is as follows: 1:

Figure 1 General Design Process

At the beginning of my initial programming career, I always felt that casual nature was the source of a programmer's maximum creativity. Copying books would only make development a simple pile of code without any art. However, in fact, some rules based on experience are as follows, you can maximize the development speed and consider every possible situation as much as possible-it won't get stuck in debugging after 400 lines of code.

  • For details about how to create an overall design interface, access control, and whether to inherit/be inherited, see "available classes".
  • Create a subroutine in the class
  • Review and test the entire class
Process 2 for creating a sub-program: Figure 2 general process for designing a sub-Program

When designing a sub-program, using pseudo-code for pre-design is a good habit. Generally, programmers have basically developed this habit. However, there are still some details to note when writing high-quality pseudo codes:

  • Avoid using the syntax in the target language for description
  • When writing pseudo code, there is also an iterative process. First, we start to design the code at the High Level, constantly breaking down the problem, and discovering details until we can quickly write the pseudo code.
  • Finally, it should be noted that a well-written pseudo code can serve as a comment !!!
The general process for defining a sub-program:
  • Check prerequisites: Are requirements determined? Can it be consistent with the overall design?
  • The problem to be solved by defining subprograms: What information needs to be hidden? Input and Output? What are the definitions of pre-and post-conditions?
  • Name subroutine
  • Prepare test cases
  • Is there reusable code? An important factor in improving Code productivity is the reuse of high-quality code.
  • Consider error handling (try to be consistent with the error handling in the Program Framework)
  • Consider program efficiency issues. (In general, a good abstraction is required, so that optimization can be performed quickly when performance requirements are met. Generally, the performance of subprograms does not affect the system performance, high-level architecture has a greater decisive impact on system performance ).
  • Study algorithms and data structures (when the existing library cannot provide support)
  • Write a pseudo code
  • Try more implementation methods in the pseudo code, leaving the best one (multiple iterations)
Compile the subprogram code: After the design is complete, you can start to implement the subprogram. Here there are some basic procedures for reference, as shown in 3: figure 3 Procedure for writing subprograms:
  • First, determine what the subroutine is to do, determine a complete interface, and determine how to output the result.
  • After completing the design, give the function a good name and then write the function definition.
  • Use the vim plug-in to add a comment framework to the function and write basic comments, such as the front and back conditions, functions of the function, functions of parameters, and meanings of returned values.
  • If the variable of the condition after the definition is a valid value, add the condition before and after the assert statement is used to verify.
  • After the execution is correct, modify the post-condition to an invalid value and write the code according to the design framework (I like to complete the pseudo code and design framework on paper.
  • Prepare test cases and use automated testing tools for testing
Do not have any fantasies about the development method of make after finding out the error and modifying it again, because it is a shameless waste of your own life.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.