this post was submitted on 27 Dec 2023
82 points (92.7% liked)

Programming

17343 readers
334 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS
 

Both zig and go use the dot operator, but I find the '::' operator much more readable.

Vec::new();

Makes it clear that were accessing a static method belonging to the Vec struct/namespace.

Vec.new()

Makes it seem like Vec is an object with a 'new' method.

Am I alone in thinking this?

all 17 comments
sorted by: hot top controversial new old
[–] vext01@lemmy.sdf.org 36 points 10 months ago

The rust devs agreed with you...

[–] Pyroglyph@lemmy.world 20 points 10 months ago

I used to only use C#, and I liked the simplicity of only using one symbol to access any prop/field/method. But now I've used Rust for a while I do prefer separating the two for the same reasons you mentioned.

So no, you're not alone. Even cross-lang!

[–] ono@lemmy.ca 7 points 10 months ago

C++ was my language of choice for a long time, but I can't say I'm with you on this one. If I'm going to use Vec, I had better know what it is already. Littering the code with a special double-glyph operator when a dot would do is just needless noise to me.

(I won't criticize you for liking it, though. Cheers.)

[–] shotgun_crab@lemmy.world 6 points 10 months ago (1 children)

Anything is fine as long as it's not an arrow (I'm looking at you, PHP)

[–] owenfromcanada@lemmy.world 8 points 10 months ago (1 children)

Sweats nervously in C pointer

[–] shotgun_crab@lemmy.world 4 points 10 months ago (1 children)

C is the cool grandpa of today's programming languages so he can get away with this

[–] MaoZedongers@lemmy.today 1 points 9 months ago

Nobody would cry if it disappeared tomorrow though

[–] BmeBenji@lemm.ee 1 points 10 months ago

I don’t understand the C++ hate. I’m definitely biased since I learned it before anything else, but the flow of the code and the object-oriented principles just make sense to me. And yeah, I appreciate the scope resolution operator a lot.

[–] CrypticCoffee@lemmy.ml 0 points 10 months ago (5 children)

I don't agree. Many languages differentiate in terms of standards. In Java, your objects start lowercase, so if you see uppercase, its a static call.

:: looks nice, I guess, but many languages and standards improve clarity of code.

[–] lysdexic@programming.dev 1 points 10 months ago* (last edited 10 months ago)

In Java, your objects start lowercase, so if you see uppercase, its a static call.

Not really, that's just the way a specific coding style was specified. You're free to refactor all your projects to follow any other coding style if you really want to, and your programs will continue to work just fine.

[–] cactusupyourbutt@lemmy.world 1 points 10 months ago

in java ovjects start lowercase

by convention only though

[–] Ephera@lemmy.ml 1 points 10 months ago

Yeah, kind of curious what Go does here then / what the actual experience is like.
It abuses casing for public/private, so presumably there's no way to see whether a given sequence of letters is a variable or a type.

[–] huginn@feddit.it 1 points 10 months ago (1 children)

Also: :: in Java is method reference. In Kotlin it's reflection.

I'd say if you care a lot about distinguishing contexts it's really the job of the IDE to highlight syntax.

Don't write code as though you're going to read it in plain text imo.

[–] eluvatar@programming.dev 1 points 10 months ago

I like how Java uses it. As a C# dev I wish for it sometimes.

[–] vext01@lemmy.sdf.org 1 points 10 months ago (1 children)

That's just convention.

:: is enforced by the compiler.

[–] CrypticCoffee@lemmy.ml -1 points 10 months ago* (last edited 10 months ago)

It don't get past review if it doesn't follow standards. I'm yet to see a deviation.

If a language is bad because devs do stupid things, they're all bad.