Recent

Author Topic: How to solve this coding problem?  (Read 3355 times)

sysrpl

  • Sr. Member
  • ****
  • Posts: 315
    • Get Lazarus
How to solve this coding problem?
« on: April 15, 2018, 07:17:49 pm »
So I am writing a tool to share with the community and found a problem with using Lazarus and packages. I hope someone has an answer to this.

The problem is that when you are using packages, often there is no practical way to find the methods and properties even if you have the source code.

Here is an example of the problem:

https://cache.getlazarus.org/videos/code-tools-problem.mp4

Whats happening here is there is a VERY deep hierarchy of inherited classes, there is no documentation, and the IDE provides no tool or way to view the methods and properties of a type, except for what's actually declared on the class.

This makes it near impossible to effectively make use of many things unless you are the original author and know the methods and proeprties of the entire hierarchy by memorization.

What we need is a tool window in the IDE that shows you a list of all classes/interfaces/types/vars/consts in the packages loaded in a project, and selecting said class/interface shows you all its methods and properties. Both the methods and properties on the class, and also inherited methods and properties in one single list, all the way down to TObject/IInterface. This would be without the need to open the inherited class or method to view them separately. It needs to be a single list, otherwise your chasing a bunch of different windows/tree nodes just to figure things out.

So, we should be able to view these methods and properties in a single window that isn't a hint window. We need window that can stay open for browsing. A window hopefully with the ability to be docked so it can be used as a reference or guide to use other objects while writing code. PRefereably somethhing that also shows you additional information like method parameters along side visibility and virtual or static modifiers.

We need something like this, which Delphi 3+ had:

https://cache.getlazarus.org/images/object-browser.gif

Let me know your thoughts. Thanks.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: How to solve this coding problem?
« Reply #1 on: April 15, 2018, 09:50:39 pm »
Generally I use the Help file which I can click my way all the way back to the start.

But I guess a off the side tool could be written.

the IDE is getting kind of fat as it is, hard on the compiler etc..

Something to think about I guess.
The only true wisdom is knowing you know nothing

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to solve this coding problem?
« Reply #2 on: April 15, 2018, 09:56:21 pm »
as far as I know there is no object browser in fpc/lazarus. I usually find the object I'm interested in, with various searching methods including help files, internet, grep and after I found it I declare it as variable in a dummy procedure and invoke the auto completion drop down list to see its properties and methods. Once I find an interesting method/property i simply ctrl+Click on it and it will take me to its declaration and so on and so forth.

Now I'm a bit confused are you looking for the object browser to help right your tool or you writing an object browser?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

sysrpl

  • Sr. Member
  • ****
  • Posts: 315
    • Get Lazarus
Re: How to solve this coding problem?
« Reply #3 on: April 15, 2018, 10:34:29 pm »
If you watch the video you'll see an example fo what I was looking for: The methods/properties of TCodeTool.

To jamie: This class is not in the help. It's part of a package used by the IDE, and those types of files are not in the help files, so that is not an option.

To tazz: I am writing a control, but wanted to add some features that require CodeTools to make its use a bit easier. In this case the class hierarchy of TCodeTool is VERY deep (as shown in the video), and opening a file to examine it isn't really going to help much. Your going to need probably 10 files to find all the methods, and they span off the screen in 7 of them. There is no clear place to see them all in one place.

But in general, this is a problem. For any moderately complex class or interface outside the scope of the RTL, FCL, and LCL it's currently not practical to start learning how to use such code unless you are the original author or a guide has been written.

What should be possible, with a tool like an object browser, is that anyone could browse through classes, and other code, and see all their methods, properties, and inherited members without chasing through multiple files. This would give the user a much greater head start on understanding how something works.

Try it yourself. Start a new project, add CodeTools (or IDEIntf, or chrome Cef, anything complex really) to the requirements, and try to figure out what's going on. Same thing goes with just about any package of moderate complexity that isn't part of the LCL.

For anyone that wanders outside of the LCL, we need some tool like I mentioned.
« Last Edit: April 15, 2018, 10:45:53 pm by sysrpl »

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: How to solve this coding problem?
« Reply #4 on: April 15, 2018, 11:04:36 pm »
What does not suit in the Code Browser?

sysrpl

  • Sr. Member
  • ****
  • Posts: 315
    • Get Lazarus
Re: How to solve this coding problem?
« Reply #5 on: April 15, 2018, 11:30:44 pm »
It only shows code per unit. It does not show inherited members. There is no relationship between a class or interface and its decedents. You have to click on nodes, expand them, then scroll through.

How it should work is you see all classes with their inheritance across in all units, you click a class and you see all members, be they on the class or inherited. You should can see the protection level and virtual nature of all methods.

What the tool code browser is doing is just like opening a file, except in tree view form. In the case I've outline you're still stuck trying to switch between 10 different nodes to find the methods on one class. Also you can't see derived/inherited types.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to solve this coding problem?
« Reply #6 on: April 15, 2018, 11:47:09 pm »
If you watch the video you'll see an example fo what I was looking for: The methods/properties of TCodeTool.

To jamie: This class is not in the help. It's part of a package used by the IDE, and those types of files are not in the help files, so that is not an option.

To tazz: I am writing a control, but wanted to add some features that require CodeTools to make its use a bit easier. In this case the class hierarchy of TCodeTool is VERY deep (as shown in the video), and opening a file to examine it isn't really going to help much. Your going to need probably 10 files to find all the methods, and they span off the screen in 7 of them. There is no clear place to see them all in one place.

But in general, this is a problem. For any moderately complex class or interface outside the scope of the RTL, FCL, and LCL it's currently not practical to start learning how to use such code unless you are the original author or a guide has been written.

What should be possible, with a tool like an object browser, is that anyone could browse through classes, and other code, and see all their methods, properties, and inherited members without chasing through multiple files. This would give the user a much greater head start on understanding how something works.

Try it yourself. Start a new project, add CodeTools (or IDEIntf, or chrome Cef, anything complex really) to the requirements, and try to figure out what's going on. Same thing goes with just about any package of moderate complexity that isn't part of the LCL.

For anyone that wanders outside of the LCL, we need some tool like I mentioned.
I understand, but as far as I know there is nothing ready you can use. You can try to use a UML tool to reverse the units in it until your tool is ready, I can't think of anything else at this time.

EDIT:
One last idea, in similar situations I opt to use a mindmap application (portable blumind on windows), attaching property and method names and of course ancestors, but I'm only doing that on libraries that I need to work on change or extend them, to get a birds eye view of the project. In most other cases I simple use the autocomplete and ctrl+click to see what is where if everything else fails I usually end up asking in here where to find what.

Sorry, I can't be of more help.
« Last Edit: April 15, 2018, 11:54:50 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

sysrpl

  • Sr. Member
  • ****
  • Posts: 315
    • Get Lazarus
Re: How to solve this coding problem?
« Reply #7 on: April 16, 2018, 12:46:47 am »
tazz, I've already started writing an object browser like tool that integrates into Lazarus and the current CodeToolsBoss instance. It's rough going because of many many different inherited classes the CodeTools package has, but as I progress with development on the tool, I can use it to better view said classes.

Hopefully at some point someone with has expertise in CodeTools can offer me advice on how it could be better implemented.

 

TinyPortal © 2005-2018