Questions tagged [headers]
77 questions
135
votes
8 answers
Is it better to document functions in the header file or the source file?
In languages that distinguish between a "source" and "header" file (mainly C and C++), is it better to document functions in the header file:
(pilfered from CCAN)
/**
* time_now - return the current time
*
* Example:
* printf("Now is %lu…
Joey Adams
- 5,615
99
votes
5 answers
Why do we need to put private members in headers?
Private variables are a way to hide complexity and implementation details to the user of a class. This is a rather nice feature. But I do not understand why in c++ we need to put them in the header of a class. I see two annoying downsides to…
Simon Bergot
- 8,020
92
votes
5 answers
Best practices for making header file?
What things should absolutely always/never be included in a header file?
Functions: what must go in the header file and what mustn't
Constants: Is it good practice to define lot of constants in a header file?
Any other good practices for C header…
Moshe Magnes
- 1,071
65
votes
9 answers
Is it good practice to rely on headers being included transitively?
I'm cleaning up the includes in a C++ project I'm working on, and I keep wondering whether or not I should explicitly include all headers used directly in a particular file, or whether I should only include the bare minimum.
Here's an example,…
futlib
- 2,205
53
votes
7 answers
How can I prevent header hell?
We are starting a new project, from scratch. About eight developers, a dozen or so subsystems, each with four or five source files.
What can we do to prevent “header hell”, AKA “spaghetti headers”?
One header per source file?
Plus one per…
Mawg
- 4,298
50
votes
3 answers
Copyright statements in source code
Ever since I started programming I've seen a header at the top of most code files indicating some sort of copyright: e.g.
/* Copyright (c) 1998 Innotech */
or
/* Copyright (c) 1998-2008 Innotech */
Conceptually I get the idea... depending on your…
scunliffe
- 704
47
votes
4 answers
Why is #include bad?
I was reading another thread where a guy asked about C++ books for beginners, and one of the programmers answering wrote this:
Some warnings: avoid all books that present an "hello world" stating with
#include
I opened my C++ book…
Daniel Scocco
- 5,892
45
votes
6 answers
Why can you have the method definition inside the header file in C++ when in C you cannot?
In C, you cannot have the function definition/implementation inside the header file. However, in C++ you can have a full method implementation inside the header file. Why is the behaviour different?
Joshua Partogi
- 3,905
41
votes
1 answer
Where to place an API key: a custom HTTP header VS the Authorization header with a custom scheme
I'm designing a REST API using authorization/authentication via an API Key.
I tried to figure out what is the best place for it and found out that many people suggest using a custom HTTP header such as ProjectName-Api-Key, eg:
ProjectName-Api-Key:…
RomanG
- 521
23
votes
7 answers
Why do we need to include the .h while everything works when including only the .cpp file?
Why do we need to include both the .h and .cpp files while we can make it work solely by including the .cpp file?
For example: creating a file.h containing declarations, then creating a file.cpp containing definitions and including both in…
reaffer
- 365
16
votes
4 answers
Why do we need to write a header file?
Before you whip out your snarky comments, I know -- this is a nooby question. This is my first time using a C based language.
I'm an undergrad student learning Objective C for a computer science course on mobile development. I know that, in an…
Hartley Brody
- 354
13
votes
3 answers
Is it safe to transmit access tokens via HTTP headers?
It's the first RESTful web service and I am concerned about security issues. Is it safe to transmit my access token via HTTP headers? For example:
POST /v1/i/resource HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Api-key:…
ahmedsaber111
- 233
12
votes
4 answers
Ways to organize interface and implementation in C++
I've seen that there are several different paradigms in C++ concerning what goes into the header file and what to the cpp file. AFAIK, most people, especially those from a C background, do:
foo.h
class foo {
private:
int mem;
int bar();
…
Felix Dombek
- 2,129
11
votes
1 answer
Is there any reason *not* to forward declare all forward declarable function parameter/return types?
I ran into a situation where my build speeds have started to become large and have affected productivity. I had already minimized header dependencies before using forward declarations. Now I've turned to forward declarations to further reduce…
Krupip
- 1,340
11
votes
2 answers
Updating copyright headers each new year just because Jan 1st has passed?
I've seen some projects that - with each new year - start to change all files in their source-tree to update the copyright year.
Isn't this just pushing hot air on a level of magnitude? AFAIK:
Copyright year is based on relevant changes of a work…
hakre
- 1,165