Heater
Posts: 10266
Joined: Tue Jul 17, 2012 3:02 pm

Re: Easy Way to code Raspberry with blocks

Wed Jan 24, 2018 5:08 am

asandford,
In my mind a program flow chart is a data flow chart
I'd be interested to hear how your mind came to that conclusion.

A traditional flow chart has symbols (nodes) for start, end, input, output, expressions, decision statements (if, then else), loops (for, while), etc. Those nodes are joint together with lines. The lines have arrows on them to indicate direction. Those lines represent the required flow of algorithm execution. This all maps down onto the flow of control within an actual program.

For example:

Image

Other kinds flow charts are intended to show data flows within a program. node-red takes this approach. In node-red the connecting lines indicate data flow not program execution flow.

For example:

http://noderedguide.com/tag/example/#h.lmdr2oaawxxr

Of course there are many other diagrammatic techniques. For example UML https://en.wikipedia.org/wiki/Unified_Modeling_Language

Heater
Posts: 10266
Joined: Tue Jul 17, 2012 3:02 pm

Re: Easy Way to code Raspberry with blocks

Fri Jan 26, 2018 1:05 pm

asandford,
And I'd be more interested to hear how you (apparently) don't.
OK. Let's take a look at the little example of a traditional flow chart in my last post here...

We see empty boxes at the top and bottom, that would often be labeled "START" and "END" or some such. They only serve to tell you where this algorithm is to be started and when it terminates.

We see three rectangular boxes, A, D and C, that indicate that some operation is to be performed when one reaches that position in the flow chart. The actual operations are not specified.

We see a diamond shaped box, B, that indicates that some test is to be performed producing a logical result, TRUE or FALSE. The box has two exits, the intention being that the flow of execution of the algorithm proceeds along one, and only one, of those paths depending on the result of the test.

We see some lines joining these boxes together. Importantly these lines are directional, as indicated by the arrow heads.

The intention of all this is to start at START, which does nothing, and follow the lines from box to box performing whatever operation/test the boxes you encounter indicate. Proceed this way until arriving at the END box. At which point in time there should be a useful result somewhere.

So, to answer your question, I don't see any data in this diagram. Never mind data flows. Those connecting lines do not indicate any data flow, they indicate how to proceed from one operation to the next.

Clearly the traditional flow chart, as taught to kids learning about programming for decades, is not any kind of "data flow chart".

Exercise for the reader: The procedure described above is very long winded. Can we draw a flow chart that indicates clearly and unambiguously how to work through any other given flow chart?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 20929
Joined: Sat Jul 30, 2011 7:41 pm

Re: Easy Way to code Raspberry with blocks

Fri Jan 26, 2018 2:40 pm

Please keep it polite and vaguely on topic please.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

asandford
Posts: 1996
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 12:49 am

Heater wrote:
Fri Jan 26, 2018 1:05 pm
asandford,
And I'd be more interested to hear how you (apparently) don't.
OK. Let's take a look at the little example of a traditional flow chart in my last post here...

We see empty boxes at the top and bottom, that would often be labeled "START" and "END" or some such. They only serve to tell you where this algorithm is to be started and when it terminates.

We see three rectangular boxes, A, D and C, that indicate that some operation is to be performed when one reaches that position in the flow chart. The actual operations are not specified.

We see a diamond shaped box, B, that indicates that some test is to be performed producing a logical result, TRUE or FALSE. The box has two exits, the intention being that the flow of execution of the algorithm proceeds along one, and only one, of those paths depending on the result of the test.

We see some lines joining these boxes together. Importantly these lines are directional, as indicated by the arrow heads.

The intention of all this is to start at START, which does nothing, and follow the lines from box to box performing whatever operation/test the boxes you encounter indicate. Proceed this way until arriving at the END box. At which point in time there should be a useful result somewhere.

So, to answer your question, I don't see any data in this diagram. Never mind data flows. Those connecting lines do not indicate any data flow, they indicate how to proceed from one operation to the next.

Clearly the traditional flow chart, as taught to kids learning about programming for decades, is not any kind of "data flow chart".

Exercise for the reader: The procedure described above is very long winded. Can we draw a flow chart that indicates clearly and unambiguously how to work through any other given flow chart?
I passed A level Computer Studies with a grade A back in 1985, and have been working in IT for the last 30 years, I know how flowcharts work.

And it clearly is a data flow as all the variables contain data which controls the flow of the program.

All these conditional statements you mention; what are they comparing? To my mind they are comparing data.

The input data to the program must surely direct the flow of the program to produce the final output? If it doesn't then the program is doing its own thing.

ejolson
Posts: 2164
Joined: Tue Mar 18, 2014 11:47 am

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 7:05 am

Heater wrote:
Mon Jan 22, 2018 8:24 pm
...they used a flow-charting system that could output Python, C++, JavaScript and many others to compare how similar the same algorithm looks in the different programming languages.
I would love to see the output of said flow-charting system.
Did you ever check the JavaScript output of flowgorithm? It is reasonable?

User avatar
PeterO
Posts: 4294
Joined: Sun Jul 22, 2012 4:14 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 8:30 am

asandford wrote:
Sat Jan 27, 2018 12:49 am
And it clearly is a data flow as all the variables contain data which controls the flow of the program.
I think you just destroyed your own argument !
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Heater
Posts: 10266
Joined: Tue Jul 17, 2012 3:02 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 9:58 am

asandford,
I passed A level Computer Studies with a grade A back in 1985, and have been working in IT for the last 30 years, I know how flowcharts work.
It does not matter what papers we have collected. Possession of paper does not make ones argument more correct.

As it happens I earned an A Level in Computer Science in 1976. Only grade B mind, but I know how flowcharts work too :)
And it clearly is a data flow as all the variables contain data which controls the flow of the program.
That is true. The value of variables and intermediate results will end up controlling flow of execution around a flow chart. But that data flow is not what is depicted in the flow chart itself and is not the purpose of the diagram.

Please show me the graphical elements/symbols that represent data flow in the example above or any traditional flow chart. As we are talking "data flow" here I would expect to see symbols for data stores, sources of data, sinks of data, the paths that this data takes as it moves through the system, operations performed on the data on its journey, etc.

You can't, there are none. Rather, data and its flow can be inferred from such a flow chart by careful study of its operation.
All these conditional statements you mention; what are they comparing? To my mind they are comparing data.
Quite often true. Not always. A test could be checking the time. An operation could just be setting a GPIO bit. No data in the normal sense there.
The input data to the program must surely direct the flow of the program to produce the final output? If it doesn't then the program is doing its own thing.
Also true. But still, those directions of data flow are not what is depicted in a traditional flow chart. In fact, actual data flow is pretty well hidden in a traditional flow chart.

jahboater
Posts: 3268
Joined: Wed Feb 04, 2015 6:38 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 10:55 am

I have not used a flow chart since college, despite 35 years or so in the IT industry :)

Heater
Posts: 10266
Joined: Tue Jul 17, 2012 3:02 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 11:45 am

That is a whole other can of worms.

I don't recall having to create a flow chart since that A Level course back in the depths of time either.

Turns out that flow charts are not a very good way to think about the design of complex software. In fact they can be detrimental to to good program design. Each one of those paths on a flow chart is conceptually a GOTO. There is no control over where anything goes to. This is the antithesis of the "structured programming" concepts.

Flow charts do nothing to express data, data flows. They do nothing to constrain program structure. They do not help with ideas of encapsulation, data hiding, composition etc, etc, etc.

Those traditional flow charts perhaps had a purpose in thinking about code that we kids were going to write in BASIC at the time. The chaos one created in the flow chart could be mapped easily into chaos in our BASIC source code! :)


User avatar
scruss
Posts: 1863
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 2:45 pm

Blockly-gPIo does look like a neat concept, but Raspblocks works without installing anything. That's its selling point to me.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

jahboater
Posts: 3268
Joined: Wed Feb 04, 2015 6:38 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 3:09 pm

Heater wrote:
Sat Jan 27, 2018 11:45 am
Turns out that flow charts are not a very good way to think about the design of complex software. In fact they can be detrimental to to good program design. Each one of those paths on a flow chart is conceptually a GOTO. There is no control over where anything goes to. This is the antithesis of the "structured programming" concepts.

Flow charts do nothing to express data, data flows. They do nothing to constrain program structure. They do not help with ideas of encapsulation, data hiding, composition etc, etc, etc.

Those traditional flow charts perhaps had a purpose in thinking about code that we kids were going to write in BASIC at the time. The chaos one created in the flow chart could be mapped easily into chaos in our BASIC source code! :)
100% agree with all of that, especially the last paragraph!

Flow charts are far too low level to be useful for a competent programmer.

Heater
Posts: 10266
Joined: Tue Jul 17, 2012 3:02 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 3:22 pm

On the other hand....don't I always have another hand...

Flow charts do come in useful when a non-programmer has to describe some system to programmers so as to get something automated. Could be some manual office/business procedures or a manufacturing process whatever.

I once coded up a crypto algorithm and packet protocol handed down to us by GCHQ. I had no idea how or why it worked exactly and they were not about to explain it. They did have a lengthy textual description of the process but it was full of ambiguity. Luckily they provided a flow chart that was more rigorous.

Which is not to say that such a flow chart should become a model for the code you are going to create to implement it.

User avatar
PeterO
Posts: 4294
Joined: Sun Jul 22, 2012 4:14 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 4:19 pm

jahboater wrote:
Sat Jan 27, 2018 3:09 pm
Flow charts are far too low level to be useful for a competent programmer.
I strongly disagree with that.

Over the years I've often found flowcharts to be a very useful tool when dealing with code that has non-trivial flows. I find that creating a visual representation of program flow is a helpful step, especially when trying to explain a process to others or verifying the "completeness". I also find it encourages the breaking down of code into small pieces. If you can't get the flowchart on one piece of A4 you are probably trying to do too much and should break it down into smaller parts.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
PeterO
Posts: 4294
Joined: Sun Jul 22, 2012 4:14 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 4:22 pm

Heater wrote:
Sat Jan 27, 2018 3:22 pm
Which is not to say that such a flow chart should become a model for the code you are going to create to implement it.
So you come up with a solution represented by the flow chart, and then code something different ? :o

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Heater
Posts: 10266
Joined: Tue Jul 17, 2012 3:02 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 4:34 pm

PeterO,
Over the years I've often found flowcharts to be a very useful tool when dealing with code that has non-trivial flows
Actually that has happened to me from time to time. When confronted with hundreds of thousands of lines of spaghetti code it's helpful to draw yourself a map of what on earth is going on in an effort to understand it.

The worst case I had was recreating the functionality of thousands of lines of Intel assembler in C such the project could move to different architectures. Not just random control flow, cryptic symbol names and very few comments, the comments that were there were in Swedish! I mapped all that out in a tool called Prosa which allowed creating of program structure charts and state machines. Prosa then generated the C code for me!

But all that is a bad example. Why does that code you are looking at have non-trival control flows in the first place?

Flow charts are not a good tool for large program design. The idea that a lump of functionality should fit on a page is good, but the same can be said of other techniques. Certainly other kinds of map will be required. Data flow diagrams for example.

Heater
Posts: 10266
Joined: Tue Jul 17, 2012 3:02 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 5:08 pm

PeterO,
So you come up with a solution represented by the flow chart, and then code something different ?
[/quote]
Not really what I said.

Actually it is very likely that the solution in code looks nothing like the flow chart.

User avatar
PeterO
Posts: 4294
Joined: Sun Jul 22, 2012 4:14 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 5:11 pm

Heater wrote:
Sat Jan 27, 2018 4:34 pm
Why does that code you are looking at have non-trival control flows in the first place?
Probably because it solves a non-trivial problem !
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

jahboater
Posts: 3268
Joined: Wed Feb 04, 2015 6:38 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 5:16 pm

Heater wrote:
Sat Jan 27, 2018 5:08 pm
Actually it is very likely that the solution in code looks nothing like the flow chart.
As you said earlier, flow charts represent simple tests and branches.

Powerful and expressive languages such as C++ work at a different level.

User avatar
PeterO
Posts: 4294
Joined: Sun Jul 22, 2012 4:14 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 5:26 pm

Heater wrote:
Sat Jan 27, 2018 5:08 pm
PeterO,
So you come up with a solution represented by the flow chart, and then code something different ?
Not really what I said.
If your code doesn't correspond to the flow chart, why have you bothered with the flow chart ?

For example: I use flowcharts to show how the code will react to a particular set of inputs. I can trace through the chart to see that the correct processing happens for the given inputs. If I then implement something else I can no longer use the flowchart to answer questions about the code will react.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Heater
Posts: 10266
Joined: Tue Jul 17, 2012 3:02 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 5:33 pm

I'd love to see an example.

I guess it might be a bit too big for a post here!

:)

Heater
Posts: 10266
Joined: Tue Jul 17, 2012 3:02 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 5:44 pm

PeterO,
If your code doesn't correspond to the flow chart, why have you bothered with the flow chart ?
I don't.

What I was talking about there was was capturing some process, a manual business procedure for example, as part of a software requirement to automate that process.

There is no reason that the resulting software looks anything like that flow chart. No more so than the existing manual procedures actually look like the company procedures manual.
Last edited by Heater on Sat Jan 27, 2018 6:50 pm, edited 1 time in total.

User avatar
PeterO
Posts: 4294
Joined: Sun Jul 22, 2012 4:14 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 6:43 pm

Heater wrote:
Sat Jan 27, 2018 5:33 pm
I'd love to see an example.

I guess it might be a bit too big for a post here!

:)
They are all on bits of paper !

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Heater
Posts: 10266
Joined: Tue Jul 17, 2012 3:02 pm

Re: Easy Way to code Raspberry with blocks

Sat Jan 27, 2018 11:29 pm

Bits of paper?

Therein lies a whole other problem.

Any long lived and useful software changes over time. To fix bugs, meet new requirements and so on.

Those bits of paper soon become out of date, inaccurate and misleading.

I have not seen many projects that invest in the time required to keep all those bits of paper up to date. Sometimes in the military or aerospace industries.

asandford
Posts: 1996
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Easy Way to code Raspberry with blocks

Wed Jan 31, 2018 2:48 am

PeterO wrote:
Sat Jan 27, 2018 8:30 am
asandford wrote:
Sat Jan 27, 2018 12:49 am
And it clearly is a data flow as all the variables contain data which controls the flow of the program.
I think you just destroyed your own argument !
PeterO
I didn't have an argument, full stop, heater did. I I think the flow of data thru' a program is the same as the dry run flowchart. So (in my mind) data flow = program flow (if that isn't the case then one of them runs into a dead end).

Return to “Other programming languages”