Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungRefreshed repository pull requests page generally available(22.09.2026 um 03:25 Uhr)
Sichere ProgrammierungThe Joy of Learning the Basics Again(22.09.2026 um 03:28 Uhr)
Sichere ProgrammierungZero-Code OpenTelemetry Tracing for Dagster(22.09.2026 um 03:39 Uhr)
Linux Tipps & Hardening`prime-all`(22.09.2026 um 02:28 Uhr)
IT Security Toolsopensoho v0.15.2(22.09.2026 um 03:33 Uhr)
IT Security NachrichtenUS Proposes AI Incident Alert System in Talks With China, Bessent Says(22.09.2026 um 04:01 Uhr)
Sichere ProgrammierungRefreshed repository pull requests page generally available(22.09.2026 um 03:25 Uhr)
Sichere ProgrammierungThe Joy of Learning the Basics Again(22.09.2026 um 03:28 Uhr)
Sichere ProgrammierungZero-Code OpenTelemetry Tracing for Dagster(22.09.2026 um 03:39 Uhr)
Linux Tipps & Hardening`prime-all`(22.09.2026 um 02:28 Uhr)
IT Security Toolsopensoho v0.15.2(22.09.2026 um 03:33 Uhr)
IT Security NachrichtenUS Proposes AI Incident Alert System in Talks With China, Bessent Says(22.09.2026 um 04:01 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Learning Go as a Ruby Developer # 2: Variables, Constants, and Why Go Doesn't Trust You

One of the first differences I noticed when learning Go was how seriously it takes types. Coming from Ruby. I rarely think about their types because Ruby figures everything out at runtime. Go has a very different philosophy. It wants to…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

One of the first differences I noticed when learning Go was how seriously it takes types.



Coming from Ruby. I rarely think about their types because Ruby figures everything out at runtime.



Go has a very different philosophy.



It wants to know exactly what every variable is, and if it doesn't know, it'll ask you to be explicit.









Why This Felt Strange Coming from Ruby



In Ruby, creating variables couldn't be easier.




name = "Alice"
age = 30
admin = true






Ruby decides the type at runtime.



Later I can even do something like this:




value = 10
value = "hello"
value = [1, 2, 3]






The same variable can hold completely different kinds of objects throughout the program.



Go doesn't allow that.



Once a variable has a type, that type is fixed.









Declaring Variables in Go



The most explicit way to declare a variable is by specifying its type.




var age int = 30
var name string = "Alice"
var admin bool = true






This is checked during compilation, long before your program ever runs.



If you later try to assign a different type, the compiler will stop you immediately.



This felt a bit strict—but it also means many bugs are caught before the program starts.









Type Inference



Fortunately, Go doesn't always require you to write the type yourself.



It can often infer it.




var admin = false






Go knows this is a bool.



Likewise:




var message = "Hello World"






becomes a string.









Short Variable Declaration



Inside functions, Go provides an even shorter syntax.




message := "Hello World"
count := 10






The := operator both declares the variable and lets Go infer its type.



If you're writing local variables, you'll probably use this style most of the time.



One thing I learned from my notes is that this syntax can only be used inside functions.









Declaring Multiple Variables



Go also makes it easy to declare multiple variables.




var x, y, z int = 12, 15, 10






or with inferred types:




var a, b, c = "hi", 30, true






For larger groups, Go encourages this style:




var (
host string = "localhost"
port int = 8080
debug bool = true
)












Constants



Constants are declared using const.




const MaxUsers = 100






You can also group them.




const (
Enabled = true
Pi = 3.14
)






Unlike variables, constants cannot be changed after they're declared.



Ruby has constants too:




MAX_USERS = 100






But every Ruby developer knows the truth...



Ruby will happily let you change it.




MAX_USERS = 200






You'll get a warning, not an error.



Go, on the other hand, simply refuses.









Zero Values



If you declare a variable without assigning anything, Go automatically initializes it.




var age int
var active bool
var name string






The values become:




























Type Zero Value
int 0
float64 0.0
bool false
string ""


Coming from Ruby, I expected something similar to nil.



Instead, Go gives every type a sensible default.



That design avoids a lot of unnecessary initialization code.









Type Conversion



Another thing that immediately stood out was that Go doesn't automatically convert between types.



Suppose we have:




var i int = 45






Converting it to a floating-point number requires an explicit conversion.




var f float64 = float64(i)






Likewise:




var u uint = uint(f)






Every conversion must be intentional.



Ruby is much more forgiving.




number = "45"

number.to_i
number.to_f






And in many cases Ruby performs conversions automatically for you.



Go deliberately avoids this.









Creating Values with make



One line in my notes that initially confused me was this:




numbers := make([]int, 3)






Unlike arrays in many languages, make creates and initializes certain built-in data structures.



In this example, it creates a slice with a length of three.



I'll dive much deeper into slices later in the series, but for now it's enough to know that make is commonly used when creating slices, maps, and channels.









So to conclude:



Changing a type?



Be explicit.



Creating a variable?



Be explicit—or let the compiler infer it.



Converting numbers?



Be explicit.



At first it felt like the language didn't trust me :D



Now I think it's more accurate to say Go doesn't trust assumptions.



Instead of guessing what I meant, it asks me to say exactly what I want.



Ruby optimizes for flexibility.

Go optimizes for correctness.

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-49449 | Joplin is an open source note-taking and to-do application that organise…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick