Skip to content

Instantly share code, notes, and snippets.

View inancgumus's full-sized avatar

İnanç Gümüş inancgumus

View GitHub Profile
@inancgumus
inancgumus / func_overloading_golang.go
Created October 19, 2017 13:13
imitating function overloading in go
package main
import (
"fmt"
)
func main() {
// imitating func overloading in Go
// this example uses this:
package main
import (
"fmt"
"time"
)
func main() {
// Sleep func let us stop the progress for a duration
//
package main
import "fmt"
func main() {
// We can assign an untyped constant to any numeric-type variable
// Numeric types:
var (
package main
import (
"fmt"
)
func main() {
// typed constant declaration
const Pi float64 = 3.14
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
package main
import (
"fmt"
)
// visible inside main package
const packageLevelConst = 1
// visible everywhere
package main
import (
"fmt"
"math"
"strconv"
)
// I used bitwise operations on iota.
// This will be handy when we want to represent months together.
@inancgumus
inancgumus / hilowconst.go
Last active October 8, 2017 15:38
high precision go consts
package main
import "fmt"
func main() {
// ------------------------------------------------
// LOSS OF PRECISION
// ------------------------------------------------
// const Pi lives in the ideal numbers universe which has at least 256-bit high-precision
@inancgumus
inancgumus / age_of_universe_overflow.go
Last active October 2, 2017 18:47
go ageOfUniverse overflows
package main
import (
"fmt"
)
// on 32-bit machines, it'll overflow
// on 64-bit machines, everything is fine
// use: uint64 instead.
func main() {
@inancgumus
inancgumus / age_of_universe_ok.go
Last active October 2, 2017 18:47
age of universe correct example
package main
import (
"fmt"
)
func main() {
// still not a good way to define a variable like this. we will see it.
var ageOfUniverse uint64 = 14e9 // 14e9 = 14 and 9 zeros which is 14 billions