Draft:Cangjie (programming language)

Cangjie is a high-level, statically typed, general-purpose, multi-paradigm, compiled imperative and declarative programming language developed by Huawei which was first released on June 21, 2024, as a beta recruitment of the developer preview version of the HarmonyOS NEXT app development for HarmonyOS operating system. It is also referred to as CangjieLang or CJ but its proper name is Cangjie.

History
Development of Cangjie started in 2019 by chief architect of Huawei's in-house programming language by Xinyu Feng, professor at the Department of Computer Science and Technology of Nanjing University alongside Tianjin University and Beihang University in its five-year development, with the eventual collaboration of many other software programmers and engineers at Huawei at that time during the development initial release of HarmonyOS that same year, after being incubated in the R&D labs.

In 2020, Huawei registered “Cangjie Language” trademark, which was classified as a “scientific instrument” and “web service” intellectual property in China. At that time, there were also rumors that Huawei was developing a new independent programming language Cangjie.

During HDC 2021, in October 2021, HarmonyOS 3 Developer Preview was officially released as the OS was moving towards declarative programming software development. Huawei also announced that at that time that it would introduce the self-developed programming language for HarmonyOS in the future.

It has also been reported between 2021 and 2022 that Huawei's programming language originally supposed to launch in 2022 or sometime around second half of 2022 which was pushed back due to ongoing development of HarmonyOS operating system internally.

On May 17, 2024, Cangjie programming language was internally added into OpenHarmony source code through its foreign function interface (FFI) mechanism.

On June 17, 2024, four days before HDC 2024, Huawei renamed it's programming language lab to Cangjie programming language and announces the developer sessions of the new programming language for the event.

On June 21, 2024, at HDC 2024, Cangjie developer recruitment that is running throughout June 21, 2024 until October 21, 2024, first landed for Huawei Mate60 Pro devices first with expansions of more devices going into 2025 rollout of HarmonyOS Next version. Silicon Valley-based LeetCode, ICBC bank, China Mobile, Kelan Software, became one of the first local app developer companies recruited by Huawei using the new programming language to test and showcase to other developers and industry with the release of commercial apps in the initial Chinese market launch of the new HarmonyOS Next version platform.

On July 5 to July 7, 2024, ACM China Turing Conference 2024 held with the Huawei Cangjie Programming Language Forum showcasing the new in-house domestic programming language across universities in China for Cangjie development integrated into academia.

Version history
Version history of Cangjie releases with HarmonyOS with OpenHarmony core API Level 12 SDK via DevEco Studio IDE.

Platforms
The platforms Cangjie supports are HarmonyOS, Linux, Windows and macOS for app development.

A key aspect of Cangjie design is its ability to attach with or without ArkTS code developed for HarmonyOS development. On Huawei devices running HarmonyOS, it allows Native APIs in DevEco Studio templates alternative to traditional Native APIs of C, C++ alongside ArkTS code to run within one program.

Features
Cangjie is a general purpose programming language which is 'autonomous and controllable' which is not based on any existing programming languages in superset unlike ArkTS which replaced previous existing legacy programming languages as the primary development language on HarmonyOS platform alongside ArkTS. The programming language employs modern programming-language theory concepts of other existing programming languages of its category that influences it such as Java with simple and advanced syntax features like Typescript-centric ArkTS language, in declarative programming development by complementing it with efficiency.

Cangjie features an embedded AgentDSL programming framework, natural language & programming language organic integration; Multi-agent collaboration, simplified symbolic expression, free combination of modes, and support for the development of various intelligent applications. It has a lightweight and scalable runtime, modular and hierarchical design, with Full-scenario domain extension, metaprogramming, and eDSL technologies support domain-oriented declarative development. In its first all-concurrent GC in the terminal scenario, for faster application threads. The lightweight threads with better concurrency performance and less overhead for programs on HarmonyOS development compared with Kotlin and Java on Android development in controlled benchmark brute force tests.

It is reported that applications that have already been developed on existing ArkTS do not need to be redeveloped into the Cangjie version on HarmonyOS Next version. HarmonyOS supports high-performance interoperability between the Cangjie language and the ArkTS language. In the future, developers can choose between Cangjie programming language or ArkTS for incremental development for developer needs. For high-throughput to high-frequency read/write data processing scenarios, high-frequency interaction and high-load scenarios, and scenarios sensitive to startup latency, it is recommended to preferably choose the Cangjie language that fills the gaps of ArkTS bottlenecks.

Cangjie also integrates 'Security DNA' into language design to help developers focus on app development functions over security functions around it that avoids vulnerabilities where it offers a static type system and automatic memory management to ensure application stability. That also includes runtime checks of detecting errors and cross-language security. Cangjie also supports various toolchains for app development, including language services such as highlighting and association, debugging with cross-language debugging and thread-level visual debugging, static checking, performance analysis, package management, document generation, Mock tools, testing frameworks, coverage tools, Fuzz tools, and intelligent assisted programming tools.

Examples
The following is an example of a simple AI Native application development program with Cangjie programming language on HarmonyOS. Definition of Agent @agent class Planner {

@prompt[pattern=APE] (   action: "Help users make travel routes",    purpose: "Let users visit more attractions and get enough rest in the planned time",    expectation: "Generate a reasonable route to a tourist attraction with information such as time, attractions, commute, etc."    )

}

Use of the agent let agent = Planner let result = agent. chat("我想前往上海")

STD module runtime
STD module runtime, known as Std.runtime is a module runtime package for Cangjie Standard Library via Cangjie Programming Language Library API that interacts with the program's runtime environment, with varaibles of controlling, managing and monitoring the program's execution. Cangjie languages uses automatic garbage collection mechanism in order to manage memory, and manual triggers around garbage collection with collection thresholds, obtaining memory statistics that regulate and monitor the garbage collection.

Compiler
With Ark Compiler, it supports a variety of dynamic and static programming languages such as JS, TS, and ArkTS as well as Cangjie. It is the compilation and runtime base that enables OpenHarmony alongside HarmonyOS based on the same platform to run on multiple device forms such as smart devices, mobile phones, PCs, tablets, TVs, automobiles, and wearables. ArkCompiler consists of two parts, compiler toolchain and runtime.

IDE and editor support
Cangjie uses DevEco Studio plug-in for HarmonyOS native development as Cangjie SDK using default declarative ArkUI, also other third-party UI frameworks on HarmonyOS NEXT version and OpenHarmony SDK with future cross-platform ArkUI-X support.