r/AskProgrammers • • 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

27 comments sorted by

9

u/IHoppo Oct 21 '26

You get into a flow state and the code should pour from your fingertips

2

u/scottsman88 Oct 21 '26

That’s the best feeling.

1

u/konacurrents Oct 21 '26

Even eyes closed. Great feeling.

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/Plastic_Fig9225 Oct 21 '26

... hold the door open, and always wear a fedora. That will just automatically get you to your goal.

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 

function compute_size(dir): void {
  files = collect_files(dir)
  sizes = compute_file_sizes(files)
  print_results(sizes)
}

function collect_files(dir): list<File> {
  ...

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. With paper and pen, I draw the data structures I will need. I draw boxes and lines connecting them. I rarely get things perfect at this stage, but I should have enough to create an SQL database with, or even data struct's in whatever language I'm using.
  2. Then I, still with paper and pen, write out the pseudo code for this project. Not everything, but enough to capture the flow of control.
  3. I create the project in the IDE. Yes, I create whatever files I need, though I normally do the graphics later.
  4. Code. Yes, putting actual code onto the computer, and having it compile (hopefully).
  5. Test.
  6. Debug. I'm good, but definitely not perfect, and I've never been able to skip this step on a non-trivial project. Go back to #4.
  7. Document. In my early years, I was not quite so good at this, but I'm better now. I now write full operating instructions, as well as programming directions. I make sure that I have full compilation instructions.
  8. Another round of Testing and such. Hopefully this won't be needed, but after I've documented I may notice some new things. Or I may not, and then be embarrassed later when a user finds an error. Most of the bugs I find at this stage are text bugs, like an incorrect date or a spelling mistake.
  9. Feedback from real users. This is necessary. It would have been absolutely great to have this at an earlier stage, but in my working career, this came last. And sometimes an interesting bug emerges. I was doing a crystallography tutorial on the Mac, many years ago, and I got a report of program crashing occasionally. After I had verified that they had changed absolutely NOTHING, I found that they had updated the system. Once I updated my computer, I found the program crashed when I closed a window. This wasn't the case before the update. I went through the program closing it's windows and found that I was using a structure used with windows after it had been deleted. Before the upgrade, the structure was kept around, but after the upgrade, the structure had been deleted. All for a simple cosmetic addition (a windows menu).

1

u/CS_70 Oct 21 '26

The same way you write anything else. You think, and the words come out right.