Draft:Cangjie (programming language): Difference between revisions

Content deleted Content added
m clean up, typo(s) fixed: in June 21, 2024 → on June 21, 2024, June 21, 2024 → June 21, 2024, (3), long term → long-term, a extension → an extension, it's → its (5), ’s → 's
 
(29 intermediate revisions by 11 users not shown)
Line 1:
{{AFC submission|d|nn|u=158.181.216.135|ns=118|decliner=Stuartyeates|declinets=20250102225902|ts=20241128073832}} <!-- Do not remove this line! -->
 
{{AFC comment|1=The article needs independent coverage, that is secondary source with in depth coverage not written or published by people associated with the language. Pretty much all of the sources below are good for sourcing details of the language but not for proving notability. [[User:Stuartyeates|Stuartyeates]] ([[User talk:Stuartyeates|talk]]) 22:59, 2 January 2025 (UTC)}}
 
----
 
{{Short description|Programming language}}
{{Draft topics|internet-culture|software|computing|technology}}
{{AfC topic|stem}}
 
{{Connected contributor|Poppodoms}}
{{COI|date=July 2024}}
{{Use mdy dates|date=July 2024}}
{{Infobox programming language
Line 17 ⟶ 28:
| typing = [[Duck typing|Duck]], [[Gradual typing|gradual]], [[Structural type system|structural]], [[type system|Static, strong, safe]], [[nominal type system|nominative]], [[manifest typing|manifest]], [[Strong and weak typing|strong]], [[Type inference|inferred]]
| memory management =
| operating system = [[HarmonyOS]], [[Linux]], [[Windows]], [[macOS]]
| license = [[Proprietary software|Proprietary]] (HarmonyOS)
| website = {{plainlist|
Line 24 ⟶ 35:
}}
| file ext = .cj
| influenced_by = [[ArkTS]], [[TypeScript]], [[JavaScript]], [[Swift (programming language)|Swift]], [[C Sharp (programming language)|C#]], [[F Sharp (programming language)|F#]], [[Java (programming language)|Java]], [[C++]], [[Go (programming language)|Go]], [[Python (programming language)|Python]]
| influenced =
}}
 
'''Cangjie''' is a [[High-level programming language|high-level]], [[static typing|statically typed]], [[general-purpose programming language|general-purpose]], [[multi-paradigm programming language|multi-paradigm]], [[compiled language|compiled]] [[Imperative programming|imperative]] and [[Declarative programming|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.<ref name="vid" /> It is also referred to as '''CangjieLang''' or '''CJ''' but its proper name is Cangjie.<ref>{{Cite web |last=Matsui |first=Emiko |date=2024-06-21 |title=Huawei programming language to make official debut at HDC 2024 |url=https://www.huaweicentral.com/huawei-programming-language-to-make-official-debut-at-hdc-2024/ |access-date=2024-07-06 |website=Huawei Central |language=en-US}}</ref>
 
== 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,<ref>{{Cite web |title= |script-title=zh:天津大学、北航深度参与华为"仓颉",推出首个基于国产编程语言的 AI 智能体编程框架"苍穹" |trans-title=Tianjin IT之家University and Beihang University deeply participate in Huawei's 'Cangjie,' launching the first AI intelligent agent programming framework based on a domestic programming language, 'Cangqiong' |url=https://www.ithome.com/0/776/987.htm |access-date=2024-07-06 |website=www.ithome.com}}</ref> 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.<ref>{{Cite web |title= |script-title=zh:华为下一代编程语言"仓颉"首席架构师揭晓:南京大学冯新宇教授 - IT之家 |url=https://www.ithome.com/0/776/982.htm |accesstrans-datetitle=2024-07-06The |website=www.ithome.com}}</ref>chief Cangjiearchitect wasof motivatedHuawei's by the need for an extension and longnext-term replacement of C++generation programming language dealing with [[cybersecurity]] and [[Artificial intelligence|Artificial Intelligence]] usage, alongside desires around ending restrictions from core American-based technologies in [[Entity List|US entity list]] when it comes to possibilities around compilers, runtimes and proprietary AI frameworks and models with technologies like [[Gemini (chatbot)|Gemini]] of operating systems such as [[Android (operating system)|Android]] owned by [[Google]] which not only carried legal baggage but also limitations for the goals of future HarmonyOS development in its underlining architecture which"Cangjie" has been re-writtenrevealed: sinceProfessor [[HarmonyOSFeng NEXT]]Xinyu upgradedfrom development version.<ref>{{Cite web |last=Matsui |first=Emiko |date=2024-01-18 |title=Huawei launches HarmonyOS NEXT Galaxy version forNanjing developersUniversity |url=https://www.huaweicentralithome.com/huawei-launches-harmonyos-next-galaxy-version-for-developers0/776/982.htm |access-date=2024-07-06 |website=Huawei Central |language=en-USITHome}}</ref>
 
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.<ref>{{Cite web |last=Amit |date=2021-09-25 |title=Huawei to launch a self-developed programming language Cangjie next year |url=https://www.huaweiupdate.com/huawei-to-launch-a-self-developed-programming-language-cangjie-next-year/ |access-date=2024-07-06 |website=HU |language=en-US}}</ref>
Line 38 ⟶ 49:
During HDC 2021, in October 2021, HarmonyOS 3 Developer Preview was officially released as the OS was moving towards [[Declarative programming|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.<ref>{{Cite web |last=Benjie |first=Joshua |date=2022-03-17 |title=Huawei testing own programming language registration |url=https://www.rprna.com/news/huawei-testing-own-programming-language-registration/ |access-date=2024-07-06 |website=RPRNA |language=en-US}}</ref>
 
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.<ref name="vid" /><ref>{{Cite web |last=Li |first=Deng |date=2022-06-16 |title=Huawei’sHuawei's programing language will launch in the second half of this year |url=https://www.huaweicentral.com/huaweis-programing-language-will-launch-in-the-second-half-of-this-year/ |access-date=2024-07-06 |website=Huawei Central |language=en-US}}</ref><ref>{{Cite web |last=Walker |first=Elyssa |date=2020-02-02 |title=Huawei is developing its own programming language - it will be presented in 2022 |url=https://www.codebugapp.com/building/huawei-is-developing-its-own-programming-language-it-will-be-presented-in-2022/ |access-date=2024-07-06 |website=CodeBug'22 |language=en-US}}</ref>
 
On May 17, 2024, Cangjie programming language was internally added into OpenHarmony source code through its [[Foreign function interface|foreign function interface (FFI)]]<nowiki/> mechanism.<ref>{{Cite web |last=Benjamin |date=2024-05-14 |title=Huawei's self developed programming language Cangjie (CJ) could be coming later this month closer than expected |url=https://harmonyoshub.com/huaweis-self-developed-programming-language-cangjie-cj-could-be-coming-later-this-month-closer-than-expected/ |access-date=2024-07-06 |website=HarmonyOSHub |language=en-GB}}</ref>
 
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.<ref>{{Cite web |last=Nick |date=2024-06-17 |title=Huawei Renames Programming Language Lab to 'Cangjie Programming Language' and Announces Insights at HDC 2024 |url=https://harmonyoshub.com/huawei-renames-programming-language-lab-to-cangjie-programming-language-and-announces-insights-at-hdc-2024/ |access-date=2024-07-06 |website=HarmonyOSHub |language=en-GB}}</ref>
 
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 Mate 60|Huawei Mate60 Pro]] devices first with expansions of more devices going into 2025 rollout of HarmonyOS Next versionNEXT.<ref>{{Cite web |title=华为开启鸿蒙 HarmonyOS NEXT 仓颉编程语言开发者预览版 Beta 招募 - IT之家 |url=https://www.ithome.com/0/776/773.htm |access-date=2024-07-06 |website=www.ithome.com}}</ref> Companies like Silicon Valley-based [[LeetCode]], [[Industrial and Commercial Bank of China|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.<ref>{{Cite web |title=华为仓颉编程语言首批合作企业亮相:中国工商银行、中国移动、科蓝软件等在列 - IT之家 |url=https://www.ithome.com/0/777/894.htm |access-date=2024-07-06 |website=www.ithome.com}}</ref>
 
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.<ref>{{Cite web |title=ACM 中国图灵大会 2024 将于 7 月 5 日举行,设华为仓颉编程语言论坛 - IT之家 |url=https://www.ithome.com/0/778/167.htm |access-date=2024-07-06 |website=www.ithome.com}}</ref><ref>{{Cite web |last=Nick |date=2024-07-07 |title=The Cangjie Programming Language Unveiled at ACM China Turing Conference |url=https://harmonyoshub.com/the-cangjie-programming-language-unveiled-at-acm-china-turing-conference/ |access-date=2024-07-07 |website=HarmonyOSHub |language=en-GB}}</ref>
 
In September, [[LeetCode]] China supports Cangjie for all problems.<ref>{{Cite web |title= |script-title=zh:编程刷题平台 LeetCode 力扣所有题目均已支持华为仓颉语言 |trans-title=All problems on the programming practice platform LeetCode are now supported in Huawei's Cangjie language |url=https://www.sohu.com/a/809062659_114760 |access-date=2024-12-03 |website=[[Sohu]]}}</ref>
 
=== Version history ===
Line 67 ⟶ 80:
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 (programming language)|C]], [[C++]] alongside ArkTS code to run within one program.<ref>{{Cite web |title= |script-title=zh: 华为仓颉编程语言首批合作企业亮相:中国工商银行、中国移动、科蓝软件等在列 |trans-title=Huawei's IT之家Cangjie Programming Language Unveils Its First Batch of Partner Companies: ICBC, China Mobile, Kingsoft Software, and Others Included |url=https://www.ithome.com/0/777/894.htm |access-date=2024-07-06 |website=www.ithome.comITHome}}</ref>
 
== Features ==
 
Unlink [[ArkTS]], Cangjie is a general purpose programming language which is 'autonomous and controllable' whichthat 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 (programming language)|Java]] with simple and advanced syntax features like [[TypeScript|Typescript]]-centric ArkTS language, in declarative programming development by complementing it with efficiency.<ref>{{Cite web |title=华为:仓颉编程语言自主可控,没有基于任何现有的编程语言演进 - IT之家 |url=https://www.ithome.com/0/776/781.htm |access-date=2024-07-06 |website=www.ithome.com}}</ref>
 
Cangjie features an embedded AgentDSL programming framework, natural language & programming language organic integration.
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, the application thread is smoother and response is faster. 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.<ref>{{Cite AV media |url=https://www.youtube.com/watch?v=odSh9kSfhas |title=Cangjie language compared with Java and Kotlin language on app scrolling |date=2024-06-23 |last=Living In Harmony |access-date=2024-07-06 |via=YouTube}}</ref><ref>{{Cite web |title=华为自研仓颉编程语言官网和开发文档上线,首次融入鸿蒙生态 - IT之家 |url=https://www.ithome.com/0/776/758.htm |access-date=2024-07-06 |website=www.ithome.com}}</ref>
 
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.<ref>{{Cite web |date=2024-06-21 |title=Huawei has announced its own programming language Cangjie |url=https://itc.ua/en/news/huawei-has-announced-its-own-programming-language-cangjie/ |access-date=2024-07-06 |website=ITC.ua}}</ref><ref>{{Cite web |title=华为开启鸿蒙 HarmonyOS NEXT 仓颉编程语言开发者预览版 Beta 招募 - IT之家 |url=https://www.ithome.com/0/776/773.htm |access-date=2024-07-06 |website=www.ithome.com}}</ref>
 
CangjieHuawei also claims that the language integrates 'Securitysecurity DNA'features into languageits design, aiming to helpallow developers to focus on appapplication developmentfunctionality functionswhile overreducing potential security functions around it that avoids vulnerabilities. whereThe itlanguage offersprovides a static type system and automatic memory management to ensureenhance application stability. That also, includesalongside runtime checkserror of detecting errorsdetection and cross-language security measures.<ref>{{Cite web |date=2024-06-23 |title=Huawei Reveals New Programming Language, Promising Native Intelligence and Strong Security |url=https://nomusica.com/huawei-cangjie-programming-language/ |access-date=2024-07-06 |language=en-US}}</ref> Cangjie also supports various [[toolchain]]s 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.<ref>{{Cite web |last=Bates |first=Kryzt |date=2024-06-21 |title=Huawei Releases Next-Generation Programming Language "Cangjie" After 5 Years of Research |url=https://www.gamingdeputy.com/huawei-releases-next-generation-programming-language-cangjie-after-5-years-of-research/ |access-date=2024-07-06 |website=GAMINGDEPUTY |language=en-US}}</ref>
 
=== ExamplesBasic syntax ===
Cangjie's [["Hello, World!" program]] is:
The following is an example of a simple AI Native application development program with Cangjie programming language on HarmonyOS.<ref>{{cite web |title=AI Native application development |url=https://developer.huawei.com/consumer/cn/doc/openharmony-cangjie/cj-wp-intelligence |website=Huawei Developer (HarmonyOS Developer) |publisher=Huawei |access-date=6 July 2024}}</ref>
<syntaxhighlight lang="swift" line="1" start="1">
Definition of Agent
main() {
@agent class Planner {
println("Hello, World!")
}
</syntaxhighlight>
 
Immutable variables are declared with the {{code|let|swift}} keyword and mutable ones with the {{code|var
@prompt[pattern=APE] (
|swift}} 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.<ref>{{cite book |last1=劉玥 |title=Cangjie Programming Quick Start |date=2024-07-01 |isbn=9787115624710 |script-title=zh:仓颉编程快速上手}}</ref>
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."
)
 
=== Pattern matching ===
}
[[Pattern matching]] in Cangjie is provided by the <code>match</code> expression, which has two forms: one with a value to match and the other without a value to match. A <code>match</code> expression with a value checks each <code>case</code> in sequence, executing the corresponding code when the pattern matches successfully. To ensure exhaustiveness, the last <code>case</code> often uses a [[Wildcard character|wildcard]] pattern <code>_</code> to cover all possible values. A <code>match</code> expression without a value evaluates does not need a pair of brackets for the condition.<ref name="vid" />
 
=== Lambda expression ===
Use of the agent
 
let agent = Planner()
Lambda expression can have no parameters:<ref name="vid">{{Cite book |last=张磊 |title= |publisher=[[Tsinghua University Press]] |year=2024 |isbn=9787302616597 |script-title=zh:仓颉语言实战(微课视频版) |trans-title=Hands on Cangjie Language (Video Course Version)}}</ref><syntaxhighlight lang="swift" line="1" start="1">
let result = agent. chat("我想前往上海")
let f = {a: Int64, b: Int64 => a + b}
let print = { => println("Hello Cangjie")}
</syntaxhighlight>
 
=== Foreign function interface ===
Cangjie has built-in [[Foreign function interface|FFI]] support for [[C (programming language)|C]] and [[Python (programming language)|Python]]. External functions are declared using the <code>foreign</code> keyword and called using the <code>unsafe</code> keyword. For C interoperability, Cangjie supports automatic conversion between basic data types. The <code>CPointer<T></code> type corresponds to C pointer types, for example, and <code>CPointer<Int32></code> corresponds to <code>int32_t *</code>. 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.<ref name=":0">{{Cite book |last=徐礼文 |title= |publisher=[[Tsinghua University Press]] |isbn=9787302625889 |script-title=zh:仓颉语言核心编程——入门、进阶与实战 |trans-title=Cangjie Language Core Programming: Introduction, Advanced Topics and Practical Applications}}</ref> Below is an example:
{|
!C code
!Cangjie code
|-
|<syntaxhighlight lang="c" line="1">
#include <stdio.h>
#include <stdlib.h>
 
int getRandom() {
int i = rand();
return i;
}
</syntaxhighlight>
|<syntaxhighlight lang="swift" line="1">
from std import ffi.c.*
foreign func getRandom(): Int32
main(): Unit {
let r = unsafe getRandom()
println("random number $(r)")
}
</syntaxhighlight>
|}
 
=== Metaprogramming ===
Cangjie supports two main types of macros: non-attribute macros, which take a single input parameter for the code being decorated, and 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 {{code|macro|}} keyword, placed in {{code|macro package|}}, and being 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.<ref name=":0" />
 
== STD module runtime ==
{{See also|Ark Compiler}}
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.<ref>{{cite web |titlename=std.runtime"vid" 包 |url=https://developer.huawei.com/consumer/cn/doc/openharmony-cangjie/libs_overview_ohos |website=Huawei Developer (HarmonyOS Developer) |publisher=Huawei |access-date=6 July 2024}}</ref><ref>{{cite web |title=Cangjie Programming Language Library API |url=https://developer.huawei.com/consumer/cn/doc/openharmony-cangjie/libs_overview_ohos |website=Huawei Developer (HarmonyOS Developer) |publisher=Huawei |access-date=6 July 2024}}</ref>
 
== Development tools ==
=== Compiler ===
With [[Ark Compiler]], it supports a variety of dynamic and static programming languages such as [[JavaScript|JS]], [[TypeScript|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.<ref>{{cite web |title=ArkCompiler Runtime |url=https://gitee.com/openharmony/docs/blob/master/en/readme/ARK-Runtime-Subsystem.md |website=OpenAtom Gitee |publisher=OpenAtom Gitee |access-date=12 February 2024}}</ref>
 
=== 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. <samp>new</samp> 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.<ref name=":0" />
 
=== IDE and editor support ===
Line 125 ⟶ 175:
{{Huawei|phones=yes|tablets=yes|laptops=yes|wearables=yes|cpu=yes|os=yes|services=yes|people=yes|other=yes|below=yes}}
 
{{Draft categories|
[[Category:2024 software]]
[[:Category:Cross-platform2024 software]]
[[:Category:ObjectCross-based programmingplatform languagessoftware]]
[[:Category:ProgrammingObject-based programming languages created in 2024]]
[[:Category:Scripting languages]]
[[:Category:Source-to-source compilers]]
[[:Category:Statically typed programming languages]]
[[:Category:Huawei products]]
}}
 
{{Drafts moved from mainspace |date=July 2024}}