Sunday, July 31, 2011

Bum weekend

I didn't read about, do, or think about coding this weekend. Too much driving around and doing pre-wedding chores. So it goes.

Add to the list of things I'd like to experiment with:

Ray tracers
databases

Wednesday, July 27, 2011

GTK program organization

Ok, so source control methods aside the one other thing I want to try differently is overall program structure.

The organization so far has had all of the GUI code right in the main() function. This is generally probably not a good idea. I've been trying to hash out the behavior of what's really happening when I'm writing some of this GUI code.

See, MOST of the stuff I'm writing is initializing pointers to GTK objects with some basic behaviors and then connecting signals to functions. The real business doesn't start until gtk_main() is called. What that means is I can offload widget initializations to other functions (in other .c files) and then call those functions in main() right before I call gtk_main().

So, here's an example of this in action:



It's important to remember that there's a lot happening in DrawWindow but all it's doing is initializing pointers that aren't going to go out of scope once the function is over. Calling the function DrawWindow was dumb since it's not doing the drawing. The function gtk_widget_show_all can be in main() instead of DrawWindow... I'm not sure which is "proper" but in this simple example it doesn't seem to make a difference.

I might add in a little interactivity just to verify things work like I expect them to, but hey I'll call tonights efforts a win.

workflow

I think the problem is I don't understand the source control workflow. Edit, compile, then push? Does it only work for the code files or can my IDE project file go with the push?

EDIT: OK well, nevermind for now. I can deal with not using source control for the first version and I have another major thing to bang out before I proper start.

Tuesday, July 26, 2011

hosting

I've hashed out what I want the first "finished" release of the front end program to be. It's going to be just a selector for single player or multiplayer, and then if multiplayer a choice between hosting or joining. My hope is that it will be a solid and clear base that will be easy to just keep adding to.

The reason I haven't started proper yet is because I want to try and host the code somewhere but I can't figure out what the best solution is. There are many options: http://en.wikipedia.org/wiki/Comparison_of_open_source_software_hosting_facilities

It's not super necessary to host it - I just want practice with something relatively simple.

Github seems all the rage, but I don't really even understand Git.

Monday, July 25, 2011

research

I spent some of my free time this weekend (and time procrastinating) researching the file selection widget in GTK. Seems straightforward. Another interesting concept I stumbled across is "graying out" text entry boxes, buttons, and other selection widgets. Good info.

Man I'm behind on Project Euler stuff. And I haven't touched much Python nor started on any of those Python books.

Bad overextended hobbyist. No biscuit.

Friday, July 22, 2011

launcher idea

I've been fiddling with GZDoom a little bit and there are several command line options for hosting and connecting to multiplayer games. There are even more for what mode of multiplayer and maps to play.

I did a little research and figured out how to run a program from C using a Windows function called ShellExecute(). It's pretty straightforward and I confirmed I could use it by making it run Notepad. The nice thing is that it's running it just like if I ran it from the console or double clicked an icon (as in, not dependent on the calling program staying open or anything).

There are several front end programs for GZDoom/ZDoom but none that I can find that are open source or written in GTK (and therefore could be cross platform easily if I can find similar program running functions in Linux/OSX).

I've been itching for some way to write a potentially useful program that would be complex enough and useful enough to a community to justify learning Git (so I can use Github) or hosting on SourceForge or something.

The only thing I don't immediately know how to do is the file selection dialog. I'd need the ability to point to the .exe and .wad files and it would be slick to figure out if the .wad files have any useful info inside of them like level names I could extract. My quick skim of the GTK documentation gives me the impression that it's not excessively tough to do a file selector. This makes sense considering how common that feature is!

Other than that it's just a matter of layout and how options should be toggled. The obvious first push should handle the most common ones. I'm getting better at string handling so storing all the options enabled and shuttling them to a string to be executed as a shell command shouldn't be too tough.

I really wish I was at the chapter in the GTK book that handles Glade so I wouldn't have to do the UI by hand, but maybe I need the practice!

old school

http://www.brackeen.com/vga/

It's super tempting to download DJGPP and Dosbox and try some of this out. Turbo-C and DJGPP we're my first C compilers. DJGPP used to be bundled with the Allegro graphics/audio/input library and I remember spending many hours reading the example code and compiling the sample games with minor variations to adjust physics and other properties.

Thursday, July 21, 2011

python download script

The second answer to this question on StackOverflow is exactly what I need to test my download speed.

http://stackoverflow.com/questions/22676/how-do-i-download-a-file-over-http-using-python

I've already tested it and it works as advertised - it downloads a 10MB file. I should be able to pretty quickly adapt some of the code from my security camera program to handle the timing so that it can run every 30 minutes and record a completion time to a text file.

Wednesday, July 20, 2011

Commas

http://mindtribe.com/2011/07/forgotten-c-the-comma-operator/

I saw a comma in a goofy place recently while reading someone else's code. I wonder if it was an instance of using it as an operator.

Friday, July 15, 2011

Prepping a library for Python

I've been reading a bit about the CTypes module in Python and I want to see if I can call a library I wrote to do something interesting, like read something out of a binary file - something I can set up pretty quickly in C now but wouldn't know where to start in Python. So, it follows I should write a library for that purpose in C and call it from Python. I'm almost done with it - here's the meat of it:



I'm writing two versions of a function that gets an array of long integers out of the file. One version of the function returns a pointer to an allocated array that contains all the data. The other version of the function (TBD) requires this allocation be done before-hand and you pass it the address of the array for it to fill. I did this because I'm not sure which is the most appropriate way to do things in Python. Hopefully both will work and that will give me a really good feel for that module and make fleshing out the library much easier.

I went a bit overboard compartmentalizing functions. The "skip" functions could have been one function but I went for verbosity over brevity.

An early draft of the function for getting data involved an elaborate flagging system where you passed NULL as the array to be filled and an address of an integer if you wanted to just get the number of data to be returned, and the opposite (address of array to fill and NULL of integer address) to get the data out. This I decided was too complicated AND I realized that the capability to overload function names (use the same function name in different contexts depending on how you call it) in C++ would have been useful.

I banged this out in two evenings but to be honest I did recycle some code from prior similar projects (maybe a dozen lines total recycled). This weekend is going to be nutty but I hope to have this code in a static library next week for some Python testing. Right now it's just a .c file in a vanilla console program project in XCode and in main.c I have some quick verification tests where I ask for data I know the values of.

Onwards and onwards.

EDIT: This project has certainly been a big retesting of my pointer knowledge - especially since I do more allocating here than I've ever done. FYI the function that returns a pointer to an allocated array assumes that you free it later.

One year

I started this journal one year ago with a netbook and enough anger at my prior failures to learn C to motivate me to push through the hard parts.

The best way to summarize my progress over the past year is this: I'm more overwhelmed by the things I can do now than the things I have yet to learn. That's a clumsy way of saying that the past year's progress has unlocked the capacity to pick any arbitrary next step and go along with it. The next step I've gone the farthest with is GTK and I'm learning now that Python and C are not mutually exclusive and I'm really itching to learn how to write Python modules.

My goal as stated in the journal header was to gain competency in C before I'm 30. I've learned now that this isn't exactly a coherent statement. Learning C is not learning how to program any more than learning the alphabet is learning how to write.

There are still several big topics that elude me, but they only remain that way because I have yet to sit down and hash through them. These topics are less about C specifically and more about data structures and programming methodologies common to most languages.

In the immediate future I'd like to get through a few more Project Euler problems and get through a few more (extremely dry) chapters of the GTK book. I'm learning about Python on the side but what's keeping me interested in that Python itself is written in C and it's well supported to write custom modules in C.

On the long term list I'd like to get a better handle on OOP and pick a (non-interpreted) language to explore that with such as C++ or Objective-C. Getting a familiarity with network programming (sending/receiving packets), a graphics library (SDL or OpenGL) and databases would be fantastic, too.

That's pretty much my one year report.

Last night I started rewriting my file reader to have all the important functions kept in a static library that I can load into Python with the CTypes module. Eventually I want to write an actual Python module to import data from the files and see if I get better results.

I'll do another general progress report in April when I turn 30.

Wednesday, July 13, 2011

moving

The move derailed my programming progress but everything is back in place and my internet connection is restored so I think I'll be continuing soon after this weekend.

I've given more thought to how to handle the Python case manager in a OO way. I had a column of database information that contained slash-delineated items and the tag column that had space-delineated items. I realized if I made them both space-delineated I could have a class for storing each item into a list (or array or whatever Python data type is best) and then have a subclass that inherits that feature and adds functions specific for the database info and another class that has specific functions for the tag info. This way if I ever have any other space-delineated items I'll always have the class for handling that which I can add on to with a sub-class (or... whatever it's called in OO terminology).

EDIT: I've been all talk and no code for WEEKS now, which is double shameful with Python since it's quick and easy to prototype something out.

Wednesday, July 6, 2011

Cases organization

I think I'm right about having class (lets call it Case) representing the data structure and methods to act on that data structure. What I also need is a class (lets call it Worklist) that contains at the least an array (or the Python equivalent) containing Case instances (instances?) and probably it will need the function for populating that array from a .csv file.

Lots to think about.

first OO step

I want to keep my C learning as straight C right now and not try to dabble in C++ or Obj-C quite yet. I'm going to use Python to experiment with object oriented programming. Hopefully once I get my head around OOP it will translate to C++ or Obj-C if I get around to that.

There isn't a Project Euler for OOP concepts (to my knowledge) but I think I have a good idea for a project. I mentioned before my interest in using Python to parse a CSV file so that I can extract certain information from it that's not quickly doable by hand. I made a test CSV file:

 

It's just example data that mimics what my support tracking spreadsheet looks like (but converted to CSV). There are many ways of formatting CSV and it's important to note that columns that include commas that aren't to be used as separators of columns have quotes around them. The columns are as such:

Date Added: This is the date I entered the case. They are always in chronological order.
Date Closed: The date that the issue is resolved. If this column is blank it means the case is not closed.
Group: The company the user is with
Contact: The person I interact with in the company on the issue. It's usually just one person but every so often I'll include two names separated by a comma.
Issue: A description of what's going wrong.
Notes: This is where I keep track of my thoughts on the matter. In the real thing I have a system for tracking my thoughts across multiple days by prefacing an entry with "UPDATE 7/5/2011: " but I left that out for simplicity until I learn more about parsing CSV in Python.
Database: If there are returns or orders made in our shipping database in regards to a support case I include the relevant numbers or names here.
Tags: This is experimental but I really want to use it. Tags are semi-standardized classifications that I'd love to use for searching. My goal is to be able to search for any case with a specific tag or tags, and obviously count cases with certain tags to keep track of what's having the most problems.

I'm an OOP newb so I'm not quite sure how to arrange the data and operation on the data into classes. If I were to do this in straight C I'd define a struct that has each of the columns as a member, and then I'd have an array (or linked list) of these structs such that each element of the array held all the info of one case (one row in the CSV file). If I wanted to print out every case that had the tag "XYZ" I could easily scan through the array and find them. This seems very straightforward to me but the goal here is to use OOP which right now doesn't seem straightforward but hopefully it will later.

Should I define a class that represents a case? What methods would that class contain, and how would the data for that class be stored? Maybe one useful method in a class would be to return how long it took for that case to close (and return NULL if the case isn't closed).

But then how to I store all of the unique instances of the classes that basically represent every line in the CSV? Then we're back to arrays. Can there be an array of instanced classes? How do I initialize each class such that it will be filled with the data from one line of the CSV, and how do I keep track of where I am in parsing the CSV? Should the functions that do the parsing be contained in a class of its own?

Headache. I feel like this is unnecessarily difficult but maybe by the time I work through those intro to Python documents I'll know enough to ask better questions.

Tuesday, July 5, 2011

long weekend

I purposefully didn't do much this weekend. My brain needed a break and I need some time to think about what direction I'm going with all this.

Unfortunately I'm swinging into a less creative mindset (which allows me to program or write music) and into a more consuming-oriented mindset (video games and TV). Some would call that "being a lazy bum", which sounds about right.