On Sun, Nov 28, 2021 at 3:09 PM Amnon <amno...@gmail.com> wrote: > > In K&R C back in the 1970s, you had to declare your local variables at the > beginning of a function, before any statements. > I think this is the source of the habit of declaring your variables first. > > Readability is key here. So it makes sense to declare a statement close to > where it is first used, > and limit it to the smallest possible scope where it is needed.
I agree, and I'll add that the location of the variable declaration makes no difference at run time. Ian > On Sunday, 28 November 2021 at 17:33:43 UTC jlfo...@berkeley.edu wrote: >> >> Some people put all their variable declarations at the beginning of a >> function. >> Others put them at various places in a function, where the variables are >> used. >> >> I've always wondered if a variable declaration results in any runtime >> overhead. >> One obvious concern is what happens if a variable declaration is inside a >> loop. >> >> Cordially, >> Jon Forrest >> >> > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/2734fbdf-ee96-49cb-8666-69c1ac775624n%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXcqVraiyeOwWQDYgbSEV6mXm2x27DJQ0dBkKnekD_%2Btw%40mail.gmail.com.