31
Comments
  • 9
    Not wrong lol

    I mean most of these are so unnecessarily hard to type for zero benefit
  • 4
    That'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
  • 6
    Ok Haskell style is the most retarded shit that I have seen in a while.
  • 4
    When 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.
  • 2
    @Lensflare The semicolons are a monoid in the category of endofunctors, you wouldn't get it
  • 0
    @Demolishun I've no idea from my head which one I use. Gets autoformatted anyway
  • 2
    @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
  • 4
    @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)
  • 7
    @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
  • 5
    @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++? 😂
  • 7
    @Lensflare I don't think you can ever be a point where you can't learn something new about c++ lol
  • 2
    @Demolishun I also do every line, never inline

    So,you have to declare int *a, *b instead of int *a, b? Damn, keep learning
  • 1
    @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.
  • 1
    @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.
  • 0
    You can count the Allman style as a mental disorder as well
    Along with tab indentations
  • 0
    @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?
  • 1
    @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!
  • 4
    I just write and autoformat so nobody will know my mental state 😏
  • 3
    Naturally 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.
  • 2
    @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.
  • 0
    You 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.
  • 0
    Mental 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).
  • 0
    @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.
  • 0
    @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.
  • 1
    @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));
  • 1
    @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.
Add Comment