this post was submitted on 13 Jun 2024
23 points (67.2% liked)
Programming
17405 readers
91 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 [email protected]
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I'm going to try to help explain this, but i'll be honest it feels like you're coming from a place of frustration. I'm sorry about that, take a break :)
(I'm not a language expert, but here goes)
These are the two forms of variable declaration and the second one is a declaration and initialization short hand. I most commonly use
:=
. For instance:This has no return type because it returns no values. It does not require passing
u
. It's a method on the User type, specificallyu User
is a method receiver. You might think of this akin toself
orthis
variable in other languages. By convention it is a singke character of the type's name.If that function returned a value it might look like:
This is confusing because of how it's written. But the intent is to have a map (aka dictionary or hashmap) with
string
keys andint
values. In your example it's initializd to have no entries, the{}
. Let me rewrite this a different way:Hope this helps. In all honesty, Go's language is very simple and actually rather clear. There's definitely some funny bits, but these aren't it. Take a break, come back to it later. It's hard to learn if you are frustrated.
I also recommend doing the Tour of Go here. My engineers who found Go intimidating found it very accessible and helped them get through the learning code (as there is with any language).
Good luck (I'm on mobile and didn't check my syntax, hopefully my code works ๐)