95
submitted 10 months ago* (last edited 10 months ago) by 3h5Hne7t1K@lemmy.world to c/programming@programming.dev

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?

you are viewing a single comment's thread
view the rest of the comments
[-] CrypticCoffee@lemmy.ml 7 points 10 months ago

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.

[-] cactusupyourbutt@lemmy.world 21 points 10 months ago

in java ovjects start lowercase

by convention only though

[-] vext01@lemmy.sdf.org 18 points 10 months ago

That's just convention.

:: is enforced by the compiler.

[-] Ephera@lemmy.ml 6 points 10 months ago

Yeah, but does that matter? I don't think, I've ever accidentally broken these conventions, where compiler assistance would have been helpful.

[-] huginn@feddit.it 8 points 10 months ago

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 6 points 10 months ago

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

[-] Ephera@lemmy.ml 3 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.

[-] lysdexic@programming.dev 2 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.

this post was submitted on 27 Dec 2023
95 points (93.6% liked)

Programming

17241 readers
257 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