View godev.bash
#!/bin/bash
# -----------------------------------------------------------------------------
# HOW TO RUN?
# -----------------------------------------------------------------------------
# . ./godev.bash
# WARNING:
#
View func_overloading_golang.go
package main
import (
"fmt"
)
func main() {
// imitating func overloading in Go
// this example uses this:
View enum_weekdays.go
// declare constants for the days in a week, and assign to them
// different numeric values.
//
// so, they won't clash. if both values of Sunday and Monday were 0,
// then, how could we know that which one is Sunday or Monday?
const (
Sunday = 0
Monday = 1
Tuesday = 2
Wednesday = 3
View enum_planet_masses.go
package main
import (
"fmt"
)
const (
Mercury = 3.303e+23
Venus = 4.869e+24
Earth = 5.976e+24
View untyped_numeric_consts_flexibility.go
package main
import "fmt"
func main() {
// We can assign an untyped constant to any numeric-type variable
// Numeric types:
var (
View typed_const_declaration.go
package main
import (
"fmt"
)
func main() {
// typed constant declaration
const Pi float64 = 3.14
View const_shadowing.go
package main
import (
"fmt"
)
// visible inside main package
const packageLevelConst = 1
// visible everywhere
View go_enum_iota.go
package main
import (
"fmt"
"math"
"strconv"
)
// I used bitwise operations on iota.
// This will be handy when we want to represent months together.
View untyped_const_flexibility.go
package main
import (
"fmt"
"time"
)
func main() {
// Sleep func let us stop the progress for a duration
//
View untyped_const_default_type.go
package main
import "fmt"
func main() {
// has default type of float
const Tau = 3.14 * 2
// implicitly converted to a float64,
// because of the assignment to a "runtime" variable