WIP: Features on homepage
lpil opened this issue · comments
A list of features with code snippets on the website would be very handy. Here's a draft for the content:
Hello, Gleam!
The power of typed functional programming with the performance and reliability of the Erlang VM, all wrapped up in a familiar modern syntax.
import gleam/io
pub fn main() {
io.println("Hello, world!")
}
Productivity focused
No nulls, no exceptions, clear error messages, and a practical type system. Whether you're writing new code or maintaining old code Gleam is designed to make your job as fun and stress-free as possible.
error: Unknown record field
┌─ ./src/app.gleam:8:16
│
8 │ user.alias
│ ^^^^^^^^^^ Did you mean `name`?
The value being accessed has this type:
User
It has these fields:
.name
Model your domain
With Gleam's custom types, generics, and pattern matching features it can implement your business logic precisely and clearly. We think it should always be clear to the reader what code is doing.
pub type Pet {
Cat
Dog
Other(name: String)
}
pub fn greet(pet) {
case pet {
Dog -> "Who's a good boy?"
Cat -> "What a little sweetie!"
Other(name) -> "Hello, " <> name
}
}
Ready out of the box
Gleam comes with compiler, build tool, formatter, editor integrations, and package manager all built in, so creating a gleam project is just running gleam new
.
Part of the wider BEAM ecosystem, Gleam programs can use the thousands of packages published Hex packages whether they are written in Gleam, Erlang, or Elixir
~/app $ gleam add gleam_json
Resolving versions
Downloading packages
Downloaded 2 packages in 0.01s
Added gleam_json v0.5.0
~/app $ gleam test
Compiling thoas
Compiling gleam_json
Compiling app
Compiled in 1.67s
Running app_test.main
.
1 tests, 0 failures
Made for production
Running on the battle-tested Erlang virtual machine that powers planet scale systems such as WhatsApp and Ericcson, Gleam is ready for workloads of any size.
Thanks to a multi-core actor based concurrency system that can run millions of concurrent tasks, fast immutable data structures, and a concurrent garbage collector that never stops the world, your service can scale and stay lighting fast with ease.
pub fn main() {
// Run a million of threads, no problem
list.range(0, 1_000_000)
|> list.map(spawn_task)
|> list.each(task.await_forever)
}
fn spawn_task(i) {
task.async(fn() {
let n = int.to_string(i)
io.println("Hello from " <> n)
})
}
JavaScript compatible
As well as running on the Erlang VM Gleam code can also compile to JavaScript. Reuse your existing backend code in the browser, on mobile devices, or anywhere else JavaScript can run.
pub fn main() {
try el = document.query_selector("button")
element.add_event_listener(el, fn() {
io.println("Button clicked!")
})
}
What about something along the lines of Carry over most of your code base into browser world or run gleam code on NodeJS, Deno, Bun et al.
.
Great idea! I'll add a JS section
Would it be good to add the import statements or is it too much noise?
I for one would not know where the document module comes from.
JavaScript compatible
Feels like it undersells itself. It pretty much feels like JS is fully featured first class.
JavaScript compatible
sounds like a hack or something diminished to me...
The intent is to sell Gleam rather than teach it here so I think we can ignore details like import statements.
Do you have ideas for other JS titles?
One thing that I noticed is that you listed some of the sponsors twice. I think it make more sense to have all the sponsors in one block/section.
Also, I think the first code snippet that’s on the page could be located right after the tag line, then after that you’d have the “let’s go” button that links to the docs.
Hi @ajstrand , the high value sponsors are given pride of place at the top of the page as well as on every other page's footer. They are the ones really bankrolling the language so they deserve to be front and centre!
The intent is to sell Gleam rather than teach it here so I think we can ignore details like import statements.
Fair!
Do you have ideas for other JS titles?
"Compiles to JavaScript"