Recent

Author Topic: anybody pseudo code?  (Read 1772 times)

Weiss

  • Full Member
  • ***
  • Posts: 191
anybody pseudo code?
« on: May 20, 2023, 03:06:58 am »
I remember from my days learning Octave, there was a suggestion to write a pseudo code first, prior to writing an actual program. Back then I gave it my half-arse go, but it was almost like its own unique skill writing a pseudo code. It was a lot easier to just code. So I never explored it further. Is there any kind of standard of writing it? Is it worth the effort?

Reason I am asking is that there are some complex tasks lately, and I have a hard time visualizing the flow. Kind of thinking of putting it on paper and work from there. I printed my code, and that helps to keep a mental picture, but not enough.

440bx

  • Hero Member
  • *****
  • Posts: 4998
Re: anybody pseudo code?
« Reply #1 on: May 20, 2023, 03:31:16 am »
It was a lot easier to just code.
It often is, particularly for an experienced programmer.

Is there any kind of standard of writing it?
Even though most pseudo-code that is found "out there" seems to follow a pattern, I am not aware of a standard (that doesn't mean there isn't one.)

Is it worth the effort?
In most cases, an experienced programmer can write "pseudo-code" using _real_ code (IOW, it's not really pseudo-code) but, when something is complicated enough that going directly for "close to working" real code proves difficult then writing pseudo-code is definitely worth it.

What I consider pseudo-code is an outline of the steps necessary to accomplish a task.  All steps are broken down (further outlined/indented) until I can effortlessly "see" the code required to implement each task/subtask (it may still be a fair amount of code but, as long as there are no tasks/subtasks I cannot see in code then, I'm done.)

I always outline the high level structure of the program in order to group functional pieces.  The program source files are made to be parallel to the outline. So far, I've never seen anyone else do that but, I've tested the method on other programmers (they weren't Pascal programmers) and have gotten very positive feedback about the programs that were structured that way.

Note: In the great majority of cases, I only do that for "real" programs.  IOW, most programs don't get this "luxurious" structure.

HTH.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

alpine

  • Hero Member
  • *****
  • Posts: 1345
Re: anybody pseudo code?
« Reply #2 on: May 20, 2023, 12:21:44 pm »
I remember from my days learning Octave, there was a suggestion to write a pseudo code first, prior to writing an actual program. Back then I gave it my half-arse go, but it was almost like its own unique skill writing a pseudo code. It was a lot easier to just code. So I never explored it further. Is there any kind of standard of writing it? Is it worth the effort?

Reason I am asking is that there are some complex tasks lately, and I have a hard time visualizing the flow. Kind of thinking of putting it on paper and work from there. I printed my code, and that helps to keep a mental picture, but not enough.
Assuming with the "visualizing the flow" you've meant the "program execution flow", IMO you wouldn't get a clearer picture when writing a pseudo-code. After all, the "flow" already exists, and you'll just get (almost) the same thing but on paper.
To me, pseudo-code is a design phase tool or something which can be used to communicate an algorithm in some language-neutral way.
When I'm attacking a complex problem I often make a skeleton program with mock-up subroutines and then gradually add details and continue to decompose in the same way down. All this with lots of comment lines explaining not only the purpose of each routine/block, but also how it works.

The 440bx is right - it depends on how experienced the programmer is and his judgement will he be able to handle it in a "cowboy way" or he'll need some aids to do it.

If you want to visualize things, take a look at some modelling language as UML for example.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12035
  • FPC developer.
Re: anybody pseudo code?
« Reply #3 on: May 20, 2023, 12:42:05 pm »
In most cases, an experienced programmer can write "pseudo-code" using _real_ code (IOW, it's not really pseudo-code) but, when something is complicated enough that going directly for "close to working" real code proves difficult then writing pseudo-code is definitely worth it.

Most pseudo code looks quite like Pascal anyway, remnants of its teaching past....

I don't write pseudo code any more for the stepwise refinement method (where you increasingly detail the pseudo code till it becomes real code), but I do occasionally use pseudo code in communication with external programmers or my  boss/client to get some confirmation of an algorithm before I fully implement it.


Handoko

  • Hero Member
  • *****
  • Posts: 5387
  • My goal: build my own game engine using Lazarus
Re: anybody pseudo code?
« Reply #4 on: May 20, 2023, 12:55:56 pm »
... there are some complex tasks lately ...

Pseudo code is good for learning/teaching newbies. For complex tasks I use divide and conquer algorithm. Usually I will try to solve the harder first, write it as a module as a single project. Then continue with the others. Finally I will get several modules (or units), so I can use them in the real project.

https://en.wikipedia.org/wiki/Divide-and-conquer_algorithm

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: anybody pseudo code?
« Reply #5 on: May 20, 2023, 01:09:20 pm »
To me pseudo code is like a flowchart design, you just show/describe what you want to achieve.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

HIGH-Zen

  • New Member
  • *
  • Posts: 17
Re: anybody pseudo code?
« Reply #6 on: May 20, 2023, 01:26:03 pm »
Long time ago when I programmed VBA in Excel 2003 and Access 2003,
I did pseudocode first and then programmed. Pseudocode was very good comments later.
Now in pascal I have pseudocode in my head :) and some comments in source.
I found that in Python pseudocode is almost equal to code.
« Last Edit: May 20, 2023, 01:44:49 pm by HIGH-Zen »

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1317
Re: anybody pseudo code?
« Reply #7 on: May 20, 2023, 11:33:36 pm »
I still use pseudo code and then translate it to pascal.
When I’m doing something really confusing it helps to write down what I’m trying to do in English before proceeding further.
After that I will revise the Pseudo code several times adding things I forgot. Only when the pseudo code is almost perfect I translate to pascal and type into editor.
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

 

TinyPortal © 2005-2018