Re:The Hare programming language
by lloydatkinson on Monday April 25, 2022 @05:40AM
(#31152293)
Why do people keep choosing :: over simply .? How does adding more visual noise help anyone?
[ Parent
| on HN ]
Re:The Hare programming language
by onlyrealcuzzo on Monday April 25, 2022 @10:34AM
(#31155407)
To distinguish between an instance and a namespace?
The same can be said for why do we need to put parenthesis after functions that take no parameters? So people still know it's a function.
But why not use a single character? With the double colon, something like foo::bar(xyz) looks like bar is “closer” to xyz, when in fact it's closer to foo.
Re:The Hare programming language
by torresjrjr on Monday April 25, 2022 @01:37PM
(#31158148)
A single ':' is used for other things, like casting types.
let x: int = 0;
It's so that the compiler can distinguish between those two, and likely some other areas too.A different character could be used, such as # (like in VimScript) or \ (like in… PHP?)
Re:The Hare programming language
by torresjrjr on Monday April 25, 2022 @04:30PM
(#31160185)
True, but :: is probably more readable than # or \
Design a language, and you'll understand that there's always trade-offs.
I personally find :: very unreadable, for the very reason I mentioned.
Re:The Hare programming language
by edflsafoiewq on Monday April 25, 2022 @05:51PM
(#31161171)
Why do you want to do that? Accessing a member of a namespace is conceptually the same thing as accessing a member of an instance, and in many languages like Python or Zig its literally the same thing too.
Re:The Hare programming language
by metaltyphoon on Monday April 25, 2022 @11:12AM
(#31155990)
> To distinguish between an instance and a namespace?
I’m with OP here. C# proves that . reduces the noise substantially.
Only somewhat related, but when reading docs/comments that mention some method `class.method`, it's annoying when that's ambiguous and could mean either a static method or an instance method.
In the Ruby world, I think they have the convention of writing `class#method` in docs/comments when mentioning an instance method, and `class.method` when mentioning a static method.
Re:The Hare programming language
by steveklabnik on Monday April 25, 2022 @01:38PM
(#31158175)
Fun trivia fact: I tried to bring that convention over to Rust, but enough people didn't like it than in the end, we don't do that.
Re:The Hare programming language
by metaltyphoon on Monday April 25, 2022 @02:05PM
(#31158518)
Interesting mention about the docs. I see what you mean. I have been doing C# for over a decade and I guess that after a bit you are just blind to this kind of stuff. I guess it never "really" matter to me when coding, but I can see it as an annoyance on the documentation side. Perhaps Microsoft can do a better job of splitting static methods from instances on the docs.
i.e https://docs.microsoft.com/en-us/dotnet/api/system.console.w...
Re:The Hare programming language
by onlyrealcuzzo on Monday April 25, 2022 @12:12PM
(#31156906)
I think the question should be less about ergonomics and more about does the distinction matter.
I don't know enough about C# to know if it matters. From everything I know, it's a really well designed language, so I'm guessing they made the right call.
It doesn't mean it's the right call everywhere.