rust double colons
original source : https://www.reddit.com/r/rust/comments/3fimgp/why_double_colon_rather_that_dot/
To me, as a programmer, it leaves certain things clear so I don't have to worry. In rust when I see the following:
f.x
I know that f is a struct and x is a member value. Moreover I know that x's value depends on f's value at runtime.
When instead I see
f::x
I know that x is an associated constant, a value that is shared by all things of the same type as f. I know it doesn't matter the data f contains, but what f is.
It gets even more useful when we get to methods:
f.m(x)
I know that is calling a method that has f sent as a parameter to it. It's clear that the result of m(x) depends on what is the value of f. Now look at the following:
f::m(x)
I know that m is an associated function. The result of m(x) won't change if I change the value of f, as long as the type is the same the function will work the same way.
In all the languages you described there isn't much difference between the static and dynamic world. Even in Java, that is compiled, .object files are loaded and used dynamically, not statically. There's no reason to explicitly expose what is going on because it makes little difference to the people using it. In languages like Rust or C++ it's very important to make it clear to the programer which value is known and chosen by the compiler based on the type of the parent and which instead is calculated dynamically based on the value it has at runtime.













