• 0 Posts
  • 30 Comments
Joined 1 year ago
cake
Cake day: June 21st, 2023

help-circle
  • Write comments that explain why the code isn’t obvious just by reading it. Why did you do things the long way? What did you need to work around? Why didn’t you do the thing that anyone reading the code would expect you to do?

    Also write comments that explain the purpose of the functions you use, in case the names of those functions don’t make it clear on their own.



  • The fact that the loop is doing “find first driver matching these strange criteria” seems most obviously obscured by the pattern of assigning a value, then killing the loop or not. This strikes me as the part that makes the algorithm tedious to test, since it forces us to use a collection to test the intricacies of the inner conditions.

    Once we isolate “find first driver matching condition” from computing the condition for each driver, I consider the rest a question of personal taste. Specification pattern, composition of filters, something like that. Whatever you find easier to follow.

















  • Computers don’t directly understand the code that humans write. Humans find it extremely difficult to directly write the code that computers understand.

    Compiling is how we convert the code that humans write into the code that computers can run. (It’s more complicated than that, but that explanation is probably enough for now.)

    Different computers understand different flavors of computer code. Each kind of computer can compile the same human code, but they produce the flavor of computer code specific to that kind of computer. That’s why you sometimes need to compile the human code on your computer: it’s easier for your computer to know how to compile human code than for a human to know how to compile human code for every kind of computer that exists now and might exist in the future. There are some common kinds of computer and many projects pre-compile human code so that you don’t have to, but that’s not always easy. Also, some people insist on compiling the code themself, rather than trust someone else to correctly compile the code for their computer.

    As for how to compile, that can be complicated. When you find the human code (“source code”) for a software project, the README often gives you instructions for how to compile that project’s code. Many of the instructions look familiar, because they are similar between projects, but the detail can vary a lot from project to project. Moreover, different human programming languages have very different instructions for how to compile their flavor of human code into computer code.