Your proudest code is your worst
DaltheCow's comment pretty much sums it up

Your proudest code is your worst

The other day I sat down and worked really hard to solve a particular parsing problem. I used regex because I like a challenge, and when it works—it works beautifully.

var countableVerseRegex = /(^\n*|\n\n+)(({[Cc]omments?|#).*\n)*([^{# \n])/g,
    hasChordsRegex = /.*\[.*\].*/,
    chordlessTailRegex = /\][^\[\]]+$/,
    getChordRegex = /\[(.*?)\]/g,
    commentRegex = /^(\{ ?[Cc]omments?:|\#) *([^{}]*)}?/;

I finally got it working and was so happy and proud of myself.

Well done, you.

However, worming their way through cracks in my ecstasy, two quotes came to mind:

"You have a problem and you try to solve it with regular expressions. Now you have two problems."

"At the end of the day, take your 100 lines of code you are the most proud of, and throw them away."

Both of these are jokes—kind of. The point is that creating complex code is not only hard and time consuming for you, but also hard and time consuming for anyone who later comes to add/fix/give up and delete your code.

Sandy Metz values code on one thing: the cost of change. If your code is so simply laid out that even a grad student could jump in and make some adjustments, then your code has high value. If changing one section of your code only affects one section of your tests, your code has high value. The thing is, the code you are the most proud of is probably the most complex, the most fiddly, the most unintelligible. It took the longest time to write. By the time you finished, you're tempted to comment "https://hope I never have to touch this again". The rest of the world hopes that, too.

So write your code, do the fancy things, be proud of it, and at the end of the day have some serious thought on how to remove that fancy code, how to simplify things, and how to increase the value of your code.

要查看或添加评论,请登录

Regan Ryan的更多文章

  • Copying Prod DB => Staging on Heroku

    Copying Prod DB => Staging on Heroku

    TL;DR heroku pg:backups capture --app my-production-app heroku pg:backups:url --app my-production-app heroku…

  • OWASP Top 10 Web Application Security Risks

    OWASP Top 10 Web Application Security Risks

    The OWASP Top 10 is a global standard of the most important security risks to today's web applications. For any…

  • Changing Designs Mid-Project

    Changing Designs Mid-Project

    Can it also come in firetruck-red? It's a common and often inescapable event—the developer is halfway through building…

    2 条评论
  • The Programmer's Testing Trap

    The Programmer's Testing Trap

    "If you wish to build a ship, do not divide the men into teams and send them to the forest to cut wood. Instead, teach…

社区洞察

其他会员也浏览了