Comment Fun Friday File Function

Cecil

19+ years progress programming and still learning.
Hi,
Today I need needed a function to return the a give file size into a human readable format. Now I've written a few variation of this code over many years, but this time I looked at some Python code and I converted it into the ABL. Because of it's simplicity I thought I would share it. It could be useful for anybody else who needed formatted value of a file size.

Code:
FUNCTION fileSizer RETURNS CHARACTER (INPUT pdeFileSize AS DECIMAL):

    DEFINE VARIABLE chUnitSize AS CHARACTER   NO-UNDO EXTENT 6 INITIAL ['bytes','KB','MB','GB','TB','PB'].

    DEFINE VARIABLE inLoop AS INTEGER     NO-UNDO.

    DO inLoop = 1 TO EXTENT(chUnitSize):

        IF pdeFileSize LT 1024 THEN
            RETURN SUBSTITUTE('&1 &2',
                              ROUND(pdeFileSize,2),
                              chUnitSize[inLoop]
                              ).

        pdeFileSize= (pdeFileSize / 1024).

    END.
END FUNCTION .
 
Last edited:

Cringer

ProgressTalk.com Moderator
Staff member
You're missing a space between pinFileSize and LT :) Other than that it's a clever solution.
 

GregTomkins

Active Member
I would like to use this function, but it is clearly completely and hopelessly broken, as evident by its use of UPPER CASE keywords ;)
 

Cecil

19+ years progress programming and still learning.
I would like to use this function, but it is clearly completely and hopelessly broken, as evident by its use of UPPER CASE keywords ;)

About 12 years ago I was working alongside with Progress Professional Services UK. Any programs I wrote had to conform to their Programming Standards which included using UPPERCASE keywords and Hungarian notation and it has stuck with me ever since.
 

TomBascom

Curmudgeon
Well, you can keep the colors but please get rid of the vile hungarian notation. That has no place in modern programming. Actually it has no place in programming at all. Except as a misbegotten misunderstanding briefly promoted in Microsoft's echo chamber and then spread like a common cold far and wide.
 

Cecil

19+ years progress programming and still learning.
Well, you can keep the colors but please get rid of the vile hungarian notation. That has no place in modern programming. Actually it has no place in programming at all. Except as a misbegotten misunderstanding briefly promoted in Microsoft's echo chamber and then spread like a common cold far and wide.

Maybe somebody should update the OE documentation regarding the 'Variable naming conventions' and a quash this "vile Hungarian notation". Dam you Bedford for dragging your heals.:) I suppose it does help when we get Noobs coming to ProgressTalk asking for help and we steer them to the documentation for the answers.:oops:

http://documentation.progress.com/o...ex.html#page/gsabl/OpenEdge_3.5.html#ww625585
http://documentation.progress.com/o...ex.html#page/gsabl/OpenEdge_3.5.html#ww625585
I guess it time for me to break a habit of a lifetime. On a side note, in my very first Progress Job all variables, temp-tables and even buffers were prefixed with "wk" regardless of there datatype.:confused:
 

Stefan

Well-Known Member
One advantage of 'vile Hungarian notation' is that you generally never have to give your variables 'silly names' to prevent them colliding with keywords.

Code:
def var time as integer no-undo /* time cannot be undone ;-) */.

results in:

Code:
** The keyword time may not be used as a name. (329)
**  Could not understand line 1. (196)
 

TomBascom

Curmudgeon
That's pretty weak. A good variable name tells you it's purpose. StartTime, endTime or jobTime for instance.
 

Stefan

Well-Known Member
It's just the quickest I could come up with, I have run into others.

I find that the data type helps in preventing you from typing nonsense (which the compiler will tell you later on).

Even more interesting, IMO, is prepending the mode (global, input, output).

Moving on to the next interesting discussion CamelCase versus others. Some things are case sensitive (*nix filesystem, classes) , others are case insensitive (everything else) and others yet shout their case insensitivity at you (oracle tables / files are all uppercase). Using different casing depending on what you are doing gets tedious - so it would always be start_time, end_time, job_time for instance.
 

TomBascom

Curmudgeon
I wouldn't use the documentation or Progress provided sample code as a defense. That's like using a gang member as a character witness or using a bank robber as a job reference
 

TomBascom

Curmudgeon
"System Hungarian" is exactly the perversion that should be eliminated. Prepending gibberish to variable names is just ridiculous. Something which even Microsoft, the originator of the travesty, has realized and moved away from.
 

Cecil

19+ years progress programming and still learning.
I feel we have gone a bit off-topic. May be I should open up new thread regarding "What's the pros & cons of using innocent prefix character(s) for variables?".
 

Stefan

Well-Known Member
I feel we have gone a bit off-topic. May be I should open up new thread regarding "What's the pros & cons of using innocent prefix character(s) for variables?".

How can a discussion about great hungarian notation and other code styles be off-topic for a thread starting with 'fun friday' ?!?? ;-)

Now let's move on to how many spaces a tab should be. I call 3.
 
Top