Modern C++

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
nickjstone
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Nov 15, 2021 7:22 pm

Modern C++

Post by nickjstone »

What is the philosophy regarding updating the wxWidgets library code to modern C++? I read in the coding guidelines that "nullptr can’t be used in wxWidgets code as it must remain compatible with non-C++11 compilers." This is a bit disappointing for someone who would like to contribute to the library but enjoys modern C++. Will the requirement to be compiled by non-C++11 compilers eventually be deprecated?

I guess the same question applies to many features (some still to come) of modern C++. For example, I read that exceptions are not thrown by the library as existing code is not written to handle them; does this mean there will never be a wxWidgets library that uses this C++ feature?

Apologies if this question has been asked before; I searched but it is hard to know what search terms to use; "modern C++" "C++ 20" etc don't work!
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Modern C++

Post by doublemax »

You should better ask this at the wx-users group where the core wx developers can see it. This here is a user forum.
https://groups.google.com/g/wx-users

On a personal note: The moment wx starts throwing exceptions, i'll stop using it. That's a horrible feature.
Use the source, Luke!
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Modern C++

Post by catalin »

nickjstone wrote: Mon Nov 15, 2021 7:28 pm What is the philosophy regarding updating the wxWidgets library code to modern C++? [...] Will the requirement to be compiled by non-C++11 compilers eventually be deprecated?
Newer C++ standards have been mentioned before, last I've read was that after v3.2 "at least C++11 (and maybe C++14) will become required", here. Just for the sake of discussion, I'd like to see it going for C++17 (highly improbable), but it will surely not adopt C++20, because it would mean dropping support for almost all compilers out there.
3.2 is scheduled A.S.A.P., for the end of this year, so this subject will surely be discussed on the mailing lists after that.

nickjstone wrote: Mon Nov 15, 2021 7:28 pm I read that exceptions are not thrown by the library as existing code is not written to handle them; does this mean there will never be a wxWidgets library that uses this C++ feature?
As a separate subject, I'd say there are 0 chances of exceptions being adopted (not that I'm in favor of starting using them either).
So a short answer regarding official libs would most likely be "no".
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Modern C++

Post by PB »

catalin wrote: Mon Nov 15, 2021 10:35 pm 3.2 is scheduled A.S.A.P., for the end of this year, so this subject will surely be discussed on the mailing lists after that.
Actually, the release dates were pushed back a bit recently:
https://github.com/wxWidgets/wxWidgets/milestones
https://trac.wxwidgets.org/wiki/Roadmap ... anchand3.2

And the new stable branch after that will be v3.4 (inheriting development branch 3.3) which may not be released in this decade (the current stable branch 3.0 was released in 2013).
nickjstone
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Nov 15, 2021 7:22 pm

Re: Modern C++

Post by nickjstone »

Many thanks for the replies.

Doublemax: Thanks for the link to wx-users group; I didn't know that existed.
Catalin and PB: Thank you; your links told me all I need to know.

As someone new to wxWidgets, it is great to discover such a helpful community.
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Modern C++

Post by catalin »

PB wrote: Tue Nov 16, 2021 9:30 amthe new stable branch after that will be v3.4 (inheriting development branch 3.3) which may not be released in this decade
Things will most likely evolve that way, but saying it like that could be very discouraging :) Before 3.4 stable will be released there will be 3.3 development releases. And more than that, the master branch will accept contributions using the newer C++ standard immediately after 3.2 was released.

So an official "stable" release containing them is indeed quite far away, but the possibility of contributing using newer C++ standards is just a few months away. :wink:
nickjstone
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Nov 15, 2021 7:22 pm

Re: Modern C++

Post by nickjstone »

That's very encouraging. Thanks for clarifying.
User avatar
samofvt
Earned a small fee
Earned a small fee
Posts: 14
Joined: Sun Mar 25, 2012 2:20 pm

Re: Modern C++

Post by samofvt »

Actually... :-) ... I was compiling wxWidgets 3.x in the visual C++ environment using C14 quite a few years ago. The only hold-up was a single function in the wxArrayString class that had been depreciated in the newer stdlib. I found a 5 line work-around, and was able to compile the whole library using C14 at least 5 years ago. Haven't had the need to go to C17 or later yet.

Use of "nullptr" is difficult because some platforms use that as a special token. At least one C++ CLI/COM environment comes to mind, who adopted that to mean something special long before it became a thing in standard C/C++. "null" is fewer characters shorter anyway, and makes no difference afaik.

My point is, you can use practically any modern C++ construct you want in your user code, as long as it doesn't conflict with your environment and is supported by your compiler.

And as others have said: a big NO THANK YOU to exceptions. It creates a separate, hardly managed, alternate pathway of execution for execution. Just write clean code that doesn't throw errors, or if it does, someone will know it ;-) I hear a lot of talk about "dangerous" stuff in code. Even if it were running the space station, as long as someone monitors it and knows when it crashes, who cares ? Not really "dangerous", just inconvenient. And even then, you can still use exceptions in your user code if you're working on something experimental/half baked. It'll compile fine with the core libraries even if they were built with exceptions.

All that said, I wouldn't mind seeing a wxWidgets version 4.0 that supports all the latest "modern" features and leaves the legacy platforms behind. It's not a minor undertaking, though, and I also understand it's not a bad idea to take things slow and steady.
nickjstone
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Nov 15, 2021 7:22 pm

Re: Modern C++

Post by nickjstone »

Hi Samofvt,

Thanks for the reply but yes, I know I can use modern C++ in code that uses wxWidgets. I was asking about contributing to the library itself.

Re nullptr, the advantage over NULL is related to type safety. Also things like "Function Calling Ambiguity".

Its clear that some users of wxWidgets would be opposed to the use of exceptions within the library. I'm not going to argue the case but would say that there are times when they are enormously useful. The C++ Committee thinks very carefully before adding features and it would be a shame if wxWidgets completely outlawed any. I think that approach might alienate some of those who are passionate about C++.

As for not caring about software crashes - er, er - sometimes people do care enormously!!! When writing software, every effort imaginable should always be made to avoid crashes (usually!).

Totally agree with your final point; "it's not a bad idea to take things slow and steady".
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Modern C++

Post by ONEEYEMAN »

Hi,
You can successfully compile the library in all C++11/14/17, because the library can be used with appropriate standard. And the library should be cmpiled with the same standard as a user code.

There is a talk about requiring the higher C++ standard, but as said before it might happen after the 3.2.

Thank you.
Post Reply