PDA

View Full Version : Programing code - need a "best practice" advice



flotulopex
- 15th December 2015, 11:37
Hi,

When I start a new project, I put on paper what the thing should do and how it should it.

When it comes to write the code, I read my newly made flow-chart where I see the inputs, conditions and actions and put it in lines just as they appear on the paper.

But this way of doing doesn't look very "scientific" to me and needs almost always lots of adaptations.

Is there a way, a method or a system to prepare what the code will be, facilitating so the programing code and structure?

How is this teached in technical schools?

mackrackit
- 15th December 2015, 14:04
Flow charting is the way to do it as far as I am concerned.

I have a young guy working for me that asked me to look over his code as it was not working correctly. I looked at what he had and asked him to tell me exactly what he was trying to accomplish where or what was supposed to be happening. He was getting himself confused while trying to communicate the procedure. ( I will have to give him some credit as this is a project that involves several python scripts running on a server collecting data from a PIC and displaying in a web browser, so having trouble is expected).

I asked him for his flow chart or outline and he did not have one to show me, he was trying to keep it all in his head. I sent him away telling him t make a flow chart or outline, then we can talk about the code.

Flow charting is also a good method when there are multiple people on the project, task can then be divided out.

So keep doing the flow chart, it is a tried and true method.

flotulopex
- 15th December 2015, 14:49
Thanks Dave, that quite comforts me :smile:

Now about creating code.

Sometimes, making a kind of "truth table" of the inputs/outputs is helpful - at least, I it so to me.

But I'm stuck when it comes to "conditions" (like IFs, ORs, etc).

I don't know how to make this "on the paper", if this is possible at all :confused:

mackrackit
- 15th December 2015, 15:09
This page might give you some ideas.
http://www.logicgenerator.com/AboutLogicCoder/SampleFlowcharts.htm

Basically you could do something like this:


Check "A"
|
Check "B"
|
Does A = B ?
|
[if A = B THEN ]---------------|
| |
Do this ELSE----- Do This

flotulopex
- 15th December 2015, 15:28
Okay, I'll have a look in there ;)

Thanks for the link.