Starlark
Starlark is a lightweight, high-level programming language designed for embedded use in applications. It uses a subset of the Python syntax. By default, the code is deterministic and hermetic.[1]
History
Starlark was released in 2015 as part of Bazel under the name Skylark[2]. This first implementation was written in Java. In 2018, the language was renamed Starlark.[3]
In 2017, a new implementation of Starlark in Go was announced.[4]
In 2021, Meta announced an implementation of Starlark written in Rust,[5] to be used for the Buck build system.[6][7]
Popularity
In addition to the Bazel[8] and Buck build systems, Starlark is used by dozens of projects,[9][10] including Isopod[11], skycfg[12], Uber's Starlark Worker[13], and Tilt.[14]
On GitHub, Starlark is among the top 50 languages based on the developer activity.[15][16]
Syntax
Starlark syntax is a strict subset of Python syntax.[1] Similar to Python syntax, Starlark relies on indentation to delimit blocks, using the off-side rule.
Statements and control flow
Starlark's statements include:[17]
- The
=statement to assign a value to a variable - The augmented assignment statements to modify a variable
- The
ifstatement to execute conditionally a block of code (withelseorelif) - The
forstatement to iterate over an iterable object - The
defstatement to define a function - The
breakstatement to exit a loop - The
continuestatement to skip the rest of the current iteration and continues with the next - The
passstatement, serving as a NOP, syntactically needed to create an empty code block - The
returnstatement to return a value from a function. - The
loadstatement, which replaces Pythonimport, to import a value from another module.[18] Unlike Python, the order of load statements does not affect the semantics of the code.[19]
Unlike Python, Starlark statements don't include: while, try, raise, class, with, del, assert, yield, import, match and case.[20]
Freezing
To ensure thread safety and support parallel computing, Starlark has a feature called freezing. At the end of the evaluation of a module, all values become immutable. This means that the values that can be accessed from multiple threads can no longer be modified, which removes the risk of race conditions.[2][21]
See also
References
- ↑ 1.0 1.1 Cite error: Invalid
<ref>tag; no text was provided for refs namedspecification overview - ↑ 2.0 2.1 "A glimpse of the design of Skylark". https://blog.bazel.build/2017/03/21/design-of-skylark.html.
- ↑ "Starlark". https://blog.bazel.build/2018/08/17/starlark.html.
- ↑ Donovan, Alan (18 November 2017). A Go implementation of the Skylark Configuration Language. GothamGo 2017 – via YouTube.
- ↑ Mitchell, Neil (2021-04-08). "The Rust Starlark library". https://developers.facebook.com/blog/post/2021/04/08/rust-starlark-library/.
- ↑ "Meta open-sources 'significantly faster' build system". https://www.infoworld.com/article/2338301/meta-open-sources-significantly-faster-build-system.html.
- ↑ "5 Things you didn't know about Buck2". 23 October 2023. https://engineering.fb.com/2023/10/23/developer-tools/5-things-you-didnt-know-about-buck2/.
- ↑ Antoniucci, Javier (2024). Ultimate Monorepo and Bazel for Building Apps at Scale: Level up Your Large-Scale Application Development with Monorepo and Bazel for Enhanced Productivity, Scalability, and Integration (English Edition) (1st ed.). Orange Education PVT Ltd. ISBN 9788197223914.
- ↑ "Starlark Programming Language". https://starlark-lang.org/resources.html#users.
- ↑ Pandey, Mohit (12 December 2024). "Starlark is Basically Python, But Not Really Python, and That's Fine". https://analyticsindiamag.com/developers-corner/starlark-is-basically-python-but-not-really-python-and-thats-fine/.
- ↑ Xu, Charles; Ilyevskiy, Dmitry (2019). "Isopod: An expressive DSL for Kubernetes configuration". Proceedings of the ACM Symposium on Cloud Computing. doi:10.1145/3357223.3365759. https://dl.acm.org/doi/abs/10.1145/3357223.3365759.
- ↑ Norton, Peter (2019). "Other Faces of Python". Login Usenix Mag. 44 (2). https://www.usenix.org/system/files/login/articles/login_summer19_09_norton.pdf.
- ↑ "Open-Sourcing Starlark Worker: Define Cadence Workflows with Starlark". https://www.uber.com/blog/starlark/.
- ↑ Sayfan, Gigi (2019). Hands-on microservices with Kubernetes: build, deploy, and manage scalable microservices on Kubernetes (1st ed.). Packt Publishing. pp. 353. ISBN 9781789809732.
- ↑ "Global Metrics: Programming Languages". GitHub. https://innovationgraph.github.com/global-metrics/programming-languages.
- ↑ "Languish - Programming Language Trends". https://tjpalmer.github.io/languish/.
- ↑ "starlark/spec.md at master · bazelbuild/starlark". https://github.com/bazelbuild/starlark/blob/master/spec.md#statements.
- ↑ "starlark/spec.md at master · bazelbuild/starlark". https://github.com/bazelbuild/starlark/blob/master/spec.md#load-statements.
- ↑ Le Brun, Laurent (December 2024). "A practical introduction to the Starlark language" (in en). https://laurent.le-brun.eu/blog/a-practical-introduction-to-the-starlark-language.
- ↑ "starlark/spec.md at master · bazelbuild/starlark". https://github.com/bazelbuild/starlark/blob/master/spec.md#lexical-elements.
- ↑ "starlark/spec.md at master · bazelbuild/starlark". https://github.com/bazelbuild/starlark/blob/master/spec.md#freezing-a-value.
