Idea of "Modeling" for procedural languages

Need help with C, C++, perl, python, etc?

Idea of "Modeling" for procedural languages

Postby larienna » 2020-05-18 11:16

I moved recently and I have much more bus transportation to do than before. So though I could plan ahead my programming in the bus by doing some modeling in order to speed up the development process when I am in front of an actual computer.

Now the problem is that I don't use object oriented programming (for reasons I will not specify here). I use instead procedural and data oriented programming. Under that paradigm, data is separated from code. Most UML models are based around object oriented programming, so they do not seem to fit my needs. I searched a bit if UML could be used with procedural languages, and it seems that in certain situation it's possible. Like for example, you could model a state machine if you need a state machine in your program.

Still, by looking at the various UML models, I cannot find what I need. From my perspective, I need to model 2 things: data and code. Data is easy, I could use relational database models, or class models (with only variables). But for code, I have not really found anything. Workflows are just too much detailed. So I came up with an idea to model the code structure without thinking too much of the details. My questions are:

Have you seen anything similar?
What do you think about it?
Am I missing anything?

----------------------------------------------------------------------
Procedural program modeling

The idea is that procedural programs are organized as a tree structure. Since you first start with the main() that get subdivided into smaller methods or tasks. The sorting of the method names could be done in execution order but it's not mandatory. The idea is to get a general view of the program (who call who) without having to write every loop and condition.

So far there is 2 special markers:

- A circle before the method indicated that a certain condition must be met to execute this method. (ex: "O - method_name" )
- Brackets could be used after the method name to indicates it's going to be repeated a certain number of times( ex: "| - repeat_me {5}" )

Here is an example for selection sort.

Code: Select all
main
| - select_sort
|   | - inner_loop {n}
|   |   O - swap {n-1}
| - dispose_resources


Normally, I would probably stop at "select_sort", like I said, I don't want to reproduce every loop and condition in the program. But here it's just for the demonstration purpose.

After wards, it could be possible to group those methods into modules by drawing boxes around them. I want to make the model valid for plain C and Java language, so in C, methods will be put in the same .h/.c file, while in java it will be put into the same class as public static methods. The grouping of methods is based on thematic resemblance between methods, or if they need to have access to the same private methods. It's possible that private methods could be removed from the model for better clarity.
larienna
 
Posts: 62
Joined: 2014-09-27 20:54

Re: Idea of "Modeling" for procedural languages

Postby LE_746F6D617A7A69 » 2020-05-18 14:10

larienna wrote:Still, by looking at the various UML models, I cannot find what I need. From my perspective, I need to model 2 things: data and code. Data is easy, I could use relational database models, or class models (with only variables). But for code, I have not really found anything. Workflows are just too much detailed. So I came up with an idea to model the code structure without thinking too much of the details.

I would say that the first thing is to have the right tool for the job - have You seen/tried the Dia Diagram Editor?
It offers a lot of ways for visualizing data structures/dependencies/flow charts etc, and it's available in Debian repositories.

Here's a link to a combined data/program flow that I've created a long time ago for one of my projects:
https://imgur.com/J3RR1CJ
<I'm not posting the image, because it's too big>
Of course, this is just an example of what You can do with Dia.

I disagree with Your claim that "Workflows are just too much detailed" - the level of details depends entirely on who is creating the workflow chart and for what purpose.

I think that Your method for modelling procedural languages is OK, but it's as good as any other method - because it's just a matter of personal preferences.

Regards.
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed
LE_746F6D617A7A69
 
Posts: 414
Joined: 2020-05-03 14:16

Re: Idea of "Modeling" for procedural languages

Postby neuraleskimo » 2020-05-18 23:42

larienna wrote:I moved recently and I have much more bus transportation to do than before. So though I could plan ahead my programming in the bus by doing some modeling in order to speed up the development process when I am in front of an actual computer.

Do you mean you want to do this via pencil and paper or via a phone/tablet while on the bus?
Black Lives Matter
neuraleskimo
 
Posts: 195
Joined: 2019-03-12 23:26

Re: Idea of "Modeling" for procedural languages

Postby larienna » 2020-05-25 12:54

Probably pencil paper as tablets are harder to write. Still, right now the road I am taking has a lot of construction making the road unstable which makes it harder to write. The subway was much more stable, I could even draw artwork.

Right now I switched to reading, but when construction is over I could try to write again. Else, playing games on a tablet on phone/tablet is OK. So another option is that I could debug and playtest my mobile software on the bus.

I originally though of upgrading an old netbook to code on the bus, the problem is sometime setting up the computer to start working will sometimes take 10 minutes, while the biggest bus segment is between 25-35 min. So going paper or mobile seems like the best option.
larienna
 
Posts: 62
Joined: 2014-09-27 20:54

Re: Idea of "Modeling" for procedural languages

Postby neuraleskimo » 2020-05-27 00:12

larienna wrote:Probably pencil paper as tablets are harder to write...So going paper or mobile seems like the best option.

About 20 years ago, I fell down the rabbit-hole called formal verification. Eventually, I climbed out, but it left me emotionally scarred. :-) Two problems people who do this kind of work face is how do I represent a program or a VLSI circuit and at what level?

Let's start at the question of at what level? (Fortunately, this is something you can do with pencil-and-paper.) This is really a question of what are your preconditions, post-conditions, and invariants? You can write these in any form: prose, a mix of prose and logic, or all logic. From your comments, I doubt you want something terribly rigorous. However, you might find some inspiration from model checkers and temporal logic. I can expand on this if you want to know more.

Once you have your preconditions, post-conditions, and invariants, you have answered two questions: 1) what are the features I want to model, and 2) what are the features I want to test (e.g., model checking or unit tests)? You would then only model enough detail to convince yourself that your program, when written, will be correct. I can expand on this if you want to know more.

How you represent your program is up to you. I usually use C/C++/Python-like pseudo code. What you have above is also fine. My main advice is to make your specification language more declarative and less procedural. Doing so will help you focus on the task at hand. If you want to risk falling down the rabbit-hole called verification, model checkers use Kripke structures. It might be good to look for inspiration there. This is especially true if you plan to model parallel tasks. UML, as LE_746F6D617A7A69 recommended, is also fine. You might also take a look at systems engineering. Systems engineers use a lot of UML, but it isn't the only tool in their toolbox. You might find some inspiration in how engineers model the world (as they see it).

Knowing that you like to draw, there are other places to look for some inspiration. Neuroscientists study a different kind of "computing device" and produce beautiful descriptions that look a lot like NDFA or Kripkey structures. Their drawings show just the necessary detail of a cellular pathway to convince the reader that their description is correct. Their drawings also involve sequential and parallel processes, loops (i.e., feedback), and more. One distinguishing feature, though, of brain cells is that there is no clean separation of instructions and data.

Good luck and let me know if I can help.
Black Lives Matter
neuraleskimo
 
Posts: 195
Joined: 2019-03-12 23:26

Re: Idea of "Modeling" for procedural languages

Postby larienna » 2020-05-30 13:27

I take a quick look to what you have proposed. I am allergic to math (after getting my first calculus class), so verifying with math algorithm is not for me. I am more an experimental programmer who want to try stuff and see what it happens. I tend to use the "Code first, design later" approach. It avoids getting in the infinite loop of design, where you constantly design and redesign stuff and progressing very slowly.

So what I am looking for could be to separate the activity of design and planning, from the activity of programming. This way, when I have some time to program, I will have maximum efficiency as I know exactly what I need to do. So I am wondering if I should be more borrowing from project planning than computer software engineering.

Also, my focus is more video game development, so there will be little automated testing. When designing a video game engine, there might be a little more thought on the design aspect, since you need to think about reusability. But when you are coding the game itself, you just want to make it work.

In video game dev, there is also other aspect to think about like game design, artwork, level design,etc. So it might be more convenient to integrate everything together in a project management system.
larienna
 
Posts: 62
Joined: 2014-09-27 20:54


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests

fashionable