Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API

From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
12bitfloat10227247dNot wrong lol
I mean most of these are so unnecessarily hard to type for zero benefit -
typosaurus10776247dThat's haskell style? Saw it in php once. I did use allman style for a while. Now K&R. I use an rc file for formatter for all projects. It's quite basic with custom line length
-
cafecortado7814247dWhen I was a noob I used the Ratliff style, because it made more sense to me. But then I realised I was probably the only person on earth using it, so had to back down to K&R.
-
12bitfloat10227247d@Lensflare The semicolons are a monoid in the category of endofunctors, you wouldn't get it
-
typosaurus10776247d@Demolishun I've no idea from my head which one I use. Gets autoformatted anyway
-
typosaurus10776247d@Demolishun before I started c I thought that there was a difference based on position of the asterisk. Spaces around expression like ( <expr> ) is insane indeed. I think my clang formatter does it your preferred way regarding asterisk usage btw. Myself did it in the middle. int * var
-
12bitfloat10227247d@Demolishun I'm in your camp too, but I think int *foo; is actually more correct
As far as I know, C and C++ consider foo a pointer variable of type int, instead of a variable of type int pointer
There are only a few cases where the distinction shows itself in syntax though (can't remember them) -
12bitfloat10227247d@Demolishun Ah right now I remember, here's an example: `int* a, b;` only declares the first variable as a pointer, the second is just an int
https://godbolt.org/z/vdvW41cnh
That has tripped me up before lol -
Lensflare18821247d@Demolishun I don‘t want to brag or something but how is it possible that I knew about this thing in C++ and you didn‘t?
I think your main language is C++? 😂 -
12bitfloat10227247d@Lensflare I don't think you can ever be a point where you can't learn something new about c++ lol
-
typosaurus10776247d@Demolishun I also do every line, never inline
So,you have to declare int *a, *b instead of int *a, b? Damn, keep learning -
Lensflare18821247d@retoor there is a reason why none of the languages who were inspired by and came after C/C++, haven’t adopted this multiple-declarations-in-one-line syntax. :)
But I wouldn’t be surprised if something like php had this. -
Lensflare18821247d@Demolishun I just realized that I might have learned it when I was doing code golf 😂.
I‘d never use this in normal code either. -
devRancid636247dYou can count the Allman style as a mental disorder as well
Along with tab indentations -
CoreFusionX3429247d@Demolishun
Constructors only run before main for global or static objects, and their order of execution is order of statements.
Did you mean static constructors? -
Lensflare18821247d@Demolishun this "no order for compilation units" kind of makes sense for me intuitively 😂.
Maybe I‘m more suited to be a c++ coder than I thought 😅
I fucking hate c++. But I also love it! -
iSwimInTheC41708246dNaturally typing out Kernighan is easy.
foo() {}
And then you just stick your crap in between, and hit newline where necessary.
Allman is does the newline in a different order but still not as bad.
My editor does most of the work though, so I don't think about it. -
CoreFusionX3429246d@Demolishun
Aha, yes, the good ol' static initialization order fiasco.
Which is, in short, undefined behaviour, so if you are relying on it, you're walking on the edge.
It's a very big code smell and you should rework it ASAP.
Also, the way you declare your classes (in CPP struct just means public class) screams C coder left and right XD. -
CoreFusionX3429246dYou can, by the way, solve this, by just encasing all these modifications you make of the global into a function each in its own translation unit, then have another function that calls these in whatever order you need. Call it first thing into main() or in a static constructor if you will, and there you go.
For reference, it's called the construct on first use idiom. -
Pogromist2412231dMental disorder is also enforcing particular code style by a compiler itself, instead of using linter. I understand if there's no other way because there's no brackets like in python (but it's interpreter so idk).
-
Pogromist2412231d@Demolishun
struct Point {
int x, y;
} p, *pPtr;
I only knew about this from this syntax, but at the same time didn't correlate with regular variable syntax of pointers. -
Lensflare18821231d@Pogromist I know this syntax and I always wondered who would use this. I mean you are declaring a name for the type anyway, so there is no point in doing it inline.
It would make more sense for anonymous types. -
Pogromist2412231d@Lensflare
when it's regular struct declaration, the names before ';' or after '}' are variable declarations of that struct
struct Point { int x, y; } p, *pPtr;
struct Point { int x, y; } p = { 5, 5 }; // you can even initialize it there
struct { int x, y; } p, *pPtr; // variables of that unnamed struct could be declared only once
When it's typedef it makes alias for "struct Point"
typedef struct Point { int x, y; } Point, *PointPtr;
So you can use "Point p = { 5, 5 };" instead of "struct Point p = { 5, 5 };"
When it's anonymous typedef
typedef struct { int x, y; } Point, *PointPtr;
you can only use "Point p" and not "struct Point p"
And it's useful when the type name shows that it's a pointer
PointPtr p = (PointPtr)malloc(sizeof(Point)); -
Lensflare18821231d@Pogromist yeah, as I said, the anonymous type thing makes sense and is quite nice actually, but naming it (Point) and still using it inline without a typedef is just weird.
So true
joke/meme
code styles