Live data from Hacker News

Rust from a Gopher – Lessons 7, 8 and 9

levpaul.com

21–30 of 58 posts

Re: Rust from a Gopher – Lessons 7, 8 and 9

#21
post #3

What's the rationale for making files modules? Modules being namespaces, and namespaces being collections, it's not desirable to have a file being a (large) collection of code. The feature that gives mixed feelings to the author (Re-exporting Imports) is indeed a workaround to this; since each file would externally generate one extra namespacing level, one reexports data structures in order to remove that level. This…

One important technical reason is that you need to be able to add attributes to modules, like these examples: // Only compile this code if the “foo” Cargo feature is enabled. #[cfg(feature = "foo")] pub mod foo; // Platform-specific stuff, as with std::os. pub mod os { #[cfg(windows)] pub mod windows; #[cfg(unix)] pub mod unix; } // You can even choose which file to load the module from. #[cfg_attr(windows, path = "w…

Interesting. This made me realize that a possible reason why some find the modules concept confusing is that it conflates the concepts of inclusion and namespacing.

edit: corrected typo

Re: Rust from a Gopher – Lessons 7, 8 and 9

#22

Earlier quoted context omitted.

As someone who mostly writes Rust these days, I find it really nice that I can always (as long as I don't use wildcard imports) use intra-file search to find either the definition or the file that contains the definition. Whenever I have to touch Go code (for reading and debugging) it's really annoying to just end up going "okay, I've got the folder, now what". Or, even more annoyingly, I've just got an interface and…

An architectural side effect, at least in the case of Rust, is that when a file includes many data structures, they're going to be visible to each other. Depending on the case, this may have practical implications or not, but architecturally speaking, it's not good form. A practical side effect is that having a lot of data structures is going to clutter the outline view in the IDE.

Hence why you'd typically stick to ~one independent data structure per module.

You can still use re-exports (pub use) to hide it from the public API.

Re: Rust from a Gopher – Lessons 7, 8 and 9

#24
post #2

As a sidenote, does anyone else find the language identification terms cringey? Rustacean, gopher, pythonista... just atrocious.

I'm really glad Elixir devs are not referred to as "Sorcerers".

Wouldn't "Alchemists" fit even better?

Re: Rust from a Gopher – Lessons 7, 8 and 9

#26
post #11
post #2

As a sidenote, does anyone else find the language identification terms cringey? Rustacean, gopher, pythonista... just atrocious.

I wouldn't say that it is cringey, but I agree with the sentiment. It always seemed kind of weird that programmers would attach themselves and identify with a programming language tribe, even though they are very well capable of learning other languages and frequently do.

Well, I sometimes use labels like these, but only in terms of 'what hat am I currently wearing'?

Re: Rust from a Gopher – Lessons 7, 8 and 9

#27
post #3

What's the rationale for making files modules? Modules being namespaces, and namespaces being collections, it's not desirable to have a file being a (large) collection of code. The feature that gives mixed feelings to the author (Re-exporting Imports) is indeed a workaround to this; since each file would externally generate one extra namespacing level, one reexports data structures in order to remove that level. This…

As someone who mostly writes Rust these days, I find it really nice that I can always (as long as I don't use wildcard imports) use intra-file search to find either the definition or the file that contains the definition. Whenever I have to touch Go code (for reading and debugging) it's really annoying to just end up going "okay, I've got the folder, now what". Or, even more annoyingly, I've just got an interface and…

Python, without wildcard imports, does the same.

Usage in Haskell is a bit more mixed, but I see a lot of 'qualified imports'.

Re: Rust from a Gopher – Lessons 7, 8 and 9

#28
post #11

Earlier quoted context omitted.

I wouldn't say that it is cringey, but I agree with the sentiment. It always seemed kind of weird that programmers would attach themselves and identify with a programming language tribe, even though they are very well capable of learning other languages and frequently do.

Yet each language does have defining characteristics, and you work differently in different languages. I regularly write both Rust and JavaScript, and I will design and architect things quite differently between the languages, playing to the strengths of each language. So languages are fairly tribal in this way, and in others also once you add the rest of their ecosystem.

Code that is written in one language in the style of another can be "interesting" - I once ported code that was Common Lisp written in the style of Occam... Also saw C sources that did the cpp thing of trying to make C look like Pascal, fortunately managed to avoid working on that!

Re: Rust from a Gopher – Lessons 7, 8 and 9

#29

Earlier quoted context omitted.

One important technical reason is that you need to be able to add attributes to modules, like these examples: // Only compile this code if the “foo” Cargo feature is enabled. #[cfg(feature = "foo")] pub mod foo; // Platform-specific stuff, as with std::os. pub mod os { #[cfg(windows)] pub mod windows; #[cfg(unix)] pub mod unix; } // You can even choose which file to load the module from. #[cfg_attr(windows, path = "w…

Interesting. This made me realize that a possible reason why some find the modules concept confusing is that it conflates the concepts of inclusion and namespacing. edit: corrected typo

Has the joke flown over my head, or have you conflated the words "conflate" (confuse) and "conflagrate" (burn)?

Edit: I honestly think I might have just misunderstood some play on words you're trying to make. It would be something around setting namespaces and inclusion on fire, but none of the combinations I've tried in my head work out quite right.

Re: Rust from a Gopher – Lessons 7, 8 and 9

#30
post #2

As a sidenote, does anyone else find the language identification terms cringey? Rustacean, gopher, pythonista... just atrocious.

Quite the contrary - I love it.

I don't identify as any of them myself, since I'd be some kind of unclassifiable chimera, but the touch of whimsy warms my heart.

Post reply on HN