mirror of
https://github.com/CompeyDev/blog.devcomp.xyz.git
synced 2024-12-12 04:40:41 +00:00
Gloss over luau article, fix some writing stuff
This commit is contained in:
parent
c41085929a
commit
4acc7387d8
1 changed files with 20 additions and 23 deletions
|
@ -10,7 +10,7 @@ draft: false
|
|||
|
||||
<!-- markdownlint-disable MD033 -->
|
||||
|
||||
Have you ever felt that you live in a loop? That’s how I feel - every time I open tech twitter (no, I am not going to call it X). There are several “programming meme” accounts which seem to regurgitate the same few jokes on a regular basis, to the point that I’m convinced they’re all AI. One of these overused meme formats is related to JavaScript, criticising its poor design choices which lead to various pitfalls a developer can face. I’ve never seen people offer solutions to these, so this blog post attempts to do so with a promising alternative to JavaScript: [Luau]([https://luau-lang.org](https://luau-lang.org)).
|
||||
Have you ever felt that you live in a loop? That’s how I feel - every time I open tech Twitter (*I refuse to call it X*). There are several “programming meme” accounts which seem to regurgitate the same few jokes on a regular basis, to the point that I’m convinced that they’re all AI. One of these overused meme formats is related to JavaScript, criticising its poor design choices which lead to various pitfalls a developer can face. I’ve never seen people offer solutions to these, so this blog post attempts to do so by proposing a promising alternative to JavaScript: [Luau](https://luau-lang.org).
|
||||
|
||||
## What is Luau?
|
||||
|
||||
|
@ -20,10 +20,11 @@ Luau has significantly diverged from Lua, with many performance improvements (in
|
|||
|
||||
Compared to JavaScript, Luau does not face most of its well-documented pitfalls – see [wtfjs](https://github.com/denysdovhan/wtfjs). This is mainly because Luau inherits a lot of Lua’s good design decisions such as:
|
||||
|
||||
* No two types can be equal
|
||||
* No two different types can be equal
|
||||
* Type coercion isn’t a thing, types must be converted explicitly
|
||||
* Arithmetic and non-arithmetic operators aren’t of the same syntax
|
||||
* Practically only one data type: the table, which can be used to implement virtually anything
|
||||
* No semicolons or indents required!
|
||||
|
||||
### Types
|
||||
|
||||
|
@ -34,9 +35,9 @@ I will mostly be speaking about TypeScript, since I have more experience with it
|
|||
1. Types present a learning curve which aren’t present in other statically typed languages.
|
||||
2. Types often overshadow the underlying business logic, since they present a large amount of logic on their own.
|
||||
|
||||
Both of these problems aren’t existent in Luau. In Luau, types are simple, while also providing sweet autocomplete and strong typechecking - adhering to the Lua philosophy of power with simplicity. Community-made tooling also tries to stick to this philosophy, leading to a killer alternative to JavaScript’s simplicity, which many prefer the language for.
|
||||
Both of these problems aren’t existent in Luau. In Luau, types are simple by design, while also providing sweet autocomplete and strong typechecking - adhering to the Lua philosophy of power through simplicity. Community-made tooling also tries to stick to this philosophy, leading to a strong competition to JavaScript in terms simplicity, which many prefer the language for.
|
||||
|
||||
A good example of simplicity in Luau types is this following generic type for excluding a type from a list of compatible ones:
|
||||
A simple example of this in Luau types is this following generic type for excluding a type from a list of compatible ones:
|
||||
|
||||
```ts
|
||||
type ExcludeTypes<T, U> = T extends U ? never : T;
|
||||
|
@ -46,7 +47,9 @@ type ExcludeTypes<T, U> = T extends U ? never : T;
|
|||
type ExcludeTypes<T> = ~T
|
||||
```
|
||||
|
||||
**NOTE**: The above type example isn’t available in stable Luau yet, and is a part of the revamped type solver, which is currently in development. It is expected to have a beta release soon.
|
||||
:::note
|
||||
The above type example isn’t available in stable Luau yet, and is a part of the revamped type solver, which is currently in development. It is expected to have a beta release soon.
|
||||
:::
|
||||
|
||||
### Performance
|
||||
|
||||
|
@ -86,17 +89,17 @@ The Luau community has developed many libraries to make JavaScript developers fe
|
|||
…And many more which I haven't listed here!
|
||||
|
||||
:::note
|
||||
It isn't currently possible for create websites using react-lua, it is mainly used for
|
||||
Roblox game development; but a port to Lune is being worked on.
|
||||
It isn't currently possible for create websites using react-lua, it is currently only used for
|
||||
frontend in Roblox game development; but web compatibility is being worked on.
|
||||
:::
|
||||
|
||||
### Lune
|
||||
|
||||
As previously mentioned, Lune is a standalone Luau runtime, similar to Node (or more closely to Deno, since they share similarities). Although Luau is an embeddable language similar to Lua, Lune tries to create a fully-fledged, batteries-included scripting language. Lune provides world-class standard library APIs (referred to as builtins), with a low learning curve. Lune builtins attempt to be obvious, while also being powerful and performant.
|
||||
|
||||
Lune has a special focus on async I/O (anything which can be async, should be!) - so that you can leverage the performance of async computation without needing to worry about complex data types like promises. Lune accomplishes this by utilising a custom scheduler powered by [Tokio](https://tokio.rs), which handles parallel Luau and I/O API execution. Unlike in regular Lua, spawning async computation in a coroutine (or a task using the `@lune/stdio` builtin) will not block the main thread from executing, ever.
|
||||
Lune has a special focus on async I/O (anything which can be async, should be!) - so that you can leverage the performance of async computation without needing to worry about complex data types like promises. Lune accomplishes this by utilising a custom scheduler powered by [Tokio](https://tokio.rs), which handles parallel Luau and I/O API execution. Unlike in regular Lua, spawning async builtin APIs in a coroutine (or a task using the `@lune/task` builtin) will not block the main thread from executing, allowing for async code to run in parallel.
|
||||
|
||||
Lune also includes nice-to-have features, such as a cross-compilation compatible build command to package Lune scripts into executables which can be run without having Lune installed, an interactive REPL, executable scripts, and more to come.
|
||||
Lune also includes nice-to-have features, such as a build command supporting cross-compilation to package Lune scripts into executables which can be run without having Lune installed, an interactive REPL, executable scripts, and more to come.
|
||||
|
||||
> To get started with Lune, [check out the docs](https://lune-org.github.io/docs)!
|
||||
|
||||
|
@ -104,15 +107,11 @@ Lune also includes nice-to-have features, such as a cross-compilation compatible
|
|||
|
||||
## Conclusion
|
||||
|
||||
I highly recommend trying out Luau as an alternative to Bash, Python and JS scripts. I have converted many of my scripts to Luau, and it has given me a much nicer developer experience in the long run.
|
||||
|
||||
:::tip
|
||||
Here's a little Lune script I often use to package Rust projects as an example of what can be done with Lune, and its bash equivalent!
|
||||
:::
|
||||
<details>
|
||||
<summary>Luau</summary>
|
||||
I highly recommend trying out Luau as an alternative to Bash, Python and JS scripts. I have converted many of my scripts to Luau, and it has given me a much nicer developer experience in the long run. Don't believe me? Take a look at the following scripts I use to package compiled Rust binaries into zip files, both in Luau and Bash:
|
||||
|
||||
```lua
|
||||
--> Packages a target-specific Rust binary into a zip file
|
||||
|
||||
local process = require("@lune/process")
|
||||
local serde = require("@lune/serde")
|
||||
local fs = require("@lune/fs")
|
||||
|
@ -182,11 +181,6 @@ end
|
|||
return process.exit(main())
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Bash</summary>
|
||||
|
||||
```bash
|
||||
# !/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
@ -205,6 +199,9 @@ cd "{{CWD}}"
|
|||
rm -rf staging
|
||||
```
|
||||
|
||||
</td>
|
||||
</table>
|
||||
|
||||
Not only is the Lune version cross-platform and much easier to read and write, it is also convenient to use, since the bash script requires the user to manually input information.
|
||||
|
||||
**All I ask you is to try something a little different the next time you start a new side-project, something a little bit more Hawaiian!** :)
|
||||
|
|
Loading…
Reference in a new issue