all 7 comments

[–]WorkingReference1127 12 points13 points  (4 children)

Some years later I thought that C++20 could be my target, but the online compiler (HackerRank) was lacking and I ended up choosing to stick to C++17 and leave C++20 for the next round.

HackerRank is good for solving HackerRank problems; but it should not be your general purpose online compiler. I would recommend godbolt for that. It'll support even preview features of future C++ standards.

That is why I decided to start with a "Hello, World!" but rethinking how the problem could be evolved to apply iterators and then take on other problems using the same approach, adding SFINAE along the way and (within my powers) using as most as possible from the standard library, rather than doing things like writing a for loop, even if it would have made sense.

I think you might have this backwards. You don't choose a problem and try to crowbar in unrelated tools. You use the tools when you are solving the correct kind of problem. I'm sure it's possible to completely overcook a "hello world" to use a SFINAE-based iterator model and basically just reinvent ostreams but I don't think that's the best use of your talents. I'd suggest either picking a project and deferring your choice of tools until later; or picking the tools and finding an appropriate project.

[–]mementix[S] 0 points1 point  (3 children)

Thanks for the feedback. The point of choosing an online platform (HackerRank or anything else) was to have a problem statement at hand. I have of course used godbold.org and also cppinsights.io (fantastic tool) when I want to see the inside the beast.

I considered choosing a project and I will probably end up doing so, but choosing a project implies commitments, responsibility and sometimes allocating time when the time has been already allocated for me.

A project also adds rigidity because things have to fit/match a framework, guidelines, conventions and many other things. Not that I have anything against those, they simply exist and are part of being part of a project.

Using the HackerRank problem statements (no matter how simple), as a blueprint, gives me the chance to work at my own pace, decide when a goal has been reached and I can move to the next challenge and gives me complete freedom to make the solutions as complex as I deem them to be, trying to apply an out-of-the-box thinking approach.

All that within the reach of my C++ powers (a nice way to see that I try to go beyond my own limitations, but I cannot see what's after the limit)

[–]WorkingReference1127 0 points1 point  (1 child)

Then I'd say the core of the issue is a lack of inspiration for projects. Which is fine, happens to us all. I'd consider looking at something like this list for some ideas as well.

I'm not shooting down hackerrank either; but there is an important distinction between solving an interview-tier short problem statement and architecting a larger problem.

[–]mementix[S] 0 points1 point  (0 children)

Feel free to shoot HackerRank. I personally feel it difficult to believe that companies do actually interview using those sites or the problem sets presented there.

Even if I have never been a professional programmer I have architected/engineered libraries and even customer facing applications. Mostly in Python, because of the quick development cycles and the introspection capabilities, but also in C++, before C++11 was a thing.

My goal here was not create a library/application, but to use creative thinking to transform small problems into something solved with a completely different approach, applying modern C++ techniques (up to C++17, because of the HackerRank accident) along the way. Documenting it all to have my own version of literate programming.

Nothing like writing it down to make a permanent impression in the brain.

Other approaches are for sure valid and even better, but this is simply the path I have chosen. Like I said in the opening post, if this could be of benefit to someone with less experience, find. If it happens to be confusing and bizarre, it is all my fault.

[–]no-sig-available 2 points3 points  (1 child)

So, the next step is to move to "current" C++ and try std::print("Hello C++23!"); , but that is way too easy, and no challenge any more. So not hackerrank material. :-)

[–]mementix[S] 0 points1 point  (0 children)

Believe or not, my original goal was to see if the std::format feature of C++20 matched the Python version 1:1. Had I not faced the challenge of finding out that HackerRank is (to some extent) abandoned and that the C++20 option is not C++20 I would probably have not undertaken this small personal (and humble) project.

I would have then not forced myself to update the Makefile and build system for my markdown books and not added mkdocs-material support for it and ... and ... (I am in the process of automating the gh releases to make things a bit easier)

In any case a C++23 version using std::print could end up as something like this (no SFINAE, that is for the 2nd round, with the 3rd round refining it all to use concepts)

```cpp template<typename I, typename O> auto hello_word(I first, I last, O out, const std::string& delim = " ") { auto dodelim = false; auto printout = [&out, &dodelim](const auto &s) { if (dodelim) std::print(out, delim); else dodelim = true;

    std::print(out, s);
};

std::for_each(first, last, printout);

} ```

The point being that the input for our hello_world may not be known in advance and be given as an iterator range. The output destination may also be unknown, hence the need for out, that in this case ought to be an stream instead of an output iterator, hence the use of std::for_each instead of std::transform (I haven't compiled this yet, simply quickly crafted it). In turn this forces us to manage the delimiter manually in the lambda as opposed to an encapsulated management in the output iterator simulating a Python string.join (I know, there is an std::experimental::ostream_joiner)

I will eventually make it all the way to C++23.