Тёмный

Golang Enums and Constants 

Nick Phillips
Подписаться 69
Просмотров 372
50% 1

Learn how Go handles constants and enumerations (enum for short).

Опубликовано:

 

7 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 7   
@DavidSmith-ef4eh
@DavidSmith-ef4eh Месяц назад
Nice explanation. can you use string as the underlying type?
@CoderNick
@CoderNick Месяц назад
Yep! You just create a new type of string.
@DavidSmith-ef4eh
@DavidSmith-ef4eh Месяц назад
@@CoderNick yeah, tried it in a sandbox. sadly neither enum is 100% typesafe, since it accepts strings/ints... but still, better than nothing.
@CoderNick
@CoderNick Месяц назад
Yes, that's true. I try to stay away from string enums for this very reason. According to the assignability spec here: go.dev/ref/spec#Assignability. I think Go could do a lot better with their enums. They feel like an after thought. For example, this code is valid even though `yell` is not a defined color. package main import "fmt" type color string const ( Yellow color = "yellow" Red color = "red" Blue color = "blue" ) func main() { fmt.Println("hello") printColor(Blue) printColor("yell") } func printColor(c color) { fmt.Println(c) }
@DavidSmith-ef4eh
@DavidSmith-ef4eh Месяц назад
@@CoderNick True. I am coming from php/csharp, trying to explore other languages. Go seems great because of the performance and simple mulitthreading system.
@CoderNick
@CoderNick Месяц назад
I highly recommend it. I came from c++ and Python background and switched to Go about 10 years ago. It’s much easier than c++ especially for big sw teams and much faster than python. No language is perfect and that goes for Go as well. Little quirks like this and generics are really confusing right now. Lots of jobs are out there in Go.
Далее
Golang Loops
4:20
Просмотров 68
The secret to making Golang error handling a breeze
13:46
PUBG MOBILE | Metro Royale: Fun Moments #4
00:16
Просмотров 386 тыс.
Поплатился за подлые удары!
01:00
Golang Channels in 16 Minutes!
14:43
Просмотров 259
Golang Constants & Unsigned Constants
12:16
Просмотров 4,2 тыс.
This Will Make Everyone Understand Golang Interfaces
21:03
Andrew Kelley   Practical Data Oriented Design (DoD)
46:40
Go Pointers: When & How To Use Them Efficiently
14:09
justforfunc #19: mastering io.Pipes
41:24
Просмотров 33 тыс.
Learn GO Fast: Full Tutorial
1:07:53
Просмотров 434 тыс.
The Power Of Struct Embedding And Interfaces In Golang
15:05
PUBG MOBILE | Metro Royale: Fun Moments #4
00:16
Просмотров 386 тыс.