Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 5th February 2008, 12:18 AM   (permalink)
3v0
Default

Quote:
Originally Posted by Pommie
3v0,

Surely, this is not a mistake that an experienced programmer would make.

...

Mike.
Maybe not when fresh, but many people work past the point where they should knock it off. All the examples here have been quite short. A few hundred or thousand lines of code is quite different. It is best to do what one can to avoided problems.
3v0 is offline   Reply With Quote
Old 5th February 2008, 12:22 AM   (permalink)
Default

Quote:
Originally Posted by 3v0
Many people work past the point where they should knock it off. All the examples here have been quite short. A few hundred or thousand lines of code is quite different. It is best to do what one can to avoided problems.
I agree with that one too. I've got a 230,000 line project and when I get new coders on board it's "Yes, I know it's slightly tedious for the one-liners. Do it anyway."


Torben
Torben is online now   Reply With Quote
Old 5th February 2008, 02:52 AM   (permalink)
Default

This is partly why I dislike C, difficult to read, susceptible to too much interpretation, and the written text becomes more effort consuming than the original reason for the code. It should solve problems and not add to it.
donniedj is offline   Reply With Quote
Old 5th February 2008, 03:20 AM   (permalink)
Default

Quote:
Originally Posted by donniedj
This is partly why I dislike C, difficult to read, susceptible to too much interpretation, and the written text becomes more effort consuming than the original reason for the code. It should solve problems and not add to it.
You assume we're talking about C (probably because I'm going on about K&R and the examples so far have been C) but this stuff applies to any language (er. . .except maybe this one). The actual semantics differ but the generalities really don't.

A good programmer can program well no matter the language; a bad programmer sucks just as hard in an academically "good" language as in any other. A bad programmer will, I freely admit, have more trouble with string handling and pointers in C than in languages which shield them from having to know what's really going on behind the scenes, though.

I'm not sure how C is "susceptible to interpretation", anyway. The code does what it says it does. Whether that's what the programmer intended is another question.

I like C for certain problems. Others demand assembly, some are solved easiest in PHP, and others just cry out for a lisp-like language. Good commenting and consistent structure are important in all.

Just my $0.02 CDN.


Torben
Torben is online now   Reply With Quote
Old 5th February 2008, 03:53 AM   (permalink)
3v0
Default

Torben nailed it.

I would add that the proper choice of names and their scope is often overlooked. It is very important in writing good code. And not always easy to do.
3v0 is offline   Reply With Quote
Old 5th February 2008, 07:58 AM   (permalink)
Default

Quote:
Originally Posted by Torben
I'm not sure how C is "susceptible to interpretation", anyway. The code does what it says it does. Whether that's what the programmer intended is another question.
C isn't strongly structured, which makes it hard to read, and perfectly working code can be written so it's extremely difficult to read, even by the author.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 5th February 2008, 08:20 AM   (permalink)
Default

Quote:
Originally Posted by Nigel Goodwin
C isn't strongly structured, which makes it hard to read, and perfectly working code can be written so it's extremely difficult to read, even by the author.
Yep. But there is no reason beyond laziness or inexperience to write bad code just because the compiler won't stop you*. Hard-to-read code is often the result of taking unnecessary shortcuts, and if a given problem requires a hairy solution, that's the time to comment and structure the hell out of it so you can remember what on Earth it's supposed to be doing when you come back to it in three months.

Bad code can be written in any computer language, just like bad prose can be written in any human language. Sure some languages help protect the rookies from common mistakes, but they're not always the best tool for the job at hand. I'm not going to apologize for C's shortcomings, but I'm not going to try to program a PIC in PHP, and I'm not going to try programming a web-based shopping cart in asm (or C, for that matter).


Torben

* I hit post and then remembered my favourite reason to write unreadable code: obfuscated code contests! They are fun. Very fun. And usually very educational to boot.

Last edited by Torben; 5th February 2008 at 08:24 AM.
Torben is online now   Reply With Quote
Old 5th February 2008, 09:04 AM   (permalink)
Default

Bad code really is due to laziness, lack of experience, or lack of education and sometimes an unfortunate combination of all three.

I find no compelling reason for C being singled out as worse than other languages other than the COBOL Cabal's(tm) campaign of fear and intimidation ;-)

Here's my favourite C++ put-down:

What's the difference between an extremely clever and sophisticated use of C++ versus a very badly written piece of code? Nothing... they're both entirely unreadable!

You may feel that's unfair... but in C++ one can abstract oneself up one's own arsehole! Besides, I met the guy who headed up the first ANSI C++ committee and his stories were just plain scary.

When it comes to the PIC... I needed to learn yet another set of assembler mnemonics like a I needed a hole in my head! I began using the 18F series as it is trivially more expensive than the 16 series and C18 gave me a productivity edge that was hard to ignore.

Just my $.02AU ;-)

P.
aussiepoof is offline   Reply With Quote
Old 5th February 2008, 09:18 AM   (permalink)
Default

Quote:
Originally Posted by aussiepoof
When it comes to the PIC... I needed to learn yet another set of assembler mnemonics like a I needed a hole in my head! I began using the 18F series as it is trivially more expensive than the 16 series and C18 gave me a productivity edge that was hard to ignore.
I've no problem whatsoever with C on the 18F series, because that's what the application notes use, and they provide a free compiler. But on the 16F series the application notes are written in assembler, so C programmers tend to not have a clue about the hardware they are trying to use.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 5th February 2008, 09:31 AM   (permalink)
Default

Quote:
Originally Posted by Nigel Goodwin
I've no problem whatsoever with C on the 18F series, because that's what the application notes use, and they provide a free compiler. But on the 16F series the application notes are written in assembler, so C programmers tend to not have a clue about the hardware they are trying to use.
. . .unless they also speak assembler, which I think they should. I learned more about the hardware from a book on Intel 8086 assembler than just about anything else (well, we did have to learn MIPS assembly in uni). Helped me code up some damn fast Turbo Pascal stuff with inline asm.


Torben
Torben is online now   Reply With Quote
Old 5th February 2008, 10:57 AM   (permalink)
Default

Quote:
Originally Posted by Nigel Goodwin
But on the 16F series the application notes are written in assembler, so C programmers tend to not have a clue about the hardware they are trying to use.
That's a ridiculously broad generalisation! Combined with a previous post in this thread one could draw the conclusion that you hate both C and C programmers... in any language, even PIC assembler, one can code very badly indeed!

I learned C well after I'd learned several assembly languages starting at the age of 13... and given I'm now 44 that's a long time ago :-) I even learned one assembly language (LSI-11/PDP-11) while at University! So I agree with Torben that everyone needs to learn at least on assembly language though I wouldn't choose PIC as my first choice.

I'm NOT saying you shouldn't learn PIC assembler. Obviously if you're forced to use the 16 series then you have little option unless you're prepared to spend $$s on a compiler, and even then it's a questionable decision due to the poor performance that might ensue. You might also need to tune a routine or three on the 18F series comet to that.

I'm open to learning as many languages as I must though I now choose carefully which I need to add to the 10+ I already know. As Torben says, even PHP has advantages... though I doubt those extend to using it on a PIC :-P

P.
aussiepoof is offline   Reply With Quote
Old 5th February 2008, 11:59 AM   (permalink)
Default

Quote:
Originally Posted by aussiepoof
That's a ridiculously broad generalisation! Combined with a previous post in this thread one could draw the conclusion that you hate both C and C programmers... in any language, even PIC assembler, one can code very badly indeed!
It's quite simple, to program a PIC you need to have a reasonable understanding of the hardware - assembler forces this on you - with C you've got to get the understanding of the hardware elsewhere.

As the 18F series provides application notes in C, it makes sense to use C for the 18F series - because what you need to know is available in C.

I've got nothing against C programmers, but you are correct that I don't like C itself.

There have been many posts on these forums about using C on various micro-controllers, and a great many of them are simply because the poster doesn't understand the hardware at all - you don't get the same questions from assembler users, because they are working at a lower level. The same problems occur with any high level language of course, it's just that most who post are using C - or perhaps the C compilers are lacking in documentation and sample programs?.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 5th February 2008, 12:11 PM   (permalink)
Default

Quote:
Originally Posted by aussiepoof
I'm NOT saying you shouldn't learn PIC assembler. Obviously if you're forced to use the 16 series then you have little option unless you're prepared to spend $$s on a compiler, and even then it's a questionable decision due to the poor performance that might ensue. You might also need to tune a routine or three on the 18F series comet to that.
There is in fact a free compiler for the 16 series. The HiTech (an Aussie company) PicC-Lite. It is limited but for short projects is perfectly adequate.

It's funny, when I started this thread, it's only by chance that I used some C code as an example. White space in asm is even worse.

Another really annoying thing about pics and asm is that the (latest) template files seem to use a tab setting of 5 Before I can use them I have to run them through my code tidier program.

Mike.
Pommie is online now   Reply With Quote
Old 5th February 2008, 12:12 PM   (permalink)
Default

Quote:
Originally Posted by Nigel Goodwin
It's quite simple, to program a PIC you need to have a reasonable understanding of the hardware - assembler forces this on you - with C you've got to get the understanding of the hardware elsewhere.

As the 18F series provides application notes in C, it makes sense to use C for the 18F series - because what you need to know is available in C.

I've got nothing against C programmers, but you are correct that I don't like C itself.

There have been many posts on these forums about using C on various micro-controllers, and a great many of them are simply because the poster doesn't understand the hardware at all - you don't get the same questions from assembler users, because they are working at a lower level. The same problems occur with any high level language of course, it's just that most who post are using C - or perhaps the C compilers are lacking in documentation and sample programs?.
Absolutely. Of course, C was never intended for microcontrollers, while assembler is a perfect fit for them.


Torben
Torben is online now   Reply With Quote
Old 5th February 2008, 12:41 PM   (permalink)
Default

As for C programmers you meet in here not being hardware-aware... many are in fact computing students without compiler or architecture background, or merely hoping those here will write the projects for them :-) Such people don't deserve to pass and I wouldn't employ them in a pink fit.

It is unfortunately possible to do a "computing" degree without learning either hardware architecture or compiler theory both of which would help them understand just how close to the hardware C and make the leap to using it on a PIC.

P.
aussiepoof is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Magnets and Electromagnets ElectroMaster Electronic Theory 11 27th November 2007 02:31 PM
PIC code problem Gaston Micro Controllers 9 7th March 2007 02:23 AM
Charge batteries using tel lines electroniks Electronic Projects Design/Ideas/Reviews 5 16th April 2006 06:54 PM
running sort of output lines.................... anand_jain Micro Controllers 1 11th July 2004 02:31 AM
TV- Lines in the picture Johnson777717 General Electronics Chat 2 1st April 2004 12:10 AM



All times are GMT. The time now is 04:24 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.