9

While the code is growing big it is getting harder and harder to keep everything well organized. One thing I liked very much the time I developed in .NET was #region/#endregion which enabled to organize the code in logical groups and made further organization much easier.

Does anyone know whether there is any similar code organization possible in Java?

Gurfuffle
  • 784
  • 12
  • 32
Niko Gamulin
  • 66,025
  • 95
  • 221
  • 286
  • 3
    Regions are evil. I explicitly switched them off in the VS IDE. You need to think of your code and organize it so that the regions are never needed. –  Sep 29 '09 at 13:14

6 Answers6

20

This works in netbeans:

// <editor-fold defaultstate="collapsed" desc=" Region Name ">

... Enter Code Block here ...

// </editor-fold>
moinudin
  • 134,091
  • 45
  • 190
  • 216
Dweep Sharma
  • 201
  • 2
  • 2
7

That is a feature of Visual Studio, not .NET. You would have to look into your Java IDE of choice and see what options they have.

Jason Miesionczek
  • 14,268
  • 17
  • 76
  • 108
3

http://wiki.netbeans.org/FaqCustomCodeFolds

anonymous
  • 31
  • 1
2

The problem with regions is they can make files filled with thousands of lines of spaghetti code look like they are compact, clean and well organized at first glance, which they are not.

If a single file is getting unmanageable, think about how you've structured your classes and is there things you can refactor out into their own classes or methods?

I got very region happy when I started .net and now I don't think I've written one in years. They lost all value in my eyes the first time I opened a file with 5 regions, thought, "Hmm...simple enough" only to expand one and get a few thousand lines of code that made no sense whatsoever.

Nick
  • 9,113
  • 4
  • 25
  • 29
-1

No, Java doesn't have anything like that. If anything you should get a better text editor that allows for arbitrary code folding or code folding based on comments.

Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
-2

In Java, you use packages and projects to organize your code.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • 1
    I believe he was interested in orgainzing code within a single source file. I don't believe packages would be too helpful for that :) – luke Sep 29 '09 at 13:46
  • I think this is (sort of) equivalent to namespaces and projects when using Visual Studio. Regions are often even smaller than classes. – Timo Dec 04 '12 at 13:15