upvote
Please don't post shallow dismissals or instigate generic tangents on HN. The guidelines make it clear we're trying for something much better here. https://news.ycombinator.com/newsguidelines.html
reply
Hello HN police!

It is actually hard to objectively define how a programming language is ugly. Let the argument be countered. No need to get hurt (w.r.t. policies or rust)

reply
Ugly is a matter of taste. But I agree Rust isn't the best language to describe UI: it makes you focus on ownership and lifetimes and explicit memory allocation, instead of the layout. That's in Slint, we uses a DSL for the UI description and keeps the logic in Rust. I blogged about the subject here: https://slint.dev/blog/domain-specific-language-vs-imperativ...
reply
I think this is more of a function of the GPUI library being very powerful. If you just write "hello world" in rust that is a lot shorter.
reply
If anything I'd argue Rust has a lot of ugly APIs.

...it also has a lot of really nice APIs, and traits allowing you to bolt on extra functionality "for free" is a big part of it.

I am relatively new to Rust but I do find shopping for API features harder than with other languages.

reply
I love Rust, but my opinion is that linear types are extremely poorly suited for making UIs.
reply
Rectangular types would obviously be more appropriate.
reply
With rounded corners, preferably.
reply
Rust is not to blame for that example. Here's the same example rewritten with iced:

    use iced::widget::{column, *};
    use iced::{Center, Color, Fill, Theme, border, color};

    fn main() -> iced::Result {
        iced::application(|| (), update, view)
            .window_size((500, 500))
            .run()
    }

    fn update(_: &mut (), _: ()) {}

    fn view(_: &()) -> impl Widget<()> {
        let swatch = |c: Color| {
            container("")
                .width(32)
                .height(32)
                .style(move |_| container::background(c))
        };
        let colors = [
            color!(0xff0000),
            color!(0x00ff00),
            color!(0x0000ff),
            color!(0xffff00),
            Color::BLACK,
            Color::WHITE,
        ];

        container(
            column![
                text("Hello, World!").size(20).color(Color::WHITE),
                row(colors.map(swatch)).spacing(8),
            ]
            .spacing(12)
            .align_x(Center),
        )
        .center(Fill)
        .style(panel)
    }

    fn panel(_: &Theme) -> container::Style {
        container::background(color!(0x505050)).border(border::color(color!(0x0000ff)).width(1))
    }
Also this is a pretty shit example because it's mostly showing styling... and in any sane app, you have a predefined theme

The typical GUI example is a counter

Syntax is rarely a reason to choose a language

If Rust feels "ugly" to you, may I suggest you consider how that comes from lack of familiarity, rather than an intrinsic shortcoming of the language?

reply
With Dioxus Native:

    use dioxus::native::{Config, LogicalSize, WindowAttributes};
    use dioxus::prelude::*;

    fn main() {
        let window = WindowAttributes::default().with_surface_size(LogicalSize::new(500.0, 500.0));
        let config = Config::new().with_window_attributes(window);
        dioxus::native::launch_cfg(app, vec![], vec![Box::new(config)]);
    }

    fn app() -> Element {
        rsx! {
            Stylesheet { href: asset!("/assets/tailwind.css") }
            HelloWorld { text: "World" }
        }
    }

    #[component]
    fn HelloWorld(text: String) -> Element {
        rsx! {
            div { class: "flex flex-col gap-3 bg-[#505050] size-[500px] justify-center items-center shadow-lg border border-[#0000ff] text-xl text-white",
                "Hello, {text}!"
                div { class: "flex gap-2",
                    div { class: "size-8 bg-[red]" }
                    div { class: "size-8 bg-[lime]" }
                    div { class: "size-8 bg-[blue]" }
                    div { class: "size-8 bg-[yellow]" }
                    div { class: "size-8 bg-black" }
                    div { class: "size-8 bg-white" }
                }
            }
        }
    }
You can also use standard CSS if you prefer it over tailwind. And if you wanted to deduplicate, the 6 divs can be written in a loop like so:

    for color in ["red", "lime", "blue", "yellow", "black", "white"] {
        div { width: "32px", height: "32px", background_color: color }
    }
reply
> fn update(_: &mut (), _: ()) {}

> move |_| container::background(c)

There's no way anyone can see this and thinks it is legible

reply
Looks pretty clear to me and I’ve not written a line of Rust in my life.

New languages always feel a bit inapproachable. It’s like learning Russian (for a westerner). Super impenetrable at first, but at some point (early on!) the alphabet just clicks and then the rest is “just” regular language learning. Same with PL syntax. Overwhelming at first, until it clicks and then you can’t remember what you found overwhelming about it.

reply
> There's no way anyone can see this and thinks it is legible

I see this and think it is very legible. It is hard to imagine why anyone can have issues with this.

reply
Are you old enough to remember Perl hackers? Some of those guys might ;)

I really like :()), it looks like a monkey with two chins!

reply
I've been using Rust pre 1.0 and even though it has come leaps and bounds, it is a very ugly language. Where I will give credit though, it is consistently and uniformly ugly.
reply
I'm pretty familiar with Rust at this point but I'll never look at something like

    fn view(_: &()) -> impl Widget<()> {
and think "nailed it"
reply
Why? () is an empty type, it is used here twice because... well it is a hello-world example, they don't need any state to render, but API expects you to pass a reference to a state, so they use &() and _ as a placeholder for an arg name. And Widget gets () as a type parameter for the same reason.

Pretty straightforward to my mind.

reply
Nah still ugly, like C++ said hold my beer. ;-)
reply
Or, there is a lot going on there and the library/Rust doesn't hide it from you. Your mileage will vary depending on which format you prefer and that's why I pick Rust.
reply
Idiomatic Rust seemed to always use a ton of method chaining much more than any other language, even TypeScript, so a lot of Rust code just reads like "names.iter().cloned().map(|name|name.trim().to_string()).filter(|name| name.is_empty()).map(|name| name.to_lowercase()).filter_map(...)" all the time.
reply
You see this in functional programming languages. Personally, I prefer it, but I get that it's not for everyone.
reply
I've observed this too. I consider it more of a style (You did say idiomatic) or DSL than a core part of the language. I avoid it.
reply
I guess I'm used to it coming from Swift.
reply
Rust is ugly as a beginner, beautiful as an intermediate, and sorta ugly again as an expert.
reply
well, luckily we don't have to write the code ourselves anymore
reply
It comes with the multi/cross-platform territory because at the end of the day (at varying degrees from one such lib/tool/paradigm to others) it's just one piece of clothing trying to dress every body type, size, shape, and colour.
reply
I'm not sure what you mean... It's a beautiful dialect of Klingon.
reply
I agree. There are some languages that looked at all the possible symbols on a keyboard and decided that every single one must be used as part of hello world. Then on the opposite end there are those who stopped at open and close parentheses.

This is common in most lower level languages in a large part because they are more powerful.

The funny thing is the replies insulting you for a fairly tame and rather accurate opinion. Almost like rust has this weird subset of users who cannot handle anything negative about their favorite tool.

reply
Who cares. You might as well be saying assembly is verbose and ugly. That is just the output of "create a hello world gpui app" prompt.
reply