7 ms·
Rust Is a Scalable Language
- behnamoh 4y agoRust is SCALAble :) #dadjoke
- eminence32 4y ago> And you would only need Rust — while it excels in the lowest half of the stack, it’s pretty ok everywhere else too. A younger me, in search of a new language to learn, would have been turned off by something that is only "pretty ok" But 20 years later, something that is "pretty ok" is exactly what I'm looking for. My experience has been that finding the perfect language (or perfect anything) is futile, and all I want is something that let's me solve my problems, don't get in my way, and don't really surprise me. For a long while, python was my go-to "pretty ok" language, but eventually it stopped being "pretty ok" for me. Rust has now taken that spot.
- cglong 4y agoWhat soured Python for you?
- eminence32 4y agoOne too many TypeError at runtime. I became increasingly annoyed that nothing was catching my silly typos or other mistakes. These days there are some really good python static checkers available, but I'm not sure I really knew about them half a decade ago when I started to move away from Python
- kitkat_new 4y agocan you recommend a checker?
- leetrout 4y agoNot Op but once I experienced Go I started writing less Python by choice. Then TypeScript and hopefully soon more Rust. Typed Python 3 is just awkward enough to not make me enjoy it on small scripts and not accurate enough (yet) to be confident in it on large projects. I don't use numpy & friends so Python doesn't offer me much any more compared to newer typed languages once I go beyond a simple script.
- culi 4y agoYou should try out deno. TypeScript with zero set up. You can write a .ts file anywhere on your computer and run it with, e.g., `deno run hello-world.ts`. It's my new goto for quick scripts
- leetrout 4y agoYea! I actually wanted to teach using Deno back in 2019! It was a stretch topic for the last couple weeks of class in my syllabus but we were too far behind. Excited to see where it continues to go and we are writing more scripts in TS at work (without Deno, tho).
- prottog 4y ago> Then TypeScript Have you done any backend TS? I'm curious what the best practice there is, these days.
- leetrout 4y agoI am definitely not the person to ask there. I have been on a couple teams that used Node. Everyone was/is still using express and various ORMs / query builders. Knex and Prisma are what I saw. Lots of neat stuff with Zod and relatedly EdgeDB.
- raincole 4y agoI don't know if I just use Python "wrong" or something. When I worked as a TA, I've written a lot of untyped Python as Blender/Houdini plugins, and I think it worked pretty well for this purpose. But later I did some backend stuff, I tried to use typed Python and wrote safer code. Then the whole toolchain becomes so cluncky. MyPy, Pylinter, Flake8, etc. They're so slow, and their VSCode extensions are so weird to configure. And I never got the best practice to work with other untyped libraries. It's not that I don't know how to use typed language. Actually I do backend stuff faster in Rust than Python. It's probably just me or my VSCode acting up.
- kitkat_new 4y agoMy experience with Python recently: I have been working on a mediumish project (without tests or type hints) where I needed to add functionality including a bit rewiring. My main problems were: - I didn't know what data (types) were passed around when looking at parts of the code, so I had to look were the data structures were created, adapted and passed along to actually know more (or just debug it) - After changing parts of the code, I was 100% certain that I had to run it a dozen times to fix new bugs or things I had forgotten How it works with Rust: - I see the types in the function signature - I know the properties of 'classes' without scanning the whole code of the class - when it compiles, it works 90+% of the time, because the compiler tells me where I forgot something before, if the IDE hasn't already told me
- kazinator 4y ago> How it works with Rust ... You will be amazed to find that that's how it works with C, Pascal, Java ... Types being declared in function headers and checked is 1960's technology.
- johnny22 4y agoexcept the type system in C isn't that good.
- amluto 4y agoThat’s an understatement. If you see a function in a header like: char *func(char *in, size_t len); It’s anybody’s guess what the actual input type is, not to mention the ownership or lifetime of the output.
- kazinator 4y agoHN now supports backslash escapes for asterisks (which, unescaped, are markup notation for italics).
- iudqnolq 4y ago
- lmm 4y agoI left Python when I found Scala, and while a good type system was a big factor, the groundhog day of "Python dependency management is awful with 4 different tools none of which quite work right, but this new tool has fixed it, for real this time" every few years was the part that really made me despair.
- epage 4y agoNot OP but to me the ecosystem is too disjoint. To ship "production python", you need to figure out which of the "current" tools are to cobble together to build, test, and share your code. `cargo` combines poetry, ruff, pipx, sphinx, pytest, etc. You might expect this to be worse. In some cases, it is (e.g. pytest). The super power is in being able to get a project up and going immediately without wasting time on figuring out which tools to use, scaffolding them together, setting up a host for your documentation, etc. Then there comes the problem of distributing it where the target system has to have just the right version of Python.
- artursapek 4y agoit’s slow and there’s no helpful compiler
- ldjkfkdsjnv 4y agoPython doesnt really scale to large code bases, and refactoring is very hard.
- HervalFreire 4y agoNot if you use modern python. And by modern python I mean typed python. Heavily typed.
- aeyes 4y agoDo you have any real world experience? I'm working on a Python codebase which is almost 2 million lines of code with almost 100 developers and I haven't seen development speed slow down over the years. Of course you need to have a structure within this codebase or you'll bump into the typical problems of large codebases. Some languages force you to work this way, we do it by enforcing certain rules in the lower level framework code of the project. Also you need to keep pace, we are on the latest Python version and code is heavily typed. This project was started in the 2.7 days.
- HervalFreire 4y agoIn my opinion it's not pretty ok. It's actually superior to many other languages. I think for web stuff though the borrowing and move semantics is a bit of an overkill. Usually you don't need to thread or handle state in these areas (frameworks and databases handle it for you) so a GC works better here. But everything outside of that is superior to something like ruby, python or go when it comes to safety.
- vlovich123 4y agoI think if Rust could integrate a GC pointer elegantly into the ecosystem and put some of the knobs for running the GC the responsibility of user-space libs (ala pluggable GC), add in more optional type inference in places, and make it easy to refactor code to remove the GC, then it could become quite interesting for higher level glue code. As is, it’s not quite as good as TypeScript I think
- HervalFreire 4y agoThere is a reference counting GC in rust. It's just not default and you have to be explicit about invoking it. It's similar to shared pointers in C++. See Arc. For something like python the heap allocation or stack allocation is handled behind the scenes so the entire concept is abstracted away from you.
- vlovich123 4y agoI meant a tracing GC like https://docs.rs/gc/latest/gc/ https://docs.rs/gc/latest/gc/. Arc still requires you to reason about ownership as does this GC. I think single threaded async w/ easy no copy message passing is more akin to what most people want when thinking about concurrency (eg Go channels) and actually happens to perform exceedingly well when it’s done up and down the stack (eg io_uring). In such a model you don’t even need to worry about ownership so much because you can’t Send anything except for things that need to be so there’s not a lot of value in many of the protections Rust tries to put in place.
- platinumrad 4y ago
- Existenceblinks 4y agoassembly/c/c++/perl/ruby/elixir/elm/js are "pretty ok" to me no matter how long I had written with. python is absolutely not ok to me .. always think "really?" I want to write it in another way, but it can't be.
- cameronh90 4y agoIt's not popular among the crowd here, but my favourite "pretty ok" language is C#. It's not really the best at anything, but it's pretty good for most use cases. That being said, because there's no one perfect language, it's handy to have a few in your arsenal. As much as I like C#, I'd still reach for Python for any data or ML type use cases.
- imwithstoopid 4y agoOr Go, whose guiding principle seems to be "Pretty OK"
- shakow 4y agoGo guiding principle is rather “the lowest common denominator”.
- ostenning 4y agoC# is, in my opinion, a fantastic language. I haven’t used it in a long time, but the “ergonomics” were really nice. The downside of C# was microsoft, but maybe thats changed now? I know they made a lot of effort to make the .NET framework more cross platform.
- throwawaymaths 4y agoThe downside of c# is it's easy until you run into the 80 flavors of async it has.
- schemescape 4y agoWhat is there besides Task<T>?
- legulere 4y agoFirst there was APM https://learn.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/asynchronous-programming-model-apm https://learn.microsoft.com/en-us/dotnet/standard/asynchrono... then there came TPL (using Task but without async await but ContinueWith) and finally async await with some later refinements like ValueTask. Generally you just use async await nowadays with maybe the complication of when to use Task or ValueTask
- est31 4y agoIt's hard to overestimate how extremely Rust is optimized towards making refactors as easy as possible. This often means a greater cost for initially writing some code, but once that code exists, it's way easier to search around in that code and also way easier to refactor it. Often times, being written is only the start of some piece of code's journey through the years and decades until it is finally deleted.
- sfpotter 4y agoWhy? Give some examples. As someone with little Rust experience, it appears similar to C++, which I have a lot of experience with. C++ is a chore to refactor.
- iudqnolq 4y agoIn one sense it's impressive Rust has mediocre refactoring support despite orders of magnitude less investment in tooling. But that isn't worth all that much. It's no worse than any other typed language I've tried. Rust in theory has a lot of potential here because it's designed to minimize action at a distance.
- syntheweave 4y agoIt's the type system. When people say a language is easier to refactor it's usually because the types are designed more like ML, with a little more formal rigor, so the compiler errors can actually help you along as you make changes. Rust's model of mutability adds context to what you're doing - which is also what makes it hard at first(since it adds ceremony and constricts your initial design). In a large system where data can move through a lengthy code path with a lot of indirection, more nuance in types becomes a major advantage to your confidence in making changes. C++ can never quite get there despite all the innovations made because of its descent from C style types, which are much more simplistic.
- dgunay 4y agoIt's not that it isn't tedious, but the workflow is a lot more reliable. Refactor, `cargo check`, fix the errors, repeat. When there are no more errors, it is very likely the code will still work. I would say C++ is mostly the same experience, with the exception of anything involving memory safety & lifetimes. It can't guarantee you didn't accidentally introduce a use-after-free/move or anything else of that nature.
- boringuser1 4y agoI feel like programming language designers should see themselves as quite beleaguered at the moment. Even prior to full AI replacement, a properly trained AI will be able to take English language and effectively translate it to machine code, assembly code, or C code. It doesn't really make much sense to have the human at the this layer for much longer.
- schemescape 4y ago> Rust is so easy to compose reliably that even the stdlib itself does not shy from pulling dependencies from crates.io. The standard library depends on external crates? (Edit to remove that last part since it seems irrelevant.)
- iudqnolq 4y agoI just peaked at the crates.io dependencies in the standard library. There's three dependencies to high-quality libraries in the rust-lang GitHub organization: a macro to make conditional compilation easier (cfg_if), a port of Google's SwissTable hashmap library (hashbrown), and bindings to libc. These all have maintainers in common with the standard library. The rust standard library hashmap is (zero cost) wrapper around a hashbrown hashmap with a subset of hashbrown's methods. cfg_if is probably used just for the convenience. I guess they're not ready to commit to stabilizing that macro in the standard library for some reason. libc was originally autogenerated from the c header files, but if I recall correctly updating it involves a bunch of annoying manual processes necessary to ensure perfect compatibility. It's obvious used in the implementation of standard library features. Then there's a handful of dependenencies for the optional but enabled-by-default backtrace feature like a symbol demangler and a zlib encoder/decoder. I'm not familiar with their quality, but I don't think it's as excellent as the other dependencies.
- lifthrasiir 4y ago> The standard library depends on external crates? Yes: https://github.com/rust-lang/rust/blob/478cbb42b730ba4739351b72ce2aa928e78e2f81/library/std/Cargo.toml#L12C15-L23 https://github.com/rust-lang/rust/blob/478cbb42b730ba4739351... Of course it is not "some random" crate; all of them is either in the same repository (when `path` is used) or in other repositories under the `rust-lang` organization with well-known contributors. But the latter is conceptually no more special than other repositories, so Cargo works same.
- schemescape 4y agoThanks! I was interpreting the comment to mean code that wasn’t in the standard library repository, which surprised me.
- sacnoradhq 4y agocargo and rustc need work: - sccache helps with some parts of builds but rustc needs to be caching a whole lot more for rapid TDD iterations. It shouldn't take seconds or many minutes to build things. (Invoke "go does it in milliseconds" card.) - cargo should migrate away from git and sparse protocols. Both are slow because one abuses git and the other fetches each crate metadata as a file using individual requests. It would be faster and simpler to send either a total compressed sqlite database OR a compressed SQL transaction to migrate between versions. N files on disk representing each crate is asking for fs performance problems in the real world on fses people actual use.
- cyann 4y agoI've found the sparse protocol many times faster than git since Rust 1.68 To use the sparse protocol with crates.io, set the environment variable CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse, or edit your .cargo/config.toml file to add: [registries.crates-io] protocol = "sparse" https://blog.rust-lang.org/2023/03/09/Rust-1.68.0.html#cargos-sparse-protocol https://blog.rust-lang.org/2023/03/09/Rust-1.68.0.html#cargo...
- shp0ngle 4y agoThe author talks about http servers. So I will throw a question here. I am a gopher that wanted to try rust, and I looked into http servers in rust, and it looks like there is like 10 different http servers, and each of them carries with them something that is called “async runtime”, and there are different async runtimes, and you cannot (or can?) use them together, and I realized async rust is not yet finished (or it is?), and I got kind of lost. What http servers people used? Do the asynch runtimes matter? If I want to “just” build a http server, do I need to study different async runtimes?
- Klonoar 4y agoPretty much all the http servers of worth, short of tide, just use Tokio at this point. For the most part, you really only need to care about Tokio. async-rs is used by some libraries, but it's relatively small in comparison - and many now go to lengths to just support both. There are other runtimes you could tinker with, but really: just use Tokio. The "easiest" web server/framework to get started with in 2023 is, in my opinion, Axum. It's from the same people who work on Tokio and it does make it somewhat straightforward to dive into as a result. I have a few actix-web servers in production as well, and it's a fine framework - hard to say where the mindshare falls on it these days. Rocket is a very nice web framework but effectively has a bus factor of 1 at this point and it's started to show. People coming from e.g Rails may appreciate it though. Don't use warp (IMO) because http routing is not rocket science and doesn't need the amount of magic it tries to bolt on. Have fun.
- TheDong 4y agoI mean, there's only one http server people actually use, which is hyper. Just like in go where everyone uses net/http, even though fasthttp and so on exist and everyone just ignores them. Just like in go, there's also a lot of web frameworks built on top of it (like all the ones listed here for go: https://github.com/mingrammer/go-web-framework-stars https://github.com/mingrammer/go-web-framework-stars) Just like in go, you can choose not to use any if you want and use hyper directly, or use one that is a quite thin layer on top of hyper like axum. In terms of async runtimes, just pick tokio and get on with your life. It's the default choice, so picking it is the simplest option.
- 4y ago
- phamilton 4y agoOn the topic of vertical scalability, I have found that many runtimes require something else to scale. Ruby requires passenger/unicorn/puma/etc. It requires pgbouncer if you're using postgres. It requires redis for background work. Similar situation with Python, or node. You need a process manager to handle forking for concurrency, you need external connection pools etc. I can see and appreciate the unix philosophy at work, but it's also adding complexity. More things to tune, more things that can go wrong or become a bottleneck. As we've moved our services to Rust, we've found that all those special tools disappear. Sure, we need to make similar decisions around how our system runs, but (as an example) configuring an in-process db pool is much much simpler than pgbouncer. And that's a big part of a runtime being scalable. We won't be forced to reach for another tool as our requirements expand. We still might, but we don't have to. (Certainly golang and the JVM fall into this category as well)