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

Show parent comments

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.

1

u/teroxzer Aug 26 '21

Can you show to me when self not work like value member? Or did I just not get your point?

#include <string>
#include <iostream>

class test final
{
public:

	test() = default;
	test(std::string a, int b, double c) : self
	{
		.a = std::move(a),
		.b = b,
		.c = c,
	}
	{}

	auto print() -> void
	{
		std::cout << "\ntest: " << self.a
		          << ", "       << self.b
		          << ", "       << self.c; 
	}

private:

	struct self final
	{
		std::string a {};
		int         b {};
		double      c {};
	}
	self;
};

auto main() -> int
{
	test x { "1", 2, 3.4  };
	test y {};
	test z {};

	y = std::move(x);
	z = y;

	y.print(); z.print();
}

// output:
// test: 1, 2, 3.4
// test: 1, 2, 3.4