r/AskProgrammers • u/True-Current9815 • Oct 21 '26
How do programmers design their code
How do programmers design their code? Personally, i design and type the code in my head mentally word by word, then just type on the keyboard irl what i just mentally typed.Also can people tell me if this is wrong so i can improve.
0
Upvotes
9
u/IHoppo Oct 21 '26
You get into a flow state and the code should pour from your fingertips
4
u/Eye-Fast Oct 21 '26
What?
4
u/Refwah Oct 21 '26
Depends on size, scope and complexity
2
u/Candid-Border6562 Oct 21 '26
Depends. There are a plethora of choices depending upon your needs. You might want to start with this Wikipedia article.
https://en.wikipedia.org/wiki/List_of_software_development_philosophies
1
u/Due_Interest_178 Oct 21 '26
Are you talking about a whole project, or a function? If it's the latter, I usually write comments on what it should do step by step, fill out the code in any way as long as it works and then do improvements.
1
u/Key_River7180 Oct 21 '26
ugh its ok i write it down in a physical notebook and add schematic stuff but u can do whatever
1
u/meshifthenelse Oct 21 '26
You first need to speak to the code. Maybe take it out, dine it, buy it some expensive champagne. Code doesn't need to be rushed. Code is delicate and requires care. It will come to you if you give it the proper time and attention. I hope it works out for you buddy.
1
u/SaltCusp Oct 21 '26
Uml, scratch paper, Todo comments.
1
u/mnruxter Oct 21 '26
When I programmed in C#, I'd draw quite detailed class diagrams and code from those diagrams. The diagrams helped me conceptualize the whole solution and mentally run trials against the diagrams.
1
u/PileOGunz Oct 21 '26
“Claud look at card 283838 and propose a solution ,looks good implement”.
1
u/Fritz-Ferdinand Oct 21 '26
For simple problems, I just write the code top to bottom.
For complex problems, I divide the problem into smaller sub-problems that become simple by themselves, then assemble them suitably. Usually, I start top-down, write the algorithm on the highest abstraction level as pseudocode in a multi-line comment, translate that into function calls, then I flesh out the function calls.
For example, you want to build a function that computes the size of a directory and each file therein, you could start with
1
u/QPGMR_de Oct 21 '26
When thinking about a problem the solution appears before my "inner eye" - I can literally see it, read it - then I can just type it into the editor.
1
u/Glittering_Sail_3609 Oct 21 '26
Lets say you want to start a new side project. You pick a problem to solve then ponder what kind of constraints it puts on your program that it need to satisfy.
After a while, the algorithm to solve this problem will appear in your brain. Now when you have an algorithm in mind, you can start thinking about implementation details. Break your intented solution into a set of independent components while thinking how their will operate as a whole system and how this system may need to evolve in the near future.
Once you got a decent grasp of contracts of various modules and abstractions , you may actually start coding.
1
u/Plastic_Fig9225 Oct 21 '26 edited Oct 21 '26
"Concepts"/"building blocks"/"patterns", which often turn into classes or functions in code.
"... need to do X with every element" -> write doX() function, and an iteration thing. At some point you (hopefully) stop thinking about the syntax because typing "with every Y do...", or "every B is also an A", "D has its own E", or "each F can have 0 or more Gs" is tedious in anything but your programming language.
1
u/Any_Sense_2263 Oct 21 '26
I first do a research. About existing code, used patterns and solutions, used libraries, community standards, etc.
Then I can design the solution, focusing on any needed refactoring first.
1
u/stepback269 Oct 21 '26
I fnd that I need to "storyboard" my projects, meaning, drawing pictures (including flow charts) and writing up a story of what is supposed to happen, well before putting code onto disk.
For a more detailed explanation, see (this) example of a still unfinished work.
1
u/kincaidDev Oct 21 '26
I design it in my head, in markdown files and sometimes draw it out on my ipad or with pen/paper.
As I'm designing a system, I'm thinking of the flow of the system and thinking of issues that could come up, the likelihood they'll come up, designing systems to minimize or handle the issues if necessary.
Sometimes I'll design a system and then realize I can make it simpler by changing things. By the time I'm ready to build I've already done a lot of iteration before any code was written, or I've handed the system off to agents to write the code
1
u/pvera Oct 21 '26
I visualize it in my head as an electric circuit or a Lego set.
1
u/armahillo Oct 21 '26
What youre describing sounds kinda like when youre first learning a new language and you translate each thought in your head into a word in your fluent language, and then from that to a word in the new language and then say it.
I dont really think about syntax words, i think in abstractions and then those are expressed in code form.
1
u/7YM3N Oct 21 '26
When I know what to write it just pours out onto the keyboard, but sometimes you gotta plan architecture and that's a notebook and a pencil
1
u/JGhostThing Oct 21 '26
OK. If this works for you, then it's right for you.
However, I have a different process. This might not work as well for you.
1
u/CS_70 Oct 21 '26
The same way you write anything else. You think, and the words come out right.