Recent

Author Topic: PartialUnit  (Read 12418 times)

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: Split Unit
« Reply #45 on: March 18, 2020, 11:52:19 pm »
There were a lot of advantages in Modula-2.

I miss the endif, endfor .... This helps you realy at the end of a long procedure through the Pascal end Jungle.

Just in case (experienced programmers, please I know you know that), first things first. Normally if my code has more than 3 levels of indentation (except for tries), then I know I have to split the code in methods/functions. Also if the code is way too big for a function maybe I'm doing too much in the same place and again I know I have to split things up.
But sometimes split things is not an option. When this happens, in my case an "endfor", "endif", or an "endwhatsoever" is not enough. To tackle that I heavily use code templates like this one (I have a lot to create "for", "repeat" and "while"):
Code: Pascal  [Select][+][-]
  1. for $param(ind) := Low($param(SomeArray)) to High($param(SomeArray,sync=2)) do begin
  2.    |
  3. end; //<---  for $param(ind,sync=1)  ( array $param(SomeArray,sync=2)) //
  4.  
and even have one like thiis to paste whatever i have on the clipboard at the end of something:
Code: Pascal  [Select][+][-]
  1.  {<--- $Paste() }|    
  2.  

it helps me a lot to navigate my code.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Split Unit
« Reply #46 on: March 19, 2020, 12:29:40 am »
Hi!

I do it the simpler way since I returned from Modula2 to Pascal:

Whenever I write a "begin" I add at once after the "end" the reason.
So the last lines of a procedure look like:

     end; // if <> transparent
  end; // for x
 end; // for y
end; // proc

If the IDE could do that for me it would be helpful.

Winni

Otto

  • Full Member
  • ***
  • Posts: 226
Re: Split Unit
« Reply #47 on: March 19, 2020, 07:34:28 am »
Hi winni.

Hi!

I do it the simpler way since I returned from Modula2 to Pascal:

Whenever I write a "begin" I add at once after the "end" the reason.
So the last lines of a procedure look like:

     end; // if <> transparent
  end; // for x
 end; // for y
end; // proc

If the IDE could do that for me it would be helpful.

Winni

That's exactly what I proposed in the previous post.
Perhaps it is achievable through a change in the "Jedi Code Format". I used this feature to troubleshoot conversions from other software.

Otto.
Kind regards.

soerensen3

  • Full Member
  • ***
  • Posts: 213
Re: Split Unit
« Reply #48 on: March 19, 2020, 09:40:32 am »
Also there is the outline feature if you use Lazarus: https://wiki.freepascal.org/Lazarus_IDE_Tools#Outline
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

soerensen3

  • Full Member
  • ***
  • Posts: 213
Re: Split Unit
« Reply #49 on: March 19, 2020, 09:46:07 am »
@soerensen3
Hi.
Your code is definitely interesting, unfortunately I have not yet managed to compile it. I think I'm missing a few packages.

Otto.
It only uses the Codetools package. I use trunk, maybe that's the difference. Do you get an error?
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Split Unit
« Reply #50 on: March 19, 2020, 10:12:38 am »
Also there is the outline feature if you use Lazarus: https://wiki.freepascal.org/Lazarus_IDE_Tools#Outline
+1
This feature was a bit distracting in the beginning because of the many colors. But once I got used to it, I use it every day. It makes finding the position of a missing "end" extremely easy.

Otto

  • Full Member
  • ***
  • Posts: 226
Re: Split Unit
« Reply #51 on: March 19, 2020, 10:23:49 am »
Hello everyone

I also always use outline features, but sometimes they are not enough.

@soerensen3
I got an error while compiling, I will send you a message with details as soon as possible.
Unfortunately these days I had little time to investigate the cause of the problem, I only tried to compile on Windows 10 64bit In Lazarus-Trunk, FPC 3.0.4 and 3.3.1. Coming soon I will update FPC and I will also try it on Linux (usually I use Manjaro Linux).

Otto.
« Last Edit: March 19, 2020, 01:25:25 pm by Otto »
Kind regards.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: Split Unit
« Reply #52 on: March 19, 2020, 10:36:20 am »
I will respond in separate posts to reduce the risk of confusion.

@mercurhyo
Thank you mercurhyo.
That is exactly what I was referring to.
This "SMARTLINK" feature should certainly be used to implement the theoretical concept of PartialUnits. In essence, the idea of PartialUnits would be nothing more than the concept of "Divide et impera" applied to a single Unit while always maintaining an OOP-type approach.

I would have a question:
What is the "MyUnit.thisfunction;" syntax used by Delphi called? Looks a lot like the syntax that is used in C# (.Net in geneneral) to access the sub-Classes.

Unfortunately, at the moment, SMARTLINK only works on applications (standalone executables) it does not work on libraries that you create. it's explained somewhere on the wiki, and it is due to compiler limitations (the compiler do not work with an artificial intellig. neuronal). SO it is stable!!! and SAFE!

Ehm... smartlinking also works for libraries. Everything that is exported from a library is considered "referenced" (just like an executable's entry point is considered "referenced") and everything that is referenced by a "referenced" function is considered "referenced" as well, thus it's in your hand what gets linked in.

.... maybe one day, with dynamic packages instead of static, let say, around 2030

Dynamic packages will solve nothing there. In that regard they are even worse, because all interface-sections of all units are considered exported and thus "used". A package will contain all code for its contained units (except private functions that are not used). The main advantage here is that packages can be used by multiple applications and thus the required storage space in total can be reduced. For only one application the required space will be larger however (see also this mail where I demonstrated the sizes).

mercurhyo

  • Full Member
  • ***
  • Posts: 242
Re: Split Unit
« Reply #53 on: March 19, 2020, 11:01:22 am »

Ehm... smartlinking also works for libraries. Everything that is exported from a library is considered "referenced" (just like an executable's entry point is considered "referenced") and everything that is referenced by a "referenced" function is considered "referenced" as well, thus it's in your hand what gets linked in.

rhaaaa DEF NO!

what would happen if one of the caller executableS run some code in a Lib that the SmartLinker have eliminated. Feel free to buy a brain, friend, or search into the wiki... as i said , it is explained somewhere on it
« Last Edit: March 19, 2020, 11:03:03 am by mercurhyo »
DEO MERCHVRIO - Linux, Win10pro - Ryzen9XT 24threads + Geforce Rtx 3080SUPRIM
god of financial gain, commerce, eloquence (and thus poetry), messages, communication (including divination), travelers, boundaries, luck, trickery and thieves; he also serves as the guide of souls to the underworld

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11459
  • FPC developer.
Re: Split Unit
« Reply #54 on: March 19, 2020, 11:07:28 am »
Also there is the outline feature if you use Lazarus: https://wiki.freepascal.org/Lazarus_IDE_Tools#Outline
+1
This feature was a bit distracting in the beginning because of the many colors. But once I got used to it, I use it every day. It makes finding the position of a missing "end" extremely easy.

I had to do some minor verilog work to customize a (FPGA based) device, which was a 20 level nested if. Verilog uses keywords similar to Pascal. Martin helped me configuring outline, and then I hacked the IDE so it the verilog code was colored, which was a great help.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11459
  • FPC developer.
Re: Split Unit
« Reply #55 on: March 19, 2020, 11:08:30 am »

Ehm... smartlinking also works for libraries. Everything that is exported from a library is considered "referenced" (just like an executable's entry point is considered "referenced") and everything that is referenced by a "referenced" function is considered "referenced" as well, thus it's in your hand what gets linked in.

rhaaaa DEF NO!

what would happen if one of the caller executableS run some code in a Lib that the SmartLinker have eliminated. Feel free to buy a brain, friend, or search into the wiki... as i said , it is explained somewhere on it

It can only call exported functions, and those are linked in as PascalDragon says.

mercurhyo

  • Full Member
  • ***
  • Posts: 242
Re: Split Unit
« Reply #56 on: March 19, 2020, 11:13:16 am »
@Marcov

I thrust better the wiki than any forum. It awlays brought me luck and I spared a lot of time this way.

So if the wiki is wrong, someone have to correct it.
DEO MERCHVRIO - Linux, Win10pro - Ryzen9XT 24threads + Geforce Rtx 3080SUPRIM
god of financial gain, commerce, eloquence (and thus poetry), messages, communication (including divination), travelers, boundaries, luck, trickery and thieves; he also serves as the guide of souls to the underworld

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: Split Unit
« Reply #57 on: March 19, 2020, 03:48:22 pm »

Ehm... smartlinking also works for libraries. Everything that is exported from a library is considered "referenced" (just like an executable's entry point is considered "referenced") and everything that is referenced by a "referenced" function is considered "referenced" as well, thus it's in your hand what gets linked in.

rhaaaa DEF NO!

what would happen if one of the caller executableS run some code in a Lib that the SmartLinker have eliminated.

You are aware that I'm one of the compiler developers? That I'm also the one developing FPC's dynamic package implementation? Thus I do know what I'm talking about. This is how smartlinking works: an executable (or another library) can only call functions of a library that are exported from said library (this is ensured by the operating system). For smartlinking the linker simply needs to build the transitive hull of all function and data that is accessed from the exported functions (and transitive means that if function A references function B and B in turn references function C that means that A also references C). Anything else can not be accessed by outside code. This is the same approach that is used for executables.

Feel free to buy a brain, friend, or search into the wiki... as i said , it is explained somewhere on it

The wiki can be edited by anyone so that information needs to be taken with a grain of salt.

dsiders

  • Hero Member
  • *****
  • Posts: 1084
Re: Split Unit
« Reply #58 on: March 19, 2020, 04:03:18 pm »
rhaaaa DEF NO!

what would happen if one of the caller executableS run some code in a Lib that the SmartLinker have eliminated. Feel free to buy a brain, friend, or search into the wiki... as i said , it is explained somewhere on it

For the want of a "Bozo" filter another forum is stained... <sigh>

Or at least be more selective about who you engage in a pissing contest.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

Otto

  • Full Member
  • ***
  • Posts: 226
Re: Split Unit
« Reply #59 on: March 19, 2020, 06:29:53 pm »
I really hope not, especially now that the conversation had taken the right direction.

After all, I think mercurhyo was joking or that in his home area his was an idiomatic phrase.

For example, in Italian to wish good luck it is often said "In bocca al lupo!" (→"Good luck!") that saying in full would be “Vorrei che tu finissi in bocca al lupo!” that literally translated would "I wish you'd end up in the wolf's mouth!" with an obvious different meaning.

Otto.
Kind regards.

 

TinyPortal © 2005-2018