Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Courses On Generic Programming Principles

Hi all!

First off, thanks for reading! I've just joined and so far treehouse looks great. I did have one quick question- as an beginner / intermediate level programmer, I would describe myself as a "hack it together until it works" style programmer. I know my code can be better from an organizational standpoint, but I don't know enough to make it better / do a proper code refactoring.

(a prime example of this for me, as I work in Python, is making code "Pythonic")

Are there currently / are there plans to have courses on generic design principles for a program, and if not would anyone be willing to point me to books / resources that have helped them get a better intuitive understanding of this?

Thanks!

I too love hacking something together to get a feel for things. Then when everything works, it's refactoring time!

I like to do refactoring in passes so they are manageable and not all encompassing. It can be as simple as just reading through the code from start to finish with an eye out for improvement opportunities. Things like... can I make a function with an argument that would replace three other functions? Ooh yeah do that. Can I organize my variables into one object instead of all these separate strings? Ooh do that too! Can I lazy load a module that doesn't get used used all the time for faster startup times? Ooh yes, and so on and so on.

If software was an automobile, I guess my refactoring style is many passes of polish vs. ripping out the engine and leaving the car looking like a mess in the garage.

I would say that if you make any improvements without changing functionality, no matter how miniscule they may seem to your inner judge, you are doing proper refactoring. :)

2 Answers

As far as code conventions go, they can be wildly different depending on where you work or who you work with. There are general best practices though and there are design patterns that are heavily used. I agree that a Design Patterns course would be great, but it would have to use several languages. The implementation might look different depending on which language you use. It's tricky.

First thing's first, learn the basics of the language thoroughly. I cannot stress enough how much easier it will make life to never have to guess on simple implementations. (I didn't do this the first time)

I can recommend you 2 great books. The first is 'Design Patterns: Elements of Reusable Object-Oriented Software'. This is THE book for design patterns. Understand these patterns and you'll be golden. The one issue is that it uses C++ and SmallTalk examples. That brings me to the second book.

Learning JavaScript Design Patterns. JavaScript is easier to learn and implement (opinion). As a web developer we'll have to learn it anyways so why not do it like a Boss. Best of all read it free here

Next, get into Test/Behavior Driven Development TDD/BDD. It will will help with the 'hack it together until it works' style of programming. Every decent language has a good test framework.

Once you have the above handled you should be able to tackle any and all frameworks and immediately recognize how they work based on the design patterns you've studied.

Hi guys!

Thanks so much for the quick and very thoughtful replies! I will definitely think about the minor improvement style of refactoring, and I will also check out those book recommendations and TDD / BDD (from what I can see, TDD is definitely something I'll benefit from).