As you might have noticed, Go seems to be quite the star right now. Strangely enough, I just started with it right before I suddenly heard it every...
For further actions, you may consider blocking this person and/or reporting abuse
You can do some pretty nifty stuff with generics. For example, they're one of the ways you can implement what are called "session types", which can be used to verify, at compile time, that your use of a finite state machine is valid.
(Basically, you implement a type with a generic parameter representing the state, then only "impl" functions on the states where they make sense. Rust's ownership system then ensures that you can't keep and use a reference to an old state once you've transitioned to a new one.)
Hyper uses them to implement an HTTP request type where it's a compile-time error to add a header after the body has already started streaming.
Another trick you can do is stuff like
Temperature<T>
, where operators like+
are only defined for cases where the twoT
parameters match, socelsius + fahrenheit
is a compile-time error. (Stylo uses this sort of trick to catch things like trying to add lengths of different units without first converting them to match.)If you like that, check out the lints offered by Clippy.
Just be aware that, because of how deeply it hooks into the compiler, you'll need to use
rustup toolchain install
to install a nightly version of the compiler,cargo +nightly install clippy
to install clippy, andcargo +nightly clippy
to run it on your code.(Last I heard, the end goal is to distribute it via rustup, same as the compiler, so it can use the "allow unstable interfaces in stable builds" trick used to compile the standard library.)
If you're on Linux, I've got all of the setup and dispatch automated (and well-documented) using just in my CLI utility project template.
The difference is that Rust has a much more advanced dependency management story than Go. (In fact, it's the best I've used in any language)
Because of that, Rust erred more on the side of learning from the Python community's statement that "things in the standard library have one foot in the grave".
(If it's part of the standard library, the only way to offer 1.x in maintenance mode and 2.x to fix design flaws is to put two copies with different names in the standard library for all eternity.)
You seem to be undervaluing Rust's type system. Generics aside, one of the biggest complaints I see Rust users having when they try Go is how there's no middle-ground between using exact types and using
interface{}
.In Rust, you've got much more of a middle-ground to specify what is valid and invalid in terms the compiler can verify before you ever run your program. See, for example, Writing Idiomatic Libraries in Rust by Pascal Hertleif (28 minutes).
Go has interfaces beyond
interface{}
, and you should use them exactly for that. They allow you to refer to things based on what functions they provide instead of what someone wrote in aninherits
or similar.Good point. That was a big phrasing mistake on my part. A better expression of what I was thinking would be "insufficient middle-ground".
I'm sure at least some of it is that we've been spoiled by Rust's excellent support for using sum types (enums containing data... A.K.A. compiler-verified tagged unions) to extend the compiler's ability to catch mistakes in variably-typed fields.
(The name "sum type" refers to the set of possible combinations. A tagged union is the sum of the possible combinations of its values. A struct is an example of a product type because its possible combinations are the set product of the possible combinations of its members.)
...but then the Rust community are overachievers that way. They've been working hard to design a viable system of Pi/Dependent types. (Types where, as in Ada, you can say that type
Rating
is "Typeu8
where the value is in the range '1
through5
'" and get various kinds of compile-time goodness from it.)Whoop, thanks for your comment!
already running it when I remember to :)
Yup! Forgot to mention anything about generics or "you pay for what you use" in that equation.
C does that too
You mean GCC? Or which compiler? Anyways, sounds good!
any compiler that supports -Wall
You can do that in Go as well and in any other language that implements "higher order functions". You don't need macros for that, they serve a different purpose for more advanced tasks.
Oh so that's Rust! I think I got quite the good impression from this, thumbs up. (-:
Thanks =)
Indicates a fundamental misunderstanding of what "trade space for speed" actually means.