Programmer's Purgatory

I don't ordinarily subscribe to any judeo-christian hocus-pocus.

But i have a vague feeling that when programmers die they are made to spend many centuries in a purgatorial-place, as punishment for all the bad code, the slow code, the sloppy code, the unmaintainable code...

Here's a recent slab that probably earnt me a couple of millennia in the cosmic wait-state:

Imports System.Text.RegularExpressions

Public Function DisPascalize(ByVal psPascalString As String) As String
  Dim sResult As String
  sResult = psPascalString
  sResult = Regex.Replace(sResult, "([^A-Z])([A-Z])", "$1 $2").Trim
  sResult = Regex.Replace(sResult, "([A-Z])([A-Z])([^A-Z])", "$1 $2$3").Trim
  sResult = Regex.Replace(sResult, "([A-Za-z])([0-9])", "$1 $2").Trim
  sResult = Regex.Replace(sResult, "([0-9])([A-Za-z])", "$1 $2").Trim
  Return sResult
End Function

Notice the way there are no comments at all. Because 'DisPascalize' is just so self-explanatory, no?

What does it do?

InputOutput
"PascalCase""Pascal Case"
"ABCPascal""ABC Pascal"
"Pascal123""Pascal 123"
"123Pascal""123 Pascal"

I've used it for converting PascalCase Enums into presentable words. Wonder if anyone has advice on a nicer way to do this. It feels so wrong.

 

I'm currently writing a book about how to build your first product. If building a product is something you'd like to do, then sign up to be notified when the book is available.

Your comment, please?

Your Name
Your Url (optional)
Note: I may edit, reuse or delete your comment. Don't be mean.