NEW IN-PERSON EVENT: ARDAN LABS LIVE IN LONDON (NOV. 1 - 4, 2022) |
Our training paths
Grow your skills
You’ll get our FREE Video Series & special offers on upcoming training events along with notifications on our latest blog posts.
Valid email required.
Submit failed. Try again or message us directly at email@example.com.
Check your email for confirmation.
IntroductionOne of the first things I learned about in Go was using an uppercase or lowercase letter as the first letter when naming a type, variable or function. It was explained that when the first letter was capitalized, the identifier was public to any piece of code that wanted to use it. When the first letter was lowercase, the identifier was private and could only be accessed within the package it was declared.NEXT Level Go & DevOps TrainingLearn More
I have come to realize that the use of the language public and private is really not accurate. It is more accurate to say an identifier is exported or unexported from a package. When an identifier is exported from a package, it means the identifier can be directly accessed from any other package in the code base. When an identifier is unexported from a package, it can’t be directly accessed from any other package. What we will soon learn is that just because an identifier is unexported, it doesn’t mean it can’t be accessed outside of its package, it just means it can’t be accessed directly.Direct Identifier AccessLet’s start with a simple example of an exported type:AlertCounter inside the package counters. This type is an alias for the built-in type int, but in Go AlertCounter will be considered a unique and distinct type. We are using the capital letter ‘A’ as the first letter for the name of the type, which means this type is exported and accessible by other packages.Now let’s access our AlertCounter type in the main program:AlertCounter type has been exported, this code builds fine. When we run the program we get the value of 10.Now let’s change the exported AlertCounter type to be an unexported type by changing the name to alertCounter and see what happens:counters and main packages, we attempt to build the code again and get the following compiler error:
We have taught Go to thousands of developers all around the world since 2014. There is no other company that has been doing it longer and our material has proven to help jump start developers 6 to 12 months ahead of their knowledge of Go. We know what knowledge developers need in order to be productive and efficient when writing software in Go.
Our classes are perfect for both experienced and beginning engineers. We start every class from the beginning and get very detailed about the internals, mechanics, specification, guidelines, best practices and design philosophies. We cover a lot about "if performance matters" with a focus on mechanical sympathy, data oriented design, decoupling and writing production software.
Interested in Ultimate Go Corporate Training and special pricing?
Our courses have been designed from training over 30,000 engineers since 2013, and they go beyond just being a language course. Our goal is to challenge every student to think about what they are doing and why.
Please fill out the form below, and we'll get back to you soon.
Check your email for confirmation of your sent message. We'll get back to you shortly.
Ardan Labs Copyrights © 2022