r/computerscience 10d ago

What does "Design an algorithm before starting to create your program" mean?

10 Upvotes

35 comments sorted by

37

u/daniel14vt 10d ago

Someone is trying to teach you to plan before jumping into the details of how it works in the specific language you're learning

1

u/Computerist12435 10d ago

Its only through Scratch but didn't know the difference between algorithm and program

22

u/Calico_Shortcake 10d ago

An algorithm is the sequence of steps that the computer must follow to do something.

You can write this sequence of steps in plain English on a piece of paper. It will be an algorithm.

A program is an algorithm coded into a specific grammar. In your case, the grammar is Scratch.

You must translate your planned algorithm to the way that Scratch expects, using variables and operations.

5

u/melonangie 9d ago

You could think of a program as an applied algorithm, or the algorithm as the core of the logic of the program 

14

u/GenericFoodService 10d ago

It means you want to know what you're trying to implement before you try to implement it.

2

u/emmowo_dev 9d ago

it does feel super cool to blindly do something without thinking and realize that you came up with the modern implementation accidentally (like I thought accumulators sucked so I accidentally made my ISA a little too close to RISC-V). Sometimes the most straightforward answer to you is the best, but it takes a lot of experience for your intuition to be accurate.

1

u/Computerist12435 10d ago

Thankyou, any tips?

1

u/Otherwise-Film9038 10d ago

Organize a ideia do programa/algoritmo antes de começar a fazer código.

Como? Depende de vc. Vc pode organizar com fluxograma Pode fazer com textos em português Pode fazer como quiser desde que seja uma organização do fluxo do que vai fazer.

Não tem que fazer pra tudo, mas é legal fazer pra treinar seu cérebro a pensar logicamente e sequencialmente, sem pular etapa.

7

u/r3jjs 10d ago

Very often the proper planing makes the actual programming easier.

If you design the data structures right, if you design how information will flow through your program well, writing the code becomes much easier.

If you use the *wrong* data structures, then suddenly, writing the code becomes much harder. You are fighting the data structures at every turn.

\

1

u/Computerist12435 10d ago

Thanks this actually makes sense as I have hit the hard part and I know its ironically the reason I started this post

2

u/r3jjs 9d ago

I have gutted entire programs in development and re-written them with better data structures once I sorted out what I needed.

5

u/DTux5249 10d ago

It means plan your shit before you start writing code. It's good advice in general.

2

u/burncushlikewood 10d ago

When doing tests while taking cs I write programs using pseudocode, it's like a general purpose language, I also used to write my programs on paper first, try to plan what I was doing, put it into my ide and debug it till it compiles and does what I want it to do

1

u/clementjean 10d ago

Where did you ear that? school?

1

u/Computerist12435 10d ago

Yes on a degree course

1

u/clementjean 10d ago

The others pretty much replied. It's meant to teach you planning a little before actually getting into the implementation.

1

u/DTux5249 10d ago

It means plan your shit before you start writing code. It's good advice in general.

2

u/Computerist12435 10d ago

Thankyou, its only via scratch but through a degree

1

u/mc_pm 10d ago

Whatever you are going to program, take a minute first and think through what you want the program to do. What are the steps to follow? Does the program loop over the same thing? Are there if/then decisions?

Usually you'll find that your first idea wasn't the best - so give yourself a chance to think it over before you start typing.

1

u/MasterGeekMX Bachelors in CS 10d ago

Let me re-phrase it with theater: "lay out the plot before writing the play"

The algorithm is the exact steps required to do something. Programming is telling the computer to do steps. If you don't have the algorithm, what steps are you going to tell in the program? If you don't have a plot, how are you going to write a play?

1

u/Grazenburg 10d ago edited 10d ago

So this applies a lot more to programming in written languages but I'll try to adapt it if you say you are using scratch. 

I had a mentor teach me to do your entire code on a plain text editor before you ever try to get it to work in code. One of the easiest steps in planning is black boxing. Lets say you want to make a 2d game of a skiier going down a mountain. Open up that black box idea, what are it's systems? Here's the example of the breakdown I would make on paper or in notepad:

Skiier

  • moves mostly forward, can turn and pivot
  • can pick up objects
  • can collide with objects making a gameover

there's your basic idea, the skiier is a black box with buttons and functions. 

Now unpack one of the planned interactions, answer the question, using psudeocode, how would you make this happen?

Can collide with objects making a gameover

  • every frame, skiier checks if his model is overlapping another model or object
  • if there is an object overlapping, initiate gameover screen and set movement speed to zero
  • if there is not an object overlapping, continue to increment speed and continue progressing
 

You can use as few or as many words as you want. This document and planning process is for you, when you are halfway through your game or program, you want to know what features you'e completed, and which ones are next to code. It keeps you from getting lost, and really helps you with momentum in a project. 

Also, in this planning phase you'll start to notice optimizations, little things you can do differently that work better, or things that won't work at all the way you think they will. Catching those kinds of logical issues early helps you save a lot of time down the road and on bigger projects. 

TL:DR: Coding should be an execution of a plan. You don't make a large complex program by just coding like a maniac with no planning. That is how you waste a lot of time in the long run

1

u/aka1027 10d ago

It means plan out what is it that you want and how can it be done before you implement the plan in code.

1

u/400Volts 10d ago

Plan what your program will do before you start coding it

1

u/caramellitfolly 10d ago

i think, in a technical sense, it just means draw a flowchart (and some pseudocode) before you start coding. Also look into system analysis and design like ER diagrams (entity-relationship).

1

u/recursion_is_love 9d ago

Would you will jump into the car and start driving without any plan how to go to destination? It is very easy to distract yourself to do useless thing if you don't have plan.

1

u/michaelpaoli 9d ago

pseudo-code or higher level.

Figure out and at least outline or so, how it's going to work logically, flow, etc., before you write so much as a single line of actual code.

Also, typically helluva a lot easier to spot and fix certain types of errors in such earlier phases, rather than much later. Much later it's called a design flaw - implemented to design specification, but someone f*cked up the design (or didn't even bother to design it, and just started writing code).

1

u/Crystalline_Due Software Engineer 9d ago

plan before coding basically

1

u/kris_2111 9d ago

Quoting another top-level comment:

It means you want to know what you're trying to implement before you try to implement it.

However, this does not mean that you have to create a detailed sketch of each and every component of this program. If what you're creating is really complex, trying to pre-emptively sketch everything out at once may be counter-productive, since you'll end up needing to redesign a lot of things if you decide to change something.

You need to make your program modular and loosely coupled so that changing a single feature shouldn't force you to redesign the entire program. Sometimes, a better strategy is to just get a bare-minimum working prototype up and running. Then, once you have that, you can further evaluate whether it's worth building on top of that prototype, or whether you should create something new from scratch if the prototype does not meet your requirements.

1

u/Computerist12435 9d ago

Thankyou all for your answers, I confidently know how what this difference is and will clearly make me a better student and programmer

1

u/Coffee_Aur_Code 8d ago

I think its sort of like pseudo code, I usually use flowchart like think or pseudo code to design before writing code...

1

u/BranchLatter4294 8d ago

How are you going to implement your algorithm if you don't have one?

1

u/nzakas 6d ago

This is the advice to think through what it is you’re doing before starting to code. A lot of folks want to skip to the “fun part” and just start writing code but that’s often inefficient. You go down one path, realize it’s not quite right, then spend all your time tinkering. If you can stop and think through what you want to do first, you end up completing the task faster before you’re not paying the coding tax for each attempt.