Alex Rivera | Logout

Placement of instance variable declarations

Asked 2008-10-20T14:10:13.707
11

I've seen some developers put instance variable declarations at the end of classes though I mostly see them placed at the top. The only reasons I can think of for doing this are stylistic preference or maybe it somehow makes them easier to work with in an IDE. Is there a more legitimate reason for choosing this style?

Edit
Report

2 Answers

2

It's mostly (if not entirely) personal preference. I like them at the top, but I couldn't really give a better reason for it then that it's the way I'm used to.

answered 2008-10-20T14:13:46.150
1

Most instance variables are private, so I tend to put them at the bottom because I declare members in order of decreasing visibility. If I declared them in order of increasing visibility they would be at the top, which is also reasonable.

What I don't like is having private fields followed by public fields followed by private methods. If I am developing a client class I want all the public parts together (since that is all I am interested in.)

answered 2009-09-11T15:56:57.160

Your Answer