Generic C++ with STL and Boost

Who among us knows C++?

Would anyone like to discuss what it is, how it works, how to become proficient, even if it is just copying and modifying open source?

1 Like

i know some, enuf to get some things done

the tl;dr of why anyone should care about c++ in 2020 is that as it is a ‘lower level’ programming language than many options out there. it can compiles very quickly and effeciently at the expense of being more confusing for humans to parse and has 1 big feature that makes it simultaneously incredibly useful for managing streams of data that also makes it a bit more ‘dangerous’ to work with than Java or whatever else is out there

to be longer winded: c++ allows you to act explicitly upon the addresses that ‘Point’ to the data you are working with in RAM. These are called Pointers. As a Pointer is literally an integer number that directly refers to a physical location inside of your computer you can do arithmetic with pointers that can drastically speed up operations when dealing with massive data structures like audio and video buffers. And if you are not careful with your pointer arithemtic then you can end up doing crazy things like accessing parts of memory that were not allocated to any local variables which can either have fun glitchy effects or like crash the fuck out of your program and also other programs as well. This is essentially why most languages dont allow for pointers anymore. For example Java has ‘references’ which function similar to pointers except you can’t do any arithmetic on them, they are more for passing memory addresses into functions and whatnot.

c++ also allows for dynamic memory management. This is another low level feature that has to do with allowing users to dynamically allocate and deallocate memory. This has the ability to both speed things up and also catastrophically fuck up yr program.

this kind of trade off is not even remotely accidental. Essentially designing computer languages is about attempting to trade off making things easy for the CPU to understand (how many layers of compiling?) and making things easy for humans to understand (how much grammatical intuition is baked into the syntax?). Generally speaking the easier it is for a computer to understand something the harder it is for a human to understand something. The fastest compiling program would be written entirely in Binary, second fastest would be in Assembly. The Converse of that statement is not tru tho b/c you can have languages that are simultaneously difficult for humans to understand and also compile for shit

for getting started with c++ for creative purposes openFrameworks is the place to start. its a little wonky to get used to but if you’ve had any experience with Processing you’ll find that it flows pretty decently from one to the other. if you have had no experience with either I would highly recommend getting started with Processing first because its a lot more instant gratification for beginners and you don’t have to fuck around with installing old IDE’s and whatnot just to get started with a hello world.

1 Like

Where you use the word ‘dangerous’ I would use the phrase ‘completely unrestricted’.

C++ is a strongly typed language. You must know exactly what kinds and combinations of the atomic data types you want to use. You can conglomerate them into your own named types. Not just data, but functions can be types. Type itself is a type. The C++ compiler will halt with an error if you try to pass the wrong type in the wrong way.

You must know the difference between automatic memory allocation and dynamic memory allocation. But, if you are wanting to create complex data structures, particularly data containers or collections, you should probably use the generic containers defined in the Standard Template Lib. Then you don’t need to worry so much about dynamic memory allocation. But you should know about how it works, so you can be sure to give memory back to the OS when you are done with it. If your app has a habit of asking for memory and not giving it back, over time it will eat up your available system RAM. This is called a memory leak.

Other languages have mitigated this by expecting you to register your memory usage within a memory management architecture that becomes part of your running executable; so called ‘garbage collection’. This can actually bloat your executable and cause some serious performance issues.

Since you can define your own data types, C++ allows you to define all of the standard arithmetic and logic operators on them. This makes it possible to write code that is in fact very human readable, to anyone who understands infix algebraic notation and how it would apply to the data at hand. Imagine being able to create your own 3D vertex class of float X, Y, Z; and then being able to define any of the standard operators like + - * / and the logic operators > < == != ! ~ | & && || and the increment, decrement ++x x++ --x x-- and the bit operators << >>, between this class as the first operand and this and any other class as the second operand (for binary operators). C = A + B; could have an extremely powerful meaning and represent many lines of code, depending on what the types of A, B and C are.

Another thing that C++ is really all about is Object Oriented Programming. This is why it was written in the first place and what differentiates it from C (which is entirely defined and works within a C++ environment). OOP is another thing that makes it possible to write code that is very human readable. A class is the definition of an object. The class can contain data and it can also have functions defined upon it that act on that data. So an object is data and an interface to it. Wherever the data goes, so goes all the functionality that makes it work. It is through this mechanism that defining the operators as described above works.

Then there is inheritance! WOW!

You don’t really need any API to get started in C or C++ as long as you are content starting out with the keyboard and the command prompt (console). But you do need to have a compiler and know a little bit about how to use it.

1 Like

i would personally recommend some level of caution with diving too deep into object oriented programming. from my own personal design perspective i have found there is a sweet spot that lies somewhere in between higher level oop and functional approach that optimizes creativity in ones designs. a pure oop optimizes readablity but at the expense of obscuring information and reinforcing an assembly line approach to design. pure functional optimizes debugging at the expense of bloating ones memory usage and piling up parenthesis in difficult to parse amounts.

trial and error and a nearly complete lack of any kind of formal or ‘professional’ education in coding has led me to a wonky kind of signal flow based design where i think of coding more in terms of optimizing how data flows and operations execute on the hardware while making every step of the process as easy to tweak and customize as possible. this is more of what ‘creative coding’ actually means to me: ‘code that is approached as a creative design’ vs ‘code that is utilized for creative purposes’. i rely heavily on using emergence and principles of chaos theory and complex adaptive systems to generate complex behavior with a minimum of computational complexity involved as kind of my trademark. this has the side effect of making most folks actively upset when reading my code tho! a complete disregard for anything but the barest minimum of formatting mores adds to this as well

C++ to you is all about what you can do with it.

It’s like materials to make any craft. But the materials are your own understanding of C++.

If you really understand C++, you find it much easier to understand almost every other computer language or script. You’ll know all about binary and the atomic data types and you will know that files and streams are serialized data structures.

1 Like