Go परिचय
What is Go?
Go एक open-source, statically typed, compiled programming language है जिसे Google में design किया गया और 2009 में publicly release किया गया। यह किसी scripting language की तेज़ compilation और simplicity को किसी compiled language की performance और safety के साथ combine करती है।
Programs सीधे machine code में compile होते हैं, इसलिए runtime पर किसी अलग virtual machine या interpreter की ज़रूरत नहीं।
उदाहरण: What is Go?
// Every Go file belongs to a package; main builds an executable
package main
// Import the fmt package
import "fmt"
// main is where the program starts running
func main() {
// Print the values followed by a newline
fmt.Println("Go is a statically typed, compiled language")
}
Login to try C/C++/Java/PHP code in the editor
Why Go Was Created
Go के creators बड़े C++ codebases में धीमे builds, जटिल dependency management, और भ्रामक language features से निराश थे।
उन्होंने Go को जल्दी compile होने, एक छोटा और readable syntax रखने, और concurrent programming (एक साथ कई tasks handle करना) को out of the box सरल और सुरक्षित बनाने के लिए design किया। परिणाम एक ऐसी language है जो सीखना आसान है लेकिन बड़ी teams और systems के लिए अच्छी तरह scale करती है।
उदाहरण: Why Go Was Created
// Every Go file belongs to a package; main builds an executable
package main
// Import the fmt package
import "fmt"
// main is where the program starts running
func main() {
// Short declaration: create goals and infer the type
goals := []string{"fast compilation", "simple syntax", "built-in concurrency"}
// Loop over goals; the blank identifier _ ignores the index
for _, g := range goals {
// Print the values followed by a newline
fmt.Println("Design goal:", g)
}
}
Login to try C/C++/Java/PHP code in the editor
Where Go Is Used
Go अपनी speed, छोटे memory footprint, और आसान deployment (बिना external runtime के एक single binary) के कारण backend web servers, cloud और networking tools, और command-line utilities के लिए लोकप्रिय है।
Google, Uber, और Cloudflare जैसी companies performance-critical services के लिए Go उपयोग करती हैं। इसका built-in concurrency model इसे कई simultaneous network connections juggle करने वाले systems के लिए भी स्वाभाविक रूप से उपयुक्त बनाता है।
उदाहरण: Where Go Is Used
// Every Go file belongs to a package; main builds an executable
package main
// Import the fmt package
import "fmt"
// main is where the program starts running
func main() {
// Short declaration: create usedFor and infer the type
usedFor := map[string]string{
"Docker": "container tooling",
"Kubernetes": "container orchestration",
"Terraform": "infrastructure as code",
}
// Loop over usedFor, getting each index and value
for tool, purpose := range usedFor {
// Print using a format string
fmt.Printf("%s: %s\n", tool, purpose)
}
}
Login to try C/C++/Java/PHP code in the editor
Compiled, Not Interpreted
Python या JavaScript के विपरीत, Go source code चलने से पहले ही एक standalone native executable में compile किया जाता है।
इसका मतलब है कि compiler आपके program शुरू होने से पहले ही कई गलतियां (जैसे type errors) पकड़ लेता है, और resulting binary उस machine पर बिना Go installed के चलता है जो इसे execute करती है। यह trade-off एक compile step की लागत लेता है लेकिन runtime speed और reliability में फायदा देता है।
उदाहरण: Compiled, Not Interpreted
// Every Go file belongs to a package; main builds an executable
package main
// Import the fmt package
import "fmt"
// main is where the program starts running
func main() {
// Print the values followed by a newline
fmt.Println("This program is compiled into machine code before running")
// Print the values followed by a newline
fmt.Println("No interpreter is needed to execute the final binary")
}
Login to try C/C++/Java/PHP code in the editor
- Go को एक compiled, statically typed language के बजाय Python जैसी एक interpreted scripting language मानना।
- Go (language, कभी-कभी Golang कहा जाता है) को online मदद खोजते समय असंबंधित board game या दूसरे Go products के साथ confuse करना।
- Go के सरल struct + interface composition model के बजाय Java/C++ जैसी classes और inheritance की उम्मीद करना।
- Go एक statically typed, compiled language है जिसे Google में 2009 में Robert Griesemer, Rob Pike, और Ken Thompson ने बनाया।
- यह simplicity को प्राथमिकता देती है: एक छोटा keyword set, तेज़ compilation, built-in concurrency, और automatic garbage collection।
- Go एक single native binary में compile होता है, servers और containers में deployment को सीधा बनाते हुए।
- यह backend services, cloud infrastructure (Docker, Kubernetes), और command-line tools के लिए व्यापक रूप से उपयोग होता है।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: