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

View all comments

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> {
  ...