Python function flat management, the experience of drawing program structure diagram for the first time

Software: dia
Insert picture description here
This is the picture I drew yesterday. In fact, it has completed most of the functions, but because it is all about the unicode character set function, I want to write it in a file, but when I wrote it today, I found it really difficult to separate each The module is connected well, so this structure diagram is rejected.
In fact, the flowchart can be drawn at will, how you want to draw, but it only applies to a function. When combining multiple functions together, the first time I drew a picture and the first time I integrated it, I found that this is not the same as a flowchart, so I call it a structure diagram, and the most important thing is the method of integration.
For example, I am after the character set comparison, but I want to return to the homepage, and I want to go back to the previous page, and then back to the previous page, can't I go back to the homepage directly? Although I can write the home page as a main() and call main() directly, but this is the same as the iteration structure. The current function is not released, and main is called on the current function. I wanted to start from the beginning. At first, it became a tail.
After thinking, I decided to change the structure. I found a similar template on the two online drawings on the Internet as a reference. Actually, I don’t like to draw pictures online, I prefer to master it completely. Although it may not be easy to use, I am poor and can’t bear to spend money!

processon: Distributed segmented lock template. Insert picture description here
Quick drawing: program design flow chart.
Insert picture description here
I have an idea. There is a global variable area and a function menu management area. Each module can be connected to the menu management module, so the structure in the upper module is no longer used. .
Insert picture description here

from sys import exit

def test(): # 210 µs 函数扁平化处理
    t='f1'
    def m():
        for i in range(1000):
            if t=='f1':f1()
            elif t=='f2':f2()
    def f1():
        nonlocal t
        t='f2'
        return
    def f2():
        # print('bingo')
        # exit()
        return
    m()


# t m - f1
#     - f2    

def vs(): # 259 µs 函数层层return
    def m():
        for i in range(1000):
            f1()
    def f1():
        f2()
        return
    def f2():
        # print('bingo')
        return
    m()

# m - f1 - f2

In fact, in the later stage, I also want to replace if with a dictionary containing functions. This is the case today.

Of course, you can also ask, why not write them all in one layer? It is indeed possible to write them in one layer, but in terms of logical function, at least judging characters have nothing to do with the character set, unless you write a judgment method yourself, which is better than based on the statistics. Collection, faster than is. But I think the possibility is low.

For another example, comparing a general collection, it’s easier to separate it out. If you don’t make a separate list, but there are historical records, you have to write a little more complicated, but viewing the history is still a separate list function. For example, save the result of a set comparison into another dictionary.

Guess you like

Origin blog.csdn.net/jhsxy2005/article/details/113735546