logoalt Hacker News

drnick1 • today at 12:56 AM • 8 replies • view on HN

The hello world code example reinforces my opinion that Rust is verbose and ugly.


Replies

airstrike • today at 2:46 AM

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... any 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?

cevn • today at 1:03 AM

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.

➕ show 1 reply
csomar • today at 1:47 AM

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.

YuechenLi • today at 2:12 AM

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.

➕ show 2 replies
bloppe • today at 2:11 AM

Rust is ugly as a beginner, beautiful as an intermediate, and sorta ugly again as an expert.

keyle • today at 2:28 AM

I'm not sure what you mean... It's a beautiful dialect of Klingon.

thousand_nights • today at 1:03 AM

well, luckily we don't have to write the code ourselves anymore

eddythompson80 • today at 1:55 AM

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.