I have a few code files that are rather large in length. The one I have open right now is approaching 750 lines and is growing quickly. I'd rather not split the class among multiple files, doing that just makes me nuts (even when VS puts the control declarations in the separate file makes me nuts, I wish I could turn that off), having to move between tabs to compare code (yeah I know you can split the screen but that makes me even crazier).

I was wondering if anyone had any tricks to make it easier to find methods or regions in the code file without searching forever. Either colour schemes or anything!

I'm one of those code writers that people seem to hate looking through my source, just because I LOVE space. I always put my brackets on a line of their own, my "get set"s used to take 8 lines, now they just take 4, but that's still a lot for some people.

I also had a bad experience once of reviewing code that I had written back in 2008-2009 and practically documented nothing, except for obvious things, and even then the comments were useless, like before a confirmation message box I'd put "Make sure the user isn't an idiot!"

I've gotten into the habit of documenting the purpose of methods (XML Comments) and parameters etc.. but only comment unobvious things inside my methods. But I'm worried that I'm not documenting enough, because what's obvious now, might not be later.

Anyway, are there any suggestions or ideas for:

  1. Easier code reading using fonts, backgrounds etc... in the code editor so when I am visually scanning a code file I know if I moved from one region to the next or something.
  2. What should be commented on, what should not be commented on?
  3. I know I asked before and it seemed that many people did the same as me, but how do you organize your methods? Alphabetically? Logical order (what logic?)? Just the order you wrote them (your nuts in my opinion if you do that)? Do you use regions? If you use regions, what do you group by and do you have subregions?

I'm just soliciting ideas and suggestions, I know there really is no "Standard" it's just whatever works for you, but when I'm working in the code files, I alphabetise my methods and organize them into regions, but obviously what I am doing doesn't work well enough so I just wanted to see what other people did.

Ideas and maybe even skeleton code files would be cool. Screen shot colour schemes would be nice too if you feel ambitious! :)

I appreciate ahead of time anyone who wants to share their tricks for working quickly in their code files.

Most seasoned professionals would tell you:
1) to NOT use regions
2) to break your code up into chunks of functionality
3) to break up your functions into separate files
4) to use self-documenting/intuitive code rather than commenting.
5) that modern tools remove the need to sort your code

Check out "Clean Code" by Bob Martin
http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882

Hanselminutes 145: Solid Principles with Uncle Bob
http://www.hanselman.com/blog/HanselminutesPodcast145SOLIDPrinciplesWithUncleBobRobertCMartin.aspx

I disagree with (1) above, I use regions all the time, as does everyone that I've worked with. YMMV, I guess.

I organize code into:
Class variables
Constructors
Properties
Methods
Interface Implementations
Private methods
Nested Classes

I do use regions, but only to hide large blocks of SQL code.

My regular methods are not large enough to need them and I have only heard Negative Press about them.

Since methods (in Visual Studio) automatically have collapsible regions, there is no need for me add extra ones (other than mentioned above).

There is too much of an opportunity to hide something that should probably be broken-up anyway.

This blog post disagrees with the one you posted. So which is right? For me, it depends on what you are using regions for. If it is to hide code in the middle of a method (something I've never seen anyone do) then I'd agree, it's bad. But to organize your code into groups I'd say is good.

Which one is right? --That's for future generations to tell.

I appreciate the feedback!

I do divide my code using regions, I group things similarly to how Momerath does. It works well, but it's kind of a drag when the file is nearly (or over) 1000 lines and you need to find a method in the middle of the file for whatever reason and you scroll.....slowly....until you find it. I just wish there was a way to change the background colour of every other method or something, or highlight the text inside of a region with some sort of color you could set, like #Region Some Name [BG:Red] or something so that, without looking at the top of the region to find out what region you are looking at.

I know, I know, the code should be obvious just by looking at it what region it's in, but if I was looking for the red region, I could scroll faster until I just saw red, and knew it was the one I was looking for.

Oh well.

I do appreciate the feedback though! What colour schemes do you guys use for your code editor? Or do you just use the default (that's what I use).

I use the object browswer if the code is large enough that I'd have to do a lot of scrolling to find what I want.

You can also find a method definition by placing the cursor where it is being used, and pressing F12 (Go to definition).

Just in case you didn't know :)

I use the object browswer if the code is large enough that I'd have to do a lot of scrolling to find what I want.

You can also find a method definition by placing the cursor where it is being used, and pressing F12 (Go to definition).

Just in case you didn't know :)

I use the object browswer if the code is large enough that I'd have to do a lot of scrolling to find what I want.

You can also find a method definition by placing the cursor where it is being used, and pressing F12 (Go to definition).

Just in case you didn't know :)

I use the object browswer if the code is large enough that I'd have to do a lot of scrolling to find what I want.

You can also find a method definition by placing the cursor where it is being used, and pressing F12 (Go to definition).

Just in case you didn't know :)

I use the object browswer if the code is large enough that I'd have to do a lot of scrolling to find what I want.

You can also find a method definition by placing the cursor where it is being used, and pressing F12 (Go to definition).

Just in case you didn't know :)

I use the object browswer if the code is large enough that I'd have to do a lot of scrolling to find what I want.

You can also find a method definition by placing the cursor where it is being used, and pressing F12 (Go to definition).

Just in case you didn't know :)

Wow, it sure freaked out on me. Wouldn't show me that I'd posted at all.

Yeah, I've tried this in three different browsers and get different results with each. --not one being fully better than another.

LOL!

Not sure why it did that, but that's kinda funny.

Anyway, I did know about the F12 trick. I don't use it that often, but maybe I should, and also that little drop down at the top I guess as well. I just need to get used to doing it that way.

Thanks for the tips!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.