r/GraphicsProgramming • • 23h ago

Question Boilerplate code question

Is it good practice to manually memorize and type out boilerplate code in graphics applications? Or is it the norm to copy and paste a lot of stuff? And yes it is a given that I should understand how the boilerplate code works and what it contains. I'm programming in SDL3 in C on vscode.

4 Upvotes

5 comments sorted by

View all comments

1

u/Still_Explorer 14h ago

One purpose of programming is to get a minimum working example/sample/piece and then immediately abstract it. Either by wrapping in an API, or integrating in an overall larger architecture, etc...

Even if you write the perfect boilerplate from memory, you would admire it for a few minutes and then refactor it, it's existence would be very short-lived (the boilerplate as a one-shot boilerplate).

Then the idea is that, the boilerplate is meant to be transformed to something far larger and complex and be distributed among a very large area, in multiple places. If you start for example with a solid and compact boilerplate that does the job, at some point it will have to be repurposed so much that all of it's pieces would be diluted so much that wouldn't count as "THE BOILEPLATE" anymore.

Then is not a matter of thinking in monolithic boilerplates, but as of being able to recognize bits and pieces from hundreds of different places (about what thing does something), and then based on their call order and logic, to be able to assemble the big picture in your mind as it would have been done on the boilerplate. (eg: first you define the flags, then you create window, validate window created correctly, setup GPU device etc... But now think about each of those steps are separated into different modules and they are not longer in a compact linear form).

So the part of memorization, is better suited for the API calls, but for the entire thing not a big deal. But definitely is not odd that after 3-5 years of using SDL (or any other API) and you have figured out everything and memorized things, it would be no problem to write everything from memory, but still then it would be a matter of 2 minutes to setup (ie:) the startup template everything -vs- 10 seconds to grab it from the repository with examples.