July 7, 2008
Jeff Atwood complains with the use of hidden code regions. I fully agree. I use Delphi!
Jeff Atwood of Coding Horror fame complains with the use of hidden code regions: "The Problems with Code Folding". I fully agree. Using regions for hiding tens of lines of "not-so-great" code is not an approach I like. Inheritance is better than code generation. Better "componentization" can help reducing the actual code in your very own program. Truly, Delphi "hides" the form configuration in a separate DFM file, but this is quite different from long database-oriented code generation used in .NET.
For those who dislike regions, Delphi is a good choice!
posted by
marcocantu @ 6:11PM | 11 Comments
[0 Pending]
11 Comments
Delphi is Regions Free
Delphi *isnt* 'free' of #regions. The feature is there
for those that choose to abuse it ;-)
{$region 'My stuff'}
var i:integer;
{$endregion}
I agree with you and Jeff that they're not a good idea
in practice....
Comment by Roddy on July 7, 19:47
Delphi is Regions Free
You know Delphi has something like:
{$REGION 'Ugly code inside - don't look you have been
warned I really mean it'}
On Error Resume Next
{$ENDREGION}
Comment by Daniel Lehmann
[http://www.visionarytools.com]
on July 7, 20:10
Delphi is Regions Free
I agree, even if the structure of delphi code is
more reader oriented than other languages. Delphi
uses Interface section and Implementation sections
just to evidence the structure of the code. Regarding
DFM files I think It is a better choice than Partial
Class! Region can be use for long procedures body and
could be automatic following coding indentation.
Comment by bertoncini luca
[http://sviluppoesviluppi.blogspoot.com]
on July 7, 21:41
Delphi is Regions Free
I find that regions can be great to breaking code
apart in to conceptual sections.
Yes, most of the time I favour sub procedures, but
sometimes it makes the code easier to maintain if you
keep it as a cohesive whole, particularilly code that
drives those sub-procedures.
<setup region>
<work region>
<cleanup region>
Works pretty nicely in that scenario.
Could also be useful for grouping procedures by
task...
<ui procedures region>
<data processing procedures region>
that sort of thing.
Regions can be useful. Using them to hide
implementation issues, like how a form is designed,
is less so. Microsoft agreed, which is why they have
partial files now.
Comment by Xepol on July 7, 22:25
Delphi is Regions Free
My Delphi code is not region free.
{$REGION 'xxx'}
.. code
{$ENDREGION}
I mainly use regions in the INTERFACE area of large
files.
I think there is a lot of information about code that
is hard to comprehensibly describe using only
comments. Here regions can sometimes help
* Describe which methods are used in a specific thread
* If a field/method is threadsafe
* Method belongs to a specific interface or group of
functionality.
* Take focus away from less important aspects (like
small internal private helper functions)
Even better would be to be able to highlight code
with a color pen (like in MS Word).
Comment by Martin Liesén on July 8, 01:20
Delphi is Regions Free
What I find truly bizarre is the fact that regions
have to be explicit, when the language already
contains blocks that form nice regions automatically.
SOME of these are foldable automatically (class
declaration, interface/implementation section, entire
procedure bodies etc) but why not others?
Visibility sections in a class, for example (fold
Private, but not Public declarations), loop bodys,
case and if statements, var declarations.... all of
these things that form well defined blocks in the code
should be foldable.
But then I "grew up" on SQLWindows, where an
application was a highly foldable outline down to a
very fine degree.
:D
Comment by Jolyon Smith
[http://www.deltics.co.nz]
on July 8, 02:32
Delphi is Regions Free
I find Regions one of the better features introduced
since D7.
I use regions like comments, with the advantage of
being able to define up to where the comment applies.
Most annoyingly, in Delphi, regions jump open at the
slightest provocation! That should be fixed.
Delphi supports local functions, a feature I have
always used whenever a "closed concept" needs doing
but which never gets used anywhere else (in other
words, I'm not interested in the details). But in C#,
local functions are not possible, so there I use
regions copiously.
Comment by delfi phan on July 8, 13:20
Delphi is Regions Free
I love the concept of regions. Especially if you have
a large file, being able to hide part of the (done)
code is great. However, the support for working with
regions in Delphi and in Visual Studio is so poor
that it's a nuisance at present time.
There is no problem in having a lot of code in one
file (sometimes you even need to have it there). But
having all the code all of the time to work through
makes that hard. If you could only show pieces of the
code that are relevant to you at a certain time, that
would make life a lot easier.
Comment by Bart Roozendaal
[http://blogs.sevensteps.com]
on July 8, 15:33
Delphi is Regions Free
I sometimes use regions in Delphi for
compiler-generated XML documentation, and I've written
an IDE extension to hide/show them all with a
keystroke (I usually don't want to see them in the
editor).
http://cc.codegear.com/Item.aspx?id=23955
Comment by TOndrej
[http://tondrej.blogspot.com]
on July 9, 08:37
Delphi is Regions Free
Reading comments from the CODING HORROR's article make
me think whether is possible or not to write a plug-in
for delphi IDE that can automatically offer a fold up
to the unstructured and messy code!!!
Comment by ahmoy on July 9, 14:09
Delphi is Regions Free
In my honest opinion, Regions most useful purpose is
in restructuring excessive code before object-
orienting it properly (encapsulation, inheritance &
polymorphism). If your code is so large or unreadable
that you need regions to describe it and fold it into
readable sections, then you probably need to refactor
your code so it is a bit more maintainable.
Comment by Rahlforge on December 18, 21:09
Post Your Comment
Click
here for posting
your feedback to this blog.
There are currently 0 pending (unapproved) messages.