An idea for handling custom code styles

I was having a conversation with some of my fellow programmers about coding style.  Every one of us has a different style.

Example #1:
public void method(string name)
{
  ...
  return ret;
}

public void method ( string name) {

  ...
  return ( ret);
}

Example #2:
public void method( string name )
{
  try
  {
    ...
  } catch {
    ...
  }
}

Example #3:
if (name.IsNullOrEmtpy()) return;

if (name.IsNullOrEmtpy())
  return;



if (name.IsNullOrEmtpy())
{
  return;
}



Example #4:
int orderID = 1;

int orderId = 1;


For a moment, assume that "standards" don't matter.  Why?  Because we're developers and do whatever we want, anyway.

Each of the above examples have subtle differences in style, depending on keywords, context, and usage.  Each one is harder to read by every other developer that doesn't use that style.

So what gets hindered, besides personal readability?  "Find".  Let's say I want to find every instance (without using regular expressions) of "if (name ==".  But wait, is it "if(name ==", "if (name==", "if(name ==", or "if(name=="?  The only one I care about is the style I write in, but I obviously can't find all usages of other programmer's styles.

Now let's go back to the readability problem.  What causes a problem besides "taking longer to read" other people's coding style? Let me answer with a question. How often do you change their style back to your style?  If you're like us, it happens all the time.  Too often.  Too much wasted time.  Too many check-ins as the result of code being hard to read, so somebody else "tweaks" it back to their style.

Here were our thoughts:
1)  We don't want to change how we code for anybody.
2)  We don't want other developers to suffer through our code.

What was the solution?  Have the IDE re-interpret the code file for us.

Think about it.  A file could be saved in a "standardized" format, so anyone could read it with a plain-text editor.  But, if you had something like ReSharper (assuming ReSharper could do this), it could format every code file, no matter who wrote it, and display it in "your personal style"... everytime, every file.  The file is in memory, anyway.  It doesn't matter what changes you make until you hit "Save".  So why not let everyone have what they want at the same time, then have a true standard format exist as the actual saved file?

If the compiler can read the file, and a human can read a standard format, then this should work, even for those plain text editors.  I think a small layer of abstraction might save us days in readability and writability.

And going back to "Find"... the find statement could look for keywords, then compare it to the flat format, so it finds all occurrences in all files.

Since I thought it was such a good idea, I thought I should post it for you guys.  Let's make IDEs speak "programmer".

I remember my old roommate saying, "If it's hard to write, it should be hard to read."  That's obviously non-sense... except for the fact that we can't do anything about it except re-write it if it is too hard to read.  And that, too, is non-sense.

Please sign in to leave a comment.