Path: csiph.com!weretis.net!feeder9.news.weretis.net!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail From: cross@spitfire.i.gajendra.net (Dan Cross) Newsgroups: comp.arch Subject: Re: Optimization by programmers Date: Mon, 5 Oct 2026 11:47:56 -0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Message-ID: <11a02pc$eql$1@reader2.panix.com> References: <1177fdi$26ea4$1@dont-email.me> <20260928195833.00001d42@yahoo.com> <119j4g4$4kn$1@reader1.panix.com> <20260930175006.000031dd@yahoo.com> Injection-Date: Mon, 5 Oct 2026 11:47:56 -0000 (UTC) Injection-Info: reader2.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80"; logging-data="15189"; mail-complaints-to="abuse@panix.com" X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Originator: cross@spitfire.i.gajendra.net (Dan Cross) Xref: csiph.com comp.arch:118475 In article <20260930175006.000031dd@yahoo.com>, Michael S wrote: >On Wed, 30 Sep 2026 13:57:24 -0000 (UTC) >cross@spitfire.i.gajendra.net (Dan Cross) wrote: > >> In article <20260928195833.00001d42@yahoo.com>, >> Michael S wrote: >> >[snip] >> >My only Rust program was full of casts of various integer types to >> >usize. Exactly for the purpose of array indexing. >> >> Beginning Rust programmers tend to go through a few phases, >> particularly if coming from a language like C. "Fighting the >> Borrow Checker" is well-known; "traits are awesome; let's use >> them everywhere!" is another. > >I didn't reach the second stage. Not sure about first. > >> When I started programming in Rust, most of my immediate >> colleagues and I had terribly little experience in the language. >> We were excited about the its potential benefits, but realized >> it would take a few months to build up a sufficient level of >> familiarity to use it skillfully. One quipped, "this language >> has a near-vertical learning curve." > >IMHO, he is correct. >Rust is certainly the hardest to learn out of computer languges that I >ever tried that I would not call idiotic. She, actually, but yes. I guess it depends on one's background, but in general if you are coming from many years of experience in languages like C or C++, Rust can be a real slog. I've seen some anecdotal reports that teaching it to programming neophytes as a first language is actually quite productive. >> At one point a coworker (self-deprecatingly) said, "look, I'm >> writing crust! C in Rust syntax!" Everyone thought this was a >> great play on words, but he was correct: the programs we were >> writing were essentially C programs, just expressed in Rust. We >> quickly adopted that to describe our still naive code: it wasn't >> an insult, just an expression that we were still coming to terms >> with a new way of doing things. Some of the hallmarks of that >> included using the wrong paradigms (and types!) for lots of our >> code. >> >> I'd be curious to know more about your program. > >The program was an implementation scalable flood fill algorithm (i.e. >one with much better than typical worst case BigO properties, both for >speed and for space) together with test benches for correctness and >speed. As you could guess, I didn't really wrote it in Rust. It was a >non-literal port from C. The purpose of translation was two-fold: >improvement of my knowledge of Rust and getting better feel for cost of >mandatory bound checking for one particular sort of data structures. So mandatory bounds checking will usually be compiled out in optimized builds; you can choose to keep it in, but most don't. >Before doing Rust port I did port to Golang. Unlike for Rust, where I >only read The Book and went trough part of tutorial, I had small >previous practical experience in Go, but it was not very recent. Still, >the difference in my productivity was huge. In favor of Go, of course. Indeed. Sometimes I find Go far more productive, and other times Rust. It really depends on the category of problem I am working on. >> I've written >> several hundred kloc of Rust at this point, and while what I >> write may be terribly specialized, I rarely find myself indexing >> an array; often, I'm using iterators or some other abstraction >> for that kind of thing. If that was the one program you have >> written in Rust, my _guess_ is that you were using paradigms >> appropriate to a different language, which is why you felt you >> needed to reach for casts to index an array so frequently. >> >> Again, that's not a comment on your program, so much as >> suggesting an impedence mismatch between what you wrote and how >> one would generally expect to use the language. >> >> In general, I think a person's experience writing a single >> program tells us very little. > >I never pretended otherwise. No I know, but at least one other reader appeared to. >Although I don't see how one can avoid >cast if one wants to use indices that originate in signed domain. Or, >as was often a case in this particular program, in domain of narrower >unsigned integers. Well, for narrower to wider unsigned types, there is `into()`. Depending on what you were using for the underlying collection, there is also the `std::ops::Index` trait that you could `impl` for index types other than `usize`, and container types other than primitive arrays and slices. - Dan C.