Roman Hartmann wrote:Hi Uri,
counting lines is tricky as some people (including me) prefer to have several statements on a line. At least as long as the code remains somehow readable.
- Code: Select all
if (p->board_piece[i]==1){p->board_adress[i]=j;p->pieces[j]=i;j++;continue;}
- Code: Select all
if (p->board_piece[i]==1)
{
p->board_adress[i]=j;
p->pieces[j]=i;
j++;
continue;
}
maybe the sources should be formatted with indent before counting lines.
I think it would be even better to measure the size of the
compressed source code, because this doesn't penalize newlines and long identifier names very much.
However, all simple ways of measuring code length are misleading, because it also depends on other aspects of your coding style. For instance, the source code of Glaurung 2 is much bigger than it could be, because I have to write an awful lot of ugly and verbose boilerplate code in order to force the C++ language (which I really, really hate) to behave a tiny bit more like I would expect from a decent modern programming language.
For instance, I prefer to use enums rather than plain ints for things like pieces, squares, files, ranks, and so on, because this helps me to detect a much bigger number of silly bugs at compile-time (it means that I can't assign a rank to a variable of type "Square", and that I can't pass a piece as an argument to a function which expects a color as input). When I do this, C++ doesn't allow me to use basic arithmetic operators on the different types, and I have to manually overload +, -, ++, --, * and so on for every single type where I want to use these operators. This greatly inflates my source code.
As another example, I don't like to access constant and pseudo-constant arrays (by "pseudo-constant" I mean that the array is never written to after the program has finished initializing) directly in the high-level parts of my program. I write small inline functions to access them instead, like this:
- Code: Select all
int Foo[64];
inline int foo(Square s) {
return Foo[s];
}
This style makes it easier to replace the array Foo with a simple computation without changing many different parts of the program, and also helps to ensure that I always send a square (and not a rank, a piece type, a value, a search depth, etc.) as input. It improves debuggability and flexibility, it costs nothing in terms of performance or readability, but it inflates the code size.
Glaurung 2 currently has 16888 lines of code, while Glaurung 1.2.1 has 7021 lines. I am quite sure Glaurung 2 is still a lot bigger if you look at characters, tokens, non-comment lines, compressed source code, or any other simple and precisely defined way of measuring code size. Nevertheless, on a conceptual level, I think Glaurung 2 is a simpler and more compact program.
Tord