FrederikTobner / tobot-engine

A simple 2D game engine built on top of SDL2
https://frederiktobner.github.io/tobot-engine/
GNU General Public License v3.0
2 stars 0 forks source link

New clangformat goennung #77

Open HabelJonas opened 1 year ago

HabelJonas commented 1 year ago

so ist das ganze dann auch deutlich besser zu lesen für mich :) und du gewühnst dich schon auch noch drann 👍

FrederikTobner commented 1 year ago

Bin mir nicht ganz sicher ob das qualifier placement auf der linken Seite wirklich besser ist. Hier ein Zitat aus Pointers in C:

If you declare an integer, you can make it constant by putting the const keyword before or after the type: const int i = 42; or int const i = 42; You can read the first as “a constant integer i” and the second as “an integer constant i.” Either formulation works, and both declarations do the same thing. They make it a compilation error to change the value of i. Early on, I got used to the first variant, and it is the one I instinctively use, but if you are just learning C, I urge you to use the second instead, and I have done my best to only use that variant in this book. If I have messed up in places, I beg your forgiveness. It is hard to change an old habit. The reason that I think the second is better is that it makes it easier to combine pointers and qualifiers such as const, as we shall see in this section. If we didn’t have the first variant, we would have a consistent rule for how to specify which types are constants and which are not; with the first rule, we have a special case for the base type. Special cases too often mess things up, so avoid them if you can. If you get started with the first variant, it is as hard to switch to the second as it is quitting smoking, so don’t get started. You should only ever use the second variant.

Mailund, Thomas. Pointers in C Programming 🚬

Der const qualifier wird immer auf den rechten Wert angewandt wird, außer wenn es keinen Wert auf der rechten Seite gibt, dann wird er auf den linken Wert angewandt. Wenn man beispielsweise einen konstanten Pointer hast der auf einen Integer Constant zeigt sähe das dann folgendermaßen aus: const int * const pointer oder int const * const pointer

Ich finde die zweite Variante deutlich besser lesbar da sie konsistenter in der Platzierung des Keywords ist und näher an der originalen Implementierung des Keywords ist. Allerdings ist das ganze Thema natürlich sehr subjectiv, und zudem auch wichtiger wenn du in C programmierst und nicht in C++ und beispielsweise einen zweidimensionalen Array einer Funktion übergibst, dessen Wert du nicht ändern willst.

void funnyFunction(int const * const *) In C++ würrde man da ja eher std::array verwenden. Die Leute sind auch auf Stackoverflow da fleißig am diskutieren. Wir können das ja nochmal in Discord oder am WE besprechen, was da die bessere Variante ist 😄.

Wir hatten vorher auch ein Batchskript, dass alle Dateien im Projekt formatiert. Wenn du Lua nicht nutzen willst kann man das auch wieder hinzufügen. Hab es rausgemacht um auch die Entwicklung unter Linux zu vereinfachen ohne mehrere Skripts hinzuzufügen, aber das hat natürlich auch den Nachteil das man Lua (und Luarocks) dann braucht.

FrederikTobner commented 1 year ago

Kann man ja im Nachhinein auch noch easy anpassen, da wir ja alle Dateien mit dem Skript formatieren können 🚀

HabelJonas commented 1 year ago

Ja also ich finde schon das meine Version klarer ist 😁 wenn man das liest: const int* const a; Da ist direkt klar: a ist ein constant pointer auf einen constant int

Während wenn ich les: int const * const a; Dann sieht das für mich eher wie ne Multiplikation aus :D

Aber ja können wir ja noch reden

FrederikTobner commented 1 year ago

Meinte nur das placement von dem const keyword. Wäre also const int const a; gegen int const const a; Die Platzierung von dem Asterix (*) passt so, solange es nicht rechts ist😆. Da hab ich keine Argumente warum Middle besser ist, das ist nur ne Angewohnheit/persöhnliche Präferenz.