What do you like and dislike about C++

Pages: 12
The title says it all pretty much. You can say as many things you like and dislike about C++.

Personally, I like C++ because it allows you to do low-level programming and high-level programming and allows you to do a variety of things. I also have a bias towards since it is my first language ^^.

One thing I don't like is template syntax as it looks unappealing.
My biggest complaint, other than template syntax (who actually enjoys deciphering template metaprogramming code?), is the fact that the standard libraries don't include any way to do any reasonable GUI programming. Now, obviously this makes sense for a lot of reasons given the purpose of the standard library, the fact that C++ doesn't run in a virtual machine, et cetera; I know why it's the case. It just means that making any program with a GUI takes longer in C++ than in other languages due to the requirement to go out of my way to, say, install Qt and fiddle with that.

Honestly, if I could just use some really easy language just for GUI programming and then have all of its actual code be in C++, that'd be wonderful. Code all the functions in C++ that you'd need, then in this separate language import in some fashion those C++ functions (I'unno, have it all be in a library or something) and just use those for what'd be necessary for processing everything. Kind of like extending Python with C code, except it's some GUI scripting language that's extended with C++ code.


While typing all of this up, I now realize that Qt Creator is exactly this. Goddammit. I've been making crappy little applets in Java of all things all because I didn't realize that Qt provided exactly what I was looking for in the first place. I feel like a moron.
Last edited on
@Ispil hahah it's all good man. I know that feeling when your ranting about something only to realize that it's not true a few minutes later.
Is Qt free though? I thought it got bought out and now you had to buy it.
I would like the type system to be stronger. Although sometimes useful to write some pretty elegant generic code, implicit conversions often lead to code with surprising behavior.

Some decisions carried over from C are completely irrelevant today, and often actually harmful. Namely, that variables are uninitialized unless you explicitly initialize them. One informal proposal I saw once was that variables should be implicitly initialized (the behavior of existing programs would not change, since reading the value of an uninitialized variable caused undefined behavior at the time those programs were written. The performance is diminished in only the very slightest bit) and if uninitialization was desired, it should be explicitly specified with T foo = void;.

A proper metaprogramming sublanguage would be really sweet. Templates are really clever and all, but their Turing-completeness is an unexpected side-effect of their power. While you can do some pretty cool stuff with them, it's hard to defend a template metaprogramming diff in a code review against even a separate code generation step. Template metaprogramming code can pretty much only be maintained by whoever it is who wrote it.
I dont like template syntax either, because it doesn't have braces, which would make the readability of when one starts and ends easier.
Yes, Qt is still free in both senses.
Qt is free but is under LGPL and GPL which requires you to release source code or else no static linking and commercial licenses cost a lot, even for indie developers.
So it's not free, but it's free* (with an asterisk)
It's only not free if (for some weird reason) you need to link statically from a GPL-incompatible program or if you need to modify the source.
Nobody complained when Trolltech was doing it, so I don't see what the problem is now.
Template metaprogramming code can pretty much only be maintained by whoever it is who wrote it.


Can you elaborate on that - what is difficult about templates?

To me templates seem to be the main tool for duck-typing which appears to produce very readable code.

A student is working with my template-heavy code and he seems to be quite on top of it, and further does template things on his own; I can more or less read what he writes too.
Last edited on
Metaprogramming is much more than using templates for writing generic code. Basically, imagine it as another language entirely that runs at compile time. An example is using templates to generate factorials as constants in your code:
1
2
3
4
5
6
7
8
9
10
template <unsigned int n> 
constexpr unsigned int factorial = n * factorial<n - 1>;

template <>
constexpr unsigned int factorial<0> = 1;

// ...

std::cout << factorial<0> << '\n'; // == 1
std::cout << factorial<4> << '\n'; // == 24 

Though that may seem simple, it gets crazy very quickly.
@tition

helios is talking about TMP which is an almost entirely different game to ordinary templates.

https://en.wikipedia.org/wiki/Template_metaprogramming


boost::mpl is a meta-programming library, and IMO is rather clever.

I like the way it takes advantage of C++ expressive type system.

For example, take a class for a circular arc. There are lots of ways to construct one using various combinations of the centre point, the radius, various points on the arc, angles for begin and end points, and an arc length. To overload functions, we need different types for these things. Rather than manually create different types in the normal way, I used boost::mpl::int to make it easier to create some types:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef NAMEDTYPE_HPP
#define NAMEDTYPE_HPP

#include <boost/mpl/int.hpp>

namespace mpl = boost::mpl;

//TheTypes Section
using Radius = mpl::int_<1>;
using BeginAngle = mpl::int_<2>;
using EndAngle = mpl::int_<3>;
using ArcLength = mpl::int_<4>;

using EastOrdinate_t = mpl::int_<5>;
using NorthOrdinate_t = mpl::int_<6>;

using Point2D_t = mpl::int_<7>;

using ArcBeginPoint2D_t = mpl::int_<8>;
using ArcMidPoint2D_t = mpl::int_<9>;
using ArcEndPoint2D_t = mpl::int_<10>;
using CentrePoint2D_t = mpl::int_<11>;

// T is double or better,
// TheType is one of the above in TheTypes Section
template < typename TheType , typename T = double>
class NamedType
{
public:
    explicit NamedType(T x = 0.0)
       : m_value(x)
    {}
   NamedType(const NamedType& other) : m_value(other.m_value){}

   NamedType& operator= (const NamedType& other) {
//      A& operator=(A other) {
//              std::cout << "copy assignment of A\n";
//              std::swap(n, other.n);
//              std::swap(s1, other.s1);
//              return *this;
      std::swap(m_value, other.m_value);
      return *this;
   }


   T operator()() const {
      return m_value;
   }

   void operator()(T arg)  {
       m_value = arg;
   }

    T get_value() const { return m_value; }
 private:
    T m_value;
};

#endif // NAMEDTYPE_HPP 


I overloaded the operator() to make it easier to set or retrieve the value.

So I was able to successfully test function overloading with these functions, note the underlying types are similar, either double or a Point:

1
2
3
void TestOL(Radius_t Radius, BeginAngle_t BeginAng, EndAngle_t EndAngle);
void TestOL(BeginAngle_t BeginAngle, EndAngle_t EndAngle, Radius_t Radius);
void TestOL(EndAngle_t EndAngle, Radius_t Radius, BeginAngle_t BeginAngle);


It's contrived: the arguments are just in a different order, I only wanted to test the overloading.

I have use for this in other applications where I have dozens of different types of Distances, Angles, Points (World) and Vectors (deltaX, deltaY), their underlying type is double. So now this is much easier to have a header file with a bunch of one liners for all the types I want. This is much better than creating lots of struct's and avoids any inheritance.

Another thing I have been playing with, is to try and get all this working with boost::quantity. Not sure how that is going to work out: I have copied one of the examples and added an extra template parameter to everything, but it may not work with the internal templates of the library, because not are not expecting an extra parameter. Not sure about that though.


It's only not free if (for some weird reason) you need to link statically


https://wiki.qt.io/Licensing-talk-about-mobile-platforms :
It remains to be seen whether Apple will accept applications that bundle dylibs into the iOS App Store. If Apple does not accept applications that use bundled dylibs into the App Store, then it will be necessary to link Qt statically to the application. And as the Qt for iOS port uses the LGPL version of Qt, the rules for statically linking with LGPL will kick in - this can be a problem for closed source apps.


That's one reason you may want to statically link.

I would love if they sold commercial licenses to indie devs for a cheaper price.

I know recently they have released some commercial parts of the library under LGPL and GPL, which is cool.
Last edited on
Its hard to learn, and most compilers return meaningless errors.

I find it takes me a long time to do something I can do tidily in other languages, but I like that too, because of c++ my java is clear and adequate, the pragmatism is from c++.
It's hard to learn because most of the reference material is either outdated, overly complicated, moves at an inconsistent pace, or is just plain bad, which I find strange for a language that dates some 40+ years. Of all the beginner-friendly texts, I notice a familiar trend of:

-Outdated material that isn't C++11 compliant, despite being released years after the standard.

-Material that either starts off being more complicated than it should, or starts off at the right pace, like bicycling on a straight road, then the road suddenly goes 280 degrees, Stroustrup's "Programming Principles and Practice" being a particularly serious offender in the latter category, and strangely probably the best text resource. First four chapters are written extremely well, chapter 5 starts seriously rocking the boat, then about the middle of 6 on the boat washes over Angel Falls.

But all my complaints are rather mild. It's possible to persevere, but it's not without many false starts.
I dislike the general "you're writing something in c++ I expect you to want to do everything yourself from the ground up" idea.

Want to play a play two sine waves at once on your computer? You can either buy this library or spend the next two weeks learning all about audio theory you don't care about and "roll your own"

Screw rolling my own junk. I want to program something useful for my users, I don't want to make a damn library that I'll use once. I also don't want to spend 500$ on a single license for some library for a free program I'm making.

Bologna.

I dislike the general "you're writing something in c++ I expect you to want to do everything yourself from the ground up" idea.

Want to play a play two sine waves at once on your computer? You can either buy this library or spend the next two weeks learning all about audio theory you don't care about and "roll your own"

Screw rolling my own junk. I want to program something useful for my users, I don't want to make a damn library that I'll use once. I also don't want to spend 500$ on a single license for some library for a free program I'm making.

Bologna.
This must be the first time I've seen this complaint. I've been using C++ for 10 years or so, writing a fair variety of kinds of applications* and I've never had to pay for a single library.
As far as audio goes, both OpenAL and DirectSound are free. I don't know what else you could need to just output a sum of sine waves.



* GUI, game-like, audio playback, video playback, mobile, compilers, computer vision, web scrapping, etc.
I've never had to pay for a single library.


I've not paid for any libraries for personal projects either, for the realtime generation I was referring to the Bass library (which I actually just looked up, it is free for non-commercial applications, so my bad there)

Anyways expensive libraries are not really the complaint, I probably shouldn't have really included it. The complaint is the idea that because someone is a c++ developer we tend to expect them to do extra work because of it. Obviously it doesn't keep me from programming for a living nor does it keep me from programming on my free time ^_^

In my recent history I have not experienced this because I have a relatively significant project base to pull from, and I have a large collection of useful libraries. But back several years it was a bit of a nightmare, c++ is quite vast, there are many libraries for many things- many ways you can compile your code, when I was new I found it quite difficult to get beyond the fledgling stage because of the lack of good information and general attitude of doing things manually.

Compare that to many other languages, the attitude is very different. Python for example, the general atmosphere is how can we make this easier?

Of course the languages are fundamentally different, and things need to be different because the two languages serve different roles- but that ideal is why I'm writing that GUI library I mentioned in my other post.

I wish it were easier for beginners to perform the basic tasks developers needs to perform. Making a GUI, making some noise, connecting to external devices, connecting to the internet, parsing modern data in modern formats (JSON), etc. Android and iOS have filled this gap pretty well with their APIs, but I don't feel like that has extended to the other standard platforms.

Maybe that doesn't make sense, I don't know, it's just the experience I've had- maybe others have experienced other things.
C++ doesn't offer built in support for many things, but on the other hand, there are probably more libraries accessible to C++ programmers than for almost any other language. And you have languages like Java, that have built in support for GUI, and everything else, but at the same time, IMO, they are at best meh in quality. Sure it's inconvenient especially for a beginner to have to go looking around for solutions, but this is an important skill. Especially the more advanced or novel the projects you take on, the more you have to go outside the box in any language. C++ programmers are not expected to do more work by rolling their own all the time, it's expected that they can go find and use the state of the art implementation out there for their specific needs. Meanwhile, the C++ committee is extremely careful not to start bloating the standard library with a bunch of junk.


Last edited on
Pages: 12