HarmonyOS Development: What is ArkTs

AbnerMingAbnerMing
9 min read

Foreword

this paper is based on api13.

In a word: ArkTs (Ark programming language) is currently the main language of HarmonyOs application development.

In official terms, it is a programming language designed to build high-performance applications. Seeing that it ends with Ts, it must be easy for everyone to think of TypeScript. Yes, ArkTS is more straightforward. It is a language that has been optimized and expanded on the basis of inheriting TypeScript syntax.

The TypeScript language is very popular among developers because it provides a more structured JavaScript coding method, and ArkTS also maintains most of the syntax of TypeScript. It can be said that if you have a TypeScript language foundation, you can seamlessly connect ArkTS and get started very quickly.

Declarative development paradigm

although, for different purposes and technical backgrounds, in addition to the current ArkTs language, application development can also use the Web-like development paradigm, that is, to develop applications through classic HTML, CSS and JavaScript. However, as application development, considering performance, underlying interaction, complexity, development efficiency and future development trend, ArkTs language is definitely our preferred method at present. Similarly, it is also the official way to push.

At present, the two development methods are as follows:

name of development method

language Ecology

UI update method

applicable Scenarios

applicable crowd

declarative development paradigm

ArkTS language

data-driven update

programs with greater complexity and teamwork

mobile system application developer, system application developer

web-like development paradigm

JS language

data-driven update

simpler interface for program applications and cards

Web front-end developer

what is certain is that the future must be a declarative development paradigm. You can look at the current Android or iOS. Although the regular development method still dominates, the declarative UI development frameworks Compose,SwiftUI, and Flutter are also constantly developing and growing, and are constantly moving towards the first choice of developers. Speaking of which, let's extend the advantages of the declarative development paradigm.

Advantage

as we all know, in the traditional imperative development method, if you want to render a data for a UI component, you must first obtain the specified component, and then set the data to the UI component through a certain method to achieve the function of data rendering. However, in this method, developers should not only pay attention to the essence of the problem, but also participate in the specific implementation steps, not only the code is redundant, but also the performance is consumed, in view of such a deficiency, which is not found in the declarative development paradigm, let's look at the advantages of the declarative development paradigm.

1, code simplicity and readability.

The declarative development paradigm emphasizes "what" rather than "how". It does not need to worry about the specific process, making the code more concise and easy to read. That is to say, in development, developers only need to focus on describing the page structure and behavior, without getting into specific implementation details, which helps to improve development efficiency and reduce errors and debugging time.

2, high level of abstraction

the declarative development paradigm is relatively more abstract, allowing developers to focus more on the nature of the problem rather than the specific implementation steps, and this high-level abstraction helps improve the maintainability of the code because the logic is clearer and relatively easy to maintain.

3. Great potential for performance optimization

the declarative development paradigm is usually combined with features such as reactive programming and data binding, enabling pages to automatically respond to changes in data and achieve dynamic updates, while the underlying framework can be implemented for specific optimization strategies, such as Virtual DOM, dirty check, etc., to improve rendering speed and responsiveness.

4, portability and parallelization.

The logic and structure of the declarative development paradigm is decoupled from the underlying implementation, making it easier to implement cross-platform and portable code, and some declarative programming models are easier to perform parallel calculations, further improving performance.

It should be noted that although the declarative development paradigm has many advantages, it does not force everyone to switch. In actual development, due to developer preferences, historical legacy or other factors, it is recommended that everyone choose their own suitable development method.

ArkTs ADVANTAGES

Hongmeng development has a relatively good advantage. After NEXT, it directly provides a declarative development paradigm. Therefore, when we cut in, there is no need to have any burden. As mentioned earlier, although Hongmeng provides a Web-like development paradigm, for the sake of performance, better bottom-level interaction and future development trends, both the official and the author are concerned, it is suggested that everyone develop Hongmeng application and get started with ArkTs directly.

1. High development efficiency and good development experience

the code expression is streamlined and efficient: the user interface (UI) is outlined in a way that is close to natural language, so that developers do not need to delve into the UI drawing and rendering details within the framework, thus focusing on the implementation of creativity and functionality.

Data-driven UI dynamic updates: This mechanism allows developers to focus more on the core processing of business logic. Once the UI needs to be adjusted, developers do not need to write complex UI switching code in person, but only need to pay attention to and write the data logic that triggers the interface update. Specific UI changes are intelligently processed and presented by the framework.

Excellent development experience: Because the interface design is also presented in the form of code, this feature greatly enriches the programming experience of developers, enabling them to create and debug more smoothly in the familiar code environment.

2. Superior performance

the declarative UI architecture realizes a clear hierarchy between the front end and the UI back end: the UI back end is based on the high-performance C ++ language, and carefully constructs all-round support covering basic components, flexible layout, vivid effects, rich interaction events, fine component state management and efficient rendering pipeline, providing a solid foundation and powerful functions for the front end.

In terms of language compiler and runtime optimization, a number of advanced technologies have been implemented, including but not limited to unified bytecode to improve execution efficiency, efficient external function interface (FFI) to facilitate cross-language calls, using ahead-of-time compilation (AOT) technology to reduce runtime overhead, implementing engine minimization to reduce resource consumption, and type optimization to enhance code security and execution speed. Together, these optimizations ensure superior performance and efficient operation of the platform.

3, the ecology is easy to advance quickly

it can make full use of the advantages of the mainstream language ecology to achieve rapid development. Its language design uphold the principle of neutral and friendly, easy to integrate with a variety of programming languages and tools. At the same time, with the support of the corresponding standards organization, it can follow the established specifications and roadmap, continuously evolve and continuously improve the function and performance of the platform.

ArkTs architecture

declarative UI front-end

this layer mainly provides the basic language specification of UI development paradigm, including built-in UI components, layout and animation, etc., and also provides diversified state management mechanisms to ensure accurate tracking and efficient management of application states. In order to further improve the experience and efficiency of application developers, it also provides a series of interface support, covering all aspects from component calling to state synchronization, all-Round help developers to create excellent user interface.

Language Runtime

the language runtime, which has powerful parsing capabilities for UI paradigm syntax, supports cross-language calls, and provides a high-performance runtime environment for TypeScript(TS) languages.

Declarative UI backend engine

The back-end engine integrates UI rendering pipelines that are highly compatible with various development paradigms, which not only covers diversified basic components, accurate and efficient layout calculation, smooth and vivid dynamic processing and rich interactive event response, but also is equipped with a powerful state management mechanism and flexible rendering functions to meet the needs of UI development in all aspects.

Rendering Engine

provides efficient rendering capabilities, the ability to draw the rendering instructions collected by the rendering pipeline to the screen.

Platform Adaptation Layer

provides an abstract interface to the system platform, with the ability to access different systems, such as system rendering pipeline, lifecycle scheduling, etc.

Adaptation rules (understanding)

enforce static typing: Static typing is one of the most important features of ArkTS. If static typing is used, then the type of the variable in the program is deterministic. At the same time, because all types are known before the program actually runs, the compiler can verify the correctness of the code, thereby reducing runtime type checking and contributing to performance improvements.

Prohibit changing object layout at runtime: For maximum performance, ArkTS requires that object layout cannot be changed during program execution.

Restricting operator semantics: For better performance and to encourage developers to write clearer code, ArkTS restricts the semantics of some operators. For example, the unary addition operator can only work on numbers and cannot be used on other types of variables.

Structural typing is not supported: support for Structural typing requires a lot of consideration and careful implementation in the language, compiler, and runtime, and is not currently supported by ArkTS. According to the needs and feedback of the actual scene, we will reconsider later.

Extended Capability (Understanding)

Currently, in the UI development framework, ArkTS mainly extends the following capabilities:

basic syntax: ArkTS defines declarative UI descriptions, custom components, and the ability to dynamically extend UI elements, together with the system components in the ArkUI development framework and their related event methods and attribute methods, to form the main body of UI development.

State Management: ArkTS provides a multi-dimensional state management mechanism. In the UI development framework, the data associated with the UI can be used within the component, can also be transferred between different component levels, such as between parent and child components, between father and son components, can also be transferred within the global scope of the application or across devices. In addition, from the form of data transfer, can be divided into read-only one-way transfer and can be changed to two-way transfer. Developers can flexibly use these capabilities to realize the linkage between data and UI.

Rendering control: ArkTS provides the ability to render control. Conditional rendering can render UI content in the corresponding state according to different states of the application. Loop rendering iteratively takes data from the data source and creates corresponding components during each iteration. Data lazy loading iterates data from the data source on demand and creates the corresponding components during each iteration.

Summary

this summary mainly briefly introduces the relevant knowledge of ArkTs language, which is of some conceptual nature. As an understanding, you need to know the following:

1. ArkTs is based on TypeScript and has been expanded.

2, understand the relevant architecture of ArkTs and related advantages.

0
Subscribe to my newsletter

Read articles from AbnerMing directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

AbnerMing
AbnerMing