func main()
{
}
it's a syntax error.
It appears you must have
func main(){
}
Notice, the curly brace is in the function header.
Is this a bug, or by design? I cannot seem to find this in the
language specification. Perhaps I'm overlooking something.
thanks,
John
Unfortunately John it is by design, though one which is causing a lot of
problems for a lot of people. The Go compile process inserts a
semi-colon at the end of a statement on a line, unless the line is
terminated with a {. So what happens at compile time is that the actual
compile code in your example would read:
func main();
{
}
with the extra semi-colon inserted, which is clearly an error. The only
way to avoid this is to put the opening brace on the same line as the
statement. A coding style that is unacceptable in many areas.
Regards
Nigel
--
Nigel Backhurst MSc BA(Hons) FFA
Information Engineering Associates
14 Deacon Street
Leicester LE2 7EF
Unacceptable? Ha!
On Jan 29, 2010 10:18 AM, "Nigel Backhurst - I-E-A" <ni...@i-e-a.eu> wrote:
On 29/01/2010 16:08, John wrote:
>
> I've noticed if you do the following:
>
> func main()
> {
>
> }...
Thanks!
By the way before people suggest using gofmt to reformat the code, in
SCS you cannot put the code through a formatter after
the sign off code inspection. The signed off code must be compiled as
is. The reason for this is because of the chance, albeit slim,
that the formatter may introduce an error into the code after it has
been checked.
Regards
Nigel
On Fri, Jan 29, 2010 at 17:18, Nigel Backhurst - I-E-A <ni...@i-e-a.eu> wrote:
> A coding style that is unacceptable in many areas.
Good thing those areas are all not relevant! This is go, not Java,
C++, or whatever your 'acceptable coding styles' come from. In fact,
the 'acceptable coding style' for go (gofmt) says that you should put
them on the same line.
--
Cheers,
Sverre Rabbelier
package main
func Empty ()
func main () {
println ("Hello World!")
}
Go compiles this without issue. If you attempt to call Empty you get
the error "undefined: main.Empty", so it appears that Go entirely
ignores function declarations that do not have a body. That is
strange because Go does not ignore unused imports or variable
declarations.
-Ostsol
On Jan 29, 9:16 am, Ian Lance Taylor <i...@google.com> wrote:
> I've got to wonder just why an empty function is considered a valid
> statement. If you have a program:
>
> package main
>
> func Empty ()
>
> func main () {
> println ("Hello World!")
> }
>
> Go compiles this without issue. If you attempt to call Empty you get
> the error "undefined: main.Empty", so it appears that Go entirely
> ignores function declarations that do not have a body. That is
> strange because Go does not ignore unused imports or variable
> declarations.
This is a feature which permits writing the function in C or
assembler. Specifically, see src/pkg/runtime/extern.go.
Ian
-Ostsol
Hehe, don't be to harsh but imho SCS is mostly an effectivelly
pointless reassurance for bid invitation and makes mostly no sense
for programming languages where runtime behaviour can not be
guaranteed to be side effect free or can not be formaly proved.
> --
> Cheers,
>
> Sverre Rabbelier
Reading the mailing list, the problems are very minimal. People just
make the assumption that it's like C and once told the correct syntax
there's no problem.
> A coding style that is unacceptable in many areas.
How can anywhere already have a required coding style for Go
that isn't compatible with the syntactic requirements of Go?
- jessta
--
=====================
http://jessta.id.au
In fairness, when you parse this statement as "insert characters
arbitrarily in a Go program and it becomes totally useless" it seems a
little less silly :) And, applies to plenty of other languages, too.
On Jan 30, 11:14 am, Peter Bourgon <peterbour...@gmail.com> wrote:
Its wonderful to note that word wrap a Go program and it becomes
totally useless.
It's wonderful to note that gofmt fixes these things.
word wrapping code is uncommon and breaks a lot of languages, but it's
not a problem if you gofmt
- Jessta
--
=====================
http://jessta.id.au
On Jan 30, 6:09 am, Vincent Risi <vincent.r...@gmail.com> wrote:
> ROFL.
That is where you should stay.
-ish
I prefer explicit semicolons or no semicolons at all. For example,
Python needs no semicolons, but that's because all lines end in a
carriage return unless an explicit continuation is inserted. It also
looks to the next line to decide whether a block of code should end
(else/except/finally). It is therefore somewhat unfortunate, in Go,
that opening braces appear as a sort of continuation.
In spite of all of this I have gotten used to Go's coding style and
have even imported it into my C coding practices. Perhaps this is due
to having spent so much time with Python, which is similarly strict.
-Ostsol
one's personal coding style should not matter to the compiler