View previous topic :: View next topic |
Author |
Message |
gtx15
Joined: 19 May 2018 Posts: 27
|
Proper Coding |
Posted: Sat Aug 29, 2020 7:41 am |
|
|
Where can I learn Proper coding?
When to capitalize, When to indent, I just heard to use i then k in for loops. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Aug 29, 2020 8:07 am |
|
|
Do a web search for this:
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sat Aug 29, 2020 10:30 am |
|
|
Have a look at the 100s of example programs CCS supplies in the 'examples' folder ! It'll help you get used to the CCS 'style' of coding.
The BIG thing for me is to have comments !!! You can never have enough and they don't 'cost' anything.
When using Assembler, it's often to add comments to EVERY line of code, not so when using C. Having lots of comments means you ( or others) will have a better idea what 'this' was for or 'why' a variable is what it is. I've wondered just HOURS after I coded a 'simple' program wonderer WHAT was I thinking.....
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Sat Aug 29, 2020 10:35 am |
|
|
Yes. Good comments, are critical. Also, remember that variable names
can be 'self informative'. Calling a integer used for a counter 'n', or 'c'
tells you nothing, but calling it int_ctr, tells you what it is when you look
at the code. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sat Aug 29, 2020 4:24 pm |
|
|
'self_informative' is real handy ! When I started programming, we were only allowed a maximum of 2 characters for a variable name. Things have changed since the 70s...... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Sun Aug 30, 2020 2:42 am |
|
|
Then as a further comment, 'ALL_CAPITALS', is generally used in C, to
indicate that an item is a macro.
Key is that macro 'pseudo functions', look exactly like genuine functions,
and macro value declarations in code, look just like variables. Using the
'macros use all upper case' indicator, tells you when you see these, what
they are.
Other than this, the use of capitals is generally 'unrestrained'. However
remember that by default CCS does not implement case significance, so
a variable called 'john', and one called 'John' are the same.... |
|
|
|