Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Segment.H
Message
From
08/07/2021 04:56:33
Lutz Scheffler (Online)
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
 
 
To
08/07/2021 04:49:40
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
01681722
Message ID:
01681741
Views:
36
>>>This a Header file to add a set of commands to the VFP code base. It does not alter VFP in any way. It only provides a little bit better readability to the source code.
>>>
>>>I created it because in several places in my code I was using DO WHILE loops to provide a means to exit a code blocks. By defining these SEGMENT statements, the was easier for me to follow. I realize it probably violates some practical code design, but it does help keep the code readable.
>>>Copy and Paste the code to a file called Segment.H.
>>>
>>>
>>>* Program:     SEGMENT.H
>>>* Description: VFP Language Extension - Segment Blocks
>>>* Created:     05/19/2019 08:07:03 EST
>>>* Developer:   Gregory Lynn Reichert  (GregReichert70@GMail.com) - UT #046387
>>>* Compiler:    Visual FoxPro 09.00.0000.7423 for Windows
>>>* Abstract:
>>>* Copyright:   Copyright (c) 2019 GLR Software
>>>*============================================================
>>>*--- Description --------------------------------------------
>>>*  FOR BETTER CODE READABILITY ONLY.
>>>*  Creates a looping structures using a plain DO WHILE .T. / ENDDO.
>>>*
>>>*--- Maintenance --------------------------------------------
>>>* Id Date         By      Description
>>>*  1 05/19/2019   GLR     Initial Creation
>>>*  2 11/20/2019   GLR     Added Tokens to fdkeywrd.dbf, and distibuted to all folder locations.
>>>*  3 07/07/2021   GLR     Corrected the updating the Beautify utility use indent the SEGMENT blocks.
>>>*
>>>*--- Rules --------------------------------------------------
>>>*  - Follows the basic rules that apply to the DO WHILE / ENDDO commands.
>>>*  - BEGIN_SEGMENT must have a END_SEGMENT.
>>>*  - Any text following a SEGMENT command are ignored.  The only exception is the BEGIN_SEGMENT; An .AND.<condition> can be added to extend the loop condition.
>>>*        ( I use quote a string to help identify the Segment block. )
>>>*
>>>*--- History ------------------------------------------------
>>>*--- ToDo ---------------------------------------------------
>>>*------------------------------------------------------------
>>>*    Granting permission to write to the VFP folder.
>>>*    1.  I selected the "C:\Program Files (x86)\Microsoft Visual FoxPro 9\" folder in the File Manager.
>>>*    2.  Right-clicked the folder, and selected the "Properties".
>>>*    3.  Selected the "Security" tab at the top.
>>>*    4.  Clicked the "Edit..." button to open the "Security" dialog.
>>>*    5.  In the "Group or user names:" listbox, selected the "users (SNOOPY\Users)" item.   (computer name may vary on your machine.)
>>>*    6.  In the "Permission for Users" listbox, checked the "Full Control" checkbox.
>>>*    7.  Clicked the "Apply" button.  A moment later...
>>>*    8.  Clicked the "Ok" button to exit the "Security" dialog.
>>>*    9.  Clicked the "Ok" button to close the "Properties" dialog.
>>>*    10. Now the VFP folder has the permission to be writen to.
>>>*
>>>*------------------------------------------------------------
>>>*** Update the tables used by the Beautify.app and Documentation Wizard.
>>>*
>>>* Original Copies of the DBF are located in:
>>>*    HOME()
>>>*    HOME()\Tools\Analyzer
>>>*    HOME()\Tools\xsource\VFPSource\Wizards\wzfoxdoc
>>>*    HOME()\Wizards
>>>#IF .F.
>>>    * After establishing write permission to the VFP folder. Run this code.
>>>    CLOSE ALL
>>>    SELECT * FROM (HOME()+"tools\analyzer\fdKeywrd.dbf") WHERE Token="Begin_Segment" INTO ARRAY aSegement
>>>    IF _TALLY=0
>>>        INSERT INTO (HOME()+"tools\analyzer\fdKeywrd.dbf") (Token, CODE) VALUES ("Begin_Segment","I")
>>>        INSERT INTO (HOME()+"tools\analyzer\fdKeywrd.dbf") (Token, CODE) VALUES ("End_Segment","U")
>>>    ENDIF
>>>    SELECT * FROM (HOME()+"wizards\fdKeywrd.dbf") WHERE Token="Begin_Segment" INTO ARRAY aSegement
>>>    IF _TALLY=0
>>>        INSERT INTO (HOME()+"wizards\fdKeywrd.dbf") (Token, CODE) VALUES ("Begin_Segment","I")
>>>        INSERT INTO (HOME()+"wizards\fdKeywrd.dbf") (Token, CODE) VALUES ("End_Segment","U")
>>>    ENDIF
>>>
>>>    SELECT * FROM (HOME()+"Tools\xsource\VFPSource\Wizards\wzfoxdoc\fdindent.dbf") WHERE Token="Begin_Segment" INTO ARRAY aSegement
>>>    IF _TALLY=0
>>>        INSERT INTO (HOME()+"Tools\xsource\VFPSource\Wizards\wzfoxdoc\fdindent.dbf") (Token, CODE) VALUES ("BEGIN_SEGMENT","I")
>>>        INSERT INTO (HOME()+"Tools\xsource\VFPSource\Wizards\wzfoxdoc\fdindent.dbf") (Token, CODE) VALUES ("END_SEGMENT","U")
>>>    ENDIF
>>>    CLOSE ALL
>>>#ENDIF
>>>
>>>*--- Examples -----------------------------------------------
>>>#IF .F.
>>>    ASSERT .F.
>>>    opt = 1
>>>    BEGIN_SEGMENT "Test"
>>>        DO CASE
>>>        CASE opt=1
>>>            opt = 3
>>>            CONTINUE_SEGMENT "Test"        && jump to '* do something' line.
>>>        CASE opt=2
>>>            EXIT_SEGMENT "Test"            && exit segment block
>>>        CASE opt=3
>>>            opt = 2
>>>            REPEAT_SEGMENT "Test"          && jump to start of segment
>>>        ENDCASE
>>>        * do something
>>>        BEGIN_SEGMENT "something"
>>>            * do more
>>>            EXIT_SEGMENT "something"
>>>        END_SEGMENT "something"
>>>    END_SEGMENT "Test"
>>>#ENDIF
>>>*------------------------------------------------------------
>>>* Directives Code Keywords.
>>>
>>>#DEFINE BEGIN_SEGMENT            DO WHILE .T.
>>>#DEFINE CONTINUE_SEGMENT    * CONTINUE Segment
>>>#DEFINE EXIT_SEGMENT               EXIT
>>>#DEFINE REPEAT_SEGMENT          LOOP
>>>#DEFINE END_SEGMENT                ENDDO
>>>
>>>*
>>>* EOF SEGMENT.H
>>>*
>>>
>>>
>>>"Let the flaming begin!"
>>
>>Hi Greg
>>
>>The first
>>_TALLY is not always reliable - if you have events firing, it might change. Rare, but hard to trace. For all I remember INTO ARRAY is slow. INTO CURSOR xx and USE in xx is faster, and you can test using RECCOUNT('xx'). WinWin
>>
>>The second
>>#DEFINE CONTINUE_SEGMENT * CONTINUE Segment
>>is meaningless,
>>#DEFINE CONTINUE_SEGMENT *
>>ends up the same - it just adds a comment visible nowhere.
>>
>>The third
>>You obfuscate code, nobody but you can read this.
>>
>>The fourth
>>I, personally, dislike inline comments that are not marked as such
>>BEGIN_SEGMENT "Test" in other words DO WHILE .T. "Test"
>>"Test" is a comment because it will not be reached by the expression (no operator).
>>BEGIN_SEGMENT Test will work too
>>It will fail if one will not remember to limit it.
>>
>>It might fail do to defines:
>>
>>BEGIN_SEGMENT "Test"
>>#define Test AND
>>BEGIN_SEGMENT Test
>>
>>
>>So I would add && anyway - if you real like the segments named.
>>
>>I prefer
>>
>>Do While .T.  && Loop1
>>  ...
>>ENDDO &&.T. Loop1
>>
>>Where the enddo is created by intelliscript, but this is a matter of taste.
>>
>>The fifth.
>>If you like
>>
>>        BEGIN_SEGMENT "something"
>>            * do more
>>            EXIT_SEGMENT "something"
>>        END_SEGMENT "something"
>>
>>A bit superfluous code. Needless slowdown.
>>
>>Just to indent, something like
>>
>>#DEFINE Start_SEGMENT            *
>>#DEFINE Stop_SEGMENT             *
>>
>>Start_SEGMENT "something"
>>  * do more
>>Stop_SEGMENT "something"
>>
>>might do
>>- the indentation comes from the beautifier table anyway
>>- whatever is following initial statement is a comment to the compiler
>>- it is clear distinct from your loop
>>- nice code obfuscation
>>
>>? 2;
>> Start_SEGMENT 3
>>
>>
>>the sixth
>>Anyway, I would expect a block like FOR, IF, and so on indented, that's the rule since the we left assembler. If I have a logical block I use empty lines or wrap it in comments like
>>
>>*SEGMENT "something"
>>?"do more"
>>*/SEGMENT "something"
>>
>>or short
>>
>>*something
>>?"do more"
>>*/something
>>
>>
>>conclusio
>>To wrap existing command - this is to you. I would discourage you, the code is harder to maintain for anybody else. Also DO WHILE is is a clear code block, I see less use in obfuscation. Wrapping logical blocks could also be easily achieved without obfuscation.
>
>Strange. I was expecting to be shot at for I uses comments in my code.
>The purpose of the Segment statement is to help on the readability. It neither adds or hinderers the speed of the execution of the code. Just makes it a bit easier to read. I originally used DO WHILE .T. statement, then had EXIT statements to break from the block. I did this in place of having RETURN statements in the middle of methods, with I hear is Bad design practice.
>
>But, I am retired. All the coding I do is basically only for myself. No one has seen any of my coding for years. Besides, when I was coding for others, they generally had their own style that they requested me to adhere to. (Like one client told Not to use Cursor, but use Arrays instead, because he understood them.)
>
>I agree with many of your points. But I was attempting to add more readability, not trying to violate any coding practices. Besides, I fined using Segments are easier to code then DO WHILE. The same for using CASE statements in lieu of "IF THEN ELSEIF THEN ELSEIF" structure style ( as many others have told me I should be doing.)
>
>IMO

I guess the recommended way to split code into segments is called procedure / method. :)

Just to create visible sections you only need something that beautify will respect - it does not need to be active like DO WHILE - EXIT. thats the point with declaring just a *
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform