Recent

Author Topic: Logical seperation of Units  (Read 14579 times)

motaz

  • Sr. Member
  • ****
  • Posts: 495
    • http://code.sd
Logical seperation of Units
« on: July 13, 2013, 11:15:50 am »
Lately I have used NetBeans very often in my work, and I like many features of it. One of its most important and intutive features is logical seperation and grouping of Classes, files and units in a mean of Packages.

Suppose that I'm developing a large application with my team, we need to create layers of application, for example:

  • Data Access layer
  • Processing layer
  • GUI layer

or seperation by logical modules:

  • Utilities
  • Soap Clients
  • Parsers

This helps us keep the internal untis easy to find, and you can assign any team members to specific package, and he/she can expect where to find some functionality. Also it can control the grouth of application units.

Is there any way to do this in Free Pascal / Lazarus

Note:
I have uploaded a photo of NetBeans packages sample



« Last Edit: July 13, 2013, 11:18:14 am by motaz »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12706
  • FPC developer.
Re: Logical seperation of Units
« Reply #1 on: July 13, 2013, 11:23:04 am »
1. Delphi 2009+ seem to create a nesting in the projects based on directory levels.
2. Delphi also shows packages as separate root node in the project group.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Logical seperation of Units
« Reply #2 on: July 13, 2013, 11:31:21 am »
Actually, units already form that (use dotted unit name if you want). Remember that classes are contained in units, much like java classes are contained in java packages. The only difference is that Pascal unit doesn't enforce directory structure to reflect the units' hierarchy, you may have a completely different directory structure in disk than the one in your project (actually there's another difference: Pascal class MUST reside in a unit, while Java doesn't. A default, nameless package is provided for classes not belong to any package). One advice though: don't think in Java when you code in Pascal ;)

The IDE and .lpi format currently doesn't have file grouping functionality yet, but I guess it's on development (search the bugtracker and request that if you find none).

motaz

  • Sr. Member
  • ****
  • Posts: 495
    • http://code.sd
Re: Logical seperation of Units
« Reply #3 on: July 13, 2013, 11:50:51 am »
Suppose that I have 20 classes that represent one logical group, and each Class has about 500 lines of code and is growing, did you want me to put them in only one unit and name it to that module/group, this will generate a fat unit that contains 10,000 lines of code, and this could make this unit a monster.

Quote
don't think in Java when you code in Pascal
I'm not talking about Java, but I'm talking about NetBeans, a multi-language IDE. This feature makes IDEs very productive in large scale applications.
« Last Edit: July 13, 2013, 11:53:03 am by motaz »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Logical seperation of Units
« Reply #4 on: July 13, 2013, 12:21:29 pm »
Quote
Suppose that I have 20 classes that represent one logical group, and each Class has about 500 lines of code and is growing, did you want me to put them in only one unit and name it to that module/group, this will generate a fat unit that contains 10,000 lines of code, and this could make this unit a monster.
10,000 lines is not a problem, if you don't like scrolling too much, you can use include file per class with some ifdef to switch interface and implementation like how FPC handles certain unit implementation so the unit itself only contains {$i file}, {$ifdef x}, {$define x} and {$undef x} directives.

Anyway this case is quite seldom, usually you can separate more, unless the separation criteria is somewhat too large.
Quote
I'm not talking about Java, but I'm talking about NetBeans, a multi-language IDE. This feature makes IDEs very productive in large scale applications.
You're talking in Java as well, since NetBeans only need to read the directory structure.

motaz

  • Sr. Member
  • ****
  • Posts: 495
    • http://code.sd
Re: Logical seperation of Units
« Reply #5 on: July 13, 2013, 01:04:37 pm »
10,000 lines per unit is a problem for me. Spetially that in Object Pascal Interface declaration and types should exists at the header part of the unit.
It is better for me to keep only one class per unit and use unit search (Ctrl + F12), until this feature (unit grouping) is implemented.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Logical seperation of Units
« Reply #6 on: July 13, 2013, 01:21:31 pm »
Quote
It is better for me to keep only one class per unit and use unit search (Ctrl + F12), until this feature (unit grouping) is implemented.
Feel free to do that, but I don't think the feature will ever be implemented, because it interferes with basic language feature. I suggest following the include files solution since the IDE has full support for include files and you won't feel any noticable difference.

motaz

  • Sr. Member
  • ****
  • Posts: 495
    • http://code.sd
Re: Logical seperation of Units
« Reply #7 on: July 13, 2013, 02:30:33 pm »
Quote
but I don't think the feature will ever be implemented, because it interferes with basic language feature
If the Object Pascal language restricts Lazarus from being a modern and productive IDE that means it will lead Lazarus to end of its life and becomes another Delphi death story. Flexible languages like Java will last forever.

The use of external files is not clear to me, I need an elegant solution that supports refactorying: to move Class from package to package,  to introduce new package and move classes to it, and to copy units from package to package using simple Copy and Paste method.


Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Logical seperation of Units
« Reply #8 on: July 13, 2013, 03:26:51 pm »
Quote
If the Object Pascal language restricts Lazarus from being a modern and productive IDE that means it will lead Lazarus to end of its life and becomes another Delphi death story. Flexible languages like Java will last forever.
Whatever, I've heard this yeaaaaaaaars ago and the language is still alive and growing. Just because some persons think something is not right doesn't mean it's not right.

By the way, Java popularity has decreased in recent years, if you watch the trends.
Quote
The use of external files is not clear to me
An example:
Code: [Select]
// x.pas
unit x;

interface

{$define readinterface}
{$i class1.inc}

implementation

{$undef readinterface}
{$i class1.inc}

end.
// class1.inc
{$ifdef readinterface}

type
  TClass1 = class
    procedure P;
  end;

{$else}

procedure TClass1.P;
begin
...
end;

{$endif}
you can have 1 include file per class and you can easily move between units by adding/removing the {$I} directive for the respective class.
Quote
I need an elegant solution that supports refactorying: to move Class from package to package,  to introduce new package and move classes to it, and to copy units from package to package using simple Copy and Paste method.
This is IDE functionality that you could ask/implement.

motaz

  • Sr. Member
  • ****
  • Posts: 495
    • http://code.sd
Re: Logical seperation of Units
« Reply #9 on: July 13, 2013, 04:09:06 pm »
Quote
This is IDE functionality that you could ask/implement.
Yes, that's the point, if this feature is not exist, I could use Lazarus as it is now, but I want to grantee that in the future this IDE is improved by such features that support large code while maintaing elegant program structure, then I can easily adopt it in my team work.

I don't want to say that Language X is better than Language Y, I feel that all common programming languages supports the same functionality and has the same features, but Development tools and libraries are making the difference.

I want Lazarus to become like NetBeans the best IDE that I have ever used, or at least like Eclipse, a widely and successfull IDE.

If I get the tree of units in the editor the same way they are located in folders, it will be enough for me, and we can consider folder name as package name




JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4689
  • I like bugs.
Re: Logical seperation of Units
« Reply #10 on: July 13, 2013, 04:25:54 pm »
It is better for me to keep only one class per unit and use unit search (Ctrl + F12), until this feature (unit grouping) is implemented.

Lazarus project inspector already supports grouping units by directories. There is a toggle button "Show directory hierarchy".

Another issue which you didn't mention yet is that you cannot always put one class per unit because of circular reference restriction.
At first it sound like a serious thing but actually it can be beneficial for the code quality.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

motaz

  • Sr. Member
  • ****
  • Posts: 495
    • http://code.sd
Re: Logical seperation of Units
« Reply #11 on: July 13, 2013, 04:44:30 pm »
Juha I can't find the toggle button "Show directory hierarchy"

motaz

  • Sr. Member
  • ****
  • Posts: 495
    • http://code.sd
Re: Logical seperation of Units
« Reply #12 on: July 13, 2013, 05:02:41 pm »
That's a very nice feature, and I have do refactoring by open Units and click Save As in directories, and it goes just fine. look at the attachement
Thanks to Leledumbo and Juha

In the future I hope that "Show directory heirarchy" becomes the default option, because if you close Lazarus and open it again it shows all units without directories
« Last Edit: July 13, 2013, 05:06:18 pm by motaz »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12706
  • FPC developer.
Re: Logical seperation of Units
« Reply #13 on: July 13, 2013, 05:21:23 pm »
Quote
but I don't think the feature will ever be implemented, because it interferes with basic language feature
If the Object Pascal language restricts Lazarus from being a modern and productive IDE that means it will lead Lazarus to end of its life and becomes another Delphi death story. Flexible languages like Java will last forever.

Since Java is so flexible, I assume you can arrange classes in anyway in your project irrespective of the package hierarchy? Can you keep classes in the same package but in different classpaths  trees separate?
When I worked (with JBuilder and Visual Cafe), I thought that was annoying.

Besides that, I don't think Java is the pinnacle of perfection and flexibility. It is rigid, very rigid.

motaz

  • Sr. Member
  • ****
  • Posts: 495
    • http://code.sd
Re: Logical seperation of Units
« Reply #14 on: July 13, 2013, 05:35:45 pm »
NetBeans and Java flexibility supported by refactorying, it is exist everywhere in the editor.

I use only one level of Package tree. Another NetBeans good feature is that it adds import (uses) automatically if you type a class that is not exist in import section, it is a simple but powerfull feature that we are using all the time in NetBeans.

As I have saied before, it is not about Java, it is about IDE, NetBeans, I think Java is the same language since JBuilder and Visual Cafee days, but NetBeans and Eclipse are something different.

I don't want Object Pascal to become like Java, to work in a virtual machine and consumes memory, but I need Lazarus to become a rich ide, docked, source control support, and rich refactorying tool that is suitable for today's needs of software development.

I'm using Java for back end development: web services and web applications, but for client and desktop application I'm using Lazarus, and when I came back to Lazarus I miss that features that I have mentioned above.

 

TinyPortal © 2005-2018