Detailed explanation of the implementation concept of the engine technology in agreed-style programming (1)

Source: Internet
Author: User

Detailed explanation of the implementation concept of the engine technology in agreed-style programming (1)

In the front-end world, we often hear about the XX engine and the XX framework. What exactly does it look like? What should we do if we want to write the engine? What should we pay attention to when writing engines? What can engine technology bring to us?

This article aims to find some valuable ideas and discuss them with you.

Author Profile

Qu Yi, a special guest at the 51 cto wot summit, once a Special Lecturer at the 7th WOT mobile Internet Developer Conference. He has been engaged in Internet R & D for 11 years. He has served as an architect, Senior Technical Manager, and Technical Director for Internet companies such as Goyang, Skynet, and lebee. I have been focusing on mobile Internet for nearly four years. I am a senior HTML 5 expert and researcher in China. I have a deep understanding and understanding of HTML 5 technology and have rich practical experience, is the creator of HTML 5 engine Crow 5. He has been invited to serve as a guest and expert at Zhongguancun online, iweb Summit and GITC global Internet conference.

Qi lekang, Senior Technical Director

1. What is an engine? What is a lightweight framework? What is a heavyweight framework?

In fact, the engine is not as magical as we think. It can be understood as a more convenient framework for encapsulation. Engine Technology is also a framework technology. There is no essential difference between the two. Our front-end frameworks are well-known, such as jquery, zepto, sea, and Kissy. These frameworks are simple to use, lightweight, and have a low learning threshold. These are advantages. These frameworks are like small blocks. Each framework has its own characteristics and solves the pain points encountered during development for specific use cases. For example, jquery encapsulates a large number of Javascript methods, freeing engineers from repeated coding, browser compatibility, and special animation effects. However, when we are working on a mobile project, we will find libraries such as Jquery that are not very practical. It is clear that Jquery solves many problems that are convenient for PC browser compatibility, which is too large for mobile devices, many compatibility problems no longer exist. Then the zepto framework appears. Zepto positioning is a mobile device, so it is much smaller. For example, we can use Sea. js to handle javascript module loading problems. Sea is a javascript module loading framework that complies with CommonJS specifications. It can be used to develop and load javascript modules.

Each framework has a self-built design concept and a solution to the pain points. Use as few code as possible to solve more problems and provide a convenient API. These are the advantages of a lightweight framework. However, this is a problem for our development engineers. When we are working on a project, we will encounter many problems, in addition to module development, dynamic loading, template technology, and animation processing. There is also cache processing. If the function is complex, you also need to call the geographic location and gravity sensing. A large number of small frameworks are required. If you do not use the database, you need to write it yourself, then you have to fill in one of the pitfalls from the ground up. Using libraries is just like playing card games. So is there any good framework that can fix all of us?

This world is amazing. As long as you have a need, someone will solve your needs. The answer is yes. In the front-end world, in the open-source world, everything is ready-made. The advantages are absolute, but we never lack tools. There are many heavyweight frameworks, such as YUI, EXT, Anglar. js, and Bootstrap. These all belong to the heavyweight framework. The advantage of using them is that they share the same track, share the same document, and unify the measurement and balance. In addition to loading their core libraries, what do you want? These heavyweight frameworks also provide many plug-ins for you to use. But the question is, how many features can we use for such a heavy item? In addition, there is a common problem in heavyweight frameworks: codoon is kidnapped, and the thinking of codoon is constrained. You can only write code in their own way. What functions are required is to mechanically find plug-ins. Extension plug-ins are required if they do not fully match each other. A small problem may occur for a long time. It's hard to solve any pitfalls. A lot of flexibility is swallowed up. Now we all know what the development speed means. In addition, the learning of heavyweight frameworks is undoubtedly the same as learning a language, and the learning cost for the team is also very high. For various reasons, the weight frame is not used much in reality. It is difficult to replace the actual situation. Programmers would rather piece it together than get a package. This is why heavyweight frameworks such as YUI are no longer updated.

The Times and concepts have been changing and revising. heavyweight frameworks have too many advantages but cannot truly occupy an absolute share. In addition to using them, there are also many reasons such as network limitations.

In short, the heavyweight framework integrates the features of many lightweight frameworks and provides unified coding rules. Many small frameworks are integrated to avoid patchwork. However, it loses flexibility, abduct development, and impede expansion. Increases learning costs.

So what is the engine? The first engine is the framework. Then the engine must have the advantages of lightweight and fast. It is a plug-in and a mode. We also need to have the idea of a heavyweight framework. We can give a unified methodology to avoid piecing together. At the same time, the engine should not kidnap development like a heavyweight framework. It should be able to provide flexible methods for developers to use.

2. How did engine technology come into being?

Engine technologies must carry forward the advantages of lightweight frameworks. Plug-in development is also non-intrusive and cross-cutting. It can be used when you are willing to use it, and can be easily extracted when you are unwilling to use it, the engine should continue to learn the unified idea from the heavyweight framework, and provide a complete solution to solve the problem as much as possible.

During coding, the most common idea is encapsulation, which is also an important idea of framework and engine technology. We encapsulate the operation, animation, rendering, and business classes, and then check whether we can extract smaller granularity. Finally, we encapsulate these classes into a class library, finally, store them according to a good directory and naming rule. Facilitate reference, and then provide a suitable method for loading and scheduling to combine code. When open, programmers will constantly expand various granularity libraries. Future development will be a bit like building blocks. Then, a simple small framework suitable for our project has taken shape.

But these are far from enough, because at least one important thing missing is the rule. Although code can be built by building blocks during code writing, a lot of hard work is missing. But there are still base code operations. Finally, we will find that, when doing a function, there will always be loading template resources, request data, rendering processing, event processing, and so on, however, the methodology repeats countless times. Imagine if we can turn these repeated methods into rules so that the code can automatically execute them according to a certain relationship, we can save a lot of mechanical repetitive base code processes.

Based on this idea, I designed the rule engine. Crow5 was born under such guiding ideology. Although the Code cannot be fully automatically generated by the code, the code should be as close as possible to generate more code. So why can code be generated based on some logic? Very simple: I wrote a kernel, and this kernel does nothing, that is, to read the commands I issued and complete the base code process through the commands I issued. So What Are commands? Is a configuration file that I gave this kernel. In such a thinking process, we have the following designs.

Based on the module development, we used to implement the control, service, module, and dao hierarchical processing function. The final mode has changed. The final layer is the code assembly by the kernel. At last, we only need to give instructions.

We can see that when writing code, the method has changed. In the past, we had to write logic control code and functional code. Now you only need to provide a command called the configuration file.


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.