Re: [PIC] Learning C
"Harold Hallikainen" <[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.pic |
|---|---|
| Message-ID | <[email protected]> |
I like clear and heavily commented code. I comment most lines as I go along, explaining what I'm trying to accomplish. And, of course, comments at the start of a function give an overall explanation along with what goes in and what is returned. About 40 years ago, I taught a class in assembly language programming for the PDP-8. I wanted my students to comment their code. They would get their code running, then go back and comment it. By then, they had forgotten how it worked, so the comments did not accurately describe what was happening. Harold https://w6iwi.org On Thu, November 14, 2024 7:26 am, Allen Mulvey wrote: > Yes, I think today, for some, it is a kind of "snob appeal" to use > obscure code but decades ago code optimization was mostly done by the > coder not the compiler. I think that is where some of it may have > originated. Today the compiler can optimize much better than I can and > most decent editor have auto-format. This not only makes the code more > readable but far easier to debug. I frequently use "unnecessary" local > variables knowing that the compiler will take them away. It makes the > code much easier to follow if I need to come back to update the section. > I actually discovered this by accident a long time ago. After making > some obscure code much more readable the compiled size was unchanged. > Personally, I think using obscure code is foolish. > > Allen Mulvey > > On 11/14/2024 8:57 AM, Clint Jay wrote: >> David C Brown,<[email protected]> wrote >> >>> Onew of the problems I have with trying to understand code examples in >>> C >> is >>> that so many of them are incomprehensibly dense. >>> >> There is a faction among programmers who seem to enjoy swinging their >> appendages by writing the most impenetrable, dense code to somehow show >> off >> their "prowess" and sneer at anyone who can't decode their drivel. >> >> Tabs, spaces, empty lines cost nothing and it makes me think a lot less >> of >> the people who create code intended to make other people's lives harder. >> >> >> On Thu, 14 Nov 2024 at 12:35, RussellMc<[email protected]> wrote: >> >>> David C Brown,<[email protected]> wrote >>> >>>> Onew of the problems I have with trying to understand code examples in >>>> C >>> is >>>> that so many of them are incomprehensibly dense. >>>> >>> When writing C++ code I formatted in a way which to me makes it far >>> more >>>> readable than the normal manner of presentation. >>> >>> I place { on the line following and then indent code following an >>> Indian >>> it again for any other functions such as if / while / case ... . >>> The end result is code who's structure leaps out and grabs you. I >>> started >>> off being somewhat surprised that this wasn't standard practice come to >>> accept that most people prefer density and obfuscation. >>> Apart from taking more space I can see no disadvantages and this >>> approach >>> and for me the gains are substantial. >>> >>> I spent many decades working mainly in assembler and >>> actually find it generally easier to see what's going on than in most >>> higher level languages. >>> >>> >>> Russell. >>> -- >>> 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.