Its ok to use semicolon?

Hello i notice that i can use semicolon in Go

package main

import (
	"fmt"
); //Here

func main() {
    a := 4;//Here
    b := 4;//Here
    fmt.Println("The sum is: ", a+b);//Here
}

Is ok if i use them even that i konw that i dont need them is just that i use them in javascript and i like it, will it be any diferrence or a bad idea?

By convention, all Go code should be formatted through gofmt. This way, the devs’ brains are freed from style discussions and can focus on the important stuff.

Edited to add: as a Go proverb says,

Gofmt’s style is no one’s favorite, yet gofmt is everyone’s favorite

4 Likes

Use a semicolon to join two related independent clauses in place of a comma and a coordinating conjunction. Semicolons should not be used between a dependent clause and an independent clause.

2 Likes

Effective Go has a good explanation with cases when you should/shouldn’t use semicolons: Effective Go - The Go Programming Language.

3 Likes

Well as others have said go fmt will get rid of them anyway. If you like them, that’s great, but when working with others it’s important to try to write idiomatic code, just like you can construct all kinds of “weird” sentences in English that people will likely understand. They may understand you, but it will sound odd and will affect their opinion of you.

If you are a contributor on a project of > 1, then it’s also important to follow standards so others can quickly pick up code and understand it. Of course that’s why we use auto-formatters, so we don’t spend precious time talking about things like semicolons when they don’t actually affect the program.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.