News for hackers. Stuff that matters.
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @10:22AM (#32579830)
> Dev velocity, which was supposed to be the claim to fame of Python, improved dramatically with Rust.

I don't doubt this in the least. I've been a professional Python developer for 15 years, and I can't believe Python ever had the reputation for "high dev velocity" beyond toy examples. In every real world code base I've worked in, Python has been a strict liability and the promise that you can "just rewrite the slow parts in C/C++/Numpy/etc" has never held (you very often spend at least as much time marshaling the data to the target language format than you gain by processing in the faster language and you have all of the maintainability problems of C/C++/Numpy). Python trades developer velocity for poor runtime performance.

I don't think Rust is the paragon of high dev velocity languages either, but it seems to be more predictable. You don't have something that works as a prototype, but then you run into a bunch of performance problems (which virtually cannot be worked around) when you go to productionize, nor do you get all of the emergent quality and maintainability issues that come about from a dynamic type system (and last I checked, Python's optional static type system was still pretty alpha-grade).

I strongly recommend avoiding Python for new projects. Use Go if you're looking for an easy GC language with max productivity and a decent performance ceiling. Use Rust if you're writing really high performance or correctness-is-paramount software. I'm sure there are other decent options as well (I've heard generally good things about TypeScript, but I'd be concerned about its performance even if it is better than Python).

Re:Rust – A hard decision pays off by peterkelly on Wednesday August 24, 2022 @03:30PM (#32584581)
A lot of people seem to believe that dynamically typed languages make development easier, because you don't have to worry about writing type annotations or going through the extra steps to fix compile-time errors.

This is arguably true for small scripts, but for anything non-trivial I find that static typing means I can be more productive, because type errors are caught straight away (rather than potentially in production), and I can be much more confident in refactoring code because I know certain kinds of errors will be caught by during type checking. This doesn't remove the need for automated testing, but does reduce the number of test cases you have to write.

Things have improved a lot in the Python ecosystem of late with the introduction of type annotations and mypy, so to the extent possible I treat Python as if it's a statically typed language, putting type annotations everywhere and always making sure the codebase passes type checking before pushing a commit.

However, the fact that this is optional sadly means that not everyone does it, and if you're working with parts of a codebase written without this level of discipline, you're basically back to square one. I've come to the conclusion that for medium to large projects, dynamic typing encourages sloppy programming, because it doesn't force people to think as carefully about what exactly their data types are, and whether they're being used correctly.

Re:Rust – A hard decision pays off by tlrobinson on Wednesday August 24, 2022 @03:48PM (#32584800)
> I find that static typing means I can be more productive, because type errors are caught straight away

I agree completely. I feel like there’s a pretty common arc among programmers:

1. learn to program using verbose statically typed languages

2. discover fun dynamically typed languages, eschew statically typed languages

3. discover dynamically typed languages are a shitshow for large real-world projects

4. re-discover fun/less verbose statically typed languages that make working on large projects tolerable

Re:Rust – A hard decision pays off by tralarpa on Wednesday August 24, 2022 @06:25PM (#32586614)
I hate that some universities teach dynamically typed languages as first language in their curriculum. I think for CS students the first language should be as "strict" (not in the mathematical sense) as possible, so the student is forced to think very carefully what is going where. This is of course a controversial opinion, especially among proponents of SICP (which is, in my opinion, not a good book for beginners. Yes, downvote me).

(Obviously, I am talking about CS students here, not about the general public who just want to learn what writing a program means)

Re:Rust – A hard decision pays off by xhevahir on Wednesday August 24, 2022 @08:22PM (#32587722)
What language do you recommend for beginners?
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @08:28PM (#32587766)
I think Go would make a pretty good language for beginners, but I haven't tested that theory. TypeScript might be the safer bet, especially since you can run it in the browser and see things, which is probably somewhat more gratifying than printing text to a console.
Re:Rust – A hard decision pays off by manholio on Thursday August 25, 2022 @05:27AM (#32591463)
I would go on a limb and say Rust (or more specifically, a limited dialect of it) could become a good language for beginners if:

- the compiler had better life time inference, so that you wouldn't need to annotate simple functions and introduce beginners to complex issues related to lifetimes, i.e it should "seem" to work like python, initially.

- better learning resources for absolute beginners are developed, step by step tutorial, an easy to install full IDE with friendly error messages etc.

Re:Rust – A hard decision pays off by einpoklum on Wednesday August 24, 2022 @06:08PM (#32586433)
About no. 4: That often translates into noticing C++ has gotten `auto` in C++11 with a later improvement in C++14:

  auto x { get_something_complicated() };
or

  foo(int x) -> auto {
      return get_something_complicated(bar(x));
  }
     
so it's less "not-fun" these days.
Re:Rust – A hard decision pays off by throwaway2037 on Wednesday August 24, 2022 @07:43PM (#32587413)
I feel the same. Java and C# have an equivalent called 'var'. Unless the scope is tiny, I always avoid it. Also, in Java when you create a lambda, it is possible to exclude the parameter types.

    foo(x) -> get_something_complicated(bar(x))
It is not good for readability in large source bases.
Re:Rust – A hard decision pays off by einpoklum on Friday August 26, 2022 @03:26AM (#32604234)
With C++ lambdas, it's similar, but the syntax is a bit uglier:

  [](auto&& x) { return get_something_complicated(bar(x)); }
and you can decide whether you want a value (no &'s), an lvalue reference (&), or a forwarding reference (&&). I think with C++20 you can also use a concept instead of auto for a constrained parameter type.
Re:Rust – A hard decision pays off by amelius on Wednesday August 24, 2022 @05:39PM (#32586123)
Except keep in mind that Rust adds more constraints than your typical statically typed language.

It is still more fun and efficient to program in a language that is garbage collected and statically typed.

Re:Rust – A hard decision pays off by linsomniac on Wednesday August 24, 2022 @08:34PM (#32587795)
The thing I like about Python is that I can decide, even on a line-by-line basis, but more likely on a program by program basis, if it makes sense to be type oblivious, or type checked.
Re:Rust – A hard decision pays off by rjh29 on Thursday August 25, 2022 @07:18AM (#32592179)
Exactly. For one-off scripts or code you might throw away, there is nothing wrong with skipping the types.
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @04:09PM (#32585087)
> I can be much more confident in refactoring code because I know certain kinds of errors will be caught by during type checking.

I'll add to that: static typing also guarantees that your annotations are correct and complete. Prior to Mypy, in the Python world, we would document types in docstrings, which meant that docstrings gradually came to be incorrect--a function that returns a string might sometimes return `None`, but you called it assuming it always returned a string. In other cases, people (including the Python maintainers via the stdlib) will add annotations like "argument 'foo' is a file-like object", which is ... insufficient (do I just need a "read()" method? or do I need to implement "seek()" and "close()" as well?). Ultimately, in the absence of static analysis, a lot of time is wasted reading source code trying to understand the actual type signatures.

> Things have improved a lot in the Python ecosystem of late with the introduction of type annotations and mypy, so to the extent possible I treat Python as if it's a statically typed language, putting type annotations everywhere and always making sure the codebase passes type checking before pushing a commit.

This hasn't been true in my experience. Last I checked, Mypy still couldn't express things like recursive types (think "JSON" or "recursive linked list"), and a lot of things still required jumping through obscure hoops (defining a callback with kwargs). I also couldn't figure out how to export type annotations in my packages, and I had a lot of trouble getting mypy to pull in type stubs for packages that didn't provide their own annotations. In general, Python's typing story still feels very shoe-horned, although it's been a minute since I last fumbled with it, so maybe some of this has improved.

Re:Rust – A hard decision pays off by kitsunesoba on Wednesday August 24, 2022 @04:28PM (#32585320)
> for anything non-trivial I find that static typing means I can be more productive, because type errors are caught straight away (rather than potentially in production), and I can be much more confident in refactoring code because I know certain kinds of errors will be caught by during type checking.

Fully agreed. It's not quite the same as Rust vs. Python, but I've pulled off several sweeping refactors and rewrites in Swift codebases that I wouldn't dream of even attempting with Objective-C.

Re:Rust – A hard decision pays off by cmrdporcupine on Wednesday August 24, 2022 @11:08AM (#32580428)
Yes re: Python.

Story -- I was a very early adopter of Python, back in the mid-90s. When other people wrote their CGI scripts in Perl, I always reached for Python. The first paid gig I ever had was a CGI script ("resume builder") I wrote in Python in 1996. But almost nobody was using it back then, and I'd get quizzical stares from people in job interviews etc. when it came up.

So for many years back then I really really wanted to get a job working in Python. And I was super excited to get a job around the 2001 time frame in it on a pretty cool embedded Linux project.

But my first experience working in a large codebase was disappointing. I could see right away that once many developers started working in that codebase together, best practices were really hard to enforce, and things started to fall apart into a bit of a mess, and lots of problems just showed up at runtime in bad explosions. That was the beginning of my disenchantment with dynamically typed, late-bound languages. They only give you the illusion of fast prototyping. You just shift your time to fixing type and binding errors later in your dev cycle.

Python really improved a lot with the 2->3 transition, and the community has much better best practices now. But I think the core problem with late bound languages remains.

All that said, I'm currently in another window working for my current employer wiring an embedded CPython interpreter into a Rust-based runtime...

Re:Rust – A hard decision pays off by orangecat on Wednesday August 24, 2022 @02:10PM (#32583453)
I agree with most of this, but I would argue that the 2->3 transition was on balance a mistake. Python 3 is better, but not better enough to justify the huge amount of time and resources that otherwise could have been spent on better performance, typing, packaging, tools, etc. I'd gladly trade the Python 3 improvements for Python 2 equivalents of TypeScript and V8.
Re:Rust – A hard decision pays off by cmrdporcupine on Wednesday August 24, 2022 @02:18PM (#32583581)
You are probably right, I'm not invested in enough in that ecosystem to know one way or another. I do know lots of things remain disrupted by this transition in ways that still personally inconvenience me.
Re:Rust – A hard decision pays off by agumonkey on Wednesday August 24, 2022 @08:42PM (#32587856)
I read "CGI" as computer generated imagery, python was a strong glue language in this field in the 90s.

Also I think people misread 'python speed', few c++ masters said it was more about prototyping to converge on good overall design rather than suffering the efforts of early iterations in c++ (90s c++).

Re:Rust – A hard decision pays off by cmrdporcupine on Wednesday August 24, 2022 @10:42PM (#32588791)
Definitely in the context of the times, Python was more pleasant overall for initial prototyping than any static typed alternatives, including Java.

I still use it for quick one-off scripts to "do things" with bits of data and so on. And as a calculator.

Re:Rust – A hard decision pays off by DougN7 on Wednesday August 24, 2022 @05:23PM (#32585966)
> They only give you the illusion of fast prototyping. You just shift your time to fixing type and binding errors later in your dev cycle.

That is the perfect way to describe it! And sometimes you’re out of the dev cycle and into production if your test suite didn’t hit all cases.

Re:Rust – A hard decision pays off by lijogdfljk on Wednesday August 24, 2022 @11:21AM (#32580575)
> Use Go if you're looking for an easy GC language with max productivity and a decent performance ceiling. Use Rust if you're writing really high performance or correctness-is-paramount software.

I'd add one more addition to use Rust (speaking from an ex-Go dev): Use Rust if you want a robust std lib. Go is good, i used it for ~5 years, but man Rust was a breath of fresh air with the amount of tooling that helped me solve problems. Iterators, are a great example.

I also preferred Crates vs Github Repos, but i think that's just personal preference.. not objective.

Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @12:17PM (#32581549)
I actually don't care as much for iterators as I thought I would. Beyond some simpler map().reduce() stuff they tend to fall over pretty fast, and I end up spending too much time trying to make iterator chains work before defaulting to for loops. I also dislike how anemic Rust's stdlib is. I'm sure there are good reasons, but I like that I can just reach for Go's stdlib for annotating errors or dealing with JSON. Other than that, I like the API design in Rust's stdlib.

Here's an example where the iterator-chain version is way more complex:

    let posts = read_dir(source_directory)?
        .filter_map(|result| {
            (|| {
                let entry = result?;
                let os_file_name = entry.file_name();
                let file_name = os_file_name.to_string_lossy();
                if Self::is_bundle(&entry)? {
                    self.parse_post_bundle(&file_name, &entry.path())
                        .map(Some)
                } else if file_name.ends_with(MARKDOWN_EXTENSION) {
                    self.parse_post(
                        file_name.trim_end_matches(MARKDOWN_EXTENSION),
                        &mut File::open(&entry.path())?,
                    )
                    .map(Some)
                } else {
                    Ok(None)
                }
            })()
            .transpose()
        })
        .collect::<Result<Vec<_>>>()?;
Here's the imperative version:

    let mut posts = Vec::new();
    for result in read_dir(source_directory)? {
        let entry = result?;
        let os_file_name = entry.file_name();
        let file_name = os_file_name.to_string_lossy();
        if Self::is_bundle(&entry)? {
            posts.push(self.parse_post_bundle(&file_name, &entry.path())?);
        } else if file_name.ends_with(MARKDOWN_EXTENSION) {
            posts.push(self.parse_post(
                file_name.trim_end_matches(MARKDOWN_EXTENSION),
                &mut File::open(&entry.path())?,
            )?);
        }
    }
Re:Rust – A hard decision pays off by 0x457 on Wednesday August 24, 2022 @04:56PM (#32585632)
Iterator-chain version would be a lot better looking if it was actually was a chain and not everything pushed into a single `filter_map`. "Ifs" are weird looking, one branch is using `entry`(I take it's a `DirEntry`?) and another is using `file_name` I suspect both could use the and look like `Self::is_` ?

If you're going to write an iterator chain in an imperative way, then you might as well right it imperatively.

A few notes:

- you can compare `&OsStr` with `&str` without `to_string_lossy` any explicit conversion (`&str -> &OsStr` done in `PartialEq` is basically free)

- you can get extension from `Path` by using `Path::extension`

- you can get filename without extension by using `Path::file_stem` or `Path::file_prefix`

- making your parse functions take the same arguments makes it a lot cleaner

Something like this:

    read_dir("")?
    .map(|e| e.map(|e| e.path()))
    .map(|path| {
        path.and_then(|path| {
            if Self::is_bundle(&path) {
                self.parse_post_bundle(&path.file_name().to_string_lossy(), &path).map(Some)
            } else if Self::is_markdown(&path) {
                self.parse_post(&path.file_stem().to_string_lossy(), &path).map(Some)

            } else {
                Ok(None)
            }
        })
    })
    .filter_map(Result::transpose)
    .collect::<Result<Vec<()>, std::io::Error>>()

    // Ignore this, just an example
    fn is_bundle(path: &Path) -> bool {
        path.extension().map(|ext| ext == "bundle").unwrap_or(false)
    }
    
    fn is_markdown(path: &Path) -> bool {
        path.extension().map(|ext| ext == "md").unwrap_or(false)
    }
Re:Rust – A hard decision pays off by Already__Taken on Wednesday August 24, 2022 @08:13PM (#32587641)
Forgive me for asking instead of looking, I'm still getting into rust; why do you map instead of getting the result?

    path.extension().map(|ext| ext == "bundle").unwrap_or(false)
vs

    (path.extension() == "bundle").unwrap_or(false)
or further up

    .map(|e| e.map(|e| e.path()))
    vs
    .map(|e| e.path())
Is the .map keeping any value wrapped in an iterator so you can map again? I thought it was interesting what you wrote looks a lot like what I'd write in powershell.
Re:Rust – A hard decision pays off by steveklabnik on Wednesday August 24, 2022 @09:47PM (#32588400)
Not your parent, but I do know the answer.

extension() returns an Option<&OsStr>, because not every file has an extension https://doc.rust-lang.org/stable/std/path/struct.Path.html#m...

map on option says "run this closure on the value if it's Some, or do nothing if it's None https://doc.rust-lang.org/stable/std/option/enum.Option.html...

So after the map, we now have an Option<bool>. The unwrap_or method will say "give me the value if it's Some, and give me the argument if it's not https://doc.rust-lang.org/stable/std/option/enum.Option.html...

That means we finally end up with a bool.

  (path.extension() == "bundle").unwrap_or(false)
This code wouldn't work because you're comparing an Option<&OsStr> to a &str. Even if that worked, you'd have a boolean, and unwrap_or doesn't make sense on booleans, you'd just leave off that part.
Re:Rust – A hard decision pays off by Already__Taken on Monday September 05, 2022 @05:40AM (#32722301)
Awesome thanks, I wasn't on a machine to play around with it at the time.
Re:Rust – A hard decision pays off by 0x457 on Saturday August 27, 2022 @08:39PM (#32624647)
`extension()` gives you an `Option`, remember `Path` might not be a file or file could be without extension.

Why not `((path.extension() == Some("bundle"))`? I don't know, it didn't work, and I didn't want to spend too much time on it.

`read_dir` gives us an iterator over `Result<DirEntry>`, so `e` in that map is a `Result` and not a `DirEntry`. It's two different "map" functions - on Option<T> and Result<T,E> it maps "T", but on Iterator it maps "Item" from that iterator.

Here is an explanation why `read_dir` give you a Result - https://doc.rust-lang.org/std/fs/fn.read_dir.html#errors

Re:Rust – A hard decision pays off by Already__Taken on Monday September 05, 2022 @05:39AM (#32722294)
Thanks for the insight
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @08:32PM (#32587788)
I'm sure there's plenty of room for improvement. I spent several hours with a bunch of Rustaceans just trying to get the short-circuiting to work right, and we sort of gave up on it beyond that.
Re:Rust – A hard decision pays off by mamcx on Wednesday August 24, 2022 @12:50PM (#32582183)
The thing is in Rust this is totally ok. Is NOT un-idiomatic to mix imperative + functional paradigms in the same block.
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @01:06PM (#32582448)
Agreed, but I think people make too big a deal about iterators. The simple for loops that they’re fit to replace aren’t that hard to read or write, so they aren’t causing real problems, and on the more complex end you’re writing imperative stuff anyway. Iterators certainly aren’t a bad thing, but they’re not the game changer that Go-critics made them out to be in all of the Rust-vs-Go debates.
Re:Rust – A hard decision pays off by mustache_kimono on Wednesday August 24, 2022 @03:33PM (#32584614)
> Agreed, but I think people make too big a deal about iterators.

I may just have more time to dick around, but I've been forcing myself to write everything as an iterator in Rust (instead of a for loop) just to learn the paradigm and, honestly, it's been pretty great.

First, there is a performance impact. You may think this would be small, but, in my experience, it can be relatively large. There must be several reasons of which I am ignorant, but they probably include mutable no alias inside closures, bounds check elision, etc.

Second, there is a mutability advantage to just using filter/flatten/map/collect for 90% of your use cases.

Third, the more advanced iterator methods will cover the other 5-10% of your use cases, and will make your code much easier to read, once you understand how to use them (if you're trying to learning something/anything more complex at the same time, save your brain power!). I don't have a single traditional for loop in my personal projects.

My take on iterators is, for iterator/Rust beginners (like me!/perhaps not you) -- the best way to learn is to get it working as imperative code, and when you have the time, go back a rewrite as an iterator. In the beginning, it's super frustrating. But you'll get better and better and, after awhile, you'll much, much prefer writing as an iterator. You won't even think of using a for loop.

Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @04:58PM (#32585659)
I mean, I definitely have tried to rewrite stuff as iterators even when it isn't convenient. I only got to that working example by dedicating a few hours with the good people on the Rust Discord trying to make it work (a lot of seasoned Rustaceans also weren't able to get it working, it was a collaborative effort that took a fair amount of time and rhapsodizing). And even then, the result is pretty ugly (I don't think many seasoned Rustaceans would call it "idiomatic" or advise the first version over the second).
Re:Rust – A hard decision pays off by mustache_kimono on Wednesday August 24, 2022 @06:09PM (#32586445)
Agreed. Your example is a pretty pathological case, but yeah.
Re:Rust – A hard decision pays off by efnx on Wednesday August 24, 2022 @04:36PM (#32585392)
The selling point of iterators isn’t that they replace for loops, it’s that you can make new iterators by implementing a trait. That at way downstream users can use your iterators in a for loop. Of course you also can use a more functional style if you like.
Re:Rust – A hard decision pays off by nomel on Wednesday August 24, 2022 @01:34PM (#32582858)
I disagree. If I can avoid an index variable, I’m going to have less bugs since I won’t have to index.
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @03:25PM (#32584502)
I'm not sure what you mean. You don't have to deal with index variables in a for loop:

    for item in iterator {
        vector.push_back(foo(item));
    }
You're not explicitly indexing the source iterator or the destination vector at any point.
Re:Rust – A hard decision pays off by nomel on Wednesday August 24, 2022 @03:41PM (#32584713)
Agreed. That's why I enjoy iterators, and use them whenever possible. I think they're important.
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @04:11PM (#32585114)
But earlier you claimed the for-loop version required index variables and indexing into iterators/vectors/etc ... ?
Re:Rust – A hard decision pays off by nomel on Wednesday August 24, 2022 @07:33PM (#32587308)
I clearly said the opposite, in response to, what appeared to be, your suggestion that indexing isn't so bad:

"I think people make too big a deal about iterators. The simple for loops that they’re fit to replace aren’t that hard to read or write, so they aren’t causing real problem"

Re:Rust – A hard decision pays off by MauranKilom on Wednesday August 24, 2022 @08:13PM (#32587639)
It seems like you imply that iterators = range-for and "simple loops" = indexing, which is clearly not what the previous poster has in mind (which was "range-for = imperative loops, iterators = functional style, simple loops = trivial loop body").
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @08:37PM (#32587813)
Yes, I was responding to:

> I disagree. If I can avoid an index variable, I’m going to have less bugs since I won’t have to index

Which (given thread context) sounds pretty clearly like he's advocating against `for item in iterator {...}` and in favor of iterator chains. If there's another way of reading that comment, I'm not seeing it. :)

Re:Rust – A hard decision pays off by lr1970 on Wednesday August 24, 2022 @05:21PM (#32585942)
> If I can avoid an index variable, I’m going to have less bugs since I won’t have to index.

Not only that. In safe Rust vector indexes are always bound-checked that slows execution a little bit. Iterators over a vector, on the other hand, do not suffer from bound-check overhead.

Re:Rust – A hard decision pays off by lvass on Wednesday August 24, 2022 @01:43PM (#32582993)
The first version isn't what I'd write in a purely functional language either, a recursive version would be much saner. Isn't recursion idiomatic in rust?
Re:Rust – A hard decision pays off by steveklabnik on Wednesday August 24, 2022 @01:51PM (#32583139)
Rust doesn't guarantee TCO and so recursion is a bit dicer than in many functional languages.
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @03:27PM (#32584522)
In addition to Steve's sibling comment, I'm responding narrowly to iterators versus for-loops. Recursion is out of scope.
Re:Rust – A hard decision pays off by thinkharderdev on Wednesday August 24, 2022 @01:31PM (#32582810)
Yep, agree wholeheartedly with this. I came to Rust from Scala where writing an explicit for loop is looked at as one step above using goto :) and it took me a while to just give in and write the imperative version.
Re:Rust – A hard decision pays off by SoftTalker on Wednesday August 24, 2022 @12:22PM (#32581650)
I guess that's subjective, not knowing rust I see a few more lines in the first example but beyond that it does not jump out at me as being "way more complex."
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @12:45PM (#32582081)
Hah, it took me and a bunch of other people in the Rust discord a fair amount of time to figure out how to get the first example to compile correctly in the first place, and I find the “transpose()” business to be particularly convoluted. I think even Rust people would prefer the imperative version. I also suspect there’s some hindsight benefit at play in that it’s easier to make sense of the first snippet than it was to write it.
Re:Rust – A hard decision pays off by tialaramex on Wednesday August 24, 2022 @01:06PM (#32582461)
Yes, the imperative version looks like the sane choice to me. Rust's iterator documentation does suggest that this is not a language which favours iterator chains everywhere.

However one reason to prefer an iterator chain in some cases is that the chain might imply an optimisation you'd otherwise have to write manually and might not think of.

For example if I have N things, and I map them, perhaps more than once, but I'm definitely getting N of whatever the output of the last map was, the iterator chain might very well see that I don't actually have any way to change N and so when I collect() that into a Vec the Vec it gives me is constructed with capacity N, saving the (amortized but non-zero) cost of growing it during insertions.

Imperatively I can remember to write Vec::with_capacity(N), and that's safe of course but it's an extra step to remember.

The imperative approach does particularly shine on the opposite edge of this, if I know that I'm getting no more than 100 items out of this pipeline, despite putting N in, Rust almost certainly won't see that and won't make Vec::with_capacity(100) for a collect() call whereas my imperative code can just explicitly write Vec::with_capacity(100) or whatever.

Re:Rust – A hard decision pays off by sgeisenh on Wednesday August 24, 2022 @01:35PM (#32582872)
Depending on how you write it, iterators are much better at this since most iterator methods produce iterators with size hints.

If you use "take" for example, collect should do the right thing: https://doc.rust-lang.org/src/core/iter/adapters/take.rs.htm...

Re:Rust – A hard decision pays off by tialaramex on Wednesday August 24, 2022 @02:08PM (#32583425)
Mere hints aren't enough for collect()

It will only care about your hints if you implement the unsafe trait TrustedLen (which promises those hints are correct)

Take is indeed TrustedLen if the Iterator it's taking from is TrustedLen (as in this case it can be sure of the size hint)

If you get to ~100 via some means other than take()ing 100 of them, chances are you don't have TrustedLen as a result.

Re:Rust – A hard decision pays off by Alexendoo on Wednesday August 24, 2022 @02:55PM (#32584077)
TrustedLen will mean it can safely take the upper bound, but Vec for example will still use the lower bound of the hint when something isn't TrustedLen

https://doc.rust-lang.org/src/alloc/vec/spec_from_iter_neste...

Re:Rust – A hard decision pays off by tialaramex on Wednesday August 24, 2022 @03:14PM (#32584353)
Ooh nice, I hadn't seen that. OK, so there are probably places where I assumed the iterator won't do as nice a job of collect() as I did manually but I was wrong.

I wonder how the hell I didn't see that when I was tracking down how collect() ends up caring about TrustedLen.

Thanks.

Re:Rust – A hard decision pays off by ywei3410 on Wednesday August 24, 2022 @01:08PM (#32582471)
Honestly the closure + `transpose` is really ugly as sin. I had to do a double take and reason through the steps which you took to get that particular snippet (while not reading the imperative one).
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @03:28PM (#32584542)
Thanks, I feel validated. (:
Re:Rust – A hard decision pays off by nu11ptr on Wednesday August 24, 2022 @02:50PM (#32584018)
There is no need to force something iterator style. By all means use a loop if it is more readable. Also, if your iterator style closure body gets very verbose, you can always pull the logic out into a function or closure and pass it in. In the end, both styles are idiomatic, and the best choice is which makes it more readable (subjective of course).

I personally use iterator-style for 1-3 simple ops, but go into a loop for anything more complicated. The functional part of me wants to force iterator style but I fight it for complex use cases because it is irrational on my part, and I find loops easier to read for stuff like that.

Re:Rust – A hard decision pays off by lijogdfljk on Wednesday August 24, 2022 @04:15PM (#32585156)
Fair, but i'd probably write your iterator example differently. Though, besides the point perhaps - as i agree there are plenty of cases where imperative approaches are cleaner.

I however will often have a dozen maps/filters/etc and that style in imperative is what, nesting repeatedly or using `continue`. Meh.

If your Iterator consists of a single `filter_map` i can see why you don't get much value out of them in that case. It's because.. well, there's not much value to get out of it.

Re:Rust – A hard decision pays off by drran on Wednesday August 24, 2022 @01:27PM (#32582750)
Now, compare a parallel version of both.
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @03:32PM (#32584603)
It's not obvious to me that the parallel version of the first is going to be cleaner (or more performant) than a parallel version of the second, but even if it is, I don't agree with mangling (to put it nicely) single-threaded code on the off chance that it might be made parallel one day.
Re:Rust – A hard decision pays off by dls2016 on Wednesday August 24, 2022 @12:51PM (#32582193)
> but man Rust was a breath of fresh air with the amount of tooling that helped me solve problems

The tooling is the #1 reason I'd like to learn rust. I have not kept up with C++ and I'm not sure I ever will... sometimes plain C seems more straightforward. But those languages (C++ especially) have suffered from lack of standard tooling, in my opinion.

Even C# being a few years younger than Java seems to have made a huge difference in tooling availability (I'm sure having a single corporate driver during its lifetime made a difference, too).

I'm excited by the prospect of a compiled language with modern tooling.

Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @12:58PM (#32582320)
Tooling was the reason I left C++. Having to do your own package management and script your own build system was deeply dull work. The IDE story was also pretty miserable, although I think clangd has improved it a bit. Getting decent information out of core dumps also sucked a lot. The language actually didn’t bother me too much after c++11, but everything else was such a bear that I jumped ship.

Rust has been very rewarding in that it largely fixes all of C++’s tooling and language problems. It very much is a significantly improved C++.

Re:Rust – A hard decision pays off by synergy20 on Wednesday August 24, 2022 @03:25PM (#32584498)
I actually filed a ticket at Carbon project saying c++'s top 1 problem is tooling, modern c++ is pretty nice to use already, no need for Carbon there in fact, at least not as needed as tooling.
Re:Rust – A hard decision pays off by Thaxll on Wednesday August 24, 2022 @02:51PM (#32584030)
Rust std lib is subpar compared to the Go one, yes you have iterators but that's it, basic things like async are not even provided just the interface so everyone has to use tokyo. Then for real use cases you're missing http/json/compression/crypto etc ...

https://pkg.go.dev/std

Overall tooling and std lib are better on Go, actually there are not many languages that are on part with Go to that regard.

When you see what you can do with the single go command, it's pretty powerful.

Re:Rust – A hard decision pays off by throwaway234566 on Wednesday August 24, 2022 @09:00PM (#32588011)
Agreed 100%.

Go doesn't have a standard library problem, it has a userland language problem.

* No sum types / algebraic data types in 2022.

* No exhaustive pattern matching in 2022

* No move semantics / Uses GC

* No borrow checker

* Still suffers from nil problem / No type-safe nil / No type-safe Optionals in 2022 -- (I can show you all the nil panics in kubernetes logs if you like)

Current go users are already sold so they don't expect more, and that's fine, but further evangelism will require a better host language.

Re:Rust – A hard decision pays off by foldr on Thursday August 25, 2022 @04:03AM (#32590931)
Seems a bit odd to criticize Go for using GC rather than a borrow checker to manage memory. There’s surely a place for GCed languages, even if they’re not the right choice for every domain.
Re:Rust – A hard decision pays off by throwaway894345 on Thursday August 25, 2022 @09:43AM (#32593602)
I don’t mind GC. I think it’s the right choice for the sort of applications Go targets. I wish it had algebraic data types (with exhaustive pattern matching), but the “in 2022” meme is just vapid snark.

Notably, despite its shortcomings, Go is still perhaps the most productive programming language for general purpose applications. It turns out that type system features are neat, but tooling, ecosystem, simplicity, etc outrank type system features by quite a lot. Rust does very well here too, but it’s choice of borrow checker over GC amounts to trading off a lot of productivity in the general case (but it makes sense for Rust’s goals!).

Re:Rust – A hard decision pays off by Thaxll on Thursday August 25, 2022 @08:03AM (#32592552)
And yet Go has delivered very useful software used by millions of people.
Re:Rust – A hard decision pays off by lijogdfljk on Thursday August 25, 2022 @02:21PM (#32597830)
So has C, and most other popular languages. Doesn't mean they don't have issues, often dangerous issues.
Re:Rust – A hard decision pays off by jxf on Wednesday August 24, 2022 @03:52PM (#32584849)
Quick correction for anyone searching: it's `tokio`, not `tokyo`. [0]

[0]: https://tokio.rs/

Re:Rust – A hard decision pays off by mlindner on Wednesday August 24, 2022 @07:42PM (#32587401)
I find it really curious how people consider "async" as a "basic thing". Coming from C++, asynchronous runtimes were a thing companies and large open source projects were built around. It's not at all a basic thing.

I'd argue it's almost certainly something that should NOT be in the standard library. If anything, the feature was added to Rust too quickly and has way too many rough edges.

Re:Rust – A hard decision pays off by johnisgood on Wednesday August 24, 2022 @11:56AM (#32581149)
When performance and correctness are paramount, I personally stick to Ada/SPARK. Proven to be perfect for the job, and to be honest, Rust is quite a difficult language and I am not sure it is worth learning it considering that Ada/SPARK ticks all boxes when it comes to both low-level and high-level programming for critical systems.
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @12:54PM (#32582246)
I have fond memories of using Ada in college. Unfortunately it didn’t have much of an open source footprint and the community was downright hostile toward newbies (more so than other communities that I had experienced). I’m sure Ada has the stronger story for real-time embedded systems today, but (as I have learned Rust in the interim) I look forward to the day when Rust breaks into the real-time embedded space. In particular, I’m excited about ferrocene and the broader Rust certification efforts. I would really like to write embedded Rust professionally, and I hope certification will boost the number of embedded Rust jobs (no the to Ada, I just don’t particularly want to re-learn it).
Re:Rust – A hard decision pays off by deagle50 on Wednesday August 24, 2022 @02:20PM (#32583610)
My favorite thing about learning Rust is how helpful the community is.
Re:Rust – A hard decision pays off by kylereeve on Wednesday August 24, 2022 @02:56PM (#32584090)
Do you work in Ada/SPARK professionally? Curious what industry if so.
Re:Rust – A hard decision pays off by skrtskrt on Wednesday August 24, 2022 @11:47AM (#32581000)
I think this comes with the caveat that there are a lot more mature libraries for Go just as a function of the age of the language.
Re:Rust – A hard decision pays off by lumost on Wednesday August 24, 2022 @11:53AM (#32581089)
Agree, you can see this in https://github.com/rust-unofficial/awesome-rust vs. https://github.com/avelino/awesome-go

I've noticed however that there has been an uptick in great libraries over the last 2 years, with examples like pola.rs, rust-bert, tokenizers etc. starting to build momentum in the ecosystem.

Re:Rust – A hard decision pays off by pdimitar on Wednesday August 24, 2022 @01:11PM (#32582516)
That might have been true 2-3 years ago but nowadays whatever I can think of, Rust already has a library for it.
Re:Rust – A hard decision pays off by skrtskrt on Wednesday August 24, 2022 @01:31PM (#32582805)
Most recently I've run into Hyper not having tracing support
Re:Rust – A hard decision pays off by hnfong on Wednesday August 24, 2022 @11:17AM (#32580537)
I think this is a bit unfair. As always, blanket statements in software engineering aren't really meaningful.

As I understand it, the article talks about switching from python to rust in a non-trivial database service that is required to be fast and robust. I can't imagine python to do well in this regard, especially when C/C++ extensions are required to enhance the performance.

I also agree that 'Python has been a strict liability and the promise that you can "just rewrite the slow parts in C/C++/Numpy/etc" has never held'.

I just don't agree those points necessarily imply "avoiding Python for new projects". Even in the case of the original article, was it, in hindsight, a bad decision to start with python? I'd argue not necessarily. Python is still great for quickly hacking together something that works, not necessarily fast or maintainable, but if you're under time pressure or you're still trying to feel out the market fit for your product, it's not a great idea to waste brain cycles to deal with borrow checks for example.

Python's weaknesses only show when you need to scale, both on the performance and on the lines of code / number of collaborators metric, which is a problem you have only when the project succeeds. Avoiding python because of these problems reeks of premature optimization, unless you know it's how the project will end up in advance.

As other sibling comments point out, python is still great for small scripts and weekend projects. Perhaps you do mean 'avoiding Python for new projects that are expected to grow non-trivially', which is fine advice. I'm just a bit tired of all those over-reaching blanket statements people make regarding software design that only really makes sense in a limited context (here's a funny one I've heard recently: never write nested-for-loops because it's sloooww). It would be unfortunate to have the message "don't use python for large projects" be misinterpreted as "python sucks no matter what".

Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @11:48AM (#32581006)
> As I understand it, the article talks about switching from python to rust in a non-trivial database service that is required to be fast and robust. I can't imagine python to do well in this regard, especially when C/C++ extensions are required to enhance the performance.

The article specifically talked about following the conventional Python advice to use C/C++ for the fast parts and Python for the "glue". This is precisely where Python people say Python shines.

> I just don't agree those points necessarily imply "avoiding Python for new projects".

You should avoid Python for new projects because you never know at the outset whether you will run into a performance bottleneck that can't be resolved by "just rewrite in C/numpy/etc" and there are other languages that are better than Python at both its strengths and weaknesses. The odds of painting yourself into a corner with Python are very, very high, and there are other languages that are better than Python at just about everything (the only area where Python still dominates is data science exploration libraries). Even if you don't paint yourself into a corner, you'll be dealing with lots of surprising papercuts: if you want reproducible builds, you'll have to wade through an ecosystem of package managers each with their own pitfalls including long build times (e.g., I saw pipenv take 30-45 minutes just to `pipenv lock` on a small-medium sized project); developing with docker basically doesn't work on mac (and windows?) because the VM uses all available CPU marshaling filesystem events over the guest/host boundary; your developers accidentally pulled in an API SDK that makes sync I/O calls (or else does some CPU-intensive task) which seizes up the event loop bringing the process down (and the failure cascades to remaining instances bringing the whole app down); and then there's the "regular" dynamic type system errors like forgetting to "await" things or missing/incorrect type documentation.

> Even in the case of the original article, was it, in hindsight, a bad decision to start with python? I'd argue not necessarily. I'd argue not necessarily. Python is still great for quickly hacking together something that works, not necessarily fast or maintainable, but if you're under time pressure or you're still trying to feel out the market fit for your product, it's not a great idea to waste brain cycles to deal with borrow checks for example.

My point isn't that Python is bad for literally every project--I actually think this project was probably a best-case scenario for Python (they didn't describe many of the issues I described in my previous paragraph) and they knew ahead of time where there performance issues would be so they were able to start with an architecture that was amenable to "write the slow parts in C/C++". My point is that there are languages that are better at fast iteration than Python (namely Go or TypeScript) while also excelling at Python's weaknesses (performance, tooling, distribution, type system, package management, etc etc etc). I think it's incredibly reckless to start a new commercial project in Python in almost all cases (with a possible exception for data science, but even then I would look hard at everything else first).

> Python's weaknesses only show when you need to scale, both on the performance and on the lines of code / number of collaborators metric, which is a problem you have only when the project succeeds.

This might be true for certain Django CRUD apps, but it's patently untrue in the general case. I've seen Python work fine for a prototype data science app, but fall over when real customer data was introduced. Similarly, I'm currently an SRE attached to a Python project which falls over regularly because of some event loop issue or another (often someone pulls in an SDK that makes sync calls under the hood, or else some CPU-intensive task blocks the event loop). I see stuff like this regularly, and it never happens in our Go apps.

> As other sibling comments point out, python is still great for small scripts and weekend projects.

Granted. Do what you want in your free time, but it's risky to use Python for new commercial apps.

> Perhaps you do mean 'avoiding Python for new projects that are expected to grow non-trivially', which is fine advice.

Yes, this is what I meant. I didn't mean "hobby projects".

> I'm just a bit tired of all those over-reaching blanket statements people make regarding software design

I don't usually make blanket statements, but Python really is so bad that this is a blanket statement I'm pretty comfortable with. I've scarcely ever heard of someone getting burned for picking Go over Python (there was some Python2 veteran who wrote an angry blog post once about Go back in the early days, but never since). Python just refuses to adequately progress because it wants to maintain compatibility--that's fine, but as professional engineers we should understand that the rest of the ecosystem is moving beyond where Python is willing/able to go, and it's no longer an appropriate tool for the overwhelming majority of new projects.

Re:Rust – A hard decision pays off by qsort on Wednesday August 24, 2022 @12:05PM (#32581311)
> I think it's incredibly reckless to start a new commercial project in Python in almost all cases...

> I don't usually make blanket statements, but Python really is so bad that this is a blanket statement I'm pretty comfortable with.

Speaking as someone who agrees with you that something static is very likely better than python for a large project, how do you square this with the existence of a lot of Python projects, even "very commercial", that seem to go on just fine?

It's a fine theory and something I instinctively support, but I don't see measurable evidence in support of it.

Re:Rust – A hard decision pays off by pdimitar on Wednesday August 24, 2022 @01:27PM (#32582751)
Just fine, you say? I had dozens of colleagues being in medium to large Python projects and every single one of them was terrified of every small change in the projects because inevitably something fails in an unexpected way.

These guys and girls are heroes. They are like the plumbers and electricians working at 3:00 AM so your water and electricity never stop while you're awake.

"Just fine" is likely only your external observation. I'd give them medals and help them retire at 35 for all the horrors they have endured. It's "just fine" because they tirelessly made sure of it.

Things were just fine despite Python. Not because of Python.

Plus, none of us has statistics that prove a theory beyond any doubt. Forget about that; this scarcely (if ever) existed in the programming world and likely will not exist anytime soon. We should apply our experience and the intuition that grows out of it.

Finally: a pile of anecdotal evidence can be treated as an objective evidence with, say, 50-60% probability. Insisting that the real world must comply with academically pure practices is not going to get us anywhere (and is misguided).

Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @12:19PM (#32581592)
Survivorship bias. You don't hear about the failures. Moreover, many of those things (e.g., lots of Python at Google) was written at a time when there weren't better options, so you weren't struggling to make Python work while your competitor is writing Go or TypeScript.
Re:Rust – A hard decision pays off by throwawaymaths on Wednesday August 24, 2022 @12:25PM (#32581727)
Those projects were started when python was the least bad choice and grew out quickly enough that they could hire legions of developers to work around pythons problems.
Re:Rust – A hard decision pays off by infamia on Wednesday August 24, 2022 @03:26PM (#32584510)
> This might be true for certain Django CRUD apps, but it's patently untrue in the general case. I've seen Python work fine for a prototype data science app, but fall over when real customer data was introduced.

The cognitive dissonance embedded in this statement is rather striking, considering Django itself is written in Python and is known for its ruggedness and code quality. Django manages all of this without even taking advantage of somewhat newer features in Python like typing.

Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @05:00PM (#32585685)
There's no cognitive dissonance, you just misunderstood the claim. :)
Re:Rust – A hard decision pays off by 3pt14159 on Wednesday August 24, 2022 @03:05PM (#32584204)
I disagree.

Most startups that YC has funded that became successful (Series B or higher) were written in Python or Ruby. Now you can say that this is a tradeoff for post Series B, and for that I don't know. I've never worked on a massive Python mono-repo for a company that size. But I know what I've done in Python and, yes, it includes performance optimization in Numpy / Scipy / Cython, and other than Ruby, no other language comes close to the developer performance I see with Python and the ecosystem around it.

That said, there is a good and a bad way of writing Python. You absolutely need tests and lots of them since there is no compiler for vanilla Python. Mypy helps a ton too and so do the linters and even Black. Also, get pdb++ and customize it. The tooling helps a lot.

Now I haven't ever written production Rust, but I have for Go and many other languages, and so Rust may be faster, but other than Ruby I haven't seen anything close.

Re:Rust – A hard decision pays off by badpun on Wednesday August 24, 2022 @03:08PM (#32584255)
> I disagree.

> Most startups that YC has funded that became successful (Series B or higher) were written in Python or Ruby.

It depends on what your goal is. If you want to get rich off of VC money, Python and Ruby might be a good fit. If you, on the other hand, want to write good, performant, maintenable and (relatively) bug-free software, then there are better choices.

Re:Rust – A hard decision pays off by ithrow on Wednesday August 24, 2022 @05:59PM (#32586325)
If you, on the other hand, want to write good, performant, maintenable and (relatively) bug-free software, then there are better choices.

You can do that part when the money comes in.

Re:Rust – A hard decision pays off by badpun on Thursday August 25, 2022 @03:28AM (#32590697)
Once you invite the investors in, the company isn't truly yours, and they expect 1000x growth. There will always be higher priorities than a rewrite.

If you don't take investors' money, then it's theoretically feasible, but, in practice I've seen companies stuck with their Python/Ruby stack for 10 years or longer, always wanting to rewrite but never having the time. Microservice architecture helps (not that it's not a can of worms of its own), and these companies tend to write new functionalities in their desired language (such as Go or Scala) and deploy them as separate microservice. The old code remains in Python or Ruby though, and now they have a multilingual mess that is near-to-impossible to maintain for a small team. Why not start with a better language in the first place?

Re:Rust – A hard decision pays off by manfre on Wednesday August 24, 2022 @03:37PM (#32584671)
Dev teams that are unable or willing to properly architect and test their projects will end up with buggy and difficult to maintainable code regardless of language.
Re:Rust – A hard decision pays off by eatonphil on Wednesday August 24, 2022 @03:46PM (#32584764)
That is unrelated to what the person you're responding to said.
Re:Rust – A hard decision pays off by valenterry on Wednesday August 24, 2022 @05:13PM (#32585839)
> Most startups that YC has funded that became successful (Series B or higher) were written in Python or Ruby

So, what was the percentage of YC startups that started with Python or ruby and what was the share that became successful?

Re:Rust – A hard decision pays off by Nuzzerino on Wednesday August 24, 2022 @03:07PM (#32584238)
> Most startups that YC has funded that became successful (Series B or higher) were written in Python or Ruby.

Is there data on startup lifespan ranked by tech stack? Genuinely been looking for this for awhile now.

Re:Rust – A hard decision pays off by zaphar on Wednesday August 24, 2022 @11:31AM (#32580732)
Python has high dev velocity if you only measure how quickly you can get started on a project. The dev velocity drops exponentially with the size and complexity of your codebase.

But it is indeed quite fast when you are just trying to get your first file of code written.

Re:Rust – A hard decision pays off by benreesman on Wednesday August 24, 2022 @10:28AM (#32579907)
I think Rust deserves a lot of credit for popularizing the notion of “constraints as power”, but excessive enthusiasm around it does seem to obscure the rich traditions of PLT that it has more than liberally borrowed from.

There are more rungs on the ladder.

Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @11:11AM (#32580468)
I say this as someone who has had a lot of criticism for Rust: Rust definitely borrows a lot from other languages, but Rust deserves praise precisely because it curates the right features and composes them in the right way. There are way too many languages from the PLT space that add some neat type system innovation, but they fail on syntax or performance or tooling or etc. That's not particularly laudable IMO, but Rust has great tooling (cargo, rust-analyzer, rustfmt, rustup, etc), great performance, great safety, and a bunch of type system innovations (including its approach to memory management) which were probably picked from the PLT world. The individual features are neat, but Rust is much greater than the sum of those borrowed innovations. Choosing what features to use and which to omit is a much more valuable task than any individual innovation.
Re:Rust – A hard decision pays off by benreesman on Wednesday August 24, 2022 @11:25AM (#32580641)
Credit where credit is due: Rust has done a far better job than most of free-riding on Haskell’s type class system and clang’s optimizer, but rust-analyzer is a dumpster fire next to clangd, that’s not an example I’d use.
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @11:54AM (#32581102)
I haven't used clangd since the early days, but rust-analyzer hasn't been anything other than reliable for me (which is pretty impressive considering how often Rust changes as a language and how new rust-analyzer is).
Re:Rust – A hard decision pays off by benreesman on Wednesday August 24, 2022 @12:08PM (#32581378)
I would respectfully submit that time spent pushing your toolchain from more than one direction confers many benefits, of which a realistic appraisal of the strengths and weaknesses of the various tooling options is but one.
Re:Rust – A hard decision pays off by mustache_kimono on Wednesday August 24, 2022 @11:37AM (#32580816)
Um what?

Maybe it's just that I don't understand what clangd provides that's so great, but rust-analyzer, despite a few hiccups I've had with it, seems completely amazing at what it does.

Re:Rust – A hard decision pays off by benreesman on Wednesday August 24, 2022 @11:48AM (#32581005)
Well we could start with the fact that it crashes process IDs more often than Justin Bieber crashes Maseratis: https://github.com/rust-lang/vscode-rust/issues/890 (it’s always LLVM’s fault, I know). Or move right along to the insane configuration hacks that are mandatory if you want anything upmarket of VSCode (who doesn’t need a little practice with their Emacs Lisp), or the N^2 whatever that happens when you point it at bindgen output.

What clangd does is work.

Re:Rust – A hard decision pays off by mustache_kimono on Wednesday August 24, 2022 @12:28PM (#32581760)
> it crashes process IDs more often than Justin Bieber crashes Maseratis: https://github.com/rust-lang/vscode-rust/issues/890

So -- this guy used an extension (named Rust) with rust-analyzer, a configuration known to not work, it didn't work(!), and the extension author recommends he tries the extension made for rust-analyzer.

Hardly a case for the ages. Guy uses unsupported config and things don't work?

> What clangd does is work.

Don't doubt it. I'm just saying -- I haven't had any problems with the rust-analyzer extension since it became the Rust default. But, yes, I had a few hiccups and crashes beforehand, no doubt. I just have to imagine it's both younger, and doing more/different things than clangd.

Re:Rust – A hard decision pays off by coder543 on Wednesday August 24, 2022 @12:22PM (#32581660)
You linked to an issue from over a year ago to support your case? And the solution in that issue was just "switch to the right extension"? That's hardly a compelling argument. By all appearances, that person’s environment was completely broken since they reported the other extension did nothing at all, and a broken environment isn’t really a reflection on the tool. I can set up a broken environment for any tool and then complain about it. The absence of a bunch of other people encountering the same issue in that thread indicates this was not some big issue with rust-analyzer.

If I search for "Rust" in the VS Code Extension Marketplace, it shows the extension you linked to... but it is clearly marked as deprecated, and VS Code won't even let me install it. So, it’s even more of a non-issue today than it was a year ago.

The actual rust-analyzer extension works fine for me. I think Go's tooling is slightly better in my experience, but both are far better than any experience I've had with C++ tooling.

Re:Rust – A hard decision pays off by nindalf on Wednesday August 24, 2022 @03:22PM (#32584458)
The other comments have pointed out this was a simple misconfiguration that was easily fixed.

What I take exception with is "it’s always LLVM’s fault, I know". If you're going to trash other people's hard work in such a glib manner, it behooves you to know the details of what you're talking about. Tell us, why would a language server that doesn't generate any code use LLVM?

Re:Rust – A hard decision pays off by benreesman on Saturday August 27, 2022 @08:55AM (#32618435)
This thread is a bit stale but I try to check once or twice a week to tie off loose ends. I appreciate that probably no one will read this, but, you never know.

One of several issues around engaging with the Rust community at least as personified on HN is that it's very difficult to see any other outcome than being backed into a pretty extreme corner: I started my involvement with this thread saying that I like Rust and want to like it more, but found taking a piece of software that seems interesting on its own merits and headlining the Rust part (whether due to the original post authors or the submitters, makes no difference) contributes to a skepticism-inducing sense that there's an agenda other than "cool software" sitting close to "Rust" in the embedding space.

And, if you care to, you can watch me go from "Rust is cool, great stuff written in it" -> "hey some of these claims are seeming extravagant" -> "ok let's not get carried away, the cited examples are mostly Haskell semantics and clang optimization" -> "alright I'm calling bullshit that all the tooling is superior, that's fucking stupid" give or take. It's a pragmatic cool programming language that people write great software in. That's plenty, that's more than most languages ever achieve, and Rust is far from done achieving things.

`rust-analyzer --version` reports: "rust-analyzer 2022-04-11" on my primary Nix shell. `clangd --version` reports "clangd version 13.0.1" on the same env. I drive both of these things on the command line, in CI, and via `emacs` (on `eglot`) every month at a minimum, every week almost certainly, and usually every day.

I have seven nontrivial elisp `defun` and/or `defadvice` (deep into `rustic-mode`) stanzas for keeping `rust-analyzer` working ok. I have to defeat it's naive `Cargo.toml` search in interesting projects, I have to turn off big blocks of my buffer going RED ALERT RED while a brace remains missing which is statistically most of the time, and most importantly, I have to manually restart it with save excursion trickery so that I can survive a crash without blowing my session. Some of these defects may be as old as earlier this year when I last audited all that.

For `clangd` I have zero such nonsense. Which is completely understandable, it's an older and therefore more mature piece of software. That's not a knock on Rust or `rust-analyzer`.

But I made the fatal mistake of posting the wrong link to the issue tracker, for which my reward was to cause the "Flying Fucking HN Rust Brigade Gangbang Comment/Downvote Battalion" to put the Batman light on.

If you folks are comfortable being the "extremists people are too tired to fuck with", then do you. But I know for absolute certain that I am not the only person doing some level of Rust adoption in spite of this bullshit rather than because of it.

Re:Rust – A hard decision pays off by lenkite on Friday August 26, 2022 @02:06PM (#32610798)
".. but rust-analyzer is a dumpster fire next to clangd.."

Sorry, but this is patently false and is just straight-up misinformation. rust-analyzer is an extraordinary piece of work with careful, well-thought out idiomatic software design, easy usage and relatively low productive defect count.

Rust, the language, itself might be rather over-hyped here on HN - its most loved status will drop significantly with larger real-world adoption. However, the rust-analyzer project isn't overhyped and is a clean and elegant product of software engineering. I wish I was good enough to design and code language software like this.

Re:Rust – A hard decision pays off by Kinrany on Wednesday August 24, 2022 @10:41AM (#32580095)
"Constraints as power" describes the proposition of all statically typed languages. But the compilers of popular languages weren't smart enough to cover many common scenarios, forcing language designers to offer many unsafe escape hatches.
Re:Rust – A hard decision pays off by benreesman on Wednesday August 24, 2022 @11:00AM (#32580332)
It’s a very valuable thing to be able to separate the mental model one uses from the target machine language.

I worry about the more ardent Rust enthusiasts because it seems popular in those circles to embrace an attitude that we’ve somehow arrived at the right conceptual framework.

Rust is a competent, pragmatic embedding of a few of the big ideas from serious PLT into a well-optimized C++ compiler toolchain, and it’s cool and useful as a result.

But I hope to God it’s not the endgame on fast ML/Haskell/Lisp.

Re:Rust – A hard decision pays off by tialaramex on Wednesday August 24, 2022 @11:28AM (#32580686)
I'd be disappointed if the best language people are writing software in when I retire (perhaps a decade or at most two in the future) is Rust. We can surely do better.

But I'd be even more disappointed if the best language people are writing software in when I retire isn't even Rust.

Re:Rust – A hard decision pays off by ldng on Wednesday August 24, 2022 @05:04PM (#32585736)
To be successful a language still has to be approachable to most dev. I just hope you are not conflating PLT with Functional. Look what functionalist did to Scala... It had an interesting balance and they destroyed it.
Re:Rust – A hard decision pays off by pjmlp on Wednesday August 24, 2022 @11:20AM (#32580567)
Interestingly Object Pascal was my introduction to data type modelling for constraints, followed by Caml Light, Modula-3 and Ada.

Naturally one can argue they weren't popular, with exception of Object Pascal.

Re:Rust – A hard decision pays off by pjmlp on Wednesday August 24, 2022 @11:17AM (#32580540)
Yeah, specially when people refer to stuff taken from ML as Rust "features".
Re:Rust – A hard decision pays off by AtNightWeCode on Wednesday August 24, 2022 @11:26AM (#32580654)
Docker is built with Go. Compare doing things with Docker api between Go and Python. I usually recommend people to "script" things with Go but I start to think that Go has to go...

https://docs.docker.com/engine/api/sdk/examples/

Re:Rust – A hard decision pays off by rob74 on Wednesday August 24, 2022 @12:35PM (#32581904)
I would say in this case it's more the API designers' fault than Go's fault. Looks like the Python API is operating at a higher abstraction level than the Go API - using the Python API you can just call a "macro" that does everything required, in Go you have to call each operation individually.
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @03:38PM (#32584675)
It probably is Go's propensity to return error values whereas Python would bubble them up. Every action in Docker involves an I/O error at a minimum (since you're talking to the Docker daemon) so this is basically a worst-case scenario for error handling boilerplate. I don't doubt that Python is better for scripting in this case, but if you want to make an application that interfaces with Docker, Go is probably the better of the two (despite its boilerplate). In fact, I vaguely recall running into a bunch of Python-related bugs in docker-compose (it was at an old gig, and I haven't used docker-compose since, so I don't recall the particulars).
Re:Rust – A hard decision pays off by rob74 on Thursday August 25, 2022 @04:09AM (#32590958)
Still, creating a method that calls several other methods one after another is programming 101, so I refuse to entertain the though that creating a "containers.run" method similar to the one from the Python API is not possible in Go. The error handling is definitely not the culprit, you can check the error after each "subcommand" and return early with this error. The question is just, why didn't they do it?
Re:Rust – A hard decision pays off by throwaway894345 on Friday August 26, 2022 @06:01PM (#32613234)
Fair enough. I didn't look deeply at the API differences.
[dead]
Re:Rust – A hard decision pays off by dang on Wednesday August 24, 2022 @03:33PM (#32584608)
Can you please avoid flamebait comments and make your substantive points thoughtfully, per https://news.ycombinator.com/newsguidelines.html? We don't want flamewars here. Programming language flamewars are especially tedious.
Re:Rust – A hard decision pays off by AtNightWeCode on Wednesday August 24, 2022 @04:17PM (#32585192)
Not sure what you are talking about. When I learned C back in the 90’s I was learned to handle every error state by hand. Exactly as you are expected to do in Go about 30 years later. And it sucks.

Maybe you can explain why Gophers are such whiners always crying about every freaking comment at any forum.

Re:Rust – A hard decision pays off by dang on Wednesday August 24, 2022 @04:40PM (#32585435)
Can you please just not post like this? We're trying for a different kind of forum. I know it feels justified, and I'm sure it is, but the problem is the 'other' side always has its legitimate justifications too, and then everyone goes after each other and there's no more curious exchange.
Re:Rust – A hard decision pays off by danwee on Wednesday August 24, 2022 @12:02PM (#32581251)
Wow. That's quite something. I like Go, but more often than not I keep stumbling upong these kind of situations (N LOC to do something in Y, 10xN to do it in Go).
Re:Rust – A hard decision pays off by reitanqild on Wednesday August 24, 2022 @12:16PM (#32581512)
In addition to a emulating certain teachers dogged insistence of making sure students can't have nice things (an absolute no-brainer feature like generics only showed up recently...!), last time I tried to use Go for a web project a few years ago I was also amused by the lack of templating libraries - the way to make pages was to string together header + main + footer, the old PHP way...! Not a single library supported template composition.
Re:Rust – A hard decision pays off by coder543 on Wednesday August 24, 2022 @12:39PM (#32581970)
Umm... what are you even talking about?

Go has had templating built into the standard library since... forever?

And Go templates can use other templates, as long as they're all loaded into the same context, if that's what you were getting at.

simple examples of Go's built-in templates: https://gowebexamples.com/templates/

templates using other templates: https://levelup.gitconnected.com/using-go-templates-for-effe...

Re:Rust – A hard decision pays off by merely-unlikely on Wednesday August 24, 2022 @01:01PM (#32582364)
I've found Go's templating to be pretty great
Re:Rust – A hard decision pays off by reitanqild on Wednesday August 24, 2022 @02:22PM (#32583649)
That doesn't look too bad on a quick glance, but the possibility to say that "this content goes in that template" still seems to be missing.

Look at this page: https://quarkus.io/guides/qute-reference

and read about “Template inheritance” in 3.5.6 to see what I mean.

Re:Rust – A hard decision pays off by coder543 on Wednesday August 24, 2022 @03:01PM (#32584153)
In this example, I'm passing an object with a single value into the header template, but it could have as many values in it as needed: https://go.dev/play/p/kC8pm4Z4WrH

Go doesn't really do template inheritance in the way I think you're meaning. Go prefers composition over inheritance, and that carries over to the templating system. Go templates let you pass a parameter to the template you're calling, which I believe addresses the need you linked to. Calling another template is not just simple string concatenation; the other template can act on input provided by the calling template.

There are a lot of different ways to approach templating pages in a web app. I think Go's templating system is one of the least objectionable ones I've used.

I have no experience with Quarkus, so I can't say how good or bad that one is, but my experience with Ruby templating systems is that people often start mixing complex logic into the templates, including database calls, and that causes things to get messy. Go's template environment is very minimal by default, and you can extend it with custom functions if you want to give more power to the templates, but Go encourages you to compute your data ahead of time, then pass it into the template... and just have your template be a template for formatting the data.

Re:Rust – A hard decision pays off by reitanqild on Thursday August 25, 2022 @10:36AM (#32594239)
> people often start mixing complex logic into the templates, including database calls

Sometimes you can solve social problems with technical interventions, but at this point, someone needs to sit down and talk :-)

> Go encourages you to compute your data ahead of time, then pass it into the template

Same elsewhere including modern PHP and Java.

The thing that is missing in Go is a natural way to group together what goes around the content.

Sure, stringing together the templates (yes, I know the other template can act on input provided by the calling template, but they are still stringed together) feels weird when what one really wants is to fill in slots in a design, which is my thought process.

Re:Rust – A hard decision pays off by metaltyphoon on Wednesday August 24, 2022 @03:23PM (#32584474)
Re:Rust – A hard decision pays off by rkwasny on Wednesday August 24, 2022 @11:49AM (#32581034)
Exactly this, in rust it will even more complicated than in Go
Re:Rust – A hard decision pays off by lowbloodsugar on Wednesday August 24, 2022 @01:12PM (#32582530)
I would recommend Rust even if writing a simple tool, the kind of thing I might previously have used python for. We had some data munging to do and someone started it in python. On the real dataset it ran for an hour then ran out of memory. I took a crack in rust, as a n00b rust programmer, and the rust version runs successfully in less than a minute. I haven’t tried server side yet, because the learning curve for that is more of a learning cliff, but for small things I am already faster in rust than with my decade of python.
Re:Rust – A hard decision pays off by vonseel on Wednesday August 24, 2022 @06:46PM (#32586851)
>for small things I am already faster in rust than with my decade of python.

That seems like a bold claim? I've also been writing Python for a decade and it takes no time at all to whip up a small script. I have no doubts the Rust version will be much faster, but stepping into a new language would take me at least longer to write the script than an equivalent version in Python. Plus there's all the other stuff to learn.

Once you get past learning the basic syntax (creating variables, loop structure, assignment/etc.), you still have to pick up new things, like executing your work with parallelism, downloading files, parsing and dumping JSON, connecting to databases... Each new topic introduces a bunch of stuff that takes a little bit to figure out. I guess you could get through most of it in a few hours though if you had the right problem to work on.

But still, there's the muscle memory aspect. Can a new language really sink in so fast that it's faster to use than Python after 10 years of writing Python?

Re:Rust – A hard decision pays off by HeyImAlex on Wednesday August 24, 2022 @02:25PM (#32583680)
I had the same experience with go, 100x performance improvements on data crunching scripts with roughly the same code. Worst part of writing it in python was simple misspellings in the last stages of the computation breaking things.
Re:Rust – A hard decision pays off by vonseel on Wednesday August 24, 2022 @06:49PM (#32586875)
> Worst part of writing it in python was simple misspellings in the last stages of the computation breaking things.

I'm not sure I understand. Was the typo in something like a dict key? Or did you add two of the wrong variables together? How did another language protect you from this? I fail to see how you couldn't also add two of the wrong variables (with the correct type) together in a different language.

Re:Rust – A hard decision pays off by HeyImAlex on Tuesday August 30, 2022 @09:57PM (#32657465)
Python (out of the box) will only complain about missing variables or methods at runtime.
Re:Rust – A hard decision pays off by queuebert on Wednesday August 24, 2022 @02:15PM (#32583536)
Completely agree. Rust shines as a language for small tools that need to be performant and correct, like Unix utilities. Exa and fd are great examples of this.
Re:Rust – A hard decision pays off by nurettin on Wednesday August 24, 2022 @03:46PM (#32584763)
Python is fine, use the typing module, don't be weird with the return types and you will be fine. Sure, you will actually have to think about your algorithm when writing for speed, and naive loops won't work most of the time. But "avoid python in production" or "don't write new code in python" is way too harsh.
Re:Rust – A hard decision pays off by the__alchemist on Wednesday August 24, 2022 @10:49AM (#32580178)
I think Python shines as an interactive calculator, eg an iPython REPL. Calculations, plotting etc. Or for website backends since Django is very nice. Or scripting OS tasks like file manipulation etc.

For full projects outside websites, Rust for almost every case.

Re:Rust – A hard decision pays off by zozbot234 on Wednesday August 24, 2022 @10:56AM (#32580272)
Funnily enough, a REPL environment is in the works for Rust: https://github.com/google/evcxr
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @04:14PM (#32585141)
I could get down with that, although my experience with the Python REPLs has been a mixed bag. Specifically, you can't easily deal with async stuff IIRC (not sure if that's been fixed or not).
Re:Rust – A hard decision pays off by lowbloodsugar on Wednesday August 24, 2022 @01:14PM (#32582564)
I like Octave (gnu matlab) for that.
Re:Rust – A hard decision pays off by salamanderman on Wednesday August 24, 2022 @01:47PM (#32583078)
I've seen the transition from a Javascript codebase to a Typescript codebase with all strict checks in place to have a similar step change in dev velocity. The speed of debugging stupid mistakes, confidence in larger changes, and removal of a need for a lot of unit tests that were poor-person's type checking, is really significant. And runtime errors are a lot less weird than they were.
Re:Rust – A hard decision pays off by mhink on Wednesday August 24, 2022 @05:14PM (#32585855)
> I've seen the transition from a Javascript codebase to a Typescript codebase with all strict checks in place to have a similar step change in dev velocity.

The important factor here is "with all strict checks in place". Whenever I hear fellow FE devs complain about how they dislike Typescript, the complaints often seem to center around how it doesn't really offer that many guarantees... only to find out that their typechecker is set to the least strict settings!

I'm not gonna lie, though: the transition from JS to TS absolutely comes with growing pains. This obviously includes actually updating the codebase and adding types, as well as the developer onboarding/learning process. Personally speaking, I found it very jarring to go from a permissive, lightning-fast JS dev cycle to a more methodical Typescript one.

And don't get me started on how frustrating it can be to diagnose weird type errors related to generic types :D

Re:Rust – A hard decision pays off by FartyMcFarter on Wednesday August 24, 2022 @10:29AM (#32579926)
If people only used Python as originally intended (as a language to write small scripts in), this kind of problem never would have happened.
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @10:40AM (#32580082)
Sure, but the Python community itself promoted the idea that Python was suitable for general application development and so on. And it probably was a really good option back in the day when people were using C, C++, Perl, and PHPv4. And I'm sure there are still some areas where it's a fine option (maybe heavy data science stuff?). But I would only use it as an absolutely final resort.
Re:Rust – A hard decision pays off by ekidd on Wednesday August 24, 2022 @08:18PM (#32587680)
Greenfield Python programs that had strict type checking from day 1 can be pretty reasonable, as long as you know you never plan to write heavy data-munging code.

I often work on codebase that involves typed async Python plus a collection of Rust CLI tools that do most of the heavy lifting. And it's really not bad at all.

Re:Rust – A hard decision pays off by pjmlp on Wednesday August 24, 2022 @11:21AM (#32580576)
The only use case that makes sense for Python.
Re:Rust – A hard decision pays off by sharno on Wednesday August 24, 2022 @03:00PM (#32584141)
I'd argue that C# (dotnet core) is a much better option than Go for an easy GC language with max productivity and great performance ceiling.
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @05:10PM (#32585804)
I haven't worked with C# since ~2013, but I mostly liked it. I'm sure it's a different beast now though. Some things I prefer about Go:

1. Tooling. `go build` just needs a `go.mod` file with a list of dependencies. There's no MSBUILD stuff (I think dotnet had a similar JSON file format, but then went back to MSBUILD?)

2. Runtime. I love that Go's default is static, native binaries, and that the ecosystem revolves around that. I especially love that this enables ~2mb Docker images. (I'm of the impression that you can do this in dotnet, but it's not clear to me how easy it is in practice or if there are performance tradeoffs)

3. Value types. Go doesn't have a classes; everything is a struct, and polymorphism and so on work on structs.

4. No inheritance. I'm pretty militantly opposed to inheritance. I know you don't have to use it in C#, but in Go I also don't have to deal with APIs or coworkers that assume inheritance.

That said, these aren't major things; I'm sure C# is a great language in general, and I'd definitely reach for if I wanted to make a Windows GUI app.

Re:Rust – A hard decision pays off by CharlieDigital on Thursday August 25, 2022 @08:04AM (#32592562)
1. `dotnet build` requires a .csproj file. It's XML based (they tried a JSON based format a few years back, but reverted to XML).

C# and .NET's main strength, IMO, is the web API framework and general purpose utility; everything from web apps to Unity and Godot. It's easy to start with `dotnet new webapi -minimal` will give you a scaffolded project which is pretty similar a barebones Express or Flask app. But you get much more headway and scalability and the room to layer more complexity as needed.

It's main detriment is, as you mentioned, the need for a somewhat heavy runtime and the relatively slow cold starts which make it a poor choice for things like CLI tools and serverless functions.

Re:Rust – A hard decision pays off by labrador on Wednesday August 24, 2022 @03:45PM (#32584758)
C# 2022 is much improved over earlier versions. For starts it's cross platform and compiles to reasonably sized single executables (touted as a strength of Go). Moreover, C# designers have started reducing boilerplate as much as possible, so for example, you don't need to declare a namespace, a class or a main to start coding.

That said, Go is a fine language. It doesn't have exceptions last I checked, so that could be a deciding factor. Exceptions are handy in a lot of cases.

Re:Rust – A hard decision pays off by nly on Wednesday August 24, 2022 @06:45PM (#32586838)
Garbage collector is still a steaming pile though
Re:Rust – A hard decision pays off by hu3 on Wednesday August 24, 2022 @10:24PM (#32588667)
Source? I thought .NET GC was tuned for high throughput.

Their performance is, impressive, to say the least.

https://www.techempower.com/benchmarks/#section=data-r21

Re:Rust – A hard decision pays off by nly on Thursday August 25, 2022 @04:12AM (#32590987)
It has terrible latency characteristics
Re:Rust – A hard decision pays off by throwaway894345 on Thursday August 25, 2022 @09:47AM (#32593646)
IIRC it also doesn’t do much/any escape analysis, so ~everything ends up on the heap as an individual allocation (except for values), putting even more pressure on GC.
Re:Rust – A hard decision pays off by metaltyphoon on Wednesday August 24, 2022 @03:20PM (#32584424)
Not only that, but greater tooling too.
Re:Rust – A hard decision pays off by Jack_rando_fang on Wednesday August 24, 2022 @11:01AM (#32580338)
Agreed. I still give Python credit for allowing us to write software in an extremely efficient way. But after I wrote the initial version of the software with Python, I always procrastinate on testing, fixing existing issues, and as the software grows larger I simply want to give up as the different issues keep piling up. In comparison, Rust code usually just works out of the box due to the error handling and type system designs. With rust I develop much more consistently, and even more efficiently as the project progresses due to IDE hints, rust's built in `cargo check`, `cargo clippy` commands etc.
Re:Rust – A hard decision pays off by nprateem on Wednesday August 24, 2022 @12:03PM (#32581281)
Don't you find thinking about the borrow checker unnecessary overhead while prototyping?
Re:Rust – A hard decision pays off by jhgg on Wednesday August 24, 2022 @04:45PM (#32585497)
No. Not anymore. 4 years in and I maybe run into a borrow checker issue very rarely in a given week.

Once you understand how the borrow checker works and how to write/structure your code in a way that the borrow checker is happy with it sort of becomes second nature.

I think by side effect coding in this style does lend itself to simply writing better to understand code. Nowadays I just write my code this way without much thought. It happens effortlessly. I find myself writing programs in other languages like I would in Rust nowadays.

This is compared to when I started and ran into borrow checking issues many times a day. Additionally the borrow checker has improved since then and NLL borrow checker will accept more programs as valid than the previous one.

Re:Rust – A hard decision pays off by nprateem on Thursday August 25, 2022 @01:44AM (#32589969)
Interesting. I tried rust maybe 6 years ago and the combination of the BC and its slow compile times drove me away. Actually my main gripe was something to do with it not being obvious when calling a function that it needed a reference (I forget the specifics), but maybe that's been improved with better code completion in intellij. I may take another look.
Re:Rust – A hard decision pays off by pdimitar on Wednesday August 24, 2022 @01:36PM (#32582888)
Of course. That's rarely debatable (unless making sure that you have a very small memory footprint is one of the project's critically important goals).

The point is that you pay more upfront but can then iterate much more confidently and quickly.

Re:Rust – A hard decision pays off by _benj on Wednesday August 24, 2022 @02:25PM (#32583676)
Also, +1 for Go. I think that one of the things that makes Rust and Go such great language is how strict their compilers are. This moves the cognitive load of writing same code from the developer/team, to the compiler.

Go is also simpler because of the GC, given that Rust can get a bit tricky with lifetimes. Go routines and channels are a delight to use together with contexts.

Rust allows for a lot more ways to solve one problem, i.e. you can iterate over an array, of use a loop. Go only provided a for loop and that is pretty much the only way to iterate over something.

Some people might find this limiting but I find it refreshing given that I can focus on what I need to do instead of how I should do it.

Re:Rust – A hard decision pays off by golergka on Wednesday August 24, 2022 @10:30AM (#32579940)
> I've heard generally good things about TypeScript, but I'd be concerned about its performance even if it is better than Python

I wouldn't recommend Typescript for CPU-bound tasks, but for I/O-bound tasks with complicated business logic it's type system is on the order of magnitude better than Go, and makes you able to get really close to the "make invalid states of the system a type error" ideal of functional languages like Haskell, while still being a lot more approachable.

Re:Rust – A hard decision pays off by xmonkee on Wednesday August 24, 2022 @11:43AM (#32580923)
I am launching my startup on Typescript (backend and frontend). So far, it's been an amazing experience - I can define the problem in terms of types even before I start writing any executable code, and refactoring is a breeze if you make your types hard enough. There are mature libraries, you can share code between the two sides, infinite options for PaaS providers who can "just deploy" a typescript codebase. As a solo dev, it's saving me an incredible amount of time to go to market.

I've had experience with large codebases in Python, Java, Go and Javascript before.

Python - as everyone already said, just sucks. Refactoring is a nightmare, you have to test every single line of code for any sort of dependability and that makes refactoring even harder. It allows for too much meta-programming and within 3-6 months your codebase is legacy.

Java is just not fun to write for me, but Kotlin is kinda fun and I could see myself choosing that. The problem is that my product deals with a lot of deeply nested, user-defined objects, and converting JSON (or YAML, or XML) to POJOs is a verbosity nightmare.

I just fucking really hate Go. I can't explain it, but I find the language infuriating. It somehow manages to be less expressive, more verbose and more straight up boring than all the other options.

Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @12:10PM (#32581416)
> I just fucking really hate Go.

As a Go fanboy, this made me chuckle. :)

> I can't explain it, but I find the language infuriating. It somehow manages to be less expressive, more verbose and more straight up boring than all the other options.

I sort of get it. I think people fixate too much on the for loops and the `if err != nil` boilerplate, but there's definitely some validity with respect to "how to properly annotate errors" and emulating enums (in the Rust sense of the word) is pretty error prone and it still doesn't get you exhaustive pattern matching.

The stuff I like about Go:

* Single static, native binaries - being able to just send someone an executable is pretty nice, not needing to make sure people have the right libs and runtime installed is phenomenal.

* Great tooling. I love that the Go tool takes a list of dependencies. Unlike Gradle/CMake/etc I don't have to script my own build tool in a crumby/slow imperative DSL.

* Compilation speed. Go compiles really fast.

* Small language, easy learning curve. Any programmer can read just about any Go project with very little experience. Any Go programmer can jump into any other Go project and be productive immediately (no extensive configuration of IDE or build tools or anything like that). You can also write surprisingly abstract code without reaching for generics, but you will likely have to change your programming habits.

* Value types done right. Most other mainstream languages don't have them, and the ones that do very often implement them poorly (e.g., IIRC in C# you can define a type as a struct or a class and only structs can be value types, and classes are more idiomatic).

* Go eschews inheritance and prefers data-oriented programming over object-oriented programming (although OOP is poorly defined and some people think it means "anything with dot-method syntax").

* I'm just more productive in Go than any other language

Stuff I don't like about Go:

* No enums

* I wish there were fewer tradeoffs between abstraction and performance

* Needs a better system for annotating errors

* Doesn't run on embedded systems (although I've heard good things about TinyGo)

* Doesn't make me feel as clever (this is a nice property for professional software development, but for hobbies not so much)

On balance, I think Go is the better language, but I can also understand why it chafes people. Different strokes. :)

Re:Rust – A hard decision pays off by AmpsterMan on Wednesday August 24, 2022 @02:01PM (#32583293)
I am still fairly early in my career. I've worked mostly in Java, but my current job is a mix of Python for E2E testing, PHP and JS for application work. Go is my preferred language for tools.

My favorite language is by far Java with Go a close second. I dislike the others. The only thing I wish Go had is more functional support, but only in the style of Java's fluent API. I strongly dislike PHP, JS, and Python functional style and would almost prefer they not exist.

Re:Rust – A hard decision pays off by zeroc8 on Wednesday August 24, 2022 @03:02PM (#32584184)
I on the other hand like the fact that Go keeps things simple and primitive.

Don't need those functional constructs at all, allthough I'm using them quite often in Typescript.

But for Go - please no. Go is like C. Adding things just makes it worse.

Re:Rust – A hard decision pays off by Xeoncross on Wednesday August 24, 2022 @01:30PM (#32582796)
> I can define the problem in terms of types even before I start writing any executable code

This is how code is supposed to be written. Sort out the logic first, don't write the actual implementation details until later (models, http handlers, file parsers).

The support for this type of SOLID design is much more common in Go than in Typescript projects which often seem to inherit bad practices from Javascript developers.

Re:Rust – A hard decision pays off by reitanqild on Wednesday August 24, 2022 @12:24PM (#32581705)
> I can't explain it, but I find the language infuriating. It somehow manages to be less expressive, more verbose and more straight up boring than all the other options.

I don't hate it like you, I just find it amazingly backwards, and I think I can explain why:

The community has the same persistence as certain teachers when it comes to locking things down and making things harder than necessary for no good reason, all for our own good.

Prime example: announcing a supposedly cutting edge language without generics in 2009, launching version 1.0 without it in 2012, 8 years after notoriously conservative Java got it, then waiting until 2022 before listening, that is some hardcore teacher mentality IMO.

Re:Rust – A hard decision pays off by xmonkee on Wednesday August 24, 2022 @04:16PM (#32585173)
Yeah, honestly I would respect them more if they never added generics. Still wouldn't use it. I haven't tried go-with-generics but I can't imagine it can be a good addition so late in the game.
Re:Rust – A hard decision pays off by reitanqild on Thursday August 25, 2022 @10:26AM (#32594137)
Was absolutely a brilliant addition to Java.

I haven't used Go for years but it was sorely lacking last time.

Are you sure you aren't suffering from the Stockholm Syndrome?

Re:Rust – A hard decision pays off by blueslurpee on Wednesday August 24, 2022 @02:06PM (#32583393)
We have similar experiences. I absolutely love Typescript. But I don’t like Node very much. So I keep TS in the browser.

I’ve been looking at Nim or Scala for the backend. It’s either that, or just dive into Rust.

It really seems if you don’t want to use Node, Java, or Go the available choices for a statically typed backend get quite slim.

Re:Rust – A hard decision pays off by elcritch on Thursday August 25, 2022 @01:55AM (#32590050)
If you like doing compile time things with types like typescript enables then Nim is fantastic. I've been learning Rust recently and I'm continually disappointed with how little compile time or type based stuff you can do.
Re:Rust – A hard decision pays off by formerly_proven on Thursday August 25, 2022 @06:02AM (#32591655)
With prior C++ experience it's easy to equate C++ templates and Rust generics (similar syntax - usually does similar things - quack like ducks etc.); I know I did. And through this lens generics will soon seem very limited compared to templates. But the underlying reason for this is because C++ templates aren't generics - they're much closer semantically to hygienic, declarative macros. C++ templates are based around rules like SFINAE and allowing multiple alternatives and the compiler will work out which is the most-specific match that works. C++ templates (even with concepts) are unconstricted - when you give a template a type, there aren't any checks enforced by the language about the types; many templates have a list of requirements and you, the programmer, have to check them, unless the template itself has guards and checks the types.

Through this lens, the semantic equivalent of C++ templates in Rust isn't generics, but macro_rules! - but for most uses of C++ templates you would rather use generics and traits.

Re:Rust – A hard decision pays off by elcritch on Thursday August 25, 2022 @07:42AM (#32592360)
Yah the type level programming in Rust really is limited to traits which provide little compile time functionality. It's pretty straight jacketed which is nice in some ways as you wont have un-anticipated interactions with user types. On the downside that limits un-anticipated usage of libraries or types.

Even macro_rules! aren't as capable as modern C++ templates with types. I am let down with how lacking Rust is when doing compile time type based programming. There's no CTTI or RTTI in Rust. The procedural macros don't have access to type information, just syntax. The constexpr equivalents are so limited, etc.

Re:Rust – A hard decision pays off by formerly_proven on Thursday August 25, 2022 @08:20AM (#32592706)
Yep, true. Stuff like Zig's famous MultiArrayList, where you write pretty simple Zig code to take apart and reify types and functions just doesn't seem to be much of a thing for Rust by design. Procedural macros also have build time issues, because the macro must be fully compiled before any code using it can be compiled (hence why they must be put in a separate crate), and as I understand it procedural macros only get TokenStreams, so if they want to work with Rust code, they must re-create the AST from tokens with their own parser. Unfortunately, derive macros also happen to be procedural and subject to those limitations, handy as they may be.

What I really like about Rust generics on the other hand is that, while limited in many ways, those limitations allow them to be complete in the sense that as far as types concerned, the generic signature is the law of the land; it'll compile with any type fulfilling the trait bounds, and the implementation behind the signature is fully limited to exactly what's provided by the trait bounds.

Re:Rust – A hard decision pays off by xmonkee on Wednesday August 24, 2022 @04:14PM (#32585153)
Look at Kotlin if you haven't. Sure, "it's just Java" but really it's not. A good example is the collections all have an astoundingly uniform API and everything can map into everything else. It's really quite enjoyable.
Re:Rust – A hard decision pays off by ithrow on Wednesday August 24, 2022 @04:13PM (#32585135)
What don't you like about nodejs? seems like a solid choice for most things, the only use one language (nodejs/browser) is very attractive (besides SQL).
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @11:19AM (#32580562)
I sort of agree, but I also think type systems are somewhat overrated compared to performance, static compilation, native compilation, easy cross compilation, good tooling, expansive ecosystem (esp devoid of C dependencies). I think TS and Go are on par with respect to tooling and ecosystem, but I would rarely trade Go's static, native compilation model (distributing a single static binary is pretty awesome) for some extra type system features.

Specifically, I posit that returns on type system features diminish--there's a ton of value in going from a dynamic type system to Go's pre-generics type system, but every addition thereafter offers decreasing value.

Re:Rust – A hard decision pays off by golergka on Wednesday August 24, 2022 @11:27AM (#32580681)
> distributing a single static binary is pretty awesome

It is, but does it really matter when you write backend? I've written and operated Node-based backends at scale, and I can't honestly remember any bugs or outages that would have been prevented by this.

At the other hand, there's a lot of potential bugs and problems that didn't happen because proper usage of TS's type system prevented me from committing them.

Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @12:29PM (#32581785)
I'm not claiming a single static binary is going to prevent bugs or outages. It's just a surprisingly nice property (though less-so on the backend). For example, because Go distributes as a single static binary, we can make scratch images that weigh in at only a couple of megabytes. This (alongside fast compilation) means we can iterate more quickly in the cloud (pulling images onto nodes and starting them is almost instantaneous). This is particularly helpful when you have an outage and you're trying to get things un-stuck (you can try a lot of things in a short amount of time). It's one of those things that aren't obviously valuable until you've tried it.

Again, it's not the end-all-be-all, but it's a surprisingly nice property.

Re:Rust – A hard decision pays off by hu3 on Wednesday August 24, 2022 @12:24PM (#32581711)
> I've written and operated Node-based backends at scale.

I'm interested in producing fullstack typesafe web projects using typescript on both backend and frontend.

My question is how do you scale nodejs since it is single-threaded? Say I need 10k concurrent connections. These connections doesn't have to be all hammering the system at once but I need to accept 10k connections and perform something like 2k requests/s.

How do I approach this? One server with clustered nodejs? pm2?

I ask because there are a ton of outdated info on how to scale nodejs.

Some rudimentary benchmarking with clustered or pm2 nodejs tells me that 95 response times go from 30ms to 1000ms once I hammer the server. Whereas Go and C# keep it under 100ms without any effort or extra tooling, just using standard library.

Re:Rust – A hard decision pays off by nazka on Wednesday August 24, 2022 @11:12AM (#32580479)
Talking about Haskell and stuff. You what I want? Rescript to replace entirely Typescript. That will be so much better.
Re:Rust – A hard decision pays off by golergka on Wednesday August 24, 2022 @11:25AM (#32580644)
Personally, I love ML-family languages and would enjoy writing in Rescript more, indeed.

But I write software not to enjoy the process, but to solve business needs. And using Rescript, Scheme or Haskell drastically limits the talent pool and rises the cost. Which, BTW, can be very good for some businesses, that would want to hire only the best programmers anyway and are ready to pay for it. But that's some, not all.

Re:Rust – A hard decision pays off by nazka on Wednesday August 24, 2022 @12:31PM (#32581835)
Yes I agree. Also if you know your business won't need a lot of dev, like stuff like Instagram where I think they were still at 60 engineers even after hitting 1B active users, it can also be a good thing to use a niche (but viable) language to attract some bright engineers and they will be thrilled to be able to have a job to use it. Now I don't have such startup (yet) so I can't do it :)

I just wish ReScript would have gained traction and replaced Typescript. But who knows maybe it can still happen.

Re:Rust – A hard decision pays off by still_grokking on Wednesday August 24, 2022 @11:46AM (#32580979)
I would endorse that.

TypeScripts's type-system soundness holes kill the fun with that language very quickly, imho. That was a really big disappointment for me.

A "static" language that compiles fine and than crashes at runtime with complete WTF-bugs is not much better than a dynamic language. You just can't trust the compiler and need to double check every line of code anyway. So there is not much additional value in this kind of "type safety".

I would prefer Rescript of Scala.js anytime to TypeScript. Got really disillusioned by TS.

Re:Rust – A hard decision pays off by rjh29 on Wednesday August 24, 2022 @05:15PM (#32585878)
Having recently used it, my impression is Python's type system is pretty damn powerful. It might not be as crazy as TypeScript, but it can handle recursive types, dictionaries with a fixed set of keys, functions, union types and generics. Types can be re-used or exported. There are generic types for things like 'Iterable'.

If a package does not supply its own types (increasingly rare now), you can generate stubs and put them in typings/$package.

It's picked up a bunch of bugs for me already. And if runtime performance is not a priority, I'd rather write Python than Go or Rust any day. It's more fun and more expressive.

Re:Rust – A hard decision pays off by rowanG077 on Thursday August 25, 2022 @06:43AM (#32591940)
Does it support annotating numpy arrays with their dimensions yet? Last time I checked I was incredibly surprised the status quo was basically all numpy arrays are np.ndarray.
Re:Rust – A hard decision pays off by rjh29 on Thursday August 25, 2022 @07:17AM (#32592170)
I think so:

https://numpy.org/devdocs/reference/typing.html

Which is cool, even strongly typed languages don't usually support that.

Re:Rust – A hard decision pays off by rowanG077 on Thursday August 25, 2022 @08:10AM (#32592620)
There is no example there that show that. I mean something like np.ndarray[1024, 1024, 1024, type=Int] which would mean a 3D array where each dimensions has 1024 elements. Basically all statically typed language support it. Even in C you can do it.
Re:Rust – A hard decision pays off by agumonkey on Wednesday August 24, 2022 @01:03PM (#32582393)
Started a small project with rust and serde(toml config). Having static checking of config an its parsing felt really good.
Re:Rust – A hard decision pays off by Gigachad on Wednesday August 24, 2022 @05:20PM (#32585919)
We started just writing configs in typescript which has the benefit of static checking in your editor with suggestions/underlines. Could likely do the same in rust.
Re:Rust – A hard decision pays off by agumonkey on Wednesday August 24, 2022 @08:40PM (#32587841)
I'm afraid by typescript "typesystem" even more so than rust borrows/lifetime. It's so versatile and stringy .. that said it's still good to have some.
Re:Rust – A hard decision pays off by Gigachad on Wednesday August 24, 2022 @08:48PM (#32587901)
What I'm proposing is rather than have Rust validate yaml/toml files, just write the actual config itself in Rust so that your editor can verify/show issues before running. Unless you require ability to edit configs without recompile.
Re:Rust – A hard decision pays off by queuebert on Wednesday August 24, 2022 @02:12PM (#32583491)
Dev velocity in Rust is directly proportional to how well you grok lifetimes and ownership.
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @03:41PM (#32584717)
Eh, I like Rust and started my career doing embedded C and C++, so I definitely "grok lifetimes" but I'm probably always going to be more productive with Go than Rust (for general app development, anyway) if only because I don't have to think about memory at all with GC (again, general app development, not talking about performance optimizations). Even if I do a bunch of unnecessary cloning + Rc/etc in Rust, I'm not going to move as fast as I would do in Go.
Re:Rust – A hard decision pays off by keyle on Wednesday August 24, 2022 @05:21PM (#32585934)
I said this for years... no type checking by the compiler? Then you are the compiler.
Re:Rust – A hard decision pays off by gmadsen on Wednesday August 24, 2022 @08:18PM (#32587689)
python i think is still good prototyping. I can do numerical work, visualisations, animations, game dev, web dev, etc. for me python is just the biggest collection of tools while not being the best at anything. which is an ok trade off a lot of the times
Re:Rust – A hard decision pays off by zmix on Wednesday August 24, 2022 @12:29PM (#32581796)
> Use Go if you're looking for an easy GC language with max productivity and a decent performance ceiling.

Why not D?

Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @12:48PM (#32582136)
I haven’t used it. As I mentioned, I’m sure there are other languages that fit the bill besides Go and TypeScript.
Re:Rust – A hard decision pays off by sitkack on Wednesday August 24, 2022 @11:55AM (#32581129)
If Go replaces your Python this easily, you have always been writing Go. The abstractions available in Python are in a totally different class than that of Go.

Nothing you said is verifiable.

Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @12:25PM (#32581722)
> Nothing you said is verifiable.

Right, I was pretty explicitly speaking from experience. See my first paragraph.

> If Go replaces your Python this easily, you have always been writing Go

Go is only a 10 year old language, and I've been writing Python professionally for 15 years. I definitely have more hours on Python by a wide margin.

> The abstractions available in Python are in a totally different class than that of Go.

Python definitely is more abstract than Go, but I don't think that's a feather in its hat. Moreover, most of my criticisms of Python had nothing to do with its abstract nature.

Re:Rust – A hard decision pays off by fwip on Wednesday August 24, 2022 @04:40PM (#32585439)
I think the intent of saying "you've always been writing Go" was along the lines of "you can write FORTRAN in any language." E.g, implying that you are not making use of Python's abstractions, but writing it in the same procedural style you would write Go (or C) code in.
Re:Rust – A hard decision pays off by sitkack on Thursday August 25, 2022 @12:28AM (#32589474)
That is exactly what I am saying. I not talking trash about Go. But if one isn't using Python for what it is good at, don't use it, use the language you are actually using.
Re:Rust – A hard decision pays off by throwaway894345 on Wednesday August 24, 2022 @05:14PM (#32585859)
Fair enough, but that's still not the case. :)