C vs C++

Not about OpenMW? Just about Morrowind in general? Have some random babble? Kindly direct it here.
User avatar
psi29a
Posts: 4881
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: C vs C++

Post by psi29a » 02 May 2017, 17:55

afritz1 wrote:I started my Arena re-implementation from scratch in C++11. I never have to worry about memory management at all because of std::unique_ptr, which is a big deal for a language biased towards systems programming. Restricting yourself to the "modern" subset of C++ is very worthwhile if you can do it. It eliminates an entire class of bugs. I also frequently use bounds-checking (i.e., std::vector::at) because I'd rather have an out-of-range exception than a segmentation fault/access violation.
Might I interest you in my PR turning OpenMW into a C++11 project? :)
https://github.com/OpenMW/openmw/pull/1017

User avatar
afritz1
Posts: 47
Joined: 05 Sep 2016, 01:18
Contact:

Re: C vs C++

Post by afritz1 » 02 May 2017, 18:40

kcat's comment in that pull request already said most of the things I was thinking. I haven't needed Boost at all, so if that could be steadily removed from OpenMW over time, I think that's another bonus you could have from switching to C++11. I haven't touched the OpenMW codebase yet, so I don't know how tightly coupled Boost is with everything. I'm not familiar with OpenSceneGraph's API either, but maybe there could be some small improvements done around that code as well.

User avatar
AnyOldName3
Posts: 1876
Joined: 26 Nov 2015, 03:25

Re: C vs C++

Post by AnyOldName3 » 02 May 2017, 18:59

The configuration system makes heavy use of Boost Program Options, and I think that might be quite a pain to remove, as it'd need replacing.
AnyOldName3, Master of Shadows

User avatar
Jyby
Posts: 408
Joined: 10 Dec 2013, 04:16

Re: C vs C++

Post by Jyby » 06 May 2017, 00:06

The real pain is converting C to C++ in legacy projects. Imagine the 15 million line Linux Kernel converted to OOD with C++... What a pain in the ass. My company is in the process of doing this now for one of our products.

Even if your project is C++, it can still be a pain/not worth the effort to upgrade the code base to C++11 onward. And who knows if it's even good OOD.

Removing a complex feature from a code base that is essentially obsolete can be awful too. For example my company's project in QNX has code that no longer works to compile and run on Windows 98.. The code is littered with #if #endif. Awful design, but what are 2 engineers on proof of concept hardware supposed to do.

At some point you gotta ask yourself, do we port or do we do a rewrite or nothing at all. I'm definitely for rewriting 20+ year old projects if the goal is more modern code.
Macbook Air 2013 - 1.7GHz Intel i7 - 8 GB - 512 GB SSD - Intel HD 5000
Windows 10 PC - 4GHz Intel i7 - 16 GB - 512 GB SSD - EVGA GTX 1060 SSC

User avatar
raevol
Posts: 3085
Joined: 07 Aug 2011, 01:12
Location: Caldera

Re: C vs C++

Post by raevol » 06 May 2017, 00:37

Wow that sounds like a mess. Sounds like a really interesting problem though!

User avatar
psi29a
Posts: 4881
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: C vs C++

Post by psi29a » 06 May 2017, 07:59

Jyby wrote:The real pain is converting C to C++ in legacy projects. Imagine the 15 million line Linux Kernel converted to OOD with C++... What a pain in the ass.
I know this was an example, but no one in their right mind would think that converting the Linux Kernel to C++ would be a good thing.

Then there is Linus with his Troll hat on:
Linus Torvalds wrote:C++ is a horrible language. It’s made more horrible by the fact that a lot of substandard programmers use it, to the point where it’s much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C [for the Git project] were to do *nothing* but keep the C++ programmers out, that in itself would be a huge reason to use C1.
This hasn't aged well IMO, I think many substandard programmers have moved on to other languages now. ;)

ezze
Posts: 428
Joined: 21 Nov 2013, 13:20

Re: C vs C++

Post by ezze » 06 May 2017, 16:45

First, let us start with a famous quote: "There are only two kinds of languages: the ones people complain about and the ones nobody uses." The are only two should be taken with a bit of salt.


I used C++ much more than C so I might be biased. But I honestly find most of the complains on C++ totally unfounded.
Each language has its quirks and idioms, but unlike other languages C++ never takes a break. And most complains sounds like this: "I find this feature not necessary for my project, so it is bad." or "I misused this feature and now I have a problem. The language sucks" or "I like this feature from language X, C++ does not have it and I do not care about (possibly superior) alternatives, the language suck".


The real problems I see are: (1)horrible error messages, (2)no good places to learn it, (3)terrible community. (The strong adjectives are hyperboles...)

C is meant to be an universal assembly and this is what it does. Is this what you need? Good, do it. Don't waste your time to state how your language is better, it's not. Otherwise everyone would use it. Besides, many of the worst stuff in C++ come from its compatibility with C, I really think Stroustrup wanted to merge the two languages so the two standards committee could work together and define C as a subset of C++. It did not happened and now the two languages are separated.

C++ does much more, gives you a lot of extra flexibility and expression power. I goes from low level (almost) as C to high level. As consequence also the complexity increases, fortunately as programmers usually this complexity is hidden from you and you do not have to worry (Unless you finish in problem 1). An example I like to bring is about namespaces, you use them, they help you and they work as you naively expect. They are more complex of what you might think, but you do not really care unless you need to write a compiler. This point is fairly universal but once again, people see the problem on C++ but not on other languages; Java7 specification is longer than C++11 specification, yet you will hardly ever hear somebody stating "Java is more complex that C++" Why? Because usually this complexity does not really bother you.

About point 2, we are not in the '90 anymore and C++ should not considered as derived by C, now they are sibling languages, just like with Java. So, it should be thought as a new language, the C compatibility part is actually advanced C++ that comes in if you want to make libraries or combining C++ with other languages. Yet, lots of people, even professionals, still teach C++ as "C with some more complex stuff." Obviously, as result, you have bad programmers that do not understand the advantages/differences of C++. Sure it's stupid that int a[5] passed to a function decays to a pointer, but you should use std::array and not think about it. Sure the [[carries_dependency]] attribute is difficult to grasp, but do you really need it?

About point 3, the language is complex. The complexity is an unavoidable effect of having a such general purpose language, but as I said in most of the cases you do not really care. Yet, the community tend to focus on little technicalities more than helping. The effect is frustrated beginners and bad documentations. I saw multiple times almost unreadable documentation (overall in template libraries) when actually the functions worked as you naively expected. So, just writing a little example and a high level explanation first and putting after the technicalities would make the read much easier.
I also notice an annoying elitarianism, just think that the official FAQ insults you for trying to learn! Or the How to mix C and C++ question does not bother to tell you how to map C++ exceptions in C code. You know catch(...)? Good. You don't? The FAQ does not help you.

I could continue for hours... but better stop.

User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: C vs C++

Post by sirherrbatka » 06 May 2017, 17:38

Besides, many of the worst stuff in C++ come from its compatibility with C,
I disagree. Does stuff like:

Code: Select all

int foo(int a)
{
 return a;
}

class foo
{
 public:
  foo(int a);
};

int main()
{
 something(foo(5));
}
Comes from C? Does glaring hole in templated constructors does? Lack of any higher level control over templates? Symbol mangling? Preprocessor is not everything.
About point 3, the language is complex. The complexity is an unavoidable effect of having a such general purpose language
It is avoidable. Issue here is that C++ has no layered structure. Standard template library has, but it came later. Anyway, tell me a single language with comparable crap as error messages.

As a matter of fact I think that C++ is language that derives it flaws from design errors in the earliest stages of design. And it is really horrible language. But I still rather use C++ over C. Mostly because it is C with crap load of sometimes broken but at the very least optional extensions. It is not a downgrade from C in any possible way.

ezze
Posts: 428
Joined: 21 Nov 2013, 13:20

Re: C vs C++

Post by ezze » 06 May 2017, 18:32

Actually, I am fairly sure it comes from the C name spaces of identifiers so... yeah?

About the "glaring hole" you are speaking of gotw 76? I never honestly saw the problem, when you are extending the interface to a new type accessing the privates becomes normal.

The other two... yes, it is hard to say what they where thinking. Templates obviously evolved strangely, hopefully it will get better in the future. The symbol mangling is a necessity for overloading, but why it is so messy escapes me.

And the crap error messages are my problem nr 1 so I obviously agree. On the other hand there are not so many languages that go from low to high level and with such expression power (Rust promises well, we'll see the test of time) and the gcc guys for decades fought against better diagnostic for "technical and philosophical reason," from this point of view Clang helped a lot.
I also agree about initial design error, in fact now that it is clear that C and C++ will never become one C++ improved, the jump between C++03 and 11 shows it well.

Oh well..

User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: C vs C++

Post by sirherrbatka » 06 May 2017, 18:51

Actually, I am fairly sure it comes from the C name spaces of identifiers so... yeah?
Nah, they could just have keyword new alongside, let's say, create. One allocates on heap, another on stack. But nobody thought about that.
About the "glaring hole" you are speaking of gotw 76? I never honestly saw the problem, when you are extending the interface to a new type accessing the privates becomes normal.
Nope. I wast talking about that:

Code: Select all

class foo {
 public:
  template<typename S>
  foo() {};
};
Now please try to use this constructor. There is no syntax to do so. This is what i mean by saying that C++ is badly designed language: it even has undeterministic syntax. You simply can't parse C++ and be 100% correct because nobody can ever be correct when parsing C++. And there is a lot of other design mistakes.
On the other hand there are not so many languages that go from low to high level and with such expression power.

That is poor man excuse. C++ provides you with all sorts of tools to introduce complexity, but not so many tools to manage it. For instance, where are concepts? Not in C++11, not in C++14, not sure about C++17… Syntax that can't do it's job does not make things any better. Besides, C++ is not so high level anyway.

Post Reply