Santosh Shrestha 157 Followers Stay humble. Refresh the page, check Medium ’s site status, or find something interesting to read. Let’s say you had some configuration variables such as the following. Working with Constants and iota in Golang by Santosh Shrestha wesionaryTEAM Sign up 500 Apologies, but something went wrong on our end. It’s not just about the space though, especially with how powerful modern hardware is. If you have a group of 4, 10, or even 100 unique values, do you really need to store an entire string? An int will take up less room in your program’s memory. Go is a general-purpose language designed with systems programming in mind. ![]() ![]() Why not just use strings for unique values? For example, const Head = "head" and const Shoulder = "shoulder"? □īesides the overlapping answer of the compiler not guaranteeing uniqueness, a string takes much more memory and can lead to performance issues under constrained circumstances. Head, Shoulder, Knee, and Toe, have the same value. By using an enum, you’re ensured by the compiler that none of the constants in your group, e.g. Yes, you could do that, but enums are powerful by how they group sets of constants together and guarantee unique values. And if you want an integer constant, can’t you just use a normal const? E.g. At first, enums may not seem useful, but I can assure you they are. Let’s look at some questions you may have about enums. Type BodyPart int const ( Head BodyPart = iota // Head = 0 If you want to get involved in the community, need help with setting up, have any issues or just want to discuss IOTA with other people, feel free to join our Discord in the clients-dev and clients-discussion channels. Standard library strconv strconv package standard library Version: go1.20.3 Latest Published: License: BSD-3-Clause Imports: 5 Imported by: 684,577 Details Valid go.mod file Redistributable license Tagged version Stable version Learn more Repository cs.opensource.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |