best practice for structure of code
Douglas Ivers <[email protected]>
| Newsgroups | gmane.org.user-groups.trijug.juglist |
|---|---|
| Message-ID | <[email protected]> |
If I need to execute a section of code more than once (not in a loop),
then I of course create a named method so that I don't have multiple
copies of the code. On the other hand, I sometimes create methods
that exist solely for readability and are only called once, see below
for example. Is there any drawback to this style of code? Are there
differences in opinion, or is there a widely accepted best practice?
public void init() {
parseConfigFile()
loadImages()
loadData()
buildGui()
}
This often leads to class fields that could otherwise be local
variables, which I see as a slight drawback.
I've also experimented with unnecessary braces to improve readability,
but I suspect this is very unconventional. For example,
public void init() {
{ // parse config file
foo
bar
etc
}
{ // load images
foo
bar
etc
}
...
Of course any variables defined within the braces are not visible
outside the braces and working around that can reduce the readability
somewhat.