💾 Archived View for gemlog.blue › users › wasabi › 1676900116.gmi captured on 2023-04-20 at 01:00:55. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-03-20)

-=-=-=-=-=-=-

   _     _      _     _      _     _      _     _      _     _      _     _   
  (c).-.(c)    (c).-.(c)    (c).-.(c)    (c).-.(c)    (c).-.(c)    (c).-.(c)  
   / ._. \      / ._. \      / ._. \      / ._. \      / ._. \      / ._. \   
 __\( Y )/__  __\( Y )/__  __\( Y )/__  __\( Y )/__  __\( Y )/__  __\( Y )/__ 
(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)
   || G ||      || O ||      || L ||      || A ||      || N ||      || G ||   
 _.' `-' '._  _.' `-' '._  _.' `-' '._  _.' `-' '._  _.' `-' '._  _.' `-' '._ 
(.-./`-'\.-.)(.-./`-'\.-.)(.-./`-'\.-.)(.-./`-'\.-.)(.-./`-'\.-.)(.-./`-'\.-.)
 `-'     `-'  `-'     `-'  `-'     `-'  `-'     `-'  `-'     `-'  `-'     `-' 

February 2023

I've been learning GoLang for a few days and strangely enough I've come across multiple elements bothering me. For instance, I've noticed that exportable functions depend it's name's case. So today, let's talk about this!

Disclaimer

This gemlog is about one issue I had with Go. For more details on GoLang, refer to the Ressources block at the bottom of this page.

GoLang is case sensitive

Coming from a background of atomic designing JavaScript projects, I'm used to work with modules and components. I actually find this way of coding a lot better for me, since my ADHD makes me a person who needs to find some kind of order and consistency in my projects. Having one big file makes it insanely hard for me to understand how the code works. That's why refactoring old code takes me a lot of time, since I need to understand independently each bit of code in order to break it down into smaller parts. That's actually why I thought that learning GoLang would be a great idea, since everything is made of packages.

Writing a package sounds simple and forces you to think about the project's structure first and break down each functionnality into small components.

While learning through examples, I had some trouble figuring out why some functions I wrote couldn't be accessed through my main file. At least until I finally found this article:

(https) Digital Ocean: "Understanging package visibility in Go"

I found this article to be very well explained and it actually helped me figure out how to handle package visibility in Go.

Unlike other program languages like Java and Python that use access modifiers such as public, private, or protected to specify scope, Go determines if an item is exported and unexported through how it is declared. Exporting an item in this case makes it visible outside the current package. If it’s not exported, it is only visible and usable from within the package it was defined.

This external visibility is controlled by capitalizing the first letter of the item declared. All declarations, such as Types, Variables, Constants, Functions, etc., that start with a capital letter are visible outside the current package.

I find this to be the best way of describing it, using examples from other programming languages and explaining the difference is actually the perfect way for me to understand why my code wasn't working.

Ressources

(https) Go Programming Language

(https) Go By Example

Contact

(https) Mastodon : @wasabi@raru.re

(https) Akkoma: @wasabi@outerheaven.club