17
Comments
  • 9
    Not wrong lol

    I mean most of these are so unnecessarily hard to type for zero benefit
  • 3
    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
  • 3
    Not convinced about K&R either.

    The opening brace isn't part of the while (...).

    The block with its opening and closing braces is one thing, and the while (...) is another thing.

    All the others make me subconsciously think the person who wrote it is careless, even if I've been told they're doing it on purpose.
  • 6
    Ok Haskell style is the most retarded shit that I have seen in a while.
  • 3
    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.
  • 3
    @Lensflare The semicolons are a monoid in the category of endofunctors, you wouldn't get it
  • 1
    The mental disorder is all of these is the fucking whitespace in between elements!

    while(condition < 1){ // good

    while (condition < 1) { // mental disorder!
  • 1
    @Demolishun I've no idea from my head which one I use. Gets autoformatted anyway
  • 3
    @retoor I think the most bizarre one I have seen is this:

    while ( condition < 1 ) { // just why?

    One of my pet peeves is this:

    int *var;

    The datatype is int*, not int. It should be:

    int* var;

    But my autoformatters all want to do the first one. I know its adjustable, but it really isn't that important.
  • 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)
  • 2
    @12bitfloat I will have to think about that.
  • 5
    @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
    @12bitfloat oh that is just stupid. Okay, the language is retarded. Is this why I avoid putting variables on same line? Maybe.
  • 3
    @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++? 😂
  • 5
    @Lensflare I don't think you can ever be a point where you can't learn something new about c++ lol
  • 3
    @Demolishun I also do every line, never inline

    So,you have to declare int *a, *b instead of int *a, b? Damn, keep learning
  • 2
    @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.
  • 2
    @Lensflare I dunno, maybe I just don't care. I don't put multiple variables on a line.
  • 2
    @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.
  • 2
    @Lensflare one thing I found about C++. There is so much shit you don't know until you have a wtf moment. This causes you to dig into the language to search for the reason. When I found that there is no order for compilation units to execute constructors in any specific order I was kind of shocked. (this is code that executes before main) But I had to dig into cppreference to find that detail. Even after I explained this to people I work with they just tried blaming the OS itself. It has nothing to do with the OS at all. lol
  • 2
    @Lensflare in before ostream:

    "how is it possible that I knew about this thing in C++ and you didn‘t?"

    Something, something German master race... ;-)
  • 1
    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?
  • 2
    @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!
  • 1
    @CoreFusionX different compilation units. For simplicity: files like .cpp. Have no defined order in which they run. Sure within the unit it is defined. But the order in which each unit is run is not and can change depending upon the compiler and possibly even compiler settings.

    We ran into this issue because we had one file defining an array of structs. Different compilation units would modify this struct at defined indexes. This is fine, but there was a constructor that zeroed out the array in one unit. This caused the structure to be wiped out if another compilation unit updated the array before the constructor ran.

    I also found that globals are initialized by the OS. So it was unnecessary to have the constructor zero out the array. The solution was to remove the constructor that zeroed the array in one of the compilation units.

    To me the code smells really bad to begin with. I have not convinced anyone to address this issue yet.
  • 0
    @CoreFusionX

    file1.cpp:

    struct GlobalStruct1 {

    int stuff[10];

    GlobalStruct1(){

    // init stuff to zero here

    }

    } gloablstruct1;

    file2.cpp:

    extern GlobalStruct1 globalstruct1;

    // update an entry in struct in some global classes constructor

    The order in which these are run in the different units is not guaranteed.
  • 4
    I just write and autoformat so nobody will know my mental state 😏
  • 2
    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.
  • 3
    @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.
  • 1
    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
    @CoreFusionX we usually use class.

    Code base is old. I fix what I can.
Add Comment