• Lucid Dreaming - Dream Views




    Results 1 to 3 of 3
    1. #1
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935

      What is the purpose of header files?

      No one has given me a straight answer. It seems that once upon a time they would have been useful for quick reference and for modulating large project. But now with OOP modulating is impossible to avoid (Java doesn't even have header files and Cocoa discourages them) and API documentation is done for us by Eclipse, XCode, .NET...

      Is there any reason to still use header files?

      Don't yell at me for doing poor programming, in C and C++ I do use them (for my own code, other files I often import as frameworks)

    2. #2
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Well,
      you've pretty much answered it already
      it's primarily for modularised code, and code reuse

      Splitting files into Declaration (Header) and Implementation (source) files is a common concept, used in both procedural and OOP
      however, it comes into it's own with OOP, so I'll stick with that

      One of the core OOP concepts is the ability to hide the internal "workings" of an object, and only show certain, outward facing functions

      you have your main program,
      and it uses some object
      You don't need to know "how" that object actually works internally
      You only need to know how to use it

      Classic example is the standard string library
      you know how to use the string library
      but you don't need to know exactly how it works
      (all the dynamic allocation and resizing of buffers, and whatnot, is completely hidden)
      You just #include the declaration and off you go

      Code re-use also becomes important here, as well
      if you have a common object that is used in many of your files, why keep repeating the same code?

      Bung the object in a linked library and #include the objects header file in your source files (so they know how to use the library)
      All of your files, when calling the common object, re-use the same library
      (\_ _/)
      (='.'=)
      (")_(")

    3. #3
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      But the point remains valid that modulation can be done without headers. As much as I hate java, Sun does it very well. They use interfaces, which are like headers to hide implementation. And I don't (even in C and C++) use the headers to figure out how to use something, I use a documentation of it's API, especially when the headers are HUGE.

      OpenGL will be my example. I just opened it, it's 3034 lines of code. I'd much rather use the index of my Bluebook to find parameters instead of find it in that mess. The declarations are grouped, but not in any order.

      gcc won't allow it but cocoa will allow you to #include a header or the cocao file itself.

      Why did Seis get banned?

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •