Some misunderstandings about betl

original
2016/09/14 10:32
Reading amount 1.5W

Beetl is becoming more and more popular in China. There are thousands of visits to community websites every day, and the number of downloads is about 20 every day (Maven cannot be counted). Before the QQ group is full, it has kicked off a number of inactive members and a small number of people whose values do not match (when writing this article, it was the fermentation of Ali mooncake event). It has become famous and has many negative comments. I listed some negative comments

Beetl is missing a document

If you search for beetl tutorials and documents, you will find that you can only locate the official website documents of beetl and a small number of beetl instructions written by the author. You can't think that it is caused by a small number of users of beetl. This just shows that the documentation on the official website of beetl is sufficient, and the community provides various demos and timely answers to questions. Compared with JSP, Freemaker has countless articles on how to use a cycle, and countless authors have tirelessly written articles on these simple concepts. Beetl does not have such articles or even videos. Beetl syntax is based on JS, and is originally developed by Chinese people. There is no difficulty in documentation and communication

 

Beetl uses<%%>, like jsp, which is very ugly.

This is also a mistake. In fact, the betl delimiter can allow arbitrary symbols, such as<?  ?> , <! -- # -->similar to html comments, Or a simple @ can be paired with a carriage return and line feed symbol, as shown in the following code

 @ for(u in userList){ <span>${uLP.index}:${u.name}</span> @}

Beetl's syntax is like Java

The Beetl syntax refers to javascript, so it looks like Java in form, which is also the reason for the low learning curve of Beetl. However, as a template language, Beetl is specially used for output, which is much better than Java based JSPs. For example, in the previous code, uLP is a built-in loop variable, which can obtain the current index, parity lines and other information. You only need to add LP after the loop variable, which is specifically used for template output. In addition, beetl supports else for. The above code does not enter the loop body. You can use else for explanation

 @for(){ @}elsefor{ <span>No record</span> @}

Bestl template language has the following features customized for templates:

  • Omitted ternary expression
  • Safety output
  • Select case syntax
  • Html tag
  • Format Output
  • Directly call java methods or properties
  • Multiple layout functions
  • Template Variables
  • Strict MVC control

These syntax are template specific syntax, which is totally different from java

Prefer directive rather than scripted template language.

The directive template syntax like Velocity is preferred by some people because there are fewer instructions. But the disadvantages are also obvious. When dealing with complex logic rendering, it is often more ugly and difficult to write. Beetl is a script based template engine, which may have more syntax, but it is not difficult to understand based on JS, and script based syntax is also more handy when dealing with complex rendering logic. Don't be confused by the helloworld example of the directive template engine. It looks cool, but when used in projects, it is the same as script.

 

Template performance is not important

I have also seen on the Internet that it is better to optimize database access than to optimize the template engine. I think it is right. If I also consider optimizing database access first, but if all these are optimized, I can also use a better template engine to improve performance, The performance of beetl is 6 times higher than that of freemaker and 2 times higher than that of JSP (there are also three party tests that are 3 times higher than that of JSP, which may be caused by the excessive use of JSTL). The template engine involves CPU computing and IO output, which is actually a resource consuming part in Web applications. I think that if this consumption can be reduced, it will improve the system performance. If your database access has been optimized well and your business code has been written perfectly, why can't you use a template engine with better performance? Beetl doesn't need to do any additional operations to achieve maximum performance. It already has good performance.

 

The back-end template engine is not important

This is a fact. Now the front-end template engine is becoming more and more important. Beetl has also developed a beetljs, but because of its huge size, it is not good at those 7K and 8K template engines, so it has not been launched. The volume can only be optimized in the future, and the syntax features can be reduced before the timing is selected.

Even if the trend is like this, I think the back-end template engine has its advantages and is still important at present:

  • The function and maintainability of the back-end template engine are far better than the front-end template engine
  • The back-end template engine is located at the back-end, so it is easy to obtain back-end data, while the front-end template engine needs to prepare all data
  • The back-end template engine has a wide range of applications: code generation, static page generation, and some back-end template functions, such as sending email, SMS, etc
  • Most companies are short of front-end talents, and the use of front-end template engines will lead to more people concentrating on the front end. The company tries to use less front-end analog board engine before preparing for this change
  • In terms of development efficiency, the back-end template engine has been popular for many years, so it should be more efficient than the front-end template engine
  • The back-end template engine is suitable for SEO optimization, while the front-end template engine is difficult
  • The back-end template engine has layout function

I think the correct way to use the template engine is to combine the front end with the back end. Of course, the front end template engine is also learning from the back end simulation engine, which will become more and more perfect. Maybe one day it will dominate the web application. In addition, architecture oriented services, the widespread use of mobile terminals, and front-end simulation engines are really becoming more and more important

 

Expand to read the full text
Loading
Click to join the discussion 🔥 (18) Post and join the discussion 🔥
Reward
eighteen comment
zero Collection
nine fabulous
 Back to top
Top