#include <wtf.c>



  • One of my professors uses this layout in his C++ header files. I honestly can't think of a worse idea:

    FooClass.h:
    class FooClass {
    public:
        FooClass();
    };
    #include <FooClass.c> // Not a typo!
    FooClass.c (not a typo!):
    FooClass::FooClass() { /* 200 lines of code go here */ }
    namespace { foo = FooClass(); }


  • I did that for a little bit while still learning programming and C++, but it wasn't long for me to realize why this is a Bad Idea. For a prof to be doing this... /shudder

     

    I mean, then you just have to

        gcc main.c 

    and not have to worry about all that crappy object files and linking! Win win. 



  • @JamesKilton said:

    I did that for a little bit while still learning programming and C++, but it wasn't long for me to realize why this is a Bad Idea. For a prof to be doing this... /shudder

     

    I mean, then you just have to

        gcc main.c 

    and not have to worry about all that crappy object files and linking! Win win. 

    I've seen that and worse. About 10 years ago, I worked with this woman who used to take common chunks of code (not classes or methods, mind you, just sequences of code) and put them in .c files, then #include them wherever. It 'saved typing' by only having the code in 'one place'. You could not explain the concept of refactoring to this woman for anything. *sighs*



  • Including all the source files into one file has two advantages:

    1) Many compilers can't handle template classes if the class implementation is separate from the class usage.
    2) When optimizing, a compiler can only inline those functions that are in the current source file or one of its includes.



  • @fourchan said:

    One of my professors uses this layout in his C++ header files. I honestly can't think of a worse idea:


    FooClass.h:

    class FooClass {
    public:
    FooClass();
    };
    #include <FooClass.c> // Not a typo!

    FooClass.c (not a typo!):

    FooClass::FooClass() { /* 200 lines of code go here */ }
    namespace { foo = FooClass(); }

    The prof probably learned Java first. This does make C++ work a little more like Java. I wonder if we will see more of this kind of idiocy as more and more people learn Java as their first language.

    There is a tv commercial currently running that shows people getting their money back from the actors in a bad play.




     



  • @Rick said:

    @fourchan said:

    One of my professors uses this layout in his C++ header files. I honestly can't think of a worse idea:

    FooClass.h:
    class FooClass {
    public:
    FooClass();
    };
    #include <FooClass.c> // Not a typo!
    FooClass.c (not a typo!):
    FooClass::FooClass() { /* 200 lines of code go here */ }
    namespace { foo = FooClass(); }

    The prof probably learned Java first. This does make C++ work a little more like Java. I wonder if we will see more of this kind of idiocy as more and more people learn Java as their first language.

    There is a tv commercial currently running that shows people getting their money back from the actors in a bad play.

    I've used C, C++ and Java (among others) over my career, and have seen front-page-worthy WTF-stupidity in all of them. I've also seen some really slick stuff - in all of them. Some carpenters just don't know how to swing a hammer properly...

     



  • @Rick said:

    @fourchan said:

    One of my professors uses this layout in his C++ header files. I honestly can't think of a worse idea:


    FooClass.h:

    class FooClass {
    public:
    FooClass();
    };
    #include <FooClass.c> // Not a typo!

    FooClass.c (not a typo!):

    FooClass::FooClass() { /* 200 lines of code go here */ }
    namespace { foo = FooClass(); }

    The prof probably learned Java first. This does make C++ work a little more like Java. I wonder if we will see more of this kind of idiocy as more and more people learn Java as their first language.

    How does this make C++ work anything like Java? 



  • @sycro said:

    @Rick said:
    @fourchan said:

    One of my professors uses this layout in his C++ header files. I honestly can't think of a worse idea:

    FooClass.h:
    class FooClass {
    public:
    FooClass();
    };
    #include <FooClass.c> // Not a typo!
    FooClass.c (not a typo!):
    FooClass::FooClass() { /* 200 lines of code go here */ }
    namespace { foo = FooClass(); }

    The prof probably learned Java first. This does make C++ work a little more like Java. I wonder if we will see more of this kind of idiocy as more and more people learn Java as their first language.

    How does this make C++ work anything like Java? 

    He said a little more like Java. In C++, you have the .h, which has the class declaration, and the .c, which has the class implementation. In Java, there is no concept of #include, so it's all in one file. As such, MyClass is in a file: MyClass.java, and looks like this:

     

    // This part would be in MyClass.h
    public MyClass {
    

    // The declaration of the methods would be in the .h, the body in the .c
    public MyClass() { /* body goes here */ }
    }

    By #including the .c into the .h, he's putting the declaration and implementation into one file, just like Java.

    Mind you, I'm not saying it's a good thing...



  • @snoofle said:

    @sycro said:
    @Rick said:
    @fourchan said:

    One of my professors uses this layout in his C++ header files. I honestly can't think of a worse idea:

    FooClass.h:
    class FooClass {
    public:
    FooClass();
    };
    #include <FooClass.c> // Not a typo!
    FooClass.c (not a typo!):
    FooClass::FooClass() { /* 200 lines of code go here */ }
    namespace { foo = FooClass(); }

    The prof probably learned Java first. This does make C++ work a little more like Java. I wonder if we will see more of this kind of idiocy as more and more people learn Java as their first language.

    How does this make C++ work anything like Java? 

    He said a little more like Java. In C++, you have the .h, which has the class declaration, and the .c, which has the class implementation. In Java, there is no concept of #include, so it's all in one file. As such, MyClass is in a file: MyClass.java, and looks like this:

     

    // This part would be in MyClass.h
    public MyClass {

    // The declaration of the methods would be in the .h, the body in the .c
    public MyClass() { /* body goes here */ }
    }

    By #including the .c into the .h, he's putting the declaration and implementation into one file, just like Java.

    Mind you, I'm not saying it's a good thing...

     But he's not putting the declaration and implementation into one file.... he's just making it operate as though it's one file. He still has a file for the declaration and one for the implementation. But I do see your point. And yes, it's a very dumb idea.... unless there's some kind of performance gain he's learned from this way.
     



  • namespace { foo = FooClass(); }

    wtf does this accomplish?



  • and here is me, thinking that angle brackets are used only for system headers...



  • Angle brackets alter the order of include search. If you put the name in quotes, the current directory is searched first, and then the include directories passed to the compiler. If the filename is in angle brackets, then include directories are searched first, and then the current directory. So it'll work as long as there is no "fooclass.h" header in his include tree... I've seen people using quotes with OpenGL headers that were obviously placed in the include tree, because "they're not standard", so the misconception is very common.



  • @goldsz said:

    namespace { foo = FooClass(); }

    wtf does this accomplish?

    Oops, that should have been "FooClass foo = FooClass();". The entire logic for the program is contained with FooClass's constructor, so that line creates a new FooClass and then discards it.
     


Log in to reply