Friday, 2 November 2012

Another week, another language.
This week we started looking at c. Prior to having had my first look at c this week, I was rather scared of c, as it was pronouned to be that really basic language. It turns out that it probably lacks some functionality that we're used to using in our code, but that in general its the same thing as c++, just without the shortcuts.

Looking back at assignments two and three, namely the hash table and the templated hash table, I personally have very differed views. The hash table I had implemented and running in a matter of four hours, and it works fine. Maybe not the most stablke code ever, but fine enough for normed use. THe templated hash table, didnt work at all for me and I shudder thinking back on the piece of crap I submitted... full of errors to the extent that I would call the assignment an error. I really think I'll need to revise templates, as thats the only part I dont understand about the project, but I'll procratinate that to some point in time before the exams.
Back to the untouched, or rather unprogrammed, subject of c. C compares to c++ in many ways, and only really differs in some "details". The quickest way to compare the two is to name what c doesnt have in comparison to c++: classes and members, derived classes and virtual functions, templates (juhuu), inline functions, exceptions, function overloading, new/delete, references, const in constant expressions and c++ standard libraries. Around most lacks, there are workarounds, so you can use struct and global functions instead of classes, macros instead of templates and pointers instead of references.
The next assignment, the binary tree in c, proves these possibilities. We will need pointers and nodes to make the hash table, and that possibility proves the main functionality of c, which provides the most basic functions, just not the fancy bit like templates, which I wont miss a second. Using c may become the next big thing, for "regular" programming. I dont think I'd use c for games or applications, but using c for assignments like the binary tree makes sense, as the functionality of the language allows for it, and the code will be the most efficient with c.
We learned this week that the most fundamental program running our systems are written in c, like drivers, compilers and operating systems. Therefore c, in my point of view, is there to be used for programs that have to be extremely stable and efficient at the same time. This week was unlike other weeks in a second (or fifth) aspect. We had a guest lecture from Dr. Christopher Jefferson. Dr. Jefferson gave us a different approach on templates and highlighted some techniques of using them. Next to the extreme coding speed he presented to us, he later on through his presentation begann talking about his work on the c++ committee. I found it most interesting and thoughful how the c++ committee accepts and rejects ideas. Unlike the common sense may judge, when a new idea is presented, the concept of c++ would never be changed without respecting the possible effect on the existing code. So any changes must be so minor, or happen parallel to the existing versions, that any code will resume working without being affected by the next version of c++. Ever since this presentation, I have the feeling that on the c++ committee, there are probably the brightest people our world has to offer, only judging them from their readiness to reject their own brilliant ideas for the benefit of existing code, however faulty it might be programmed.
This week we also learned about binary trees. I'm not sure what to say I learned, as I effectively saw nothing new on that subject. I have given binary trees a lot of thought last year, when we made a java implementation of a binary tree for a dictionary, using 50000 terms per language and six languages. Loading the data into the binary tree took approximately two seconds, and translating documents took something in the tenthousands of a second. Of course the translations were shit, but the efficiency was stunning. For this project I had already given binary trees a good thought. So we had developped deleting functions for any node in the tree, balancing the tree and of course doing all the simple stuff. If I had to prepare the next giant data structure, I think I would go for a combination of data structures to reach the greatest efficiency possible. Right now, I would go for a combination of a hash table and a binary tree. What I'm thinking of, in the example of a dictionary, is to have a hash table for each possible beginning letter, so 26 buckets, and a binary tree in each bucket. It may not increase efficiency enormously, but the thrill of using two such structures together is high.

In relation to other courses, I must say that the AI module has drifted off to truth tables and other cryptic, mystical activities no one seems to understand, while the computer systems course is riding in the draft of this module. So in computer systems, for next Wednesday, we're supposed to make a Cellular Automaton in c++ or c. That seems like an assignment we should be getting in this module, and not seldomly do I wonder off into the wrong module site on blackboard to search for the CA assignment sheet. I am not sure where the computer systems module is heading, starting to give us c and c++ assignments now, but ok, any practice is welcome and will benefit us. As long as we don't do the same assignments over and over again.

1 comment:

  1. Assignment 2 was designed to consolidate all the C++ learning. It is good that it has highlighted your difficulties with templates as that gives you something to concentrate on.

    Hopefully the experiences you had with binary trees last year will help with Assignment 3, however it is harder in C than JAVA. You know where I am if you need a hand. Structs are a good way to go!

    You summarise the differences between C and C++ well. Including some of the subtle differences. The main differences that you will hit are that there is no New in C you have to use Malloc there are also no classes and no references. However, it is a smaller language to learn!

    You show an good understanding of data structures.

    There is similarities between AI and tress. All of AI boils down to search of some sort!

    Overall a good blog, showing a good grip of the concepts covered last week.

    ReplyDelete