Monday, October 18, 2010

the order

If I had to talk someone through learning C that had never been exposed to programming before, I'd probably make them go through something similar to how I grew up (although accelerated over months instead of 15 years).

1) Take an existing program with a graphical element in a non-complied language and modify bits of it. My first experience with a programming language was GW Basic and QBasic. I learned how to write loops to say things like "Chris is the best" over and over again on the screen. You can easily see in the code where the parts are for what is written on the screen, and how many times it loops. After that, I messed around with QBasic's Gorillas and Nibbles demos. It's pretty simple to find where the velocity and other parts are. Changing something that's already there and straightforward to run is an easy instant-gratification thing to do. I don't think that there are modern equivalents to this!

2) Dive into Pascal. This was the second language I got familiar with, and it introduced me to modern syntax, variables, advanced loops and other control elements, reading/writing files, objects, and doing more graphically advanced things on the screen. It's possible to compile Pascal, so that's a good step to learn.

3) Baby steps into C. My first experience with C was either Turbo C++ or DJGPP, I can't remember. I could do almost everything in C that I could do in Pascal except for reading/writing files and doing interesting things on the screen. DJGPP had the Allegro libraries ready to go, but this was where knowing how structures and pointers worked would have been useful. Ultimately I got frustrated and never advanced. So, I wouldn't recommend that path. I'm working on an order of learning for C that would have helped me when I was younger. The problem is the instant gratification element. Getting things on screen these days is difficult now that the console has been marginalized. Making little ASCII art characters walk around is prohibitively difficult - in fact I probably couldn't even do it now! It seemed so trivial in Basic and Pascal in hindsight.

K&R, as I've said before, is a great reference but poor tutorial. Not that it's trying to be one, but still. It really cheesed me off over the weekend with the structure padding thing. Structure padding seems so freaking important of a thing to know, but it gets one lousy sentence in K&R.

Sunday, October 17, 2010

sizeof, structures, and fread

I just read about structure padding, and now I'm worried.

If I have a file stream going and I want to shuttle in some data to a structure with fread(), will it go "too far" into the stream if I do this?

fread(&stuff, sizeof(struct putstuffhere), 1, filepointer);

What if my structure is an int and a char... it's technically five bytes, but sizeof will return eight! Will my file pointer location go three bytes too far into the stream if I try to read data into that five byte structure?

I can't find any info on this.

gtk+ installed

It took some doing, but I have the GTK+ packages going, and I was able to compile and run the sample program that Code Blocks defaults to.

Everything worked as I expected it to except for one thing: to run my program I had to copy a whole mess of .dll files from the GTK+ library. Does this mean that if I write a program I'd have to include a dozen .dll files in the root with the program itself? How do I tell it to maybe look in a different directory?

I need to find a small program that uses GTK+ that someone else did to see how they do it.

Anyways, big moment for me. I installed and compiled against a GUI toolkit. Not easy... but now I think I have a handle on how to do it to any arbitrary packaged library out there.

Monday, October 11, 2010

not too unproductive

I didn't get any programming done over the weekend, but I did indulge my other hobbies a bit.

Wednesday, October 6, 2010

someday

The more I read about GTK+, the more I want to learn it. It seems the most "C friendly" of the GUI libraries (when compared to QT anyways).

One day I'll have time for that. I think it will come after I figure out some of the esoteric examples in the K&R book, which has been on my to-do list for weeks now.

Tuesday, October 5, 2010

one down

I finished Mysterium. Only took two evenings. Wait... isn't this supposed to be my programming notes?

I've been giving thought to leaping forward a bit. I had promised myself that I wouldn't get ahead of myself and try to do things I didn't really understand, but I want to do more than manipulate strings and read from files. projecteuler.net might be a good start for ideas.

Monday, October 4, 2010

2.5

I started learning C on July 15th. So it's been about 2.5 months. I've made pretty good progress, I think. I had hoped to make another push at understanding structures over the weekend, but that never happened. I worked on Saturday, and spent Sunday evening in The Colony because my Dad was in town. Everything in between was a frantic catchup on chores. I did take a break to go to Half-Priced Books and get $10 for a big box of textbooks I salvaged from my parent's house. Most of the $10 went to buying A Stranger in a Strange Land by Robert Heinlein, and Mysterium by Robert Charles Wilson. I started Mysterium. It's good so far - it might make me track down more "alternate history" kind of books.