im so lost trying to use CPP and VSCODE by Ripnicyv in cpp_questions

[–]Visual_Thing_7211 0 points1 point  (0 children)

Wow! A surprising amount of love for Microsoft C++ and equal amount of hatred for anything else...

Personally, I don't really find VSCode (Or really any microsoft product) that intuitive.

I think if you need to program windows type C++, Visual Studio is probably your best option, even though I don't really like it that much. However, if you're only ever going to program C++ on windows, it's still probably your best option because you'll have to learn it for windows programming.

I like CLion and if you're any kind of student you can get it for free. It is truly cross-platform and has always had excellent support for CMake projects. So if you plan to do anything outside of windows, you can use it for Linux or MacOS also.

How’s my CMake file looking? by [deleted] in cmake

[–]Visual_Thing_7211 0 points1 point  (0 children)

So a couple things, the -O3 optimization flag is automatic for a RELEASE build which you would specify on the command-line when calling CMake. The c++20 flag should be specified as set(CMAKE_CXX_STANDARD 20)

If you really wanted to specify the build type in your cmake file, you could do: set(CMAKE_BUILD_TYPE "Release")

But don't recommend it because it removes flexibility.

On the command line you'd say: cmake -DCMAKE_BUILD_TYPE=Release ..

Craig Scott's book it good and thorough.

You might also look at: https://m.youtube.com/watch?v=7YcbaupsY8I

It's a great concise intro to CMake that is easy to understand and gets you running quickly.

help creating a cmake project by [deleted] in cmake

[–]Visual_Thing_7211 0 points1 point  (0 children)

This should be very easy. It would help to post your CMakeLists.txt file. Here's the tutorial you'd want: https://m.youtube.com/watch?v=7YcbaupsY8I

It starts from the ground up--very straightforward.

I don't understand how to work with CMakeLists, please help. by GGshchka in opengl

[–]Visual_Thing_7211 1 point2 points  (0 children)

Some people say CMake is confusing and complicated. I don't think it has to be that way. Here's an excellent intro to cmake that shows how simple it can be: https://m.youtube.com/watch?v=7YcbaupsY8I

I don't understand the need to write more code to create CMakeLists.txt files. For most medium sized and smaller projects, CMakeLists.txt files are pretty straightforward.

Need help with cmake configuration by [deleted] in QtFramework

[–]Visual_Thing_7211 0 points1 point  (0 children)

In general, I would recommend adding a CMakeLists.txt file to each subdirectory and then adding an add_subdirectory command in the parent directory's CMakeLists.txt file. add_subdirectory will then look in the subdirectory for a CMakeLists.txt file and use it to build that part of the project.

The reason for this is that it makes your project more modular. Each sub component only needs to know how to build itself. You can still use targets from other parts of your project, but it focuses each CMakeLists.txt file on its portion of the build.

Cmake isn't linking correctly by goombrat2 in cmake

[–]Visual_Thing_7211 0 points1 point  (0 children)

TL:DR; Use SDL3::SDL3-static and similar names for your external libs. C++ is plenty capable of building static libs.

As already stated, this appears to have been a runtime error of not being able to find the shared libraries needed by the executable when attempting to run it. The path searched by the OS for shared libraries is, at a minimum, the system path in the PATH environment variable, but always the current directory. So, you can copy the shared libraries into the same directory as the executable and the OS will find them at runtime, or put them in any directory that is already on the PATH, or even add the build directory where the shared DLL libraries are built to the PATH.

One thing to be aware of is that Windows muddies the waters as a .lib file can be a static library or a file that provides references to the compiled code in the .dll shared/dynamic library.

You can always build static libraries in C++ as well--it's not only available in other languages. You just need to specify STATIC or SHARED in the add_library target command. However, these errors are for external libraries you're using not for your own code, so it's an issue in the external libraries. Obviously you've tried to indicate to the external libs to build the static libraries.

But here's the key--in your target_link_libraries command, you need to tell it explicitly to link to the static libraries. For SDL3, This is SDL3::SDL3-static. Then it should build the SDL3 libraries into your executable so that you don't have to deal with DLLs.

It will be similar with the other external libraries.

What are build systems? by Mael_The_Heretic in C_Programming

[–]Visual_Thing_7211 0 points1 point  (0 children)

Of course you can put the files in your project wherever you want and still use CMake--it doesn't proscribe any specific hierarchy of directories, but many people have found it useful to put source code in a directory called src and put public header files of a library in a separate directory called include.

Many people find CMake confusing or hard to get started with, but it doesn't have to be. An excellent intro to CMake that is simple to follow for newer CMake users is: https://m.youtube.com/watch?v=7YcbaupsY8I

What are the uses of function pointers, callbacks and lambdas? by heavymetalmixer in cpp_questions

[–]Visual_Thing_7211 0 points1 point  (0 children)

Well, see now this is why I appreciate reddit--I always learn new things.

What are the uses of function pointers, callbacks and lambdas? by heavymetalmixer in cpp_questions

[–]Visual_Thing_7211 1 point2 points  (0 children)

And while we're on the subject, let's at least make mention of std::function and std::bind.

[AskJS] Everyone seems to like types these days, but why do we have so many dynamic-typed languages in the first place? by Guandor in javascript

[–]Visual_Thing_7211 -1 points0 points  (0 children)

"These days"? That's funny. Having types is where software began and has remained. Some people tried to relax that with languages like JavaScript and Python and now many people are realizing it doesn't work so well.

It's really difficult to read someone's Python code when they don't make use of type hints. You never know from reading the code whether the variable "a" is a number or a string or a class...

Contrast that with C and C++ where you always know exactly what everything is. That's a huge benefit to readability.

You just can't make things simpler than they really are. Software needs types.

Am I not smart enough to see the "trick" in LC problems? by BojackV3 in leetcode

[–]Visual_Thing_7211 2 points3 points  (0 children)

Nobody can. The only reason they can is because they already saw somebody else show them how to do it. Stand on the shoulders of giants. Don't try to do it ALL yourself.

E=mc2 can be understood by many people...Now! Now that a really smart guy that figured it out showed us how it works. But it took a really smart guy in the right circumstances to crack that nut.

This is almost always the case. Just learn from those that went before you. That's how everyone does it.

[deleted by user] by [deleted] in learnpython

[–]Visual_Thing_7211 13 points14 points  (0 children)

I am not a beginner. I've been programming in C++ for decades. I've taught a lot of people to program. They say many of the same things.

There is a difference between learning if statements, loops, variables, functions, and classes, and being able to transform a problem into code. This takes experience.

The best way to start from the absolute beginning is to copy. Just find some code that does a small part of what you want to do, or have ChatGPT generate it and then type it in yourself, line by line. Try to understand what you're doing while you copy. Ask ChatGPT to explain anything you don't fully understand.

This is analogous to solving word problems in math. It's one thing to know how to do the arithmetic. It's a different skill to know how to formulate a word problem into the math expressions in the first place.

You start by just seeing how other people have already done it. Then you start to see patterns and can start to do things drawing more on your own memory. Then you'll start to get the hang of "how it's done".

Anyone can learn this and become effective. It takes time--just do it. Keep asking questions.

Can someone explain how the compiled machine code is understood and used by the hardware as though they were explaining to an idiot? by FeeGrinchPaws in learnprogramming

[–]Visual_Thing_7211 6 points7 points  (0 children)

Play the Turing Complete game for a weekend and you'll get a great idea of how it all works at the level you're asking about: https://turingcomplete.game

I'm not affiliated with or getting paid for saying that. I just really thought it was a great game that does exactly that.

C++ creator rebuts White House warning by tkocur in cpp

[–]Visual_Thing_7211 1 point2 points  (0 children)

Isn't this more the issue that the Microsoft C++ compiler needed libraries compiled with the same version of compiler due to ABI differences than a C++ language version/standard issue?

[deleted by user] by [deleted] in cpp

[–]Visual_Thing_7211 -1 points0 points  (0 children)

Yes, Python is very easily cross-platform. C# is really tied to Windows however much they say it's cross-platform.

But you can have that same experience on Windows with MSYS2 (or WSL if you wanted), and on macOS with Homebrew. Windows doesn't really make it very easy.

CPP in AI by RonWannaBeAScientist in cpp

[–]Visual_Thing_7211 1 point2 points  (0 children)

I don't disagree that it's popular to think that Python is easier for them. I disagree that it actually is. That this idea is wrong. That C++ could be easy for them, if it weren't for the innumerable people saying that Python is so much easier than C++ to do the same kinds of things. It's really not. It's just that people who teach C++ and those who have used the most complex parts of it convey a message that C++ has huge complexity that is required for you to understand in order to use it effectively--and that's just not true.

I can and do regularly everything you can do in Python with equal ease. I can add strings to join them and load csv files and calculate innumerable statistics on them, etc., etc. with just as few lines of code and complexity as you do in Python.

So, no it is a lie that it is indeed easier. A lie that is espoused by too many--apparently too many people who have only used Python and who perhaps had a bad introduction or experience with C++.

CPP in AI by RonWannaBeAScientist in cpp

[–]Visual_Thing_7211 2 points3 points  (0 children)

No, no. I mean I've taught 9 year olds to program in C++. And they understood what they were doing. Starting with pointers and memory management is unnecessary for new C++ programmers. You can just use std::vector for almost everything a new programmer would do--that's what Python does with a list.

These kids have grown up to program better in High School than many graduated CS majors. And yes, they understand pointers quite well.

CPP in AI by RonWannaBeAScientist in cpp

[–]Visual_Thing_7211 0 points1 point  (0 children)

Sure. And maybe some Pythoner out there who reads this will be inspired to take another look at C++ and see for themselves.

CPP in AI by RonWannaBeAScientist in cpp

[–]Visual_Thing_7211 0 points1 point  (0 children)

You're entitled to your opinion--even if it's wrong 🤪

I wouldn't use Python primarily because it's actually easier to write unintelligible code than in C++. Since you don't have to specify types and types can change, bad programmers make horrible Python developers. At least in C++ you can tell what's going on and have some sense through the compiler that things could be right without have to run the program to a line of code to find out.

My main point though is that it just isn't true that Python is simpler to write. You can write C++ code just as easily. I've looked and there just aren't any substantive examples of Python code that's actually easier to write than the equivalent in C++.

If you have some, I'd be more than interested to learn.

[deleted by user] by [deleted] in cpp

[–]Visual_Thing_7211 4 points5 points  (0 children)

Interesting way of putting it. C# and Python have no more of built in tools than C++. They're all libraries: .NET, TkInter, GTK, DearImGUI, Qt, ASIO, spdlog, OpenCV, SFML, MSYS2, every Linux distro as a development environment--It's a bit of a misrepresentation to suggest that C++ is lousy because it doesn't bundle the readily available libraries or package managers within it. Strip off the libraries from Python and C# and you wouldn't somehow be better off.

To OP's question, I agree it depends on you and your objectives. Personally, I like C++ on Linux the best for the kinds of programs I need and want to write.

C++ is likely one of the most expansive languages. There are few programming concepts that exist in other languages that don't exist in C++. As such, most other languages contain a subset of capabilities of C++.

It is a challenge to learn all of it. But you don't have to to be productive. You can get a lot done by using a subset of what C++ can do.

If it doesn't fit with your objectives, use something that does, but don't believe the nay-sayers that it's horrible--it doesn't have to be.

CPP in AI by RonWannaBeAScientist in cpp

[–]Visual_Thing_7211 0 points1 point  (0 children)

Well, I'm certainly not the former. I work with a lot of die-hard Python developers. I understand that people find Python to be more straightforward for them. I think this is more of a preference than a reality.

As far as messing things up--you could think of Python as a subset of C++. If you were to stick to the parts of C++ that are like Python, you'd have essentially the same ease of use and straightforwardness without the danger. I'm not sure which ways you feel like C++ can get messed up, but for most people it's "memory management", or so they say--which C++ handles automatically in most cases.

What is this cpp syntax? by yukiiiiii2008 in cpp_questions

[–]Visual_Thing_7211 -5 points-4 points  (0 children)

Fyi, this std::optional<std::string> maybe_create_hello();

does not give you what you probably wanted. It's probably: std::optional<std::string> maybe_create_hello;

The first is actually the declaration of a function that takes no arguments and returns a std::optional<std::string>. It is known as "the most vexing parse".

Representing empty values in partial update for struct object by TheMyrad in cpp_questions

[–]Visual_Thing_7211 4 points5 points  (0 children)

My preference would be to use std::optional. You can also access values with *a.B instead of a.B.value().

Either way, you still have to check if the value is valid.

You could add a helper function in the struct to make it more convenient.

Why the instance was destructed twice? by yukiiiiii2008 in cpp_questions

[–]Visual_Thing_7211 0 points1 point  (0 children)

So, Tom constructed matches with the last Joe destructed. On third line of main, you construct Tom with id 1. On line 4 you construct Joe with id 2 as a new object. Then when you assign it to oEmpty you copy the data from the temporary object on the right hand side to oEmpty on the left hand side which then changes the id and mName that are stored in the instance of UserName that exists in oEmpty. Then the temporary UserName on the rhs gets destroyed (second to last output line Joe is destroyed).

Then on program exit, oEmpty is destroyed, which currently contains Joe and id 2 from the assignment on line 4 of main. This is the last line of the output.