-3

Why do we need to put a package declaration in every file in folder to mark the specified .go files as a part of a package?

Instead the directory name itself could be a package name for all files it contains.

So what the ideological point for this decision?

7
  • 5
    The directory name is not related to the package name Commented Apr 4, 2017 at 20:01
  • 1
    As an example of what @JimB is talking about package import "google.golang.org/api/oauth2/v2" imports the oauth2 package and is used as such: oauth2.New(...). Commented Apr 4, 2017 at 20:21
  • 2
    Or pretty much any package main Commented Apr 4, 2017 at 20:23
  • I understand that it is NOT related. BUT my question was not about the current implementation. It is about the advantages of current implementation versus the old one plain directories. Commented Apr 4, 2017 at 21:12
  • Package main is just as simple as putting your main proc into main folder. Commented Apr 4, 2017 at 21:13

1 Answer 1

0

Instead the directory name itself could be a package name for all files it contains.

Egor, you probably suppose that in one directory go-files only from one package.

You are almost correct if you exclude tests.

Tests are exception from rule "one directory - one package".

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.