Skip to content

gofork-org/goFork

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code
This branch is 41 commits ahead, 2330 commits behind golang:master.

goFork (v1.19.1):

Fork golang to support Allman/Horstmann style of curly braces

The google guys don't like allman style, but it's very easy to support allman style, just added only 13 lines of code into golang compiler.

Allman/Horstmann style is for we human, K&R style is for google robots!

Gopher image

Compile goFork:

sudo rm -rf /usr/local/go && wget -qO- https://golang.org/dl/go1.18.1.linux-amd64.tar.gz | sudo tar -xvz -C /usr/local
export -n GOROOT ; hash -d go
sudo mv /usr/local/go /usr/local/go.golang
git clone --depth 1 --recursive https://github.com/gofork-org/goFork.git
#or: wget https://github.com/gofork-org/go/archive/refs/heads/master.zip && unzip master.zip
cp -r ./go/bin.bootstrap ./go/bin
cd ./go/src
#bootstrap depends on ./pkg/tool/linux_amd64/compile(23MB bin), ./bin/go(15MB bin), can't simply copy them into goFork, will be not compatible with ./src/
export GOROOT_BOOTSTRAP=/usr/local/go.golang
./all.bash             #need 50 seconds to build gofork compiler           

cd ../test-gofork
../bin/go mod init test
../bin/go build -ldflags="-s -w"
./test

#if everything is ok, we can replace golang with gofork:
sudo cp -r ../ /usr/local/go
sudo export PATH=$PATH:/usr/local/go/bin         #or append ":/usr/local/go/bin" into PATH in /etc/environment

#if you have "git pull" again, you should run ./all.bash again to match the ./bin/go with the latest ./src(stdlib)

test-gofork/test.go, Allman/Horstmann style:

package main
import
(   "fmt"
)


func main()
{   if false
    {   fmt.Println("jack")
        fmt.Println("gofork")
    } else
    {   fmt/
           .Println("hello")
        fmt.Println("gofork")
    }

    var a="hello"

    {   var b="gofork"
        fmt.Println(a, b)
    }
}

Notes:

  1. In this style, the '{' at the beginning of the line needs to be followed by a whitespace or a tab

  2. A seperate code block needs a precedent empty line

While gofork keeps support for golang's K&R style:

package main
import(
    "fmt"
)


func main() {
    if false {
        fmt.Println("jack")
        fmt.Println("gofork")
    } else {
        fmt.
           Println("hello")
        fmt.Println("gofork")
    }

    var a="hello"
    {
        var b="gofork"
        fmt.Println(a, b)
    }
}

Note: the '{' at the beginning of the line should not be followed by a whitespace or a tab

About

Fork golang to support Allman/Horstmann style of curly braces

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 87.8%
  • Assembly 5.9%
  • HTML 5.8%
  • C 0.3%
  • Shell 0.1%
  • Perl 0.1%