jarandhel: (Default)
2006-09-13 09:39 am

Programming Foo

Ok, so, the original program I wanted to improve (netpong), it turned out that I couldn't (yet) figure out a way to merge the two aspects into a single function, since they hard-code different keymappings. Moving on, the next program I wanted to work on (shareaza) was FAR too complicated for me to get into (yet). I still think it's within my abilities, but I need to get a bit more familiar with the structure of the language again. It's been a while since I've worked with C++. Finally, I think I've found something more my present speed, which will let me get refamiliar with the language and also work on structure. In a group of C++ tutorials, I found a hangman program. A VERY VERY BAD hangman program. It functions, but it isn't the least bit object oriented (it has exactly one function other than main, and all it does is run a set of four if-then statements that would probably be better formulated as a single switch statement). It also doesn't even approach human-readable... most of its variables are single letters with no indication of what they do unless you read through the code and find them in action, and they're all declared in a clump. It looks like the programmer was probably taught this as a way of shortening the program, in that you only need one declaration of variables per variable type and the variable names themselves take up less space, but any speed increase due to that would be negligible and completely countered by the increased time needed to understand the program in order to maintain or update it. I'm going to see what I can do to get it fixed up, then I'll post both versions of the code and see what people think.
jarandhel: (Default)
2006-09-07 03:06 pm
Entry tags:

I'm an idiot.

I'm a complete idiot. I've been so busy obsessing about which tools are the "best" for programming on linux, which interface builders and IDEs and everything, that I never really thought about the actual minimum I needed to begin programming on linux. Turned out, it was a lot less than I would have thought:

A text editor, and a compiler. Period.

Granted, some of the other tools may make it easier, but they're not necessary and they might actually get in the way of learning some aspects of it if I'm relying on them to simplify things for me.

I was also doing much the same thing with trying to understand all the libraries and APIs available for programming in C++. There were so many of them, I was starting to get overwhelmed. I felt like I needed a catalog of them all just to get started. Errm, no. No more than you need a catalog of an entire library to start a research project on Plato. You only need the relevant volumes. I only need the basic libraries for the relevant functions. I get that now.

Time to really start.
jarandhel: (Default)
2006-09-06 09:01 am

Code-foo

So, I was browsing around on google code, looking over the new open source projects they host. Kind of liking the format, really. Very clean compared to the format of sourceforge. You have a description page, an issues page, and a source page. That's it. Very simple, very orderly. I like that.

I was specifically browsing through the C++ projects, since that's the language I'm most focused on at the moment thanks to the phenominal books I got from microcenter. In about five minutes, I found a little open-source implementation of pong that someone had written. Small enough to browse through the code fairly quickly. Now, I'm a coding beginner really. I'm experienced enough in BASIC and LOGO (which I understand is actually a variant of Lisp?) and I've done a small amount of work with Objective C, but C++ has always been kind of over my head. Doesn't seem to be any more, though... I immediately homed in on a section of the source that is in dire need of reworking. It's nothing major, really... it's just that the original programmer hard-coded in identical initialization sequences for both players. That's kind of painful to me. It would be SO easy to split those off into a seperate function. Heck, with a little extra coding you could even set it up so you could add more players that way, and get crazy three-way or four-way games of Pong going. All from modularizing just a tiny bit more. Not to mention that it would make the code that much easier to maintain, if you ever needed to alter the initialization sequence.

... I'm really tempted to step in and make those chances, and submit them to the project. I've never submitted anything to an open source project before, but I'm really not seeing any reason not to here.

Funny thing is, I have no idea what most of the code in the sequence DOES (it uses an API I'm not familiar with)... I just know that it's not optimized, and I know enough about the language in general to know how to optimize it.

Edit: please, nobody do this before I do. I know there are other programmers on my friends lists who could EASILY do it (and probably add in enough new features at the same time to make the original programmer blush that he dared submit the program), but I really want to make the changes myself. I just can't from work, all I can do is browse the code here.

Re-edit: Or maybe I don't know enough about the language... I overlooked something. The code that I thought was identical actually is not, the hard coding involves keymapping. So while all the variables being defined are identical save for player, what they are being defined as are not. And I can't think (at the moment) of a more elegant way to store those variables so that the init sequence could be made more efficient. It seems like no matter how it's done, you're going to have to have some kind of array defined to hold the specific prefs for each player, keymapping-wise, and at that point you may as well hard code it this way since there's really no way to do that any more efficiently. The only drawback is that there's no easy way to add a new player. But then there's no easy way to do that the other way either, if you'd have to load some sort of preferences file holding the same info, since you'd have to create the pref file by hand too and make sure it contains unique mappings. I can't believe I missed that before. Oh well, back to the drawing board. Maybe I'll find something else that actually needs optimizing.