Stay up-to-date with everything C++! Content directly fetched from the subreddit just for you. Join our group for discussions : @programminginc Powered by : @r_channels
It is undefined behavior that allows me to be an engineer.
For context: I am an electronics engineer by education and practice, but I switched to full time software development in 2016.
By far, C and C++ has been most of my career. Dangerous languages perhaps, but languages that know they are dangerous, and document exactly where the sharp edges are located.
However, for about a year and a half, I've been branching out and it appears to me that every single language and technology I look at has behaviors that are not defined. They just don't admit to it.
I opened an issue in docker's documentation because they were missing an explanation for a behavior. Closed as resolved with, paraphrased, "read the repository if you want to know how docker works."
By that standard, C++ doesn't have undefined behavior either! Just read your compiler's source code and you'll know what happens.
Same problem with Microsoft's Azure cloud services. Many guides and tutorials but no authoritative source that explains how Azure works, what each option does, and how they interact - or if there is, it's sufficiently burrowed that I've been unable to find it after searching for a while, and their representatives cannot guide me to it either. Dotnet projects? Same issue again, there's any number of properties you can set for your project and you just have to guess from their name what they will do - and don't get me started on the difficulty of writing provably correct golang.
I can sign for the correctness of C/C++ software. I might be wrong because mistakes happen, but those are mistakes, not lies.
I cannot sign off on most other software. If I claim that I know something is correct, I am lying. I don't know. I'm guessing. "It worked so far."
I can write software in all these languages, use all these other technologies. I cannot do engineering with them. I wish I could.
https://redd.it/1cqgmyp
@r_cpp
[bsnes-legacy/__all__.files] Fehler 2`
`make[2]: Verzeichnis „/home/simon/Downloads/lsnes/src/emulation“ wird verlassen`
`Makefile:44: die Regel für Ziel „emulation/__all__.files“ scheiterte`
`make[1]: *** [emulation/__all__.files] Fehler 2`
`make[1]: Verzeichnis „/home/simon/Downloads/lsnes/src“ wird verlassen`
`Makefile:83: die Regel für Ziel „src/__all_files__“ scheiterte`
`make: *** [src/__all_files__] Fehler 2`
https://redd.it/1cqa75c
@r_cpp
Up to date c++ project tutorial that follows best practices
Hello All,
I am a Mid-Level React Native Developer. For the past 4 months I have been studying c++ using learncpp, which is an amazing source.
I picked up c++ because of its usage is various places and I would like to learn more low level stuff and since c++ can actually be used in react native.
Anyways I am approaching the end of learncpp and I would like to put theory into practice, but I have no specific thing in mind.
I am looking for an online tutorial thats builds up a project, can be anything but that is up to date and follows best practices.
Can anybody recommend any please?
Thank you!
https://redd.it/1cq98u9
@r_cpp
Ask from 4 yrs of exp in c++ development
Hi,
I have a mix exp of c++ and devops in my whole career of 4yrs in IT. As a person who's looking for a change what would be my best bet, to look for devops jobs or c++ jobs? I pretty much good with both but on devops side i feel the tool chain is too overwhelming.
Also if I am going for c++ side what would be expected out of me in an interview, i am looking for kind of questions and depth of knowledge that will be checked. Can somebody as an interviewer answer this?
https://redd.it/1cpy13v
@r_cpp
Q: If I'm given employee IDs and a value corresponding to them. What's the best way to solve this problem? Hashtables (std::unordered_map), using a dynamic array (std::vector), or anything else in particular?
For example, like the title says, if I'm given a bunch of employee unique ID and a number (hours of work) associated which each one of them. How would you solve this?
I know that std::vector or std::array is pretty standard (storing a string and an integer) and putting them inside a Class.
But I'm getting to know std::unordered_map and std::map and they seem be extremely useful in this cases since they store elements as key-value pairs. So it becomes very easy to add, retrieve and manipulate.
So getting back to the original question, in your expert experience what would be the best way to solve these type of problem? Going for std::unordered_list, using a std::vectors, or anything else?
Thanks!
EDIT: Providing more information: I'll need to add daily new members, and get information from them, so storing large amounts of data. The speed in which it's done it's not really that important.
https://redd.it/1cptfy0
@r_cpp
Can neovim provide perfect IDE experience for C++?
So I have recently started with Linux and don't have Visual Studio. There are two options either go with Neovim or use CLion, I have a little experience with Vim as a Editor and was wondering with which one should I continue. My inclination is towards learning Neovim so I was wondering if it would be a right choice to go with it. Can it provide every functionality that an IDE does.
https://redd.it/1cpqtm5
@r_cpp
Pyramid Using stars
Hello guys i hope u are doing well
so i have this programme and I don't know what is wrong with it
the programme should print a pyramid of stars according to the rows you input
#include <iostream>
using namespace std;
int main() {
int r=0;
cout << " Enter The Number of Rows:\\n";
cin >> r;
int c= (r*2)-1;
for (int i =1; i>=r; i++){
for (int j=1; j >= c; j++){
cout << "*";
}
}
cout << endl;
return 0;
}
https://redd.it/1cpjnss
@r_cpp
I love this language
I'm having so much fun learning, i love writing memory leaks and unreadable (to me at least) code, like "double*stupidArray{new(std::nothrow)double[((sizeof(double)*sizeof(double))/3)\^sizeof(long double)\]};" or something. Thats all i had to share :)
https://redd.it/1cpfxzv
@r_cpp
Qt vs wxWidgets vs GTK recommendation
So I'm thinking of learning a C++ GUI framework now and I wanted to hear people's opinions on which is best. People say QT is great because it's very fast and has lots of features, but the licensing model makes me a bit uneasy. If I had to some day, how much would I be able to do with just LGPL components?
GTK is cross platform, but it seems native look is not a priority for them. This leads to strange inconsistencies in different UIs which might confuse users. Is GTK still the best option for performance reasons? Or does QT have better performance too?
Finally there's wxWidgets. They compile to native toolkits on every platform, so it's probably the best for native look and feel. But is there a performance overhead because of the bindings and platform specific stuff?
What does everyone think?
Edit: I thought of another potential advantage of GTK: It has Rust bindings. I don't think any of the others do.
https://redd.it/1cp1341
@r_cpp
An informal comparison of the three major implementations of std::string - The Old New Thing
https://devblogs.microsoft.com/oldnewthing/20240510-00/?p=109742
https://redd.it/1coyneg
@r_cpp
C++ GUI social media app
So i was recently assigned a project to create a social media app to do basic functions like view posts view friends choose user like posts etc iv completed the code side of it and now the teacher has requested to add a GUI to it i have no knowledge of what to do in regards to that and whats the easiest option i was hoping anyone could suggest what i could use thanks!
https://redd.it/1cov989
@r_cpp
ClangQL 0.3.0 supports query Classes, structs and enums informations
https://github.com/AmrDeveloper/ClangQL
https://redd.it/1coppmh
@r_cpp
I need advice for school
I am a 17 yo student studying it, I am 99% sure I am not going to work in the field and I never cared much about programming.
In approximately 2 weeks time I will have a c++ test and I basically don’t know anything since I copied my way through the year.
I was wandering if it is possible to learn c++ basics + functions + sorting + arrays in 2 weeks, and if it is how.
I have lots of other subjects to study but I think I still have enough time.
Plz I need help.
https://redd.it/1cojgwf
@r_cpp
What is your experience in programming on Neovim for C++?
I feel Neovim in WSL is a goat.
https://redd.it/1ck0mqf
@r_cpp
used only up to version 3, and after that its use was reduced to nothing. That's why we can estimate the complexity of C/C++ syntax with the help of the parser's code volume only till about 1996-98, after which it was gradually phased out, i.e. a little less than ten years. But even during this period the volume of the parser's code base grew two times, which approximately corresponds to the time of implementing the C99 standard.
But even if we don't take into account the code of the parser, the volume of the total code base also correlates with the introduction of new C++ standards: C99, C11 and C14.
The graph doesn't show a pronounced peak for C+17 and the next versions, but I suppose that with the current size of the code base (more than 4 million lines of C and C++ code only), several thousand lines needed to support syntactic constructions of new standards are simply unnoticeable.
**The first conclusion is obvious. Increasing complexity of development tools**
In fact, on the example of the GCC project we can see the constant and inevitable growth of complexity of programmers' working tools.
And no matter how much they talk about degradation of development, about system crisis of software, which is generational in nature, but it seems to me that the matter is a bit different.
Personnel renewal and as a consequence - the necessity to train new employees in old developments, here it is not so much about knowledge transfer as about the possibility to **absorb** this knowledge.
And the ability to assimilate knowledge for different generations will be different, but not because the previous generation was smarter, and not because the new generation does not have enough sense to understand it. It's just that the environment itself is changing and the working tools are more complicated than those used by the previous generation.
**The second conclusion is the entry threshold**
Imagine that you need to “make your own website”. Naturally, you need to determine which CMS to use for this.
And if there are simple solutions for simple sites, then for those who are not looking for easy ways, there is the CMS Drupal, which is notable for the fact that it has a fantastically high entry threshold for starting to use it.
[Drupal entry difficulty graph](https://habrastorage.org/webt/ei/gl/z1/eiglz1cnctqm0y4dsjtfvedezuw.jpeg)
What I'm talking about? When using any tool, such as a programming language, there is a certain minimum level of comfort level.
Moreover, this level is directly proportional to the size of the target audience for which it is intended. More precisely, **the size of the possible audience** is determined, among other things, by the requirements for the level of starting knowledge and qualifications of the potential user.
**The final conclusion is disappointing**
If we consider the increase in complexity of the software itself, then this is one thing. Here's an example:
* September 17, 1991: Linux version 0.01 (*10,239* lines of code).
* March 14, 1994: Linux version 1.0.0 (*176,250* lines of code).
* March 1995: Linux version 1.2.0 (*310,950* lines of code).
* June 9, 1996: Linux version 2.0.0 (*777,956* lines of code).
* January 25, 1999: Linux version 2.2.0, initially rather unfinished (*1,800,847* lines of code).
* January 4, 2001: Linux version 2.4.0 (*3,377,902* lines of code).
* December 18, 2003: Linux version 2.6.0 (*5,929,913* lines of code).
* March 23, 2009: Linux version 2.6.29, temporary Linux symbol - Tasmanian devil Tuz (*11,010,647* lines of code).
* July 22, 2011: Linux 3.0 released (*14.6* million lines of code).
* October 24, 2011: Linux 3.1 release.
* January 15, 2012: Linux 3.3 release surpasses *15 million* lines of code.
* February 23, 2015: First release candidate of Linux 4.0 (*more than 19 million* lines of code).
* January 7, 2019: First release candidate of Linux 5.0 (*more than 26 million* lines of code) ...
And what if the complexity of software is superimposed on the tendency of constant complication of the working tools themselves? After all, the constant development of
A repository that teaches pipeline set-up for Static Library Build, Application Build and Deployment using legacy Conan Package Manager
https://github.com/electricalgorithm/conan-threesome-library-application-server
https://redd.it/1cqdm2y
@r_cpp
Errors while building lsnes emulator
I just tried to compile the lsnes emulator to run [this](https://github.com/aleju/mario-ai) AI on my PC but there are a lot of issues. Because the emulator seems to be written in c++ I thought I could get help here.
This is the error message:
`../make-ports <ports.json >ports.inc`
`g++ -c -o core.o core.cpp -I../../../include -I../../../bsnes -std=gnu++0x -pthread -g -DNATIVE_THREADS -DUSE_LIBGCRYPT_SHA256 -I/usr/include/lua5.1 -DBSNES_IS_COMPAT -DBSNES_HAS_DEBUGGER -DBSNES_VERSION=\"084\" -DLIBSNES_INCLUDE_FILE=\"ui-libsnes/libsnes.hpp\" -Wreturn-type`
`In file included from ../../../bsnes/nall/array.hpp:10:0,`
`from ../../../bsnes/snes/snes.hpp:23,`
`from core.cpp:49:`
`../../../bsnes/nall/bit.hpp: In instantiation of ‘constexpr unsigned int nall::uclip(unsigned int) [with int bits = 24]’:`
`../../../bsnes/snes/cpu/core/registers.hpp:52:69: required from here`
`../../../bsnes/nall/bit.hpp:13:3: error: body of constexpr function ‘constexpr unsigned int nall::uclip(unsigned int) [with`
`int bits = 24]’ not a return-statement`
`}`
`^`
`core.cpp: In member function ‘virtual int16_t {anonymous}::my_interface::inputPoll(bool, SNES::Input::Device, unsigned int, unsigned int)’:`
`core.cpp:792:20: error: ‘struct SNES::Justifier’ has no member named ‘player1’`
`offset = js->player1.x;`
`^`
`core.cpp:794:20: error: ‘struct SNES::Justifier’ has no member named ‘player1’`
`offset = js->player1.y;`
`^`
`core.cpp:798:20: error: ‘struct SNES::Justifier’ has no member named ‘player2’`
`offset = js->player2.x;`
`^`
`core.cpp:800:20: error: ‘struct SNES::Justifier’ has no member named ‘player2’`
`offset = js->player2.y;`
`^`
`core.cpp: In function ‘bool {anonymous}::smp_trace_fn()’:`
`core.cpp:826:73: error: no matching function for call to ‘SNES::SMPDebugger::disassemble_opcode(uint16_t&)’`
`:string _disasm = SNES::smp.disassemble_opcode(SNES::smp.regs.pc);`
`^`
`In file included from ../../../bsnes/snes/smp/core/core.hpp:4:0,`
`from ../../../bsnes/snes/snes.hpp:135,`
`from core.cpp:49:`
`../../../bsnes/snes/smp/core/disassembler/disassembler.hpp:1:6: note: candidate: void`
`SNES::SMPcore::disassemble_opcode(char*, SNES::uint16)`
`void disassemble_opcode(char *output, uint16 addr);`
`^`
`../../../bsnes/snes/smp/core/disassembler/disassembler.hpp:1:6: note: candidate expects 2 arguments, 1 provided`
`core.cpp: In function ‘int {anonymous}::smpdisasm(lua::state&, lua::parameters&)’:`
`core.cpp:2095:59: error: no matching function for call to ‘SNES::SMPDebugger::disassemble_opcode(uint64_t&)’`
`nall::string _disasm = SNES::smp.disassemble_opcode(addr);`
`^`
`In file included from ../../../bsnes/snes/smp/core/core.hpp:4:0,`
`from ../../../bsnes/snes/snes.hpp:135,`
`from core.cpp:49:`
`../../../bsnes/snes/smp/core/disassembler/disassembler.hpp:1:6: note: candidate: void SNES::SMPcore::disassemble_opcode(char*, SNES::uint16)`
`void disassemble_opcode(char *output, uint16 addr);`
`^`
`../../../bsnes/snes/smp/core/disassembler/disassembler.hpp:1:6: note: candidate expects 2 arguments, 1 provided`
`In file included from ../../../bsnes/nall/array.hpp:10:0,`
`from ../../../bsnes/snes/snes.hpp:23,`
`from core.cpp:49:`
`../../../bsnes/nall/bit.hpp: In instantiation of ‘constexpr unsigned int nall::uclip(unsigned int) [with int bits = 2]’:`
`../../../bsnes/nall/varint.hpp:32:55: required from ‘nall::uint_t<bits>::uint_t(unsigned int) [with unsigned int bits = 2u]’`
`../../../bsnes/snes/controller/controller.hpp:27:33: required from here`
`../../../bsnes/nall/bit.hpp:13:3: error: body of constexpr function ‘constexpr unsigned int nall::uclip(unsigned int) [with int bits = 2]’ not a return-statement`
`}`
`^`
`Makefile:44: die Regel für Ziel „core.o“ scheiterte`
`make[3]: *** [core.o] Fehler 1`
`make[3]: Verzeichnis „/home/simon/Downloads/lsnes/src/emulation/bsnes-legacy“ wird verlassen`
`Makefile:15: die Regel für Ziel „bsnes-legacy/__all__.files“ scheiterte`
`make[2]: ***
json.hpp not working
Hi, im an uni student and I tried to study for my programming exam when I had to include the json.hpp header to my project from github nlohmann/json. I have done it multiple times before and it worked perfectly but now randomly an error shows up in the header file in line 19369 #include <any>. The error is: "any file not found". I downloaded the header again and added to my program again (I use QT creator) but the issue is still there and I can't move on. I chechked that in previous lessons we used the same header file in a similar case but there it works perfectly.
What can I do? I don't have time to learn another method for using json files and why it's not working only in this project wtf?!?!?!?!
there is the json.hpp in github: https://github.com/nlohmann/json/blob/develop/single\_include/nlohmann/json.hpp
https://redd.it/1cq3kgj
@r_cpp
What's your favorite Boost alternative?
Just looking for discussion. Mainly curious about how y'all feel about Boost and its kin. I'm sure most folks here have experience having to deal with emulating a feature from a future C++ standard, or some other task that might fit in the STL. What's given you the least headaches? Does Boost remain king to y'all?
https://redd.it/1cpwyqj
@r_cpp
Pointers
Hi, am a beginner in C lang. After going through the pointers I have many questions than answers. Do we really need pointers, why not just use normal variables
https://redd.it/1cpttxr
@r_cpp
The unfortunate state of the C++ standard library.
Is the status quo sustainable? Everything is just getting more and more complex and tons of stuff seems to be undocumented. Two days ago I wanted to do something I thought was simple: Wrap two views as a single view such that it appears as if its concatenated (concats lazily). I look at cppreference and there's std::views::concat, but it's not in C++23. Okay no problem, just use ranges-v3. I try to use the concat in ranges-v3 and after a lot of headaches, a friendly individual from r cppquestions lets me know that ranges-v3 sometimes doesn't play nice with std ranges (apparently it's a well known problem). Okay no problem, just write a custom view that does what you want. Writing the logic outside of a view is only a handful of code, so it probably isn't that hard to wrap it around a view interface and plug it in. I look online for documentation of what a std view should have / some examples and I find nothing but a few surface level blog posts that don't really explain what's happening. Okay no problem, just fire up ChatGPT4 and ask it to give me the skeleton for a C++ range view and tell it what I'm trying to do. It produces some code. I plug it into godbolt and it doesn't work. Okay no problem, just go back and forth with ChatGPT, feeding it the compiler error messages and spot checking for any obvious problems myself. After several hours of going back and forth, still doesn't work. I can't understand why and there's no official documentation that tells me what I'm supposed to implement in terms of an interface. The compiler output just tells me that it can't find a valid begin(...) and no other information. I try testing against the type traits for input_range and it fails, but still doesn't really tell me anything about why it failed. Pages and pages of output that don't really say anything other than "I can't find this for std::ranges::begin()" or something to that effect. After several days of struggling, I go back to r cppquestions and another friendly individual helps me tack on the missing pieces. I ask them if there's any official documentation for this and the answer is "I don't think there's like an official document that explains how all these helper types like view_interface or the new range_adaptor_closure are supposed to be used. The proposals that introduce them are informative, but they're aimed at experts that are already familiar with the inner workings of ranges."
So, I have to rely on the kindness of strangers to get anything non-trivial done? Other languages have abundant documentation on what you need to do to create a new stream / range, complete with well commented examples, right in front of your face as soon as you decide you want to look at it. Why isn't this the case for C++? I just want to write some code "the way it's meant to be written" and so far it's been torture. Add to this a seemingly innumerable number of footguns, a seemingly innumerable number of edge cases, documentation that doesn't seem to exist, half-baked implementations of things in the stdlib across both clang and gcc (MSVC seems to be better with implementing things). More and more the language just seems to be a playground for people who fetishize complexity. It's so byzantine and cryptic that a commercial LLM struggles with it. Is this sustainable? At what point does the ecosystem collapse in on itself from new engineers shying away from it. Rant over.
https://redd.it/1cppdlo
@r_cpp
What is the easiest Cpp networking library?
(i mean for very simple lan socket stuff)
https://redd.it/1cph5nh
@r_cpp
Interesting projects you can write with 500 to 1000 lines of code?
Looking to do some small projects like a dozen of them in the next 3 weeks. What would you recommend?
https://redd.it/1cp1bgv
@r_cpp
Any tutorial showing you how to make a CAD system in C++?
Saw a tutorial that showed you how to load model and then modify the shape of the model and move it around with OpenGL, but I am wondering if there's something more feature-rich out there.
https://redd.it/1cp1car
@r_cpp
Limited friendship
Although I don't like to do it, sometimes I need to use friend declarations to give private access to external classes/functions. Whenever I do, those external entities only need access to 1 or 2 members of the private class. But, giving friendship opens up the entire insides to the friends. So, it can become difficult to understand which privates get used externally, without inspecting the friends. To try to keep things sane, I segregate those members to their own private section. Best I can do is put comments to say they are used externally.
```
private: // These are used by friends
Foo mBar;
Some Function();
private:
//... Other private sections are not used by friends.
```
I wish C++ supported a 'friend:' access specifier in classes, similar to public/protected/private.
```
friend:
Foo mBar;
Some Function();
private:
// ...
```
If a class has a 'friend:' section, then those members are consider private, and they can be accessed by friend classes/functions. If such a section is present, the friend classes/functions are not allowed to access other private sections.
It would be nice to have limited friendship.
https://redd.it/1coxgq3
@r_cpp
Why isn't there a C++ Collective on StackOverflow?
There are currently 10 Collectives on StackOverflow, although in the help on Collectives there is nothing about how to create one. So, I don't know how these 10 were created.
Anyhow, why isn't there a C++ Collective on StackOverflow?
https://redd.it/1cosyk1
@r_cpp
Seeking Feedback on a New Approach to C++ Event Callback Design
Hey everyone,
I've been playing around with designing an API in C++20 for an internal project and stumbled upon what seems like a fresh approach to handling event callbacks. I'm excited about it but unsure if it's a well-known technique. I'd love to get your thoughts and insights on it.
### The Challenge:
Imagine you have a function Process()
that needs to keep others in the loop by firing events like Started
, Stopped
, and Error
during its execution.
#### Approach 1: Classic Runtime Interface
In traditional C++ style, you might set up an interface like this:
struct IObserver
{
virtual void OnStarted() = 0;
virtual void OnStopped() = 0;
virtual void OnError(std::string const& error) = 0;
};
void Process(IObserver& observer)
{
observer.OnStarted();
if (something_went_wrong) {
observer.OnError("oops, an error occurred!");
}
observer.OnStopped();
}
struct MyObserver : IObserver {
// Implement methods...
};
MyObserver observer;
Process(observer);
template<typename T>
concept Observer = requires(T observer, std::string const& error) {
{ observer.OnStarted() } -> std::same_as<void>;
{ observer.OnStopped() } -> std::same_as<void>;
{ observer.OnError(error) } -> std::same_as<void>;
};
void Process(Observer auto& observer)
{
observer.OnStarted();
if (something_went_wrong) {
observer.OnError("uh-oh, an error!");
}
observer.OnStopped();
}
struct MyObserver {
// Implement methods...
};
static_assert(Observer<MyObserver>);
MyObserver observer;
Process(observer);
struct EventStarted{};
struct EventStopped{};
struct EventError{
std::string const& error;
};
void Process(Observer auto& observer)
{
observer(EventStarted{});
if (something_went_wrong) {
observer(EventError{"oh no, an error!"});
}
observer(EventStopped{});
}
Process([]<typename T>(T event) {
if constexpr (std::is_same_v<T, EventError>) {
format("error: {}", event.error)
}
else if constexpr (std::is_same_v<T, EventStopped>) {
// Handle stopped event...
}
// Ignore the start event.
});
Trip Report: C++Now 2024 | think-cell
https://www.think-cell.com/en/career/devblog/trip-report-cpp-now-2024
https://redd.it/1coi2kq
@r_cpp
programming languages inevitably raises the entry threshold for all beginners and only exacerbates the problem of software development complexity.
In other words, no matter how well documented the code is and how completely it is covered with tests, after some time the tools used become obsolete, the life cycles of external dependencies are completed, and most importantly, new people come to replace those who have developed or managed to understand the system.
And new people have a need to understand the system from the beginning, but under **different initial conditions**. And because of this, the complexity of learning the system for all new people will be higher simply by the fact that the external conditions have changed and the working tools that new employees have to use have become more complex.
It is clear that the further you go, the easier it will not be. After all, the IT field is the most competitive environment. And how not to remember Lewis Carroll, that his winged expression
>You need to run as fast just to stay in place, but to get somewhere, you must run at least twice as fast!
This applies not only to Alice in Wonderland, but to all information technology in general!
https://redd.it/1cjzdny
@r_cpp
Statistics on increasing complexity of the C++ compiler
I always pay attention to assessing the complexity of programming in a particular language. Programming is indeed not an easy task and this is perceived as a fact and usually does not require any confirmation.
But the concept of “complexity” is akin to the term “heap”. For some, five coconuts is not so much, but for someone who ate one and “didn’t want any more,” this means that even one coconut will be too much for him.
The same goes for the complexity of programs. It seems that the constant increase in the complexity of programs is obvious to everyone and is observed in all areas of application of IT technologies, and programming languages themselves become more and more complex as they develop, but assessing “complexity” using numerical metrics is a problem. obviously a thankless task, but also “You can’t manage what you can’t measure...”
Typically, talk of “complexity” only implies value judgments without any numerical evaluation. And since I am personally interested in the issue of the complexity of programming languages, I decided to calculate the complexity of implementing the gcc compiler on some conditional “parrots”. What if we could see some patterns of difficulty changing over time?
**Choosing "parrots" to measure**
I didn’t come up with my own and calculate empirical program code metrics and, as a “parrot,” I decided to take the simplest metric [SLOC (Source Lines of Code)](https://en.wikipedia.org/wiki/Source_lines_of_code) - the number of lines of source code compiler, which is very easy to calculate.
But it will be possible to evaluate the complexity of a language with its help only under the following assumption: the complexity of the language should be directly dependent on the complexity of its implementation, if simple syntactic structures require less code than more complex ones.
Of course, using the “number of lines of source code” metric has its drawbacks, since it strongly depends on the programming language used, the style of source code and, in general, does not allow correct comparison of several different projects.
But for numerically assessing the complexity of code within **one project**, the SLOC metric is well suited.
# Methodology for calculating SLOC
Initially I tried to use a simple bash script with mask search and counting the number of lines in source files via `wc -l`. But after a while it became clear that I had to invent another bicycle.
So I decided to take a ready-made utility [SLOCCount](https://dwheeler.com/sloccount/), which can analyze almost three dozen types of sources.
Moreover, it counts not just the number of lines of source code, but can ignore comments, exclude duplicate files from the calculation (compares their hash sums), and also displays the estimated labor intensity, an approximate estimate of the cost of developing the analyzed project file and other characteristics.
I was initially interested in the volume of source codes in C/C++ and, possibly, in assembler, if there were a lot of such files. But after I started working, I was very glad that I did not reinvent the wheel, but took a ready-made toolkit, because it separately calculates the statistics of the Yacc/Bison parser source files (.y), which determines the actual complexity of the parser (read the complexity of the programming language syntax).
I took the old gcc sources from [https://gcc.gnu.org/mirrors.html](https://gcc.gnu.org/mirrors.html), but before running the analyzer I deleted the directories of other compilers (ada, fortran, java, etc.) so that they would not be included in the final statistics.
**Results in "parrots"**
[Yearly сhart of GCC complexity](https://habrastorage.org/webt/yb/cs/bo/ybcsbo5gssucq3ccllzub3c6mju.jpeg)
[Yearly chart Yacc/Bison parser code size](https://habrastorage.org/webt/7l/b5/-n/7lb5-nwrjzxstyazy6msyr-jrng.png)
[Yearly chart size of entire GCC source code (C and C++ languages only)](https://habrastorage.org/webt/wn/ae/9h/wnae9haqifqpl3kib4miu1pun4i.jpeg)
Unfortunately, the Yacc/Bison parser was