This is the knowledge summary of May 2021.

Coding summary

Web Static server

When testing the front-end, debugging can be carried out directly in the browser. When there is a need for data interaction, simple background services can be built. Golang language to create web services, and specify Directory:

router := gin.New()
router.StaticFS("/", http.Dir(conf.Directory))
router.Run(":" + conf.Port)
Copy the code

A simple Web service image implemented by Golang is latelee/webdemo with a root directory of /dist, 80.

Create a Web service using NodeJS and specify the staticPath directory:

var app = new Koa();
app.use(koastatic(path.join( __dirname, staticPath)));
app.use(router.g_router.routes());
g_webServer = app.listen({
        host:SVR_HOST,
        port:SVR_PORT,
    });
Copy the code

Front-end and back-end notes

HTML files, or HTML files rendered by rendering tools (Hexo, Vuepress, etc.), need to be hosted on off-the-shelf Web servers such as Apache, Nginx, or Tomcat, with different root directories and sizes. The above implementation is also a Web server, but the volume will be much smaller, and can be directly integrated with background services. Of course, for scenarios with a clear division of modules, front-end pages and back-end services must be located on different servers/regions, which is another matter.

Other encoding

Continuing with makefiles: Last month we only practiced filtering specified files. This month, we studied the method of filtering directories. The method is relatively simple. In find, directly use grep -v to filter unwanted directories.

SRC_DIRS = .
SRCS := $(shell find $(SRC_DIRS) -maxdepth 2 -name '*.cpp' -or -name '*.c' | grep -v dir_notneed)
Copy the code

In the interest of generality, previous Makefiles used find to view the source directly, so all source files in a given directory were compiled. Of course, you can also specify the source file method manually, which is slightly more troublesome. If you first search directory, then search source file, because find found directory contains SRC_DIRS itself, use find to find, still will find the file filter directory, so we have not thought of a good solution.

I looked at some coding rules (actually VUE) and inherited some ancestral code (retaining a large number of functions written in 2015 that are no longer used), and I agree with the points mentioned in it. For example, for naming, code is first for yourself and second for team communication (some projects are always maintained by one person). Important points: Consider visuals such as caps, fixed prefixes, blank lines, comment positions, etc. Avoid abbreviations that are not commonly used and are agreed upon within the team. For the return value, some ret, some res.

Expansion: reduce user cognitive cost in software use, small scope, such as coding, everyone unified a set of code methods. Large range, such as some dialog box close button location, some upper left corner, some upper right corner; Such as “confirm”, “cancel” position is not fixed. But the environment is too large to be unified.

Simplicity is the best way to implement functionality/requirements in a simple way. Some strange skills and immoral, such as not necessarily, in addition to their own entertainment, someone appreciate, is also good, but hard to find bosom friend.

General knowledge

Research and development of thinking

Recently I looked at some object-oriented design principles, the single responsibility principle, the open closed principle, etc. General examples, to draw (triangle, circle) – based. In practice, it’s not so simple for the current project.

Code patterns, design patterns, architectural patterns.

Service intrusion: Sometimes special values (magic numbers) are assigned to certain variables or parameters for debugging or special purposes, which may affect the production environment. For example, setting the ID to a value that doesn’t exist, in case it later appears in normal business, will cause problems. Expansion: Some design needs to consider the follow-up development plan, and sometimes do not need to over-design, this degree is not easy to grasp, can only rely on experience. Example: for example, the toll station code of a province, using three digits, the maximum can only have 999, in case of more than, can be added to solve the code number, but if it involves the fundamental mechanism of the problem, affecting the whole body, the risk is greatly added.

Study and plan this month

Some front-end, back-end, microservice architecture, UML concepts and knowledge, to follow.

A static web site was built using Vuepress, with an internal server deployed.

I went round and round, from handwriting to bootstrap, to some frames, to VUE, and finally decided to go to VUE, embrace the mainstream, learn more, and keep my brain functioning properly.

Other intravenous drip

I stayed up more than last month. First, I have a lot of unlearned things to learn, second, I have to continue to get familiar with the business and code, and third, I was occupied by other things during the day and night. I feel like I just got out of bed every day. Sometimes Sledgehammer asks me to sleep with him, and then he gets lazy and sleeps a little more, but mostly he sleeps alone.

Many a night, standing on the balcony, looking up at the sky, listening to the mah-jongg in the opposite building and the cars outside, I wondered how I could balance the roles of son, husband and father. Do I have to be myself in my character? But my interests don’t take up space with those characters. In fact, the root of all is money. Learning technology and working is also for money. I can’t control how much money I have, and I can control whether I am diligent or not.