freddyfish said:
Hi
I am asking the question here since I am hoping there are some robotic engineers (or anyone else) that may have some good tips. I am pretty new to the area of programming PICs and the "lessons" I have found is about assembly code. I have read that assembly code is better when it comes to performance, but C is "easier to handle" and work with. I am not asking about a way to minimize the effort needed to learn programming the PICs, rather I am asking for some advice from experienced programmers about whether I should learn assemble, if I should skip ahead to C or maybe learn both.
If you strongly recommend C, then I would welcome any suggestions on literature etc.
Thanks
Hmmm. It depends.
I learned assembly language first, and it was a nightmare. Make one tiny mistake and you're screwed. It is very verbose and demanding. It was a terrible experience, and I never did it again.
BUT if assembly language is what you need, then there you go. So let's assume that this is what you need. The question is, how best to learn?
The basic question is whether you have solid structure and design in your programs. In my opinion most programmers hack in an undisciplined way. They do not plan ahead and their programs never work reliably. I used to be amazed by the abysmal quality of very popular programs. Recently I have been using Google groups and it just keeps getting worse. Bad programming is so prevalent that many programmers think that this is simply the way it is, and nothing can be done about it.
What I ended up doing was programming in C++, which has a lot of support for strong structure. It is possible to write highly modifiable and reliable programs with this. Look inside a modern computer and you will see strong structure. You will see independent units with very well-defined interfaces. It's like that.
In unstructured languages you tend to get unstructured programs, and that is like the inside of a radio from the 1930's. Wires going all over the place.
If I were ever to write assembly language again I would write it in a highly disciplined and structured manner. There is nothing that is going to stop you from doing this, it is just that the language gives you no support at all. If you start out writing in assembly language it will not help you to learn structure and discipline. In fact it will be a big impediment.
So should you start with C++? The trouble with that is that most programmers never learn to use it. They hack at it and the result is worse than a pure hack. Think of that computer with the circuit boards, then add a bunch of random wires connecting all the stuff together. The worst of both worlds. So if that is the result, you would be wasting your time. It takes years to get good at it, too.
C was developed as a replacement for assembly language. It's two huge advantages is that it can be ported from one computer to the other, and it isn't so verbose. It is a lot more structured than assembly language and much easier to learn and work with. So I would start with that and learn to write modifiable and reliable programs. They didn't teach me that in school -- I went to Harvard, but programming teaching was terrible, a nightmare -- I had to learn it from books and years of on-the-job training. Then I would write assembly language in that style.
Programmers will tell you how inefficient C is, and that is true, but it is also true that 90% of the time goes into 10% of the code. Over and over I have seen "optimizations" that have no significant effect other than to introduce errors and make the system very difficult to work with. I have fallen into this trap myself. Get it to work reliably first, then find out where the slow parts are and do something about it. If you need to write those in assembler, fine. It is quite possible to mix together C and assembly language.
Programmers tend to focus in minutia and miss the big picture. Don't listen to them.