/dpt/ - Daily Programming Thread

Old thread: What are you working on, Any Forums?

Attached: sample_03a2e777fe58d27644a45ac6ec993330.jpg (850x1275, 118.95K)

Other urls found in this thread:

github.com/friendlyanon/cmake-init
twitter.com/SFWRedditVideos

C++ is the most powerful programming language.

Wasting time

Attached: 1646068997798.png (540x784, 143.68K)

Reminding anons to use github.com/friendlyanon/cmake-init when creating new C++ and C projects!

Writing an Operations Manual

Attached: QhipA51.webm (720x828, 2.18M)

Dictionary CalculatedValues;
>used hundreds of times
>about 150 enums, 5 different classes
>the keys are constantly casted to other enums causing a myriad of bugs
>even uses reflection

How would you refactor this?

I thought of using just a class, but writing 150 properties by hand sounds like a gigantic pain

Ehat are those 150 enums? Are they all related?

nakadashi

what does this mean in cpp? it looks kinda like pointer syntax except reverse
MyClass &myclass
//saw it used in code like this ->
MyClass &myclass = MyClass::Instance();

//if no argument passed to program, send info to cout with some additional formatting,
//if argument passed send to file instead with no additional formatting.
//I only want to build the core info once, then decide where I send it after
void ErrorLog(std::string options)
{
auto WriteInfoToStream = [](std::ostream& ss, const auto value1, const auto value2, const auto name2, const auto value3)
{
ss

>how would you refactor this
i wouldn't, i would burn it and pretend I never wrote it.

it's a reference, you can have a temporary name (pointer, that you don't need to de-reference) to an object that already exists.

similar to passing an argument by reference, and unlike pointers they cannot be re-assigned or incremented.

Barely related, some of them are things like username, date etc, others are calculated parameters (mostly the name of chemicals and shit) and even more are things like locationOfFileOnDisk and it’s a path as a string, also png images as binary data
It is a gigantic mess, yes

lol. lmao

and I should say, normally a use like that it would just be copy-elided if you didn't use a reference so there is no benefit to using a reference, unless it is returning an instance with a lifetime managed by the class and not something that just goes out of scope when the function ends.

would prefer shared_ptr or unique_ptr or something instead.

if you aren't experienced, whatever changes you make will probably screw everything up and keep you occupied for the next year--if it is a large project.

so go easy on changing it to suit your taste, you don't know what you don't know.

You are probably right

MyClass::instance is probably a static method providing access to singleton. It should be protected from copy-construction, so you create a reference to it.

well that's a surprise, usually someone would just do it anyway then find out for themselves.

but if you eventually put together a good plan to make the upgrades, go for it.

if it ain't broke, dont fix it.

>they cannot be re-assigned or incremented
so does that mean I would be unable to do
MyClass &myclass;

if(cond) {
myclass = MyClass::Instance();
}

if(myclass) {
myclass.method(...);
}

this is my simple philosophy for programming
if its a personal project do your best to improve it by refactoring, adding tests, documentation etc. also keep on learning stuff and see if you can apply it to your personal projects.
if its for work, unless you are tasked by your manager to fix something, dont do it. in fact do the bare minimum for your work. no ticket? wont fix it.

Learning javascript by making a wordle clone!

yes, that's not possible with references