Apple's Pkl New Coding Language for Configuration
Apple recently released a new open source config language.
Hey Everyone,
Apple is full of surprises. For the coders out there, this one is for you and just a short note. In terms of software coding news, this is pretty fascinating.
See the comments on Hacker News.
Check out on GitHub: https://github.com/apple/pkl
Apple designed “Pkl” with three overarching goals:
To provide safety by catching validation errors before deployment.
To scale from simple to complex use-cases.
To be a joy to write, with our best-in-class IDE integrations.
It’s an open-source configuration coding language. Sometimes pronounced “pickle”.
🍎 Facilitating Config Pkl by Apple 🍏
We are delighted to announce the open source first release of Pkl (pronounced Pickle), a programming language for producing configuration. When thinking about configuration, it is common to think of static languages like JSON, YAML, or Property Lists.
While these languages have their own merits, they tend to fall short when configuration grows in complexity. For example, their lack of expressivity means that code often gets repeated. Additionally, it can be easy to make configuration errors, because these formats do not provide any validation of their own. To address these shortcomings, sometimes formats get enhanced by ancillary tools that add special logic.
For example, perhaps there's a need to make code more DRY, so a special property is introduced that understands how to resolve references, and merge objects together. Alternatively, there's a need to guard against validation errors, so some new way is created to validate a configuration value against an expected type. Before long, these formats almost become programming languages, but ones that are hard to understand and hard to write.
On the other end of the spectrum, a general-purpose language might be used instead. Languages like Kotlin, Ruby, or JavaScript become the basis for DSLs that generate configuration data.While these languages are tremendously powerful, they can be awkward to use for describing configuration, because they are not oriented around defining and validating data. Additionally, these DSLs tend to be tied to their own ecosystems. It is a hard sell to use a Kotlin DSL as the configuration layer for an application written in Go.
We created Pkl because we think that configuration is best expressed as a blend between a static language and a general-purpose programming language. We want to take the best of both worlds; to provide a language that is declarative and simple to read and write, but enhanced with capabilities borrowed from general-purpose languages. When writing Pkl, you are able to use the language features you'd expect, like classes, functions, conditionals, and loops. You can build abstraction layers, and share code by creating packages and publishing them. Most importantly, you can use Pkl to meet many different types of configuration needs. It can be used to produce static configuration files in any format, or be embedded as a library into another application runtime.
Launched on February 1 2024 into version 0.25, the tech giant’s team have provided a ‘quick tour’ of the language in a text post on the Pkl documentation website.
Installation: https://pkl-lang.org/main/current/pkl-cli/index.html#installation
Moreover, Per that tour, Pkl is designed around a key value structure, in a manner akin to JSON, rather than imperative instructions like many other traditional programming languages, Apple has designed Pkl to specialise in configuration, along with a few neat quality-of-life features to turn heads. Indeed, Pkl supports JSON, XML, and YAML property lists at launch to generate static configuration files.
Why Pickle (Pkl)
In software development, configuration is a frequent and crucial process that lets engineers alter the look and feel of their environments, systems, and applications.
Configuration, however, may also be difficult since it frequently entails creating intricate and prone-to-mistake code, handling many formats and languages, and guaranteeing data confidentiality and integrity.
Pkl prioritizes data integrity and security through type checking, sandboxing, and least privilege. Its versatility allows for easy configuration of various systems and applications.
While Pkl has been internally used at Apple for several years, its release as an open-source project opens up opportunities for community contributions and broader adoption.
“In the future, we hope to add support for other popular languages and platforms, realizing our vision of a polyglot config solution based on a single config language.”
Pkl
Type safety: Pkl supports both complicated kinds (like lists, maps, sets, and enums) and primitive types (like integers, strings, booleans, and null). Additionally, users may do type checking and validation at build time and runtime, as well as construct new types and schemas using Pkl.
Expressiveness: Pkl allows users to write simple and dynamic configuration code by supporting variables, functions, operators, and control structures. Interpolation is another feature that Pkl offers, enabling users to insert expressions within strings.
Modularity: Modules are supported by Pkl, enabling users to arrange and share configuration code among various projects and contexts. To allow users to access other resources and libraries, Pkl also allows imports and exports.
Security: Sandboxing, which restricts the environment in which configuration code may be accessed and executed, is supported by Pkl. The least privilege option, which gives the bare minimum of permissions needed for a configuration job, is likewise supported by Pkl.
Apple is Evolving in Open-Source Software
It seems that the release of Pkl seems to align with Apple’s growing commitment to open-source software. Recent contributions include the Swift programming language and the Foundation libraries, demonstrating their expanding presence in the open-source community.
Why Use Pkl?
Pkl is intended to be a general-purpose and flexible programming language for configuration that may be applied to a variety of situations, including:
Infrastructure: Networks, servers, cloud services, containers, and other infrastructure elements may all be configured using Pkl. Pkl is also capable of producing configuration files in XML, JSON, YAML, and property lists, among other forms.
Applications: Pkl is a tool for configuring user interfaces, features, preferences, and program settings. Additionally, configuration code in several languages, including Java, Kotlin, Swift, and Go, may be generated by Pkl.
Environments: Staging, production, testing, and development environments may all be configured with Pkl. Claims, environment variables, and credentials can also be generated using Pkl.