Have you successfully read a source code of a project? If yes, have you fully understood all of it?? I've looked at some opensource projects (vlc, filezilla, wxwidgets, ...) but it's just too huge to devour. I guess notepad++ is the only one that somehow make sense to me when reading its code.
[edit]
BTW, macros are one those things that confuse me when reading other people's code. I also notice books don't usually focus on C/C++ macros.
There's no reason to read the entire source code of a project (unless it's really tiny), you just need to figure out which parts you need to make the desired modifications and how those parts are designed.
Macros exist to make code easier to read. While it is true that they can be abused, I don't think that they are as often as they could be.
For a simple example, we have the C/C++ macro "NULL", which exists to make it obvious that we are working with pointer values. You could just write "0", and the program will be correct, but the meaning is made explicit:
if (foo == NULL) foo = do_something(); // foo must be a pointer...
Macros also allow you to parameterize on your build-environment, which is not something esoteric, but a common need. Another very simple example:
1 2 3 4 5 6 7
#if defined(_WIN32)
#include <windows.h>
#elif defined(__unix__)
#include <unistd.h>
#else
#error Alas, there is no support for your platform.
#endif
Macros are messy, and can be horribly abused, but they aren't evil. (They just make great tools for evil programmers.)
How many of those projects had "developer's documentation" explaining where you could find certain classes/functions and what they do? I usually find that such documentation helps a lot if it's rather comprehensive.
I use the pre-processor for unit testing. I put a main function at the end of the source file of every class wrapped in #if TEST_<class name> and #endif .
I've looked at some opensource projects (vlc, filezilla, wxwidgets, ...) but it's just too huge to devour
It wouldn't be so bad if many of those projects' docs were up to par. It still takes quite a bit of time from the point where you first encounter an alien code base to the point where you can actually make viable contributions to it. I've personally found it quite painful to read through the source code of many open source projects because of the variety of different coding conventions used in it.
Remember helios' thread about it? Someone was creating an array similar to the argv[] array that is passed to the main function, just to call a function within the program.
VLC is an example of horrors and what goes wrong when you have no clear architectural requirements and just keeP hacking at it. Alas, just because a program is OS it doesn't mean that it is well-written or well-designed.
I've worked with several closed source projects before and 100% of those projects were "better" than open-source alternatives. The reason being that the projects' requirements had a blueprint enforced by an iron fist. (Either you meet the requirements, or you're fired. Simple as that.) There was absolutely no room for sloppy practices.
"better" =
a) easier to use
b) easier to understand
c) easier to maintain
d) easier to extend
I guess that the term "better" is subjective, but that's based upon what I have personally experienced.
I may seem opposed to open source development, but I'm not. Open source software does what it's designed to do very well. However from my experience, customers like to have guaranteed official customer support for a product, something that *most open source projects do not guarantee.
I've seen a few close source projects that were in worse shape than your average open software, after being in production since the 1980s, but all those companies (except one, which is now gone) were/are busy switching to modern C++, setting up effective development and testing infrastructures, and otherwise regaining competitive advantage.
There's no reason to read the entire source code of a project (unless it's really tiny), you just need to figure out which parts you need to make the desired modifications and how those parts are designed.
Hmm, I see. I'm not trying to modify it in anyway though. I use it for learning how other programmers write code. I try to put myself on the authors shoes and to wrap my head around the code and try to guess what the author is thinking while he/she was coding.
Luc Lieber wrote:
I've personally found it quite painful to read through the source code of many open source projects because of the variety of different coding conventions used in it.
I'm glad I'm not alone :) Maybe that's why I somewhat understand notepad++ which I believe is written by one person (I might be wrong here)
Macros are almost always in use specially in cross platform projects just like Duoas said. So may I ask if anyone here knows any tutorials about macros? Like common tricks and pitfalls?