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

C#

Joe Consterdine
Joe Consterdine
13,965 Points

Organised way to name classes from parent to children?

Hey guys,

I often find myself writing lots of classes and thinking it's not in a very organised manner.

What rules do you have?

In terms of:

  1. How do you name them in an organised manner
  2. How do you plan it out so you're writing DRY code

I often find myself writing out three classes for three divs when I could have written one and applied it across all three divs.

I guess that comes from a lack of planning.

Do you have a root style for e.g.

'Featured container' for 3 divs... and then if you need to change one of the divs later you add another more specific class?

Cheers.

1 Answer

Hi Joe!

One thing I find useful, which may seem really simple, is just to ask yourself these questions: "What is this class going to be used for? How many places is it going to be used? What type of things does it need to do?"

Once you have ran through this list in your head you should have a clearer idea of what it is you need to do. If you have any more questions then feel free to ask away!

-Luke