fesch / Structorizer.Desktop

Structorizer is a little tool which you can use to create Nassi-Schneiderman Diagrams (NSD).
https://structorizer.fisch.lu
GNU General Public License v3.0
65 stars 20 forks source link

Perl and PHP generators do not cope with constant definitions #1156

Closed codemanyak closed 7 months ago

codemanyak commented 7 months ago
codemanyak commented 7 months ago

PHP export doesn't handle typed constants correctly, either:

grafik

This falls into the same category as the first of the two aspects for Perl export and can be fixed together with it.

codemanyak commented 7 months ago

W.r.t. the handling of constants on Perl export in general: There is a Perl pragma to specify constants via use constant. This would look like this for the example above:

use constant PI => 4 * atan(1);

This pragma has several drawbacks, though:

  1. Scope is always the package namespace.
  2. This is only applicable if the value of the constant may be computed at compile time.
  3. Constants defined this way are actually hidden functions and follow different syntactic paradigms than variables: They must not be prefixed by $ (if they are scalar) or @ (if they refer to lists/arrays) and they will not be interpolated to strings (expanded within string literals). This would have to be considered on transforming the diagram content and makes it significantly more complex.

It is utterly difficult for the generator to decide the second point, i.e., whether the expression could be computed by the Perl compiler in advance. From syntax alone it is impossible. A built-in function like atan or atan2 can hardly be distinguished from a user-defined function that is simply just not available in Arranger on export.

codemanyak commented 7 months ago

Second aspect was fixed according to https://github.com/fesch/Structorizer.Desktop/issues/1156#issuecomment-2032501779 by introducing a new Perl-specific export option: grafik

By activating it, the code will look as in the following example:

grafik

Without the option, the result will be:

grafik