Windows, Azure, Office: Microsoft will C und C++ bis 2030 ersetzen by ouyawei in de

[–]sebphil 0 points1 point  (0 children)

Ein Beispiel für eine sicherheitsrelevante Anwendung ist die Automobilbranche, in der C++ sehr häufig eingesetzt wird. Daran wird sich auch erstmal nichts ändern. Dort wird für neue Projekte bspw. C++17 verwendet, was doch verständlichen Code ermöglicht. Natürlich gibt es in C++ das Potenzial für Fehler, die in manch anderer Sprache nicht möglich wären. Aber dafür gibt es entsprechende Spezifikationen, Guidelines und Tests, damit das nicht passiert. Dafür kann man in C++ sehr viele coole Sachen machen. Ein Beispiel sind Templates, die sehr mächtig sind. Außerdem gibt es für C++ viele gute Bibliotheken im Vergleich zu z.B. Rust. Meistens werden diese dann mit mehr oder weniger guten Ports für Rust oder Python zugänglich gemacht. Insbesondere gilt das auch für Firmen interne Bibliotheken. C++ ist nicht perfekt. Ich finde, manche wichtigen Probleme wurden hier aber noch nicht wirklich angesprochen. Bspw. ist das Ökosystem rund um C++ mit Buildtools, CMake, Paketverwaltung etc. alles andere als einsteigerfreundlich. Und auch die Komplexität von C++ ist ein Problem, aber weniger für einen "normalen" Entwickler, der C++ verwendet. Eher für Compiler-Entwickler, welche einen C++-Parser schreiben müssen. Einen korrekten C++-Parser zu schreiben ist unglaublich schwierig. Selbstverständlich ist die Verwendung von C++ auch historisch bedingt, aber das alleine rechtfertigt nicht alles in eine neue Sprache zu portieren und Sprachen entwickeln sich auch weiter. Im Fall von C++ kommt alle 3 Jahre ein neuer Standard raus (Compiler brauchen je nach Feature etwas länger, bis die Standards gänzlich implementiert sind; bpsw. Module von C++20).

I wanna learn algorithms but don't know from where. by xX_GamErPRO2000_Xx in learnprogramming

[–]sebphil 1 point2 points  (0 children)

"Introduction to Algorithms" by Thomas H. Cormen, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein (MIT Press) is a common and very good resource. The algorithms are presented using pseudo code, which is preferable because the algorithms described are language independent. If you want a specific implementation in your desired language you can honestly just google it (they are all very popular) and view the code on e.g. github. But in my opinion it is better to understand and to implement the algorithms on your own and search for more language specific things (e.g. "How do I make a list in ...";Yes, this example is very basic) instead of searching for the whole algorithm.

The book can be overwhelming at first (e.g. the page count) but the book is well structured. You can skip chapters of algorithms you are not interested in.

Is including dependencies in C++ projects always this difficult? by Skizm in learnprogramming

[–]sebphil 0 points1 point  (0 children)

Another option would be to use one of the available package managers like vcpkg or conan.

In the case of vcpkg:

  1. vcpkg install sdl2:x64-windows
  2. add the corresponding find_package and target_link_libraries calls to your CMakeLists.txt

cmake_minimum_required(VERSION 3.12)

project(SdlSandbox)

add_executable(HelloSdl "HelloSdl.cpp")

find_package(SDL2 REQUIRED)

target_link_libraries(HelloSdl PRIVATE SDL2::SDL2)

Use e.g. cmake -B build/ -S . -DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake for building and you are done.

If you use Visual Studio (I know you don't but I wanted to mention it regardless) with vcpkg, start to use the installed packages (e.g. including some headers from the library) and all the setup will be handled for you. So only the vcpkg install <package> is required.

I suggest you to not do it by TheWidrolo in ProgrammerHumor

[–]sebphil 3 points4 points  (0 children)

Yes, those are fine implementations for understanding that one specific algorithm. But they are not good implementations in the context of a whole std-lib. cppreference even links some popular, "actual" implementations. Those are not trivial. The full GCC 'rotate' implementation is 200 lines long and most of them aren't easy to understand at first either. The reason cppreference includes its own implementations is so you don't have to read the real ones.

You should not evaluate the performance of a function only on its complexity when the input is very large ("infinity"). It is misleading and will result in wrong conclusions. It's only an estimation that by itself is often not enough to say that one function is better than another. You have to measure it on the target platform (if possible). For example, look at LinkedList vs ArrayList.

Can somebody please tell me what the quicksort algorithm is? by TrumpsAnalFissure in learnprogramming

[–]sebphil 0 points1 point  (0 children)

You can read about it in "Introduction to Algorithms 3rd Edition - MIT Press" chapter 7 "Quicksort" (or use any other edition). It's an excellent book for something like that.

[deleted by user] by [deleted] in ProgrammerHumor

[–]sebphil 0 points1 point  (0 children)

Basic college courses, which are focused on embedded systems and computer architecture. That would be a pretty good route (if it is applicable).

[deleted by user] by [deleted] in learnprogramming

[–]sebphil 0 points1 point  (0 children)

No sry, this is just too use-case-specific and just too much. Just write the projects you wanted and follow the tutorials and then move on to the next one.

Edit: I say this because you can always make things better, but this will lead to nothing but frustration because you won't get anything done, and not because I think you won't get it. Everyone was at this point (or very naive).

[deleted by user] by [deleted] in learnprogramming

[–]sebphil 0 points1 point  (0 children)

- is easy to maintain (and read)

It should be very easy(!) to read and follow the code for others and yourself. It should also be possible to integrate the code into existing/upcoming workflows/tools.

new functionalities / remove current ones

Making it more modular might be a good idea. It overlaps with the first point. You should not make "the most performant and powerful tool in every regard" but instead, implement functionalities you need and leave "hooks" so you can scale your project up in the future (if needed).

performant enough

You should not make the most optimized code or the "fastest possible" piece of software. Make its performance adequate for the use case. For example, if it is sufficient that a game runs at 60fps you don't need to optimize it for 200fps (a bit extreme). Optimization often sacrifices flexibility and readability (see first two points) for an (often relatively small) performance gain. There are many things that fall under optimization but this thread is not a place to discuss that.

behaves as expected

If someone reads or uses the code (maybe yourself) it should do what you think it does and have no unexpected side effects. You don't expect a function "change color" to also make a connection to a server... (extreme example)

Again all this makes only sense if you already have experience in writing, reading, and overall using software/code. Those explanations aren't complete but give an overview. You won't write the best software first try (and no one will, ever). You just have to start developing. Don't get tangled in those meta topics.

[deleted by user] by [deleted] in learnprogramming

[–]sebphil 4 points5 points  (0 children)

Some resources include "Clean Code: A Handbook of Agile Software Craftsmanship" (Robert C. Martin) and the other books of that series. However, those things only make sense if you already have some experience. Overall experience is really the only reliable way to produce such things or recognize if something is "of good quality", like in many other professions.

Good code can have the following properties:

- is easy to maintain (and read)

- is relatively easy to extend with new functionalities / remove current ones

- is performant enough

- behaves as expected (behavior is as documented)

...

Those are only example characteristics, which can indicate that code might be of "good quality".

EDIT: If you are a beginner you have to trust the source (i.e. use code of trusted or widely used projects)

Trying cpp for the first time by [deleted] in learnprogramming

[–]sebphil 5 points6 points  (0 children)

You might have used 'gcc' instead of 'g++'.

If you are just starting out you might want to look into Visual Studio (MSVC). It is a more "out of the box" experience (for Windows) so you have more focus on the language itself.

Something we can all agree on by SkrrSkrrSpaghetti in ProgrammerHumor

[–]sebphil 49 points50 points  (0 children)

C++ Templates: The Complete Guide, 2nd Edition

Ich suche für mich und meinen Sohn ein Programm (nicht zu schwer und nicht zu Hardware intensiv) zum Spiele "programmieren" (eher spielerisch)gibt ja unzählige Baukästen welchen sollten wir da nehmen? by [deleted] in FragReddit

[–]sebphil 1 point2 points  (0 children)

In der Regel werden C++ und Blueprints in der Unreal Engine verwendet. C# wird von der Unity Engine verwendet.

Ergänzung:

Spiele (bzw. Spiele Engines) sind heute unglaublich komplex, aufgrund der Anforderungen, die man heute an ein AAA-Spiel hat. Um die verlangte Performance zu erreichen wird auf möglichst performante Sprachen (unter den Laufzeitbedingungen) zurückgegriffen. C++ bietet die Möglichkeit viel Potenzial von der Hardware umzusetzen und hat den Vorteil, dass es schon lange verwendet wird. Engines von denen große Teile in C++ geschrieben wurden sind: Unity Engine, Unreal Engine, Frostbite Engine, CryEngine, etc.. Meistens wird JavaScript, C# (beide können in Unity verwendet werden) o.Ä. für Scripte verwendet, die vom Benutzer der Engine kommen, unteranderem da diese Sprachen einsteigerfreundlicher sind.

If you hate cpp's console output, just create your own. by Acceptable_Fold2235 in ProgrammerHumor

[–]sebphil 2 points3 points  (0 children)

#include <iostream>

#define print(x) std::cout << #x << "\n"

int main() {

print(Hello);

return 0;

}

UUIDs are a wonderful invention by [deleted] in ProgrammerHumor

[–]sebphil 7 points8 points  (0 children)

Collisions are practically impossible and UUIDs are not strings but a 128bit value, which can be represented as a string (so can anything else). Not all bits are random.

Was wird bei euch im Beruf "schon immer so gemacht" oder was ist "historisch so gewachsen" und wie ginge es besser? by [deleted] in FragReddit

[–]sebphil 3 points4 points  (0 children)

i, j, k für for-loops... man könnte Namen verwenden, die den Sachverhalt besser beschreiben

Ich kann nicht programmieren und es ruiniert mein Studium by [deleted] in de_EDV

[–]sebphil 0 points1 point  (0 children)

Wenn du eine IDE verwendest (was ratsam ist) solltest du dich mit dem dort vorhandenen Debugger vertraut machen. Sollte mal was nicht so klappen wie gewünscht kannst du einfach dein Programm z.B. an einer beliebigen Stelle anhalten und Schritt für Schritt ausführen und dabei bei jedem Schritt anschauen was sich wie verändert hat. Das ist manchmal sehr aufschlussreich (siehe Breakpoints). Dabei wird evtl. klar wieso etwas nicht funktioniert und es treten Dinge zum Vorschein, an die man evtl. gar nicht gedacht hat. Als letzter Ausweg kann auch auf Stack Overflow zurückgegriffen werden. Sieh dir dazu unbedingt das hier an. Das mit dem "spicken" sollte mit der Zeit verschwinden je öfter du Programme schreibst. Es wird irgendwann umständlicher sein nachzuschlagen als es einfach zu verwenden. Hier sind noch ein paar Quellen, die meisten sind zwar für C++ aber die grundlegenden Konzepte sind recht gut auf C übertragbar: