+ 1

How to build a logic in writing a code or program

Hello friends,i need help for building my logic in code or program. when i am going to write on my own i can't start don't know why and when i see the code i understand how it's working so any tips or help would be better for me.

15th Aug 2024, 5:53 PM
Sahil Shaikh
Sahil Shaikh - avatar
2 odpowiedzi
+ 3
You need a plan. And you need to visualize the end result. Then ask yourself what do I need first, because everything relies on something. Simple example: you want to write logic to calculate a simple sum. You cant calculate without input, so you first write the logic for input. Then you think of atleast 10 different ways users will give you input. Do you allow only numbers? What happens when users start using letters, what happens when the input is 0 or -5. Never trust users input! Ever! Also dont forget to build yourself a protection for other ways you didnt think of ;) Now you write logic to calculate the sum. But ask yourself, do I want to log all the calculations for future reference/UX? Now you will output the result to the enduser. Use your human every day life logic to write software logic, you will need to learn to think like a programmer.
16th Aug 2024, 11:46 PM
Ezzar
+ 1
In addition to the excellent answer from Ezzar, I'd like to suggest to write and test small portions of code about how to "solve" one idea of yours, to see how the program behaves. Above all do this when you research and find a function you dont know. Try it before and see if it is appropriate for your problem. If yes, integrate it in your code. Because no one writes a long listing in one session, rather it is a sort of puzzle where you fill gaps little by little.
17th Aug 2024, 1:31 PM
Ruben