Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Business objects cpp #1985

Draft
wants to merge 17 commits into
base: stable
Choose a base branch
from

Conversation

christopherlam
Copy link
Contributor

No description provided.

@christopherlam
Copy link
Contributor Author

christopherlam commented Jul 24, 2024

some .c were using 0 which didn't map to a valid enum. I've modified behaviour slightly to avoid them.

EDIT: they're causing PERR messages in a regular datafile.

Copy link
Member

@jralls jralls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing technically wrong here, but it has a lipstick-on-a-pig feel to it. The only thing you're changing to C++ is using std::optional to replace a boolean value pair. What's your ultimate goal?

Comment on lines 45 to 47
GNC_PAYMENT_NONE = 0,
GNC_PAYMENT_CASH = 1,
GNC_PAYMENT_CARD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as you increment by 1 you need only assign the first one, and 0 is the default so you can just add the 0 enum and skip the initializer, e.g.

typedef enum
{
    GNC_PAYMENT_NONE,
    GNC_PAYMENT_CASH,
    GNC_PAYMENT_CARD
} GncEntryPaymentType;

Comment on lines 79 to 83
{
GNC_AMT_TYPE_DISABLED = 0, /** no tax */
GNC_AMT_TYPE_VALUE = 1, /**< tax is a number */
GNC_AMT_TYPE_PERCENT /**< tax is a percentage */
} GncAmountType;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are remarkably useless comments.

@christopherlam
Copy link
Contributor Author

Main goal is to benefit from C++ stricter type checking etc.

@jralls
Copy link
Member

jralls commented Jul 25, 2024

Main goal is to benefit from C++ stricter type checking etc.

I don't think you can do that incrementally: Polymorphism in both GObject and QOFObject depends on passing and casting void* and that's fundamentally incompatible with C++ types. A bottom-up approach, meaning a fresh implementation beginning with C++ polymorphism, either run-time via derived classes or compile-time via std::variant, is much more likely to succeed. That's not too hard for the GObject side. You'll have to provide some C wrappers for the GUI to use. The real obstacle is QOFQuery. We want to get rid of it and use SQL instead so rewriting it in C++ would be wasted effort.

@christopherlam
Copy link
Contributor Author

I think there's some benefit to incrementally converting more files to c++ -- it means the next milestone can be "all of libgnucash is now c++". It means more the headers can be .hpp and have less ifdef __cplusplus clutter...

@jralls
Copy link
Member

jralls commented Jul 27, 2024

it means the next milestone can be "all of libgnucash is now c++".

No, there's a huge yawning chasm between "compiles with the C++ compiler" and "is C++". The goal is emphatically not to get libgnucash to compile with the C++ compiler. There's no real benefit to that. There's some benefit to rewriting functions to use C++ std algorithms and using STL containers instead of GLib ones, but even that doesn't really help solve our main problems of memory management errors and spaghetti code. Plus those algorithms and containers work much better when they're used with real C++ objects.

It means more the headers can be .hpp and have less ifdef __cplusplus clutter...

That requires the consumer code also to compile with the C++ compiler: Swig files, Gui files, import-export files. That's a lot of extra work that can be made less by reducing the API and pushing the specialization out to the user that needs it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants