Introduction to Cangjie Language
Cangjie is a general-purpose programming language designed for full-scenario application development, balancing development efficiency with runtime performance while providing an excellent programming experience. Its key features include:
- Multi-Backend Support: Cangjie supports two backends: CJNative and CJVM. The CJNative backend compiles code into native binaries that run directly at the operating system level, while the CJVM backend compiles code into bytecode that runs on a VM (Virtual Machine). This documentation is adapted for the CJNative backend.
- Concise and Efficient Syntax: Cangjie offers a series of concise and efficient syntax features aimed at reducing redundant coding and improving development efficiency. Examples include interpolated strings, primary constructors, Flow expressions, match statements, and re-exports, allowing developers to express logic with minimal code.
- Multi-Paradigm Programming: Cangjie supports functional, imperative, and object-oriented programming paradigms. It incorporates advanced functional language features such as higher-order functions, algebraic data types, pattern matching, and generics, alongside object-oriented language features like encapsulation, interfaces, inheritance, and subtype polymorphism for modular development. It also includes imperative language features such as value types and global functions for simplicity and efficiency. Developers can choose the paradigm that best suits their preferences or application scenarios.
- Type Safety: Cangjie is a statically and strongly typed language, enabling early detection of program errors through compile-time type checking, reducing runtime risks, and facilitating code maintenance. Additionally, the Cangjie compiler provides robust type inference capabilities, minimizing the need for type annotations and enhancing development efficiency.
- Memory Safety: Cangjie supports automatic memory management and performs runtime checks for array bounds, overflow, and other operations to ensure memory safety during execution.
- Efficient Concurrency: Cangjie provides lightweight user-mode threads (native coroutines) and an easy-to-use concurrency programming mechanism, ensuring efficient development and execution in concurrent scenarios.
- Language Ecosystem Compatibility: Cangjie supports interoperability with languages like C and adopts a convenient declarative programming paradigm, enabling efficient reuse and compatibility with libraries from other languages.
- Easy Domain-Specific Extensibility: Cangjie offers metaprogramming capabilities based on lexical macros, allowing code transformation at compile time. It also includes features such as trailing lambda, attributes, operator overloading, and optional keywords, enabling developers to deeply customize syntax and semantics. This facilitates the construction of Embedded Domain-Specific Languages (EDSLs).
- Enhanced UI Development: UI development is a critical aspect of building end-side applications. Leveraging Cangjie's metaprogramming and trailing lambda features, users can create declarative UI development frameworks to improve efficiency and experience in UI development.
- Rich Built-in Libraries: Cangjie provides a comprehensive set of built-in libraries covering data structures, common algorithms, mathematical computations, regular expressions, system interactions, file operations, network communication, database access, logging, compression/decompression, encoding/decoding, encryption/decryption, and serialization.