Re: [PIC] Learning C
"Harold Hallikainen" <[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.pic |
|---|---|
| Message-ID | <[email protected]> |
To me, one of the most valuable things is switch/case. I've seen too much code with a bunch of nested if/else with vast indentation. Switch/case is easy for me to understand. And, often, I'm switching based on a string. In those cases, I run a hash on the string and switch based on the hash. In doing this for 20 years, I've never had a hash collision. Harold On Thu, November 14, 2024 11:50 am, David C Brown wrote: > It ight be more compact but the if...else formulation is much clearer. So > clear in fact that someone not trained in programming could understand > what it means > __________________________________________ > David C Brown > 43 Bings Road > Whaley Bridge > High Peak Phone: 01663 733236 > Derbyshire eMail: [email protected] > SK23 7ND web: www.bings-knowle.co.uk/dcb > <http://www.jb.man.ac.uk/~dcb> > > > > *Sent from my etch-a-sketch* > > > On Thu, 14 Nov 2024 at 16:17, Spehro Pefhany <[email protected]> wrote: > >> At 03:56 AM 2024-11-14, you wrote: >> >Ans 404 to you :-) >> > >> >Onew of the problems I have with trying to understand code examples in >> C >> is >> >that so many of them are incomprehensibly dense. >> >What would be five or six lines in Pascal or Basic is a single line in >> C. >> >I appreciate that that is down to the programmer not the language but >> it >> is >> >off putting >> >i have to remind my self of the old adage: You can write Pascal in any >> >language >> >> I do like the ternary operator '?' in C (and in some other languages) >> which reduces several lines to one and is still very readable, maybe >> more >> so. >> >> variable = condition ? value_if_true : value_if_false >> >> instead of >> >> if (a > b) { >> result = x; >> } >> else { >> result = y; >> } >> >> >> just write >> >> result = a > b ? x : y; >> >> Best regards, Spehro Pefhany >> -- >> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive >> View/change your membership options at >> https://mailman.mit.edu/mailman/listinfo/piclist >> > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > https://mailman.mit.edu/mailman/listinfo/piclist > -- Not sent from an iPhone.