5 ms·
You don't have to split up your code manually. You just write one Rust crate, splitting your code into files on whatever granularity you like (with mutual recur
by pcwalton 10y ago
You don't have to split up your code manually. You just write one Rust crate, splitting your code into files on whatever granularity you like (with mutual recursion fully supported), and the Rust compiler automatically does the rest. You don't have to write tedious header files; the compiler figures out all the dependencies automatically.
- flukus 10y agoI don't split up my code manually for the compiler, I do it for the humans, being compiler friendly is just a pleasant side effect. You can build java files the same way without header files, worst case scenario is you have some fat compilation units.
- pcwalton 10y ago> I don't split up my code manually for the compiler, I do it for the humans, being compiler friendly is just a pleasant side effect. There is no human benefit to having to copy and paste function signatures—and worse, the bodies of functions you want to be inlined, including all templates—into header files. There's also no benefit to having the compiler parse hundreds of KB of header files over and over and over again. > You can build java files the same way without header files, worst case scenario is you have some fat compilation units. Java (production implementations used in practice) performs whole program optimization via its JIT. It's nice for Java, but that isn't how Rust works.
- flukus 10y agoI don't disagree on the header files, no sane language designed today would include that. > Java (production implementations used in practice) performs whole program optimization via its JIT. It's nice for Java, but that isn't how Rust works. Whole program optimization isn't generally something you want on dev builds, which is where incremental compilation is useful. For a production build why wouldn't you do a full rebuild anyway?
- pcwalton 10y ago> Whole program optimization isn't generally something you want on dev builds, which is where incremental compilation is useful. By "whole program optimization" I also include things like generic/template instantiation. Whenever you use, say, a HashMap, you have to recompile the implementation of the HashMap specialized to the size, alignment, destructor, etc. of types you're using with it. > For a production build why wouldn't you do a full rebuild anyway? When I profile apps written in Rust, it's important for me to be able to get good turnaround time on optimized builds.
- enitihas 10y agoDo Java generics work like that? I thought the JVM did not know about the generics as the types are erased at compile time.
- eonwe 10y agoJVM doesn't know about generic types at the runtime. There's no specialization of HashMaps, it's just arrays of points to objects all around. With project Valhalla: https://en.wikipedia.org/wiki/Project_Valhalla_(Java_language) https://en.wikipedia.org/wiki/Project_Valhalla_(Java_languag... there's been talk about specialization for value types.
- enitihas 10y agoI too thought the same. That's why pcwalton's comment confused me.
- pjmlp 10y agoIt is already available for those that want to play with it. https://adoptopenjdk.gitbooks.io/adoptopenjdk-getting-started-kit/content/en/openjdk-projects/valhalla.html https://adoptopenjdk.gitbooks.io/adoptopenjdk-getting-starte...
- pcwalton 10y agoRust generics do. Java's don't.
- jjnoakes 10y agoSplitting up code into headers and sources also helps keep interfaces separate from implementations. It allows one to not only read just the header for the full interface, but it also allows one to distribute the implementation in binary form and the interface in source form, which is important for companies.
- pcwalton 10y agoExcept for inlineable functions and templates in C++—which become a greater and greater fraction of code the more "modern" your C++ gets. Not to mention that the size of your instance variables leaks into your public interface unless you manually heap allocate and use the pimpl idiom. In any case, Rust stores the interfaces to libraries in serialized binary form (including documentation, following a standardized format understood by rustdoc), and they can be readily extracted from crates using tools that ship with the language. So what you describe isn't a benefit of headers anyhow.
- dllthomas 10y ago"C++ did it right" seems a separate position from that put forward by the parent comment. I definitely think there's benefit to being able to view interface as separate from implementation, although that might well be better supported by tooling (editor folding, documentation generation) than manual maintenance - which you seem to be doing well. I don't know whether there is benefit to being able to edit interface separately from implementation. Probably not much of one, but I could certainly be convinced otherwise.