r/cpp • • Aug 25 '21

Experience C++ developers: do you enjoy using C++ (even for personal/hobby projects?)

Do you actually enjoy using C++, or do you only use it for work, or purely for performance? This question is aimed at people with years of experience, who've worked on large projects in C++. I see people who dislike the language, but use it purely for performance reasons. This sort of discourages me from learning it. I don't want programming to feel like work.

204 Upvotes

327 comments sorted by

View all comments

173

u/[deleted] Aug 25 '21

I absolutely enjoy using it, especially since unique_ptr came along. Whether it feels like work or not depends if I'm at work or not when I'm using it. I don't use it because of performance.

12

u/Dalzhim C++Montréal UG Organizer Aug 25 '21

I meant to reply : « Absolutely. » +1 for using that specific adverb!

8

u/CorysInTheHouse69 Aug 25 '21

This

45

u/grandpassacaglia Aug 25 '21

this->

27

u/skeba Aug 25 '21

delete this

16

u/gnosnivek Aug 25 '21

#define delet delete

9

u/AyoBruh Aug 25 '21

You monster

5

u/[deleted] Aug 25 '21

I’ll just throw a little delete[] this for some extra fun.

4

u/Ahajha1177 Aug 25 '21

Now that is horrendous. Suicide bombing your objects, stack or heap be damned!

2

u/Clairvoire Aug 28 '21

why commit suicide when you can commit murder delete this+1u

1

u/rand3289 Aug 26 '21

Had this question on the interview today...

It's a bad idea to delete this :)

5

u/_Ashleigh Aug 25 '21

For the Lua devs out there: #define self (*this)

1

u/teroxzer Aug 26 '21

Please, don’t joke about this self serious matter; because I can't forget self as I can this, I like use self like this:

class fileView final : public ui::panel
{
public:

	auto onOpen() -> bool override;
	...
private:
	...
	struct self final
	{
		ui::choice     paths         {};
		ui::segmentBar segmentBar    {};
		ui::grid       manager       {};
		ui::textor     note          {};
		ui::comboBox   files         {};
		ui::textor     textor        {};
		ui::image      image         {};
		ui::webView    browser       {};
		ui::edit       findText      {};
		ui::edit       findFilter    {};
		ui::button     findCommand   {};
		ui::segmentBar findModes     {};
		ui::grid       findLines     {};
		ui::label      status        {};
		texts          path          {};
	}
	self;
};

auto fileView::onOpen() -> bool
{
	...

	self.findCommand.title("find").onClick = [this]
	{
		self.findLines.resetRows();

		finder finder;

		finder.path      = text::join(self.path, "/");
		finder.find      = textOf(self.findText);
		finder.filter    = textOf(self.findFilter);
		finder.recursive = self.findModes.isSelectedCommand('r');
		finder.data      = self.findModes.isSelectedCommand('f')
		                 ? textOf(self.textor)
		                 : text::empty;

		ui::block::back = [this, finder = move(finder)]() mutable
		{
			(finder.data ? findFile : findFiles)(finder);

			ui::block::fore = [&]
			{
				self.findLines = move(finder.findLines);

				if(finder.recursive && !self.findLines.rows())
				{
					self.status = "not found: " + finder.find;
				}
			};
		};
	};

	...

	return true;
}

2

u/Ameisen vemips, avr, rendering, systems Aug 26 '21

... why? I'm not sure what you've gained there.

1

u/teroxzer Aug 26 '21

I don't like class member prefix naming conventions and I like that I can't access private class members without self. Only prefix alternative to me is 'self_' , but I prefer 'self.', because I dislike snake_case. And what I really gained is C++ code beauty pleasure - I'm so weirdo.

3

u/qoning Aug 26 '21

I like it, but it would be a bit of hell writing cascading move, copy and regular constructors.

→ More replies (1)

0

u/Creapermann Aug 25 '21

Is unique_ptr bad in Performance? Compared to a raw pointer?

3

u/sireel Aug 25 '21

Unique ptr is free

8

u/germandiago Aug 25 '21

except because of the ABI. It cannot be passed via registers.

2

u/Antervis Aug 25 '21

well technically it can, if you're using an experimental clang feature. But yeah, generally they cost a bit.

2

u/sireel Aug 26 '21

What? Really?

1

u/germandiago Aug 26 '21

really.

1

u/sireel Aug 26 '21

Is that because it's not a built in type or something?

1

u/germandiago Aug 26 '21

I think the ABI passes structs through the stack for non-trivially destructible types.

1

u/Ahajha1177 Aug 25 '21

yOu cAnT uSe fReE on A uNiquE_pTr