Pkl,一种配置编程语言
Pkl, a Programming Language for Configuration

原始链接: https://pkl-lang.org/blog/introducing-pkl.html

Pkl 是一种新的编程语言,专门用于将现代软件系统的大型数据集配置为人类可编辑的文档。 它旨在将纯文本格式的易用性与高性能、可扩展性和生产级功能结合起来。 Pkl 通过利用类型系统设计原则,同时坚持干净、简约的语言风格来实现这种平衡。 使用 Pkl,用户可以定义自己的配置并共享包含预定义架构的包。 语言绑定允许将 Pkl 作为库嵌入到其他应用程序中,并且通过官方 IntelliJ 和 neovim 插件以及社区驱动的插件(例如 VS Code)提供强大的编辑器支持。 Pkl 团队计划根据用户反馈和输入继续开发和改进该语言。 要了解有关 Pkl 的更多信息,请参阅教程、语言参考、安装指南和编辑器插件。 还可以通过 GitHub 讨论提交反馈,并且可以在官方 Pkl 存储库中找到示例。

总之,Pkl 旨在通过提供存储和重用配置的通用目标来简化配置创建、共享和使用,而不必在较大工具的协调器中维护多个独立副本或复制块。 虽然 terraform 模块可以提供管理基础设施配置的解决方案,但 pkl 提供了一种更全面的方法,可以灵活地将其应用于更广泛的软件工程问题类别,例如包管理器配方或 YAML 替换,可能涵盖更广泛的用例。 最终,这两种方法都解决了相关的挑战,尽管范围和粒度不同。
相关文章

原文

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.

We 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.

联系我们 contact @ memedata.com