Recent

Author Topic: IDE - sort my methods - who does it for years?  (Read 694 times)

Nicole

  • Hero Member
  • *****
  • Posts: 972
IDE - sort my methods - who does it for years?
« on: July 16, 2022, 10:09:05 am »
I am greatful for any hint or trick how to write code quickly and to work on with in after one year has passed and understand what you have done one year before.

Is there a smart way to sort the methods in the source?
(not just copy and paste)

e.g. I like to have the create, destroy, onentry... at the top of the code
And all those RichMemo formatting things, shall be one by one in a row.
I prefer to have the same line what some method does in the declaration and implementation.

Do I have to copy these all by hand?
Or are there tools / hotkeys / tricks for code sort and comment?

And: What is the quickest way to write a new method?
At the moment I do it by hand: Copy the method before, delete the class name, copy it in the implemenation den initizialisation part  :-\ :-\

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: IDE - sort my methods - who does it for years?
« Reply #1 on: July 16, 2022, 04:03:00 pm »
And: What is the quickest way to write a new method?
At the moment I do it by hand: Copy the method before, delete the class name, copy it in the implemenation den initizialisation part  :-\ :-\

Declare the method in the class (name, parameters and everything), then do Ctrl + Shift + C and Lazarus will create the method source for you. This also works if you have multiple methods for which the source is missing. And also if you want to rename a parameter or change its type. And also if you want to rename a method. :)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9908
  • Debugger - SynEdit - and more
    • wiki
Re: IDE - sort my methods - who does it for years?
« Reply #2 on: July 16, 2022, 04:34:03 pm »
I am greatful for any hint or trick how to write code quickly and to work on with in after one year has passed and understand what you have done one year before.
Naming...

Once you wrote a function (or a bigger part of it), go through all variables, and give them meaningful names.
A single loop "for i :=" is fine, 3 or 4 loops with i,j,k,l => not so much. Depending an what they are you could have SourceIdx, TargetIdx, FirstNameIdx, ....

Selecting the entire function, and using "syncro edit" ( https://wiki.lazarus.freepascal.org/New_IDE_features_since#Syncron-Edit ) is a quick way to do that.

Of course good naming goes for function names too.
Also functions are not just for code that is used from more than one location. You can pack code into functions to give it a name, and make the remaining code more readable. (smaller body for loops or if/then)

Quote
Is there a smart way to sort the methods in the source?
(not just copy and paste)

Not really... Though...

1) There are option in which order auto-creation will initially place them.
Tools > Options > Codetools > Class completion

2) If needs must, fold all code to the correct level (so you only see procedures). But then its copy and paste from there.

Wouldn't spend to much time on it though.


Quote
And: What is the quickest way to write a new method?
At the moment I do it by hand: Copy the method before, delete the class name, copy it in the implemenation den initizialisation part  :-\ :-\

https://wiki.lazarus.freepascal.org/Lazarus_IDE_Tools#Class_Completion

And I do recommend to read the entire page.

 

TinyPortal © 2005-2018