Page 1 of 1

hash for storing variables

PostPosted: Tue Nov 28, 2023 7:55 am
by Otto
Hello friends,
static h := {=>}


h['mycParts'] := {"date=1900-11-21", "time=16:00"}

// Correct loop syntax for iterating over the array in the hash
FOR EACH cTmp IN h['mycParts']
? cTmp
NEXT

But when I try to use
h["cTmp"] := ""

FOR EACH h["cTmp"]IN h['mycParts']
? h["cTmp"]
NEXT

I get a syntax error.

Is there a workaround?

Best regards,
Otto

Re: hash for storing variables

PostPosted: Tue Nov 28, 2023 8:28 am
by Enrico Maria Giordano
It does not make sense to me. What do you want to get?

Re: hash for storing variables

PostPosted: Tue Nov 28, 2023 8:40 am
by Otto
Enrico, I use a patcher and preprocessor for my programming.

viewtopic.php?f=3&t=42693&p=260562&hilit=hash&sid=fef71b12cde0ab87a1d9048f22a2ff63#p260562

Best regards,
Otto




ADVANTAGES OF THE PATCHER AND PREPROCESSOR SYSTEM
The Patcher and Preprocessor system allows for the integration of components with simple instructions like
$-> DATEPICKER: id = dateInput.
This offers several benefits:
Clarity and Compactness:
The code remains clear and easy to read. Reusability: The same component can be reused in different parts of a project, simplifying maintenance. Centralized Updates: Changes to the DATEPICKER component need only be made in one place.
Separation of Structure and Logic:
The structure (HTML), style (CSS), and logic (JavaScript) of components can be edited independently. Consistency: Ensures consistent use of the date input component throughout the project.
Similarities with Object-Oriented Programming
The approach shares similarities with object-oriented programming (OOP), especially regarding modularity and encapsulation. However, it lacks classical OOP elements like inheritance and polymorphism. The use of multiple levels of patchers and preprocessors for composing components resembles the OOP principle of composition. This enhances reusability and maintainability and allows for a well-structured development of complex applications. However, it is not true OOP as the focus is more on reusing code snippets rather than creating and managing objects in the OOP sense.
Conclusion
In summary, this approach offers an efficient, modular, and component-based approach to web development. It shares many advantages of object-oriented programming, although it does not encompass all aspects of OOP. Centralizing style definitions and avoiding redundancies are important to minimize conflicts and maintenance issues.

Re: hash for storing variables

PostPosted: Tue Nov 28, 2023 8:44 am
by Enrico Maria Giordano
What is the point of using h["cTmp"] as the FOR EACH variable?

Re: hash for storing variables

PostPosted: Tue Nov 28, 2023 8:47 am
by Otto
Hello Enrico,
for e.g. my code looks like this.
All the moduls are this way independent.

Best regads,
Otto

Image

Image

Re: hash for storing variables

PostPosted: Tue Nov 28, 2023 8:54 am
by Enrico Maria Giordano
I do not understand, sorry. Anyway, it still does not make sense.

Re: hash for storing variables

PostPosted: Tue Nov 28, 2023 9:08 am
by Otto
Enrico, the advantage is that you have reusable blocks here and don't have to worry about passing the variables.

It's simply the productivity that is the advantage.
It's a method to make the source code more readable and secure.

Best regards,
Otto

Re: hash for storing variables

PostPosted: Tue Nov 28, 2023 5:21 pm
by Otto
Hello friends,

Here is an example of a test program.

All these blocks are reusable in all my programs.

Best regards,
Otto


Image

Image

Image