Power Fx is a language. Although it is recommended for low-code scenarios, we must look at it from the perspective of a language in order to better understand it.

Power Fx was created to better assist non-professional developers. Therefore, this language is designed to be simple enough. It is hoped that this language can serve both professional and non-professional developers. This is a very lofty ideal.

This week we will follow the Microsoft Power Fx overview article to learn more about how this language does it.

Overview

Notify("this is a problem", Error)

This is an example of the Power Fx language, which looks nothing special at first glance.

Power Fx describes the canvas application formula language, that is to say, this programming language is specially designed for canvas reference.

So what is a canvas application? Low code, website building, BI, and Web Excel are all canvas applications, so Power Fx is actually a language that adapts to the canvas scene, directly facing users.

So what characteristics should this canvas language have? The Power Fx team has some thoughts:

  • Simple: The language design is based on the principle of simple introduction, so that it is convenient for non-developers to get started.
  • Excel consistency: It can help Excel developers to transfer knowledge. Part of it is related to the success of Microsoft Excel. On the other hand, the exploration of Excel expressions in the field of canvas language is indeed in-depth and desirable. Try to learn from the declarative language of SQL for the unsatisfied.
  • Declarative: The most important thing is to describe what to do, not how or when to do it. This is a bit like the difference between procedural code and data-driven code when Jquery transitions to React mode.
  • Functional style: Functional style has natural advantages in flexibility and ease of use, and the feature of no side effects is also conducive to understanding logic and compilation optimization.
  • Combination: That is to use the feature of functional style, it is recommended to use existing functions to combine into new functions, rather than repeating functions such as Sort and Filter on each component or repeating configuration.
  • Strong typing: Types are crucial to maintainability. No matter how powerful a low-code language is, if there is no type support, it can't be called easy to use.
  • Type inference: The type can be inferred automatically. This is the same as strong typing, a bit of TS feeling, mainly to facilitate the writing of concise code.
  • Object-oriented is not recommended: Since functional is recommended, object-oriented is of course not recommended.
  • Scalable: Developers must have the ability to extend functions and components, and support extensions through Javascript.
  • Friendly to developers: This language should be as friendly as possible to developers as long as it does not conflict with the previous principles.
  • Language iteration: When the grammar changes, it is necessary to help users to migrate smoothly. After all, this language is directly aimed at ordinary users rather than professional developers. Power Fx provides this ability to mark the version of each document, and after the upgrade, the old syntax is automatically upgraded to the new syntax through the "compatible converter".
  • No undefined value: In order to simplify the cost of understanding the language, the specific undefined value is removed.

Therefore, Power Fx based on these considerations is designed like this:

  1. real-time

That is, no matter any UI or grammatical error, it will not block the work of other normal nodes, and the code effect and error information will be fed back in real time. This ensures a good experience of writing logic in the canvas application, because the canvas application itself is real-time, and the low-code capability itself must be integrated with the real-time performance of the canvas.

<img width=500 src="https://z3.ax1x.com/2021/09/25/4sqx1g.gif">

  1. Low code characteristics

That is, any UI component does not need to describe onChange . They only need to declare the variables used. When these variables change, the program will update the used components automatically, asynchronously, and on demand.

  1. Combine with no code

The so-called codeless is to configure the canvas application visually through the UI form.

The combination with no code is that any attribute can be written with low code, that is, expressions, but UI forms are also provided for editing. After the UI form is edited, it can be processed with low code for secondary processing, and edited with low code. Properties, the form cannot be edited, and clicking on the form edit will jump to the low-code edit box.

intensive reading

To create a programming language that can be used without learning, it needs to be simple enough to understand things from the user's perspective: For example, if the user does not know the concept of callback functions, then shield the so-called concept of callback functions and let everything be expressions.

These expressions seem simple, intuitive, and will automatically drive UI redrawing, that is, declarative programming.

Let's discuss a few interesting points below:

Why not use Js

Most canvas applications refer to Web applications. Even Excel has already transitioned to Web Excel. As far as Microsoft is concerned, it can be seen from the early transition to Office Online.

new function started is relatively low. In fact, the built-in programming language of many low-code platforms is Js, which has the advantage of low implementation cost (sandbox or even 0615117a181fe7), while Power Fx is on the browser platform In the end, it must be converted to Js for execution. With such great effort to create a new language, it is nothing more than feeling that Js is not "zero threshold" enough.

First of all, the first point is that it does not conform to the Excel expression specification. We must not forget that Power Fx is also careful. It wants to use the Excel ecology to expand the user base, so the first purpose is to be compatible with Excel grammar. For example, Excel uses the & link string, while Js uses the + link. Although I think it is obvious that the + sign is more natural, Microsoft still feels that it must conform to the habits of Excel users. To be honest, at this point, leaving aside the syntax of Excel, I can hardly see why the & connection string is "easier to use" and the + connection string is "more suitable for programmers."

But some are recognized, such as removing the undefined value, which really makes the language better understandable.

Maybe in the future Power Fx will go further and introduce SQL-like descriptive grammar, programming like a natural language. To this extent, with strong type hinting, it will be better than Js in specific scenarios.

Provide built-in functions

Js provides a large number of built-in functions, which does not seem to be a patent of Power Fx, but Power Fx provides many UI-level functions, which are alert stronger than the 0615117a182034 that Js points to so far.

Power Fx provides Confirm and Notify to pop up prompt windows for user input, and even if logic is to be formed, only almost one line of code is required:

If( Confirm( "Are you sure?", {Title: "Delete Confirmation"} ), Remove( ThisItem ) )

As you can see, here is full of asynchronous operations:

  • Waiting for user input.
  • Delete the element.

But the combination of these built-in functions converts asynchronous effects to synchronous writing, which greatly reduces development costs.

Another type of built-in function encapsulates business attributes, such as User to obtain current user information. Originally obtaining user information requires code development, but the low-code platform itself implements a full set of account systems, so the low-code platform can directly provide User().Email access the current user’s email address.

There are also Reset , which can reproduce the control to the default value, such as Reset( TextInput1 ) , which is actually abstracting all the upper-level capabilities provided by the platform into low-code functions for users to call, so that users only need to pay a little learning cost to get a simpler UI's powerful application editing capabilities are very worthy of our study.

For more formula functions, please refer to the document .

Provide operations on the table

operation on the table allows application data management to be viewed with the same concept as Excel. The unified way is to abstract the data into a table. Power Fx provides a series of functions for table processing:

AddColumns( 
    Filter( Products, 'Quantity Requested' > 'Quantity Available' ), 
    "Quantity To Order", 'Quantity Requested' - 'Quantity Available'
)

These functions can manipulate data from data sources such as Excel and Sql Server across languages, and the learning cost is similar to SQL. In fact, up to this point, the requirements for low-code users are not low, at least as good as Excel users who are proficient in using calculation formulas.

Summarize

The UI editing ability is limited but easy to use, and the code ability is the strongest but difficult to use. Power Fx provides us with a compromise solution, that is, to provide a "highly encapsulated simplified code" for users to use.

Looking at other low-code platforms, there is also a category that uses another compromise, that is, super complex editing UI. The product of the is logical arrangement. This direction is also a good choice in specific fields. Reference: 1615117a182177 Intensive Reading Low-code logic layout" .

The discussion address is: Intensive Reading of "Microsoft Power Fx" · Issue #355 · dt-fe/weekly

If you want to participate in the discussion, please click here , there is a new theme every week, weekend or Monday. Front-end intensive reading-to help you filter reliable content.

Follow front-end intensive reading WeChat public

<img width=200 src="https://img.alicdn.com/tfs/TB165W0MCzqK1RjSZFLXXcn2XXa-258-258.jpg">

Copyright notice: Freely reproduced-non-commercial-non-derivative-keep the signature ( Creative Commons 3.0 License )

黄子毅
7k 声望9.6k 粉丝