• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

One File == One Class or what ??

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    One File == One Class or what ??

    A long time ago I used to develop in C++. (Okay, not that long ago ) and used to follow the 'One Class, One file' development mindframe (and still do). Today I had a discussion with another contractor with whom I work on a day-to-day basis, he has placed all of his classes in a single file (with some weird file-naming convention) instead of having the files named the same as the contained class. The question is this: what is the norm/standard/preferred method of organising your project ?? I know that it is really a matter of choice, but I feel quite strongly that the one file per class is the 'right' way to do things, not least when working on a project that has multiple developers working on the same source code 99% of the time...

    discuss.....

    #2
    monoliths

    I have never been a fan of monolithic code. OK perhaps in the days of yore, but any language that supports splitting an application into multiple files is doing a good thing.

    It doesnt need to be OO to be a good idea, in plain C I make my code into libraries.

    Isnt modular programming seen as a good thing these days ?

    I would be worried about the competence of a developer of OO code that put everything in a single source file.
    What does he do about change control ?

    Comment


      #3
      monoliths....

      Thats exactly what I said when I joined the project, so far he has been working alone so it hasn't bothered him. He has roughly 3 or 4 classes per file at present, and he's adding to these files all of the time. I know what I 'think' we should be doing and how we should be doing it, I just can't seem to find any evidence of this on the web (even on the Microsoft site !!). Any useful URLs etc. much appreciated......

      D

      Comment


        #4
        Re: monoliths....

        i'd create new file for every class thats either:
        a) not relevant
        b) bigger than X lines
        c) total length of file is greater than Y lines

        X could differ for different people but for me 1000 would be a good number.

        Y would be 5,000

        My personal record is file 120kb big

        Comment


          #5
          Re: monoliths....

          If he has 3 to 4 classes per file then presumably he has only the one header file for the class definitions. This would be regarded by many people, including Stroustrup, to be bad for a number of reasons - organisation, encapsulation, compilation dependencies.

          The only case where I would regard this arrangement as valid is if only one class is publically available and the others are private helpers to that class.

          Comment


            #6
            re

            i use inner classes only when they're small - say <100 lines. they are usually variants of API classes as well.

            Comment


              #7
              Re: monoliths....

              Stroustrup is watching Java and biting his nails considering to retire - he wont blame ya for not doing your C++ using correct number of files cuz he would be happy enough to know someone else is using his soon to be Latin-like language

              AtW
              C++ user since 1991

              Comment


                #8
                monoliths

                So it would seem from the current consensus that the one class per file arrangement is the method of choice ?? - We know that there are reasons when you *may* wish to put more than a single class in a source file, but there don't seem to be any valid reasons (or mandatory reasons for that matter) for doing so.

                I have since spoken to the guy involved and let him know of several reasons for following this approach, I still can't seem to find any decent 'guidelines' documents on the web that specifiy this though ....

                Comment


                  #9
                  re

                  its just sometimes convenient to have them in one file i suppose.

                  Comment


                    #10
                    Re: re

                    Ah, our resident expert - concise and straight to the heart of things.

                    Comment

                    Working...
                    X