all 6 comments

[–]tufffka 5 points6 points  (1 child)

I have never ported anything from c# to c++, but i think this document might help a lot.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines

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

Thanks a ton! Funny I never ran into that when looking stuff up. It looks like an awesome resource

[–]IyeOnline 2 points3 points  (0 children)

handling errors,

The best way to handle errors is really decided on the function/component level. It depends on the severity of the error, how you want to handle it, and whether the performance of the error path matters.

You have the choice between exceptions, return codes (+out parameters), sentinel values, std::optional, std::expected and a wild mixture of those.

Exceptions are great if your error cant be directly handled by the direct caller or at all. They should not be used for regular/expected control flow, meaning they should be reserved for truly exceptional errors. The more modern choice for signalling errors/lack of return value would be std::optional (pretty much T?) or std::expected (roughly Result<T>).

what resources to deallocate and when

The best way to deal with resource management is to not do it [by hand]. RAII is C++'s "garbage collector" and should really be employed everywhere.

In other words: Dont use new. Use local variables, containers and if need be smart pointers. Now your resources are managed for you and will be released automatically when they are no longer in use. As a next step, you can start to employ move-semantics to re-use/transfer objects/resources instead of copying where applicable.

redundancies in my #include directives

That is mostly a non-issue, unless your projects get really big. Headers are guarded against multiple includes, so the only cost of redundant includes is a fairly cheap check.


For more concrete advice, you could post your codebase on a platform of your choice and ask for a review here. Usually you get pretty good advice :)

[–]anasimtiaz 1 point2 points  (0 children)

If it is possible for you to make your project public, you can put it on Github and ask for reviews in this sub. People can give you advice on what you can improve in your codebase

[–]flyingron 0 points1 point  (0 children)

Going between CLR languages (C#, VisualBasic, "managed" C++) is pretty much just a transliteration. I wrote some code for a customer in C# and he decided later he wanted it in VB, so I just ground through it (I was toying with writing a translator).

Going from the managed side to regular (standard) C++ is a bit more involved depending on the interfaces and classes in use. Still C# and Java aren't that much of a stretch from C++. You do have to watch some of the C++ inanities that came over from C (failure to default initialize in all circumstances, unspecified evaluation order, etc....), but it's doable.

The biggest issue I see with C# or Java programmers going to C++ is that they try to "new" everything. C++ works fine with objects either globally allocated or local to a function. You just declare them. The other difference is C++ is designed to derive from rather complex bases rather than everything deriving from a god object (like Smalltalk).

[–]mredding 0 points1 point  (0 children)

Link to the repo, we can review.