Skip navigation

Tag Archives: C

I just noticed that I have done all the python stuff on my laptop where I saved my executables in a directory called bin/ and all my C stuff on my desktop where I saved all my executables in a directory called scripts/

(The reason I’ve done that is because I set up my vimrc for C or Python on my desktop and laptop respectively, the reason that I named the folders that way was because I made the scripts directory for the first bash scripts I did and the bin directory to put world of goo in).

Someone on irc told me about this thing: http://projecteuler.net.

I’ve only done the first one so far (got kinda distracted by trying to put a whole bunch of disparate functions that seemed like they might be useful again sometime in a file and then trying to figure out how to add it’s path to the path for includes – which I did eventually by aliasing gcc to gcc -Idir in my .bashrc, dunno if that is a silly way or not – I think for my next distraction I should work out how to write makefiles :p).

I think it might be kind of fun to do one each day because at the moment I am in a bit of a “schedule fetishism” mood (this normally happens to me much earlier in the long unstructured summer, I think it took so long because I actually spent my time doing stuff spontaneously this year instead of just clicking “refresh” in my browser on some forum like I’ve normally done) ever since I decided to try and get myself up to speed with my maths (also, anyone reading this have any recommendations for a good stats book that would cover the stuff I would have missed out on by not doing A level stats? Because online reviews honestly do not give me a good idea of what to expect from this or that book and the range in local bookshops leaves much to be desired)).

This past week I have spent some time writing, scrapping, rewriting etc. something in Python to get my head around both using classes and python in general.

Tonight I have been thinking about this in comparison with my experiences with C so far.
A lot of websites on the internet mention that they think Python is a good first language, a good teaching language and so on. I don’t know that I entirely agree, as basically pretty much a beginner to programming, I think C is much better to start with, or was for me and probably would be for people with my personality at least.

I’ll explain why, and also why people with a slightly different personality might find the opposite. What I like a lot about C is how much it has taught me about how things work. How much insight, this short time with it, it has given me into exactly what is happening. Every little thing I had to figure out how to do in C showed me something new about what happens when my computer does that thing. All the stuff with pointers, memory allocation etc, I loved that precisely because I had never thought about it before, I had never thought exactly how programs deal with memory or how they know where information is or pass references to memory addresses or anything like that. Now that I have thought about it seems criminal to me that I never thought about it before then, but I hadn’t. I think most people who have never done this sort of thing before would similarly not have thought about those kind of really basic things, and C forces you to think about it.

Python on the other hand, does not, everything I’ve had to find out how to do has been a matter of finding out which module to include and what words to use to get the thing to magically do what I want. OK, I know it is possible to look deeper and find out what is going on, but the truth is, when I am in the middle of trying to get something to work I am not gonna get distracted by looking into what is going on at a deeper level. And yet, despite that, the reality is I am a lot more interested in “what is going on” than making things work.

And this is why I think it in some senses comes down to personality. It is also why I think I never really got into computers properly until I tried Linux. Because someone whose primary interest is in creating things, they might well, even without discovering Linux, find themselves driven to create things and get into that, but me, I never felt a drive to create things – oh I enjoy it, its always nice to finish something and have something to show for yourself – but what really excites me is finding out how things work. And when I had windows, how things work was kind of obscured to me in many ways, whereas, the most glorious thing about Linux is that, its transparent, you can look into everything about it and have a real hope of one day understanding it – or at least, if you can’t it is because of your own limitations and not because anything is hidden from you. That is so cool.

I can completely see the advantage of programming languages which do a lot of more low level stuff behind the scenes, and I think one day I might prefer that too, when I know a lot more, when things that for me now are like “wow, so that is what is going on” have turned into “ugh, I can’t believe I have to do this EVERY TIME” then you can bet I will be singing the praises of Python, I can see that day off in the distance, but for now I like C better, because I don’t know the basics, because I don’t know what is going on and its all magic to me, and anything that can make that magic into something more comprehensible, anything that beats me over the head with what it is actually doing, is something that I want and need right now.

In some ways I think it comes down to a lack of imagination. I don’t imagine what I don’t know until it sneaks up on me and laughs mockingly, and at the moment I don’t know most anything. Yet I find it so delightful to find out new things. I think for me there is no greater pleasure than that moment when things fall into place and I actually finally understand something.
I literally live just for those moments.

Wow… I was testing out threads just on their own (each one of 5 prints that its a thread and the i number count that it was created on).

Everytime its different. Sometimes all 5 get created, sometimes less than 5 get created, the order that they print their line is always different.

Should that happen? I dunno…

It’s kind of interesting. But I want to make it a bit more predictable :p

LOL they are racing to get the numbers from the memory, thats why shared memory has issues! haha.

Someone told me that what I was trying to do was too hard for a noob like me. Grr, I am annoyed. Maybe it is good because it has really given me a stronger motivation to prove them wrong (not that they will ever know most likely lol). It just bothers me that I care so much when people say stuff like that to me. I mean they don’t know me… what do they know whether I can do something or not. LOL, but yeah, I know, I am too proud, its not good for me :p.

In the meantime, I got my tamagotchi running with fork (although haven’t tried the input thing yet) BUT OH MY it is SLOW!!! So I think I will definitely try the threads thing now which might not be so slow? Although there’s a couple of things I need to check first.

Edit: yeah my suspicions were right, it was so slow because I put the fork thing in the wrong place. It’s normal speed  now :P Maybe I wont need threads…

Haha, and it slows down overtime because it keeps reforking because it was on the wrong side of a loop :p

Although…. that shared address space with threads sounds mighty fine to me right now…

I am doing my tamagotchi virtual pet program in C and passing my strings around and changing them between functions and all sorts, and getting compiler warnings galore in my tests. And google says to me “you have to allocate memory you n00b”.

So I am going to allocate some memory. Then (hopefully) free it at the right time.

It’s so exciting! It seems like such a powerful and deep thing to be able to do. Mwahahaha. Wow…

I love this…

I’ve been messing around a bit with C lately. So I have decided to make a little virtual pet type thing in it. I have no clue how to deal with a lot of things, such as, how in a text based ascii character drawn application, do you make it constantly receptive to input without being constantly demanding of input.

Secondly some more difficult aspects of my ascii animation, do I have to rwdraw everything every frame? Is it not possible to only redraw the actual moving part?

I am having a lot of fun though. So far of all the programming languages I tried (in this incredibly short space of time) I have had most fun with C. I think this is because it’s simple. Like, python was not so simple, it threw a whole load of concepts at me before I’d really grasped the basics. Because it had simpler syntax it seemed like I should be able to grasp more concepts at once, but concepts involve more cognitive load than syntax.

C had at first intimidating looking syntax, but its nice and regular and pedantic. So it quickly floated into the background.

I also think partly its because I really don’t understand this object oriented thing yet. C is not confusing me with object oriented stuff that I don’t understand (although I am told it can :p).

Anyway, even though its quite simple really, it is very satisfying to see my little ascii creature bobbing around the screen. All thanks to Linux without whom I never would have discovered the coolness of programming :p

Follow

Get every new post delivered to your Inbox.