View Single Post
  #6  
Old 11-27-2018, 01:51 PM
loramin loramin is offline
Planar Protector

loramin's Avatar

Join Date: Jul 2013
Posts: 9,343
Default

Quote:
Originally Posted by maskedmelon [You must be logged in to view images. Log in or Register.]
oo yeah, found a diagram on stackexchange that depicts the same thing you said, Lor ^^;

Glad memory isn't really an issue, but still curious about best implementation though. Going to give it some more thought.
I really think you would benefit from reading a good programming theory book. My personal favorite in that category is Martin Fowler's Refactoring. It's a bit dense and a little old, but you don't have to read it cover to cover, and the principles in it don't go out of date. Also it uses Java, but 95+% of it's ideas aren't language-dependent, and Java's syntax is very similar to C. The subtitle of the book is "Improving the Design of Existing Code", so it might not seem applicable to you and your new code, but ...

Basically the book is a giant collection of "refactorings", ie. ways to take code written one way and re-write it in a better way without altering what it actually does. It also contains a chapter on "code smells", ie. patterns/signs that some code likely should be refactored. But most importantly, it doesn't just tell you what smells and refactorings to use: it tells you why, in a very well-thought out and logical fashion.

When you start to learn how to identify "smelly" code patterns, how to improve them, and most importantly why you want to take your code from version A to version B, it really helps you build a better sense of "I should architect this code that way because of X principle".

For instance, I just flipped to a random page for "Replace Constructor with Factory Method". He spends about half a page explaining how to do the refactoring, half a page on why you'd want to, and three pages of examples that clarify both making the actual code changes and why you'd want to. After reading it you have a much better understanding of when you would be better off with a factory method, and you can use that knowledge even when you're writing new code, not just to convert an existing constructor.

If Fowler isn't your speed another really popular title (that I haven't gotten around to reading) is Code Complete. And there are plenty of other good ones, but the point is that if you learn from really experienced people what patterns have costs and benefits, it equips you much better to make architectural decisions on your own.
__________________

Loramin Frostseer, Oracle of the Tribunal <Anonymous> and Fan of the "Where To Go For XP/For Treasure?" Guides
Anyone can improve the wiki! If you are new to the Blue server, you can improve the wiki to earn a "welcome package" of up to 2k+ platinum! Message me for details.