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

Modern C++ #88

Closed
hugbug opened this Issue Oct 11, 2015 · 3 comments

Comments

Projects
None yet
1 participant
@hugbug
Member

hugbug commented Oct 11, 2015

Intro

When developing NZBGet one of the priorities always was to make it work on as many devices as possible. Due to a wide variety of platforms we could not control which version of compiler is used. To make it compatible even with old compilers NZBGet was targeting old C++ versions.

In last years C++ has been evolved dramatically. New versions were standardized by ISO as C++11 and lately C++14. These new standards bring many interesting features to the language making it much more pleasure to work with.

In the meantime major Linux distributions have updated their compilers to GCC 5, which supports C++14. Xcode on OS X includes C++14 compatible compiler. MS Visual Studio 2015 is compatible with C++14 as well.

Moreover after the introducing of universal Linux installer in v15 we now offer precompiled binaries for three major platforms (Windows, Linux, OS X). This makes it less important which compiler is installed on user machine since only few users compile themselves.

So now it is the time to upgrade the code base of NZBGet to C++14.

First steps (prerequisites)

  • upgrade Linux build machine to use GCC 5.2 for all targets included in universal installer (#101);
  • upgrade Window build machine to use MS Visual Studio 2015 (#102).

Deep refactoring and new C++ features

  • change source code naming convention (#103);
  • put all external headers together (#115);
  • improve code formatting (#176);
  • use precompiled headers (#115);
  • use size specific integer types (#116);
  • use string classes for managed string handling (#126);
  • use namespaces (#133);
  • nullptr instead of NULL (#138);
  • store objects directly in containers (#143);
  • avoid "malloc/free" for temporary buffers (#156);
  • for-range loop with iterators (#152);
  • use lambdas with containers (#154);
  • prefer references to pointers (#151);
  • prefer stack objects (#167);
  • prefer safe memory management alternatives to plain "malloc/free" (#172);
  • use in-class member initializers (#175);
  • use std::shared_ptr for shared resources (#182);
  • indicate object ownership with std::unique_ptr (#148, #168);
  • exception safe (RAII) lock handling (#185).

New standard libraries

  • built-in regex-library instead of external regex - optional;
  • built-in concurrency-library instead of system specific pthreads or windows threads - optional.

@hugbug hugbug added the meta label Oct 11, 2015

@hugbug hugbug added this to the v17.0 milestone Oct 11, 2015

@hugbug

This comment has been minimized.

Show comment
Hide comment
@hugbug

hugbug Oct 12, 2015

Member

GCC versions

C++ standard is big and complex. Compilers add support for certain C++ feature incrementally. GCC claims full support for C++14 in GCC 5.0. However many features were added in older GCC versions, since it was a long process of adding them through the years.

According to this chart the C++11 features were fully implemented in GCC 4.8; C++14 in GCC 5.0.

Even if your system compiler is an older version it should be possible to build a toolchain with newer compiler version (not necessary to install it system wide) but that is of course extra efforts.

Member

hugbug commented Oct 12, 2015

GCC versions

C++ standard is big and complex. Compilers add support for certain C++ feature incrementally. GCC claims full support for C++14 in GCC 5.0. However many features were added in older GCC versions, since it was a long process of adding them through the years.

According to this chart the C++11 features were fully implemented in GCC 4.8; C++14 in GCC 5.0.

Even if your system compiler is an older version it should be possible to build a toolchain with newer compiler version (not necessary to install it system wide) but that is of course extra efforts.

@hugbug hugbug added the refactoring label Oct 20, 2015

@hugbug hugbug modified the milestones: Modern C++, v17.0 Oct 21, 2015

@hugbug

This comment has been minimized.

Show comment
Hide comment
@hugbug

hugbug Mar 19, 2016

Member

New standard libraries

  • built-in regex-library instead of external regex;
  • built-in concurrency-library instead of system specific pthreads or windows threads.

The switch may bring compatibility and stability issues. The implementations of regex seem to not be fully standard compliant. Every compiler has its own implementation. Currently we use the same library on all platforms.

As for concurrency this requires more testing and will probably not bring much to NZBGet.

I've decided to not switch to new standard libraries for regex and concurrency for now.

Member

hugbug commented Mar 19, 2016

New standard libraries

  • built-in regex-library instead of external regex;
  • built-in concurrency-library instead of system specific pthreads or windows threads.

The switch may bring compatibility and stability issues. The implementations of regex seem to not be fully standard compliant. Every compiler has its own implementation. Currently we use the same library on all platforms.

As for concurrency this requires more testing and will probably not bring much to NZBGet.

I've decided to not switch to new standard libraries for regex and concurrency for now.

@hugbug

This comment has been minimized.

Show comment
Hide comment
@hugbug

hugbug Mar 19, 2016

Member

Considering the migration to Modern C++ completed.

That was a lot of work and the code base looks much much nicer now.

Member

hugbug commented Mar 19, 2016

Considering the migration to Modern C++ completed.

That was a lot of work and the code base looks much much nicer now.

@hugbug hugbug closed this Mar 19, 2016

@hugbug hugbug referenced this issue Mar 24, 2016

Merged

Fixed guards. #193

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment