Sunday, May 7, 2023

Pseudo Code File Logic: Open > New > Save > Save As

Just finished working out the logic for handling file logic:

File Open
File New
File Save
File Save As

This assumes you are keeping track of the following:

  • Current Filename
  • Changes to file data
I've been wrestling with this one for a few days. And then it finally hit me. "Hey, Exit can be your friend."

Exit can be your friend







Within the last year, my thinking has been influenced by Jeff Patton and his book "User Story Mapping". At work I have been involved in many meetings/discussions where everyone is in agreement that we need to implement "Solution X". However, everyone has their own interpretation of what "Solution X" is.

https://www.amazon.com/User-Story-Mapping-Discover-Product/dp/1491904909


Enjoy,
Semper Fi
Gunny Mike
https://zilchworks.com


2 comments:

  1. Using Exit along with a Try-Finally is an even more powerful construct especially if you have resources that need to be freed regardless of the ultimate results of the method. Then, for even more powerful architecture, look into a Try-Except nested inside of a Try-Finally. Then, you can use either Exit or Raise to abruptly terminate processing as well as insuring final cleanup via the outer Finally block. This can eliminate most of the dreaded if-then-else constructs you see all over amature code-dabblers' development that becomes an impossible-to-understand mass of interminable text.

    Another, related concept, is the use of Continue, that provides a similar "skip to the end" logic when it appears inside of loops. "Break" is also a great way to architect certain kinds of loop terminations.

    I don't see much of these things used on a day-to-day basis. Mostly, legacy code seems to have the myopic tendency to endlessly nest If-Then-Else constructs.

    ReplyDelete
    Replies
    1. Milan, thank you for you insight. That makes really good sense. I'm finally making good progress on porting my VCL application to FMX. I had initially planned on using a database but I've opted for a ClientDataSet solution that saves to XML. So, I've been focused on creating the logic flow for file manipulation.

      Delete