> Zig is truly compatible with C and will compile C code directly, since its compiler is actually written in C++. I assume this was intended to say something else? > Here's the brutal truth: I can't find anyone under the age of 41 in my field to say a single positive thing about D IIRC the presence of the GC in D was (is?) its Achilles heel. Because the GC is infectious. As soon as your dependency needs it (and IIRC…
Choosing Nim out of a crowded market for systems programming languages
131–140 of 271 posts
Re: Choosing Nim out of a crowded market for systems programming languages
#132I learned OCaml recently, on my own, for myself. It’s actually a pretty easily language to use and learn, but historically there weren’t EXCELLENT resources for learning it.
There are now excellent resources, predominantly: https://cs3110.github.io/textbook/cover.html
When OCaml 5 settles, its general applicability will be (imho) much larger.
Do I recommend it for everything? No. But you wont hit segfaults like you will in go, and you certainly wont wrastle the compiler like you will rust. Haskell and OCamls lack of fluent programming make them less easy to program in (read: slower iteration), if you get your design right, your final product is just a real treat :chefs_kiss:. Some newer fp langs do have fluent style syntaxes, which are
The ocaml debugging experience stinks, and the lack of builtin (de)serializers for custom/composite types is very obnoxious, to put it kindly. Still, it’s not the obscure thing everyone loves to say about it. Really, its not.
These jokers in this thread “oh rust isnt hard! Ohhh they probably didnt try much.” Respectfully, get outta here. I love rust. Taken the doubly linked list tutorial? How about needed to use anything with Pin? Rust requires a huge surface area of foundational knowledge to be productive, full stop—the author is absolutely within his right to make this very fair claim about rust being onerous, relative to his candidate pool
Re: Choosing Nim out of a crowded market for systems programming languages
#133Aside, curious what this bit of the post refers to: > Pros for Swift are focus on secure programming outside of just obsessing over memory safety like Rust. I've never used Swift at all but would enjoy learning what it brings to the "secure programming" table that I might be missing from the summary at https://www.swift.org/about/#safety Another aside, the author gets some points for looking at Pony.
I can’t speak for the author, but I’ve had a similar feeling. Where (safe) Rust’s core principle is memory safety at all costs, I feel that Swift takes a more nuanced approach, prioritizing making good programming patterns easier while still being memory safe (though perhaps not as expressive as Rust). Swift also is much more principled when it come to certain things like exceptions. Whereas Rust (if I remember corre…
Rust's memory safety protects against data races. AFAIK, Swift does not.
> Swift also is much more principled when it come to certain things like exceptions. Whereas Rust (if I remember correctly) allows arbitrary panic-ing and catching of panics, Swift forces you to acknowledge a possible panic at function call sites using “try”. Without “try” control flow can’t suddenly end.
Generally in Rust, a panic means the program has entered a state that is unexpected by the programmer. One example is an unexpected index out of bounds error.
For cases where an error is an expected program state, like a web request or input validation, it's recommended to use `Option` or `Result` instead. Rust will force you to handle the error case.
Yes, any function can panic, and any caller can catch panics, but panics are not the primary "exception" analogue in Rust. Panics are only for fatal errors.
I don't know anything about Swift, but from a quick search I see something called "Fatal Errors", which I assume act a similar way.
Now to address the points in your gist.
> lauded the Borrow Checker for discouraging people from using the borrow checker! This results in less performant code much of the time.
The borrow checker is much improved with non-lexical lifetimes which makes it far easier to deal with.
> The escape hatch of macros and build-time source generation has allowed Rust to sweep some of its usability issues under the rug (Just use a macro!). Swift strives to support all of the use cases developer have in the language itself
I have no idea how you could, for instance, implement something like `serde` without macros or reflection without building it into the language. Other common uses, like `lazy_static`, have been replaced with better APIs that don't use macros at all. Building these things into the language or standard library without enough experimentation beforehand can be problematic, as `lazy_static` shows.
Rust's development is more open than Swift. It doesn't have the luxury of a single owner that can dictate THE WAY to do things, because it must support use cases from web servers to embedded MCUs. Macros and other forms of build-time execution provide that flexibility.
> Coarse Imports
Personally, I think Rust's module system and imports area the best I've ever used. As I said, I've never used Swift. Are all of the standard library functions in a single namespace?
I imagine that this makes implementing things like refactoring much easier.
> First party IDE > > Say what you want about Xcode
Xcode is MacOS exclusive.
> With the current state of RLS, developers often forsake modern IDE features even though reliable code completion, refactoring tools and diagnostics greatly benefit developers.
RLS is now deprecated, and rust-analyzer is fantastic.
> Out-of-the-box debugging experience
I haven't ever tried interactive debugging with Rust, so I can't comment.
> One of the more powerful uses of a type system is to have functions perform different processing based on the type of its arguments.
I think one of the fundamental difference of today is that this should be handled by traits, not by standalone functions.
> In Rust, this is achived via the From and Into mechanic. The first unfortunate consequence of this is that you often have to create a new type and trait pair per argument you want to be polymorphic.
I don't think this is a common pattern at all. Generally you'd just implement the trait for each type and put the different behaviors in the trait impl, rather than in the function using an enum.
> you can effectively only ever have one generic implementation of your custom into Into… for a trait, since otherwise the type checker complains there can at some point in the future be a collison.
This is only true for types outside your crate.
> In Rust, you cannot create trait objects out of certain types of traits. Often, you could use trait objects for this type of thing, but I haven't figured out a way to do this with more complex constraints. For instance:
trait Bar {}
trait Baz {}
trait Foo {
// This is invalid
fn foo(t: &(Bar + Baz)) -> ();
}
I think what you're looking for is: trait Foo: Bar + Baz {
fn foo(&self);
}
This will work as long as Bar and Baz are object-safe.> Making it generic disallows using Foo as a trait object:
trait Foo {
fn foo(t: T) -> ();
}
// This is invalid
fn do_work(f: &Foo) -> () { … }
You can make the trait generic instead of the function: trait Foo {
fn foo(&self, t: T);
}
> Multiple if let casesThey are a work in progress, available in nightly: https://github.com/rust-lang/rust/issues/53667
But they do require an extra level of parens in some cases, though I think that's insignificant.
> Guard Statements
Rust has these now as "let ... else" statements.
let Pattern(binding) = thing else { ... };
> Explicit tryThis was covered above: use Result or Option instead. Panics are not exceptions.
And as for unwrap, yeah you just have to know that it will panic. It's just a thing you have to know about the language, like `try`.
> Rethrows
Transpose is stable now. But generally for that case I'd do this instead:
let y = Some(1).ok_or(Error)?.and_then(|i| {
if i > 3 {
Err(Error)
} else {
Ok(i + 1)
}
})?;
> Ternary OperatorI prefer the lack of a ternary, since, as you show, an if can do the same thing.
> String Interpolation
You can include variable names inline now. And they're not C-style at all.
> Named arguments
Personally, I've never felt the lack. Especially with the inline hints from rust-analyzer.
> Default arguments
I actually prefer how Rust does not have function overloading. This includes default arguments and optional arguments.
> Function-level polymorphism
And the above also applies to this.
> This is also useful for operators (in Swift, + is a polymorphic function)
This is implemented with traits in Rust.
> Alternatively, you could use use:
use MyDescriptiveEnum as E;
match e {
E::Foo => …,
E::Bar => …,
}
You can do a glob import instead use MyDescriptiveEnum::*;
match e {
Foo => …,
Bar => …,
}
> Raw types for enumerationsRust enums have this for primitive numeric types, but others do not.
> Rust's enum and struct initializers all use different syntax. In Swift, there is a single syntax
Sure, they both use parens, but they are still different syntaxes.
> Trailing Closures
I don't like this. Seems like a special case for little to no reason.
> Default Closure Arguments
Same as the above.
> Extensions, Type Inference for Associated Types
I agree these could be useful improvements.
Re: Choosing Nim out of a crowded market for systems programming languages
#134Earlier quoted context omitted.
I have bad experience interacting with members of the rust community. Biggest issue is that they don't keep their opinions to themselves and frankly make everyone misserable with their "join us now, you must" mentality.
I have mixed experiences. The evangelism on HN and reddit can be stifling. Particularly the overemphasis on "safety". The community on discord was very helpful though, when I was struggling. I feel like the community is large enough that you can find a lot of more normal people using it, and just avoid the zealots.
Re: Choosing Nim out of a crowded market for systems programming languages
#135Earlier quoted context omitted.
I have written around 30k+ lines of rust by now, and I have to agree with OP. I have encountered many situations where perfectly reasonable, zero copy, memory management that would be completely normal, fast and safe in C, it basically impossible to replicate in Rust (or at least I am not clever enough to figure it out). Are there other ways to structure the data that work in Rust? Yes, of course. Do I like them comp…
> I have encountered many situations where perfectly reasonable, zero copy, memory management that would be completely normal, fast and safe in C So you think. It doesn't matter how smart you think you are, statistically speaking you're not smarter than a compiler.
Re: Choosing Nim out of a crowded market for systems programming languages
#136Earlier quoted context omitted.
If you were clever enough to write it safely in C I can guarantee you'd be clever enough to write it in Rust.
Oh boy, that is so not true. Anything where the boundaries of the lifetimes are easily determined at runtime but unknown at compile time is extremely easy to model safely in C, and a nightmare in Rust. At least if you want the same level of performance and a similar modeling of the data
I don't even know how to respond to this seriously. I guess just imagine me pointing to every blatant instance of this not being true.
Re: Choosing Nim out of a crowded market for systems programming languages
#137Earlier quoted context omitted.
The authors reasoning makes sense to me. Rust is powerful but also complicated and tends to encourage playing "language golf" as often as solving actual problems. > there isn't a lot of reason to defer to Rust as an obvious choice outside of the usual focus on memory safety that dominates public opinion. As someone who actually hates to code for coding's sake and wants to Get Sh!t Done, Rust is just antithetical to m…
> tends to encourage playing "language golf" as often as solving actual problems. Is this your perception, or are you actually seeing this being encouraged by the Rust community? > This is an interesting take. I personally don’t agree with OP’s take on Rust at all, but I respect their decision to use whatever language works best.
In my experience, “language golf” is very popular in Rust, Scala and Haskell communities.
Re: Choosing Nim out of a crowded market for systems programming languages
#138Re: Choosing Nim out of a crowded market for systems programming languages
#139> I feel inferior for not being fluent in OCaml I learned OCaml recently, on my own, for myself. It’s actually a pretty easily language to use and learn, but historically there weren’t EXCELLENT resources for learning it. There are now excellent resources, predominantly: https://cs3110.github.io/textbook/cover.html When OCaml 5 settles, its general applicability will be (imho) much larger. Do I recommend it for every…
> These jokers in this thread “oh rust isnt hard! Ohhh they probably didnt try much.” Respectfully, get outta here. I love rust. Taken the doubly linked list tutorial? How about needed to use anything with Pin? Rust requires a huge surface area of foundational knowledge to be productive, full stop—the author is absolutely within his right to make this very fair claim about rust being onerous, relative to his candidate pool
Rust is not an easy language, but I find it strange that people take the hardest parts and act like it is most of what it is about (I can count on one hand how many times I've had to directly interact with Pin). The things you mention aren't things I spend any time on, and I write Rust nearly 12 hours a day.
P.S. - Is there actually a double linked list tutorial? What an _awful_ way to learn Rust. That is like starting at the very end of what you should be learning and then working forward. No wonder it scared people away.
Re: Choosing Nim out of a crowded market for systems programming languages
#140> OCaml, Haskell, F#, and other weirdos: I personally can't do it. I tend to not like functional programming languages. I want to, but my brain lacks the plasticity to relearn everything. Why would you find OCaml hard to learn if you know Nim? Isn't Nim a functional programming language as well? Also, how is Nim for writing real-time games that run via JavaScript where you want to avoid garbage collection pauses?
Nim is not really functional. Like most modern languages, you could probably pull of a functional style with it, but it's mutable, imperative, etc.