Top Qs
Timeline
Chat
Perspective

Cangjie (programming language)

Programming language From Wikipedia, the free encyclopedia

Remove ads

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

Quick facts Paradigm, Developer ...
Remove ads

Etymology

Cangjie is a legendary figure in Chinese folklore credited with first inventing Chinese characters.[3] Huawei has named other products after Chinese mythological creatures, such as the Huawei Kirin mobile chipset, named after the qilin creature (Chinese: 麒麟; pinyin: qílín).[4]

History

Summarize
Perspective

Development of Cangjie was started in 2019, by Xinyu Feng, who is a professor at the Department of Computer Science and Technology of Nanjing University.[5] He had assistance from Tianjin University and Beihang University in its initial five years of development,[6][7][8] with the eventual collaboration of many other software programmers and engineers at Huawei, during the development of HarmonyOS's initial release and after it was incubated in the R&D labs.[9]

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

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, at that time, it would introduce its self-developed programming language for the HarmonyOS in the future.[11]

It was also reported, that between 2021 and 2022, the programming language was supposed to have actually been launched in 2022. It was supposedly pushed back due to ongoing development of the HarmonyOS operating system.[1][12][13]

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

On June 17, 2024, four days before HDC 2024, Huawei renamed its programming language lab to Cangjie programming language and announces the developer sessions of the new programming language for the event.[15]

At the Huawei HDC 2024 Developer Conference, whose registration period was between June 21, 2024 to October 21, 2024, beta recruitment for HarmonyOS NEXT took place.[16] Only Huawei Mate60 Pro devices were supported, with more devices planned for 2025.[17] Silicon Valley-based LeetCode, ICBC bank, China Mobile, Kelan Software, were among the first local app developer companies recruited by Huawei using the new programming language. This was to test and showcase to other developers and the industry, by releasing commercial apps into the Chinese market, during the launch of the new HarmonyOS Next version platform.[18]

On July 5 to July 7, 2024, the ACM China Turing Conference 2024 was held with the Huawei Cangjie Programming Language Forum, showcasing the new domestic programming language across universities in China and integration into academia.[19][20]

In September 2024, the Cangjie programming language was officially launched on LeetCode.[21]

Cangjie was open-sourced on July 30, 2025.[6][8]

Version history

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

More information Version, Release date ...

Platforms

The platforms Cangjie supports for app development are: HarmonyOS, Linux, Windows, macOS, Android and iOS.

A key aspect of Cangjie's design is its ability to attach with or without ArkTS code. On Huawei devices running HarmonyOS, it allows the native APIs in DevEco Studio templates, C, C++, and ArkTS code to run alongside each other in one program.[23]

Remove ads

Features

Summarize
Perspective

Unlike ArkTS, Cangjie is a general purpose programming language that has not evolved based on any existing programming languages. The programming language, however, employs modern programming-language theory concepts and advanced features found in other existing languages in its category, such as Java. It can be used in a multi-language hybrid development environment, with the Typescript-centric ArkTS language, to create complementary advantages for greater efficiency gains and based on different scenarios.[24]

Cangjie features an embedded AgentDSL programming framework, natural language & programming language organic integration.

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 the Cangjie programming language or ArkTS for incremental development to satisfy developer needs.[25][26]

Huawei also claims that the language integrates security features into its design, aiming to allow developers to focus on application functionality while, reducing potential security vulnerabilities.[16][5] The language provides a static type system and automatic memory management to enhance application stability, alongside runtime error detection and cross-language security measures.[27] 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.[28]

Basic syntax

Cangjie's "Hello, World!" program is:

main() {
  println("Hello, World!")
}

Immutable variables are declared with the let keyword and mutable ones with the var keyword. Values must be initialized before they are read. Values may infer their type based on the type of the provided initial value. If the initial value is set after the value's declaration, a type must be declared explicitly.[29]

Pattern matching

Pattern matching in Cangjie is provided by the match expression, which has two forms: one with a value to match and the other without a value to match. A match expression with a value checks each case in sequence, executing the corresponding code when the pattern matches successfully. To ensure exhaustiveness, the last case often uses a wildcard pattern _ to cover all possible values. A match expression without a value will still evaluate the expression following the case and does not need a pair of brackets for the condition.[1]

Lambda expression

A lambda expression can have no parameters:[1]

let f = {a: Int64, b: Int64 => a + b}
let print = { => println("Hello Cangjie")}

Foreign function interface

Cangjie has built-in FFI support for C and Python. External functions are declared using the foreign keyword and called using the unsafe keyword. For C interoperability, Cangjie supports automatic conversion between basic data types. The CPointer<T> type corresponds to C pointer types, for example, and CPointer<Int32> corresponds to int32_t *. For Python, Cangjie supports interaction through the ffi.python library in std. It requires Python version 3.0 or above and currently only works on Linux.[30] Below is an example:

More information C code ...

Metaprogramming

Cangjie is explicitly designed for meta-programming [31] and supports two main types of macros:

  1. Non-attribute macros, which take a single input parameter for the code being decorated.
  2. Attribute macros, which accept an additional attribute parameter allowing developers to pass extra information to the macro.

Compared to functions, macros in Cangjie require the macro keyword, that can be placed in a macro package and are invoked using the @ symbol. While macro nesting is supported in calls, macro definitions cannot be nested themselves. The expansion of nested macros follows an inside-out order, and macros can share information through global variables. Macros can appear in both parenthesized and non-parenthesized calls. Developers can use quote expressions to create Token objects.[30]

Remove ads

STD module runtime

The STD module runtime, known as std.runtime, is a runtime package for the Cangjie Standard Library (via the Cangjie Programming Language Library API) that interacts with the program's runtime environment. It has functions and variables that control, manage, and monitor the program's execution.[1]

Development tools

Summarize
Perspective

Compilers

With Ark Compiler, it supports a variety of dynamic and static high level programming languages such as: JS, TS, ArkTS, as well as Cangjie, including Cangjie-ArkTS interoperability.[32] It is the compilation and runtime base that enables OpenHarmony, alongside HarmonyOS, 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.[33]

Cangjie programming language also features a dedicated LLVM-based Cangjie Compiler that includes Cangjie runtime for high level native code development on multiple-platforms such as Windows, Linux, macOS and HarmonyOS (OpenHarmony) targeted towards PC platforms and complex applications.[34]

Package manager

Cangjie Package Manager (CPM) is the built-in package management tool for the Cangjie programming language that comes installed with the cjc toolchain. In Cangjie, a package is the smallest compilation unit, with each package capable of containing multiple source files (.cj files) and having its own namespace; a module is a collection of packages, representing a complete functional unit and serving as the minimum unit for third-party developer releases. The new command creates a new module, generating a module.json file and src folder. Each module's program entry point must be in its root directory, and the top level can have at most one main function as the program entry point.[30]

IDE and editor support

Cangjie uses the DevEco Studio plug-in for HarmonyOS native development, along with other third-party UI frameworks for HarmonyOS NEXT and the OpenHarmony SDK, that have future cross-platform ArkUI-X support. The Cangjie SDK also includes a declarative user interface framework called ArkUI.[35][36]

Remove ads

See also

References

Further reading

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads