News for hackers. Stuff that matters.
Re:C++ confessions of a C developer by tluyben2 on Saturday December 03, 2016 @04:51PM (#13097689)
After many years of writing a self confessed horrible mix of C/C++ and calling it C++ (and I think more people have done that), I decided to learn C++11 and then C++14. I am enjoying it quite a bit I must say... Anyone else have that experience?
Re:C++ confessions of a C developer by eropple on Saturday December 03, 2016 @07:38PM (#13098215)
I learned how to write "C++" in the early 00's when I was the maintainer of a half-assedly "converted" CircleMUD that more or less just used function overloading so the idiot--err, charming gentleman--from whom I inherited the codebase didn't have to remember the order of arguments for "send text to character".

I then didn't touch it for most of a decade and re-learned C++ essentially from scratch maybe...three years ago? C++11 from the jump, with slowly adding in C++14 stuff as it made sense. And I like it well enough. It's never going to be my first-choice language, but that's because the environment around C++ is a mess rather than the language itself. The language has stuff to know, but I find that most of it is stuff that is totally comprehensible given that I understand how C++ works--like, of course I need virtual dtors if I've got classes, because I understand vtables and the necessity for a lookup in one. It's complex, in that there are a ton of different components, but I don't find it complicated, in that any component is difficult to understand in isolation or that the interactions between components have particularly many gremlins. (Which isn't to say that I'm a particularly good C++ developer or anything, but I understand the land mines and how to be better at stuff I need to be better at when it matters.)

These days, I can't envision ever writing more C than is necessary to wrap C++ for use as a library in Ruby, etc.; life's too short to not have dtors.

Re:C++ confessions of a C developer by revelation on Saturday December 03, 2016 @06:29PM (#13098005)
I made a conscious choice to use some of the new stuff like unique_ptr (primarily) and shared_ptr for memory management w/ move, lambdas, range loops and forward for varargs functions that are not an unsafe macro mess, constexpr, static asserts. It was quite nice, some of that is due to compiler progress, i.e. I always run with address sanitizer now.

Sadly they seem to have added more than they cleaned up. It's 2016, I don't want to have to write another freaking include guard. That should have ended years ago. UTF8 and friends are also a consistent pain, mostly because 3rd party library support is absent. This requires a strong message from the standard library or it's always going to falter.

Re:C++ confessions of a C developer by mrich on Saturday December 03, 2016 @07:29PM (#13098190)
pragma once is supported by enough compilers to be considered a standard by now :)
Re:C++ confessions of a C developer by slavik81 on Sunday December 04, 2016 @03:27AM (#13099279)
I built guardonce[1] to help mitigate complaints that #pragma once was non-standard. If you can easily convert back to include guards, you can worry less about what compilers you might support in the future and just consider the compilers you support right now.

[1]: https://github.com/cgmb/guardonce

Re:C++ confessions of a C developer by gpderetta on Sunday December 04, 2016 @05:40PM (#13102170)
FWIW we had our build system broken on MSVC because of pragma once. IIRC it was an issue with symlink.
Re:C++ confessions of a C developer by PeCaN on Sunday December 04, 2016 @02:15AM (#13099126)
The annoying thing is that in spite of the fact that everyone (including the bizarrely malcompliant and bug-ridden bcc32 compiler I use at work) supports #pragma once, it will never get standardized simply because pragma anything is supposed to be strictly implementation-defined.
Re:C++ confessions of a C developer by pizzaisthebest on Saturday December 03, 2016 @07:23PM (#13098168)
> It's 2016, I don't want to have to write another freaking include guard.

I'd say there are bigger issues with C++ than include guards, but include guards should be out when modules are in the standard (2020?).

Re:C++ confessions of a C developer by astrodust on Saturday December 03, 2016 @09:33PM (#13098522)
Modules are a gargantuan step forward. While we'll likely never get the effortless compilation speeds achieved by Pascal, hopefully the three day build on top-of-the-line hardware is a thing of the past.
Re:C++ confessions of a C developer by revelation on Saturday December 03, 2016 @07:54PM (#13098241)
It's pars pro toto, yes what I actually need is modules to do the whole forward declaration pimpl extern template stuff for me.
Re:C++ confessions of a C developer by kartan on Saturday December 03, 2016 @06:01PM (#13097913)
> and calling it C++

We used to call it C+. It was code that could not be compiled by a C compiler. But at the same time was painfully obvious that it was not proper C++.

Re:C++ confessions of a C developer by pzh on Saturday December 03, 2016 @07:26PM (#13098179)
I think there is this misconception that there is a 'proper C++'. C++ was designed to support various programming styles, including this 'transitional' style where you have a C codebase that you slowly convert to a more object-oriented style, but overall it still remains an ugly mix of the two.

What makes C++ proper is pretty much what code style and best practices your organization/project decides to adopt. For some projects, 'proper' may be object-oriented C++ with class hierarchies, whereas for others it may be a more functional or template-based style that doesn't even use classes a lot.

Re:C++ confessions of a C developer by astrodust on Saturday December 03, 2016 @09:35PM (#13098526)
As C++ features started to creep back into C you'd see a lot more of this. The // comment identifier is perhaps the most famous of these.
Re:C++ confessions of a C developer by pjmlp on Sunday December 04, 2016 @02:09AM (#13099111)
const came first.
Re:C++ confessions of a C developer by astrodust on Sunday December 04, 2016 @04:42PM (#13101922)
Nobody in the C world really cares about const, it's extremely rare to see it in the wild. The // comments, though, are ubiquitous.
Re:C++ confessions of a C developer by pjmlp on Sunday December 04, 2016 @06:18PM (#13102309)
Yet another proof why C software is so safe, when comments are more important than correctness.
Re:C++ confessions of a C developer by astrodust on Monday December 05, 2016 @01:18PM (#13107744)
The const keyword has nothing to do with correctness and everything to do with helping the compiler understand which values are immutable and can be optimized.
Re:C++ confessions of a C developer by pjmlp on Saturday December 03, 2016 @06:40PM (#13098040)
I don't get to write much C++ code at work, given that we switched focus to become mostly a Java/.NET shop around 2006.

Even C++ARM was already a pleasure compared with bare bones C.

I has lucky to be able to bring Turbo Pascal best practices into C++, and that Borland had very good tooling.

On my opinion, Turbo Vision, Object Windows Library and Visual Control Library beat anything that I saw from other vendors in regard to C++ frameworks for desktop applications.

It always saddened me that given C++'s compatibility with C, most vendors would just throw over the fence a C library and it was up to us to create sane C++ bindings for them.

A good example is the sad state of database bindings.

But I do use C++ on personal projects, and C++11/14 has been quite rejuvenating and I do enjoy using it, specially for hobby coding across mobile OSes, given that it enjoy first class support in all SDKs.

Re:C++ confessions of a C developer by slavik81 on Saturday December 03, 2016 @08:24PM (#13098313)
When I was just starting programming, I was taught that if you use printf, it's not real C++. Over the years that followed, I slowly learned about all the trade-offs involved with iostreams, and I became increasingly distrustful of complaints that were not about specific problems, but just that similar code would be possible in C.
Re:C++ confessions of a C developer by satysin on Saturday December 03, 2016 @05:19PM (#13097777)
Most C++ programmers I have known wrote C++98 as C and did a crap job at it. [0] However C++11/14/17 are almost like new languages in a way. Using C++11 or later is actually a lot of fun, it isn't the horror show it used to be. Not as comfy as C# or Java but not like walking on broken glass anymore :)

Edit [0] Not saying I was any better :o)

Re:C++ confessions of a C developer by huu on Saturday December 03, 2016 @05:09PM (#13097750)
I'm on a similar boat. The biggest change for me was to recognize that I'm not the one who's supposed to be doing the debugging. The more (modern) C++ I wrote, the more I found myself leveraging the compiler to find bugs for me.
Re:C++ confessions of a C developer by int_19h on Sunday December 04, 2016 @02:14AM (#13099124)
Back in the day, embracing the STL and Boost way of doing things, and treating C++ less like "Java where you have to write * in variable declarations", certainly did a lot to improve both productivity, and my enjoyment of the language.
Re:C++ confessions of a C developer by gpderetta on Sunday December 04, 2016 @05:34PM (#13102144)
Yes, pointers everywhere, gratuitous use of the heap and deep class hierarchies is often derogatively called Java-style, but to be honest that's unfair to Java as that style predates it; Java was explicitly designed to make that style usable.
Re:C++ confessions of a C developer by developer2 on Sunday December 04, 2016 @06:22AM (#13099615)
As a non-C++ developer, I'm curious just how many developers who choose C++ are using Boost. From what little I have heard from friends, it seems that C++ essentially implies using Boost - which could be seen as a good thing, or a really really bad thing.
Re:C++ confessions of a C developer by user5994461 on Sunday December 04, 2016 @08:00AM (#13099834)
Well. One doesn't have to use boost ever. I'd assume that most C++ programmers out here don't use boost on a daily basis.

At the heart of the languages, in C you can only make additions and divisions, in C++ you can also make classes and use containers to store data.

These are very low level building blocks, it's not enough to make any meaningful development productively. You're forced to use 3rd party libraries if you want to achieve anything. (e.g. File, IO, Socket, Thread...)

There are many libraries/frameworks out there. I'd dare saying that C and C++ are extremely fragmented [by domains, platforms, tools...].

There is a minor subset of the desktop C++ developers that pick Boost as the default library choice and try to put that in all projects. They're just very vocal on StackOverflow [and all over the internet].

Re:C++ confessions of a C developer by gpderetta on Sunday December 04, 2016 @05:36PM (#13102155)
I would say, as an heavy boost user, that today boost is no longer required. Most of boost basic utilities have either been incorporated in or superceded by the standard library.

Boost is still very useful for many advanced or domain specific libraries.

Re:C++ confessions of a C developer by int_19h on Wednesday December 07, 2016 @04:09AM (#13121373)
There are still a lot of minor conveniences, like lexical_cast, or uuid, or various helper algorithms (esp. for strings), that aren't subsumed, or at least not fully.

Also, one big deal is Asio. Which, granted, can be had separately from Boost... but Boost offers a convenient place to get it along with other minor stuff.

Then there's the question of how up-to-date the C++ implementation you're coding against is. A lot of stuff is nominally in the standard library, and if you use the latest and greatest, you might even have it out of the box... but for many people, they're still working on, at most, C++11 compilers, and so they need an outside source for stuff like filesystem.

Re:C++ confessions of a C developer by int_19h on Sunday December 04, 2016 @07:25PM (#13102572)
It is largely driven by the choice of framework.

If you use Qt, for example, it is likely that you will also use their collections, streams etc, rather than STL and Boost.

Ditto if you use MFC (though thankfully that is largely relegated to legacy code now), wxWidgets etc.

Having said that, Boost has, to significant extent, become the prototyping sandbox for things that are then added to C++ standard proper - shared_ptr, any, variant, filesystem and many others all originated in Boost, and after many years of use and polish by the community, became (or are in the process of becoming) a part of the C++ standard library. This makes Boost more important than it used to be.

Re:C++ confessions of a C developer by mschuetz on Sunday December 04, 2016 @03:27AM (#13099280)
C++11 and 14 are the reasons I started to enjoy C++. I still dislike the cumbersome build process around of it but at least the language itself has become something that is nice to use.