Stephen Horne

← Back to blog

Published on 08/05/2024 17:18 by Stephen Horne

On the Shoulders of Giants

I’ve been working on coding challenges from Codecrafters.io, and it’s been a great experience so far. Each month, they offer a free challenge, and I recently completed the Grep Clone after previously tackling the HTTP Server challenge.

The Grep Clone challenge involved implementing extended regular expression matching (-E PATTERN) and returning an appropriate exit status based on whether the pattern matched the input string. I expected it to take a few days, but I completed the implementation in about 10 minutes, thanks to C++‘s powerful std::regex library.

This experience reminded me of an important skill: recognizing when well-tested code already exists and leveraging it instead of reinventing the wheel. Unless dissatisfied with performance or memory footprint, using existing solutions like std::regex_search allows me to focus on writing safe, stable and understandable code.

While the challenge itself was simple, it provided opportunities to practice crucial skills like preventing buffer overflows, managing memory efficiently, and avoiding unnecessary object creation and copying. I learned nuances of std::string, used std::strcmp and argv** pointers to validate inputs before allocation, and passed strings by reference to prevent copying, applying knowledge of C++ copy semantics.

Overall, it was a good time, and I got just a little more comfortable with this powerful, and frankly daunting, language.

Written by Stephen Horne

← Back to blog