Work Smarter, Not Harder

So a few weeks back, I checked in over 600 files worth of code in one day, and it occurred to me that that was a lot.  Why so much?  I was reorganizing code that was scattered about one large project into multiple projects so that it would build as libraries and so that there was some semblance of sanity to the location of things like objects and methods.

I know that I'm a fast programmer, but I think other people believe that I spend all day at the keyboard sweating trying to get that much code in, and that simply isn't true.  So here's my tips on how to work smarter, not harder, and get a lot of code on the books.

I should note that all of these screen shots I'll be presenting were taken during the actual exercise of cleaning and reorganizing code.  These are not "examples" or "samples" but actual code in a real environment.  The things I'm showing here are the actual things I did in the course of building the 600 files that I checked in.

Use your IDE

I cannot emphasize the value of an Integrated Development Environment.  In the examples I'll be giving you, I'll be using Visual Studio, but there are dozens of spectacular IDEs with very similar features out there.  Using your IDE is not just a matter of understanding the text editor.  You need to explore plugins, learn the shortcut keys, try out different features, and ultimately figure out what makes you most efficient.  Yes, the learning period for an IDE is extensive (took me about 3 months to learn VS) but the payoff is worth it.  For example, in Visual Studio, the shortcut Ctrl + . is a quick way to add using statements when your cursor is on a class name that has not been imported into the file you're working on.

Learn Regular Expressions

Don't be fooled by jokes about RegEx.  Regular Expressions save my butt every day.  During my 600 file change day, I updated about 80% of the files with 2 Regular Expressions, saving myself a ton of time.  No, I absolutely do not advise you to live by them, but the rule applies with everything.  Use the right tool for the right job.  In the case of RegEx, we're talking about a jackhammer.  It can seriously dig through the crap for you, as long as you don't try and use it on a porcelain vase.

Read Documentation

In this case, I'm referring to MSDN, and how you can quickly find the assembly for a strange class so you can reference it, but the same thing applies to all documentation.  It's extremely easy to find things in the documentation if you know how to read it.  And the only way to get used to reading it is to read a lot of it, so read your documentation.

Read The (Build) Errors

Build errors aren't the only kind, but chances are your IDE is constantly presenting you with error information about your code.  Read it, and learn how to read it quickly and identify the important information.  It can save you a ton of time to know how to read a stack trace, or even just memorizing common error messages and their causes.  Below, notice how I've highlighted an example error message that is a result of other errors (the library didn't build, so the other libraries that depend on it couldn't find it) and then an example of an actual error that was part of the source problem (missing a reference).

Build Everything

Visual Studio has a feature called "Rebuild" which deletes everything in the directories before running "Build".  Most developers use "Build" because it's faster, and only builds files that VS is aware of changes to.  Most of the IDEs (well, the build commands because most IDEs are only wrappers for build commands) have configuration settings or something to define this same concept.  I always recommend taking the longer, delete first, approach to building software, because the IDE is stupid, and I once spent 6 hours debugging a project only to find that an artifact had been left behind in the build directory and was causing everything to break.  Never again, I said.  I mean it, the extra 30 seconds for a full delete and rebuild are worth it to avoid debugging hassles and serious strangeness.

Save All

This is a simple one.  Visual Studio, Eclipse, Android Studio, and heck even most text editors have a feature to Save All instead of just Save.  This saves all the file you've made changes to.  This is particularly useful if you change a ton of files at once with, for example, a regular expression.  Use Save All to save large sets of changes.

Use Search

There are literally hundreds of search features built into most IDEs.  In fact, there are even search Plugins you can download to enhance the search capabilities of your IDE.  The search box is literally thousands of times more efficient than trying to scan the code with your eyes.  Ctrl + F will save your career.  Use the search to find anything and everything, and if your IDE has fancy quick search features, all the better!  Master them!

Simplify it

The reason I made all these code changes in the first place was because the code I was looking at was basically unreadable.  Nothing pointed directly at anything.  Objects and methods were mishmashed into horrifying blobs of spaghetti code.  I couldn't find anything.  This is why code quality matters.  Taking the time to clean up code, or at least break what you're working on into small bite-sized chunks makes the extremely complex logic that is programming manageable, and even nightmarish spaghetti-code can be enjoyable.

If you guys have an other great tips, drop them in the comments.
Happy Coding.


Popular Posts