Duck is a modern, compiled and batteries included programming language for full-stack web-development, that's built on top of the go ecosystem, it leverages the concepts of duck-typing onto a fast and reliable platform while introducing JSX like server-side templating and client-side react components as first-class citizens.
| Language Features | Duck | Bun | NodeJS |
|---|---|---|---|
| Ducktyping | |||
| Static Typechecking | |||
| Multithreading | |||
| Truly native executables | |||
| CPU and Memory efficient | |||
| Server Side Rendering | |||
| Client Side Rendering | |||
| node_modules | |||
| built-in test runner | |||
| Dirt cheap to host |
fn main() {
const response_json = match std::web::fetch("https://dummyjson.com/test").send() {
String @str => str,
.http_error => return,
};
const parsed = match parse_json<{status: String, method: String,}>(response_json) {
{ status: String, method: String } @response => response,
else => return,
};
std::io::println(parsed.status);
}component Counter(props: { initial_value: Int }) jsx {
const [value, setValue] = useState(props.initial_value);
return (
<>
<div>
<div>Current value: {value}</div>
<button onClick={() => setValue((v) => v + 1)}>Increment</button>
</div>
</>
);
}
template Page(props: { param: String }) duckx {
<html lang="en">
<body>
<p>You sent: {props.param}</p>
<Counter initial_value={10}/>
</body>
</html>
}
fn main() {
std::web::HttpServer::new(.none)
.handle("GET /{param}", fn(req, res) {
const param = match req.param("param") { String @s => s, else => return, };
res.duckx(Page({param: param}));
})
.listen(":3000");
}