Showing posts with label C. Show all posts
Showing posts with label C. Show all posts
Friday, 9 April 2010
Strange Urges
I have these strange urges to restart development from scratch, only in C++ (or even C).
Monday, 13 July 2009
SQLLite and the further revenge of C
As a followup to this and this, this is the sort of thing I miss about C.
In other news, this (reasonable to me) suggestion to use SQLLite for Angband data didn't go down too well on the forums. I'm not sure why - even DCSS has used SQLLite for a long time now. Some of the objections that are raised remind me of late '99, when I was developing applications in the Telecomms Industry using C++ on Solaris boxes, and several teams in the department I was in refused to use C++ because "its too slow".
Inertia is a powerful force, it seems.
Inertia is a powerful force, it seems.
Thursday, 9 July 2009
The Revenge of C.
With all this talk on r.g.r.d. of picking up abandoned projects written in C or C++, I have an increasing urge to write a small Roguelike in said languages. Realistically though, with Kharne and with Prelude, I have enough on my plate for the time being and my copy of K & R can wait*.
I've had lots of experience with C or C++, in fact around the turn of the millenium I spent four years after graduating using both languages to a reasonably high degree of competence and complexity in a commercial environment (the company I worked for, a major international telecomms company is now bankrupt, which is not surprising given that for most of its existance, it was utter and complete cluelessness made flesh). One thing I do regret from my time there is that I never really learned to use the STL, instead we were locked into using the Roguewave libraries). I also spent a lot of time with Informix, for my sins.
However, if I do decide to get in some C or C++ coding I think I may focus my efforts away from roguelikes and do something completely different.
However, if I do decide to get in some C or C++ coding I think I may focus my efforts away from roguelikes and do something completely different.
(* Incidentally, I dislike K & R style indenting. The Kharne source code is written using Allman indenting, which is the defacto standard in the Pascal world)
Tuesday, 30 December 2008
Programming Wars (not)
Sometimes miracles do happen. A recent thread on r.g.r.d. asked for advice on programming languages to use for developing roguelikes. And the corresponding thread didn't descend into a language war. Is the roguelike community finally growing up?
Sunday, 18 May 2008
Language Wars
These last few days, I've been using some some C and C++ code from other Roguelikes as a source of inspiration for Kharne. Years ago, I used to work professionally in both C and C++, and to say I didn't miss them at all would not be inaccurate. However, looking at the Angband source code, I am experiencing not a small degree of deja-vu, and surprisingly, not all of it is bad.
Thers is no doubt that certainly C is still the most popular language for Roguelike development, and nowadays I would contend this is due to two main reasons: the strong cross-platform possibilities that it offers, and also the established momentum that such an exiting large codebase of already written (and finished!) Roguelikes can offer.
There's no doubt that C does have somethings right - I had forgotten how the increment operator was such a thing of beauty. Let's take this amusingly commented extract from the Angband source, specifically in generate.c:
/* Mega-Hack -- Paranoia -- prevent infinite loops */
if (main_loop_count++ > 2000) break;
The Object Pascal equivalent of this is much more laborious:
/* Mega-Hack -- Paranoia -- prevent infinite loops */
inc(loop_count); if (loop_count > 2000) then break;
Double the code, and nowhere near as elegant.
Parameter passing into subroutines is also not as elegant in Object Pascal as it as in C. There is a function used in tunnel building in Angband to find the correct direction between two points. It is defined and used as:
static void correct_dir(int *rdir, int *cdir, int y1, int x1, int y2, int x2)
{
...
}
correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
Now consider the Object Pascal equivalent:
procedure correct_dir(var rdir: Integer; var cdir: Integer; y1, x1, y2, x2: Integer); begin ... end; correct_dir(row_dir, col_dir, row1, col1, row2, col2);
In Object Pascal, I really miss the fact that you know straight away from the calling line which parameters are modifiable or not.
Even the use of { and } seems to be suddenly a lot less irritating than begin and end are.
This is not to say that I've become a sudden convert to Brian W. Kernighan's famous criticisms of Pascal or that I wish to rewrite Kharne from scratch in C/C++. Far from it. There are many things in C and C++ that are simply atrocious, and anyone proposing those features for a modern day language would be, and ought to be, shot. The oft-quoted string handling, for example. The ridiculous fragility of operations involving memory. And, dare I say it, pointers. And pretty much all of Kernighan's criticisms of Pascal are no longer valid when it comes to Object Pascal (though it is, I guess, slightly unfair of me to compare an effectively ancient language like C to a comparatively modern one like Object Pascal). For example, Object Pascal supports casting using the as operator, as whilst you cant quite turn apples into oranges as it sometimes seems you can do with C, as is functional enough.
Now, I think that I perhaps unfairly dissed C and C++ in the past, and with the incorporation of the standard template libary, C++ is certainly a fine development language, but I am still of the opinion that Object Pascal is better. As for C however, would argue that it is unsuitable for modern development - unless there are compelling reasons to do so - it lacks features that modern languages have by default (even C++ has some of these) - exception handling, many useful data types, function overloading and so on. But my biggest complaint about C is that it lets you shoot yourself in the foot too easily.
There are two caveats to this opinion though. The first one is that often opinions on programming languages are a function of familiarity. The second is that what is important with a programming language is how you use it to get things done. This may seem an ironic statement considering I've not released anything yet, but I find the combination of Object Pascal and Delphi allows me to implement things extremely quickly. If you're developing a roguelike, you may yourself have a different method of getting things done, but for me, I'll be sticking with Object Pascal and Delphi, although giving a richly deserved nod to C++ at least.
In other news, I've implemented a simple cave algorithm, with the following results:
Although the levels it generates are somewhat annoying to traverse, they do induce the claustrophobic and careful game play I want the Elemental Planes levels to feature (well, they will do when I add monsters!). All three types of dungeon mentioned in my last post are now implemented, although there's still a lot of refactoring to be done with the code.
Thers is no doubt that certainly C is still the most popular language for Roguelike development, and nowadays I would contend this is due to two main reasons: the strong cross-platform possibilities that it offers, and also the established momentum that such an exiting large codebase of already written (and finished!) Roguelikes can offer.
There's no doubt that C does have somethings right - I had forgotten how the increment operator was such a thing of beauty. Let's take this amusingly commented extract from the Angband source, specifically in generate.c:
/* Mega-Hack -- Paranoia -- prevent infinite loops */
if (main_loop_count++ > 2000) break;
The Object Pascal equivalent of this is much more laborious:
/* Mega-Hack -- Paranoia -- prevent infinite loops */
inc(loop_count); if (loop_count > 2000) then break;
Double the code, and nowhere near as elegant.
Parameter passing into subroutines is also not as elegant in Object Pascal as it as in C. There is a function used in tunnel building in Angband to find the correct direction between two points. It is defined and used as:
static void correct_dir(int *rdir, int *cdir, int y1, int x1, int y2, int x2)
{
...
}
correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
Now consider the Object Pascal equivalent:
procedure correct_dir(var rdir: Integer; var cdir: Integer; y1, x1, y2, x2: Integer); begin ... end; correct_dir(row_dir, col_dir, row1, col1, row2, col2);
In Object Pascal, I really miss the fact that you know straight away from the calling line which parameters are modifiable or not.
Even the use of { and } seems to be suddenly a lot less irritating than begin and end are.
This is not to say that I've become a sudden convert to Brian W. Kernighan's famous criticisms of Pascal or that I wish to rewrite Kharne from scratch in C/C++. Far from it. There are many things in C and C++ that are simply atrocious, and anyone proposing those features for a modern day language would be, and ought to be, shot. The oft-quoted string handling, for example. The ridiculous fragility of operations involving memory. And, dare I say it, pointers. And pretty much all of Kernighan's criticisms of Pascal are no longer valid when it comes to Object Pascal (though it is, I guess, slightly unfair of me to compare an effectively ancient language like C to a comparatively modern one like Object Pascal). For example, Object Pascal supports casting using the as operator, as whilst you cant quite turn apples into oranges as it sometimes seems you can do with C, as is functional enough.
Now, I think that I perhaps unfairly dissed C and C++ in the past, and with the incorporation of the standard template libary, C++ is certainly a fine development language, but I am still of the opinion that Object Pascal is better. As for C however, would argue that it is unsuitable for modern development - unless there are compelling reasons to do so - it lacks features that modern languages have by default (even C++ has some of these) - exception handling, many useful data types, function overloading and so on. But my biggest complaint about C is that it lets you shoot yourself in the foot too easily.
There are two caveats to this opinion though. The first one is that often opinions on programming languages are a function of familiarity. The second is that what is important with a programming language is how you use it to get things done. This may seem an ironic statement considering I've not released anything yet, but I find the combination of Object Pascal and Delphi allows me to implement things extremely quickly. If you're developing a roguelike, you may yourself have a different method of getting things done, but for me, I'll be sticking with Object Pascal and Delphi, although giving a richly deserved nod to C++ at least.
In other news, I've implemented a simple cave algorithm, with the following results:
Although the levels it generates are somewhat annoying to traverse, they do induce the claustrophobic and careful game play I want the Elemental Planes levels to feature (well, they will do when I add monsters!). All three types of dungeon mentioned in my last post are now implemented, although there's still a lot of refactoring to be done with the code.
Subscribe to:
Posts (Atom)
