Thread: Value order

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #19
    Registered User
    Join Date
    Nov 2015
    Posts
    72
    The first thing you should do is to have a consistent style of indentation. You can read more about indentation in programming here:

    Indenting C Programs
    The Only Correct Indent Style | Terminally Incoherent

    That will dramatically improve the readability of your code. I prefer the K&R style of indentation but to each his own.

    You also don't have to go over board with new lines. I usually add a few extra lines so that the main() function is distinguishable from other functions if the file contains many functions. Other people add a big block of comments right before the main() to make it easy to find. Integrated Development Environments such as VisualStudio has functionality built in that makes it easy to find main().

    I just added "*fields[] = ( &bluefield, &greenfield, &orangefield, &yellowfield, &whitefield );" so that you could copy and paste my code directly into yours. It will probably be more convenient to do as Salem says in post 10 and use a vector of the fields without the independent ...field variables. It's up to you anyway.

    Why use two for-loops? I don't understand what you intend with them. What is the purpose of "indeks[]"?

    I don't understand the function stacki() and what you intend to do with it.

    There are many opinions on how much comments you should have in your code. Say that you write this program and end up with say 500 lines of code. Let's say in 5 years from now you have to go back to your code for any given reason and apply necessary modification. At that point you will be punished for your lacking efforts of making it understandable.

    If you're not into commenting the code. The least you can do is to let variables and functions have names that make it easy to understand their purpose and what they are doing. You could also have each procedure in a subfunction. So instead of a long list of code in the main() function, you could have a subfunction for each step with a proper name so it is easy to understand what is happening in that step.

    Recommended naming conventions for variables and functions is "Camel case" and "Hungarian notation". So you can google these up to get a description.

    The functions can also be put after the main() function. You only need to declare the name of the function before main(), e.g. "void stacki(int *fields[], int indeks[], int colour, int die);", then the full function can be put after main(). You can do whichever. I have written programs that both have main() first and programs that have main() last and I have seen code from experienced programmers that have both ways.
    Last edited by bot; 01-09-2018 at 05:16 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 04-01-2011, 04:13 PM
  2. Replies: 4
    Last Post: 03-06-2008, 03:38 PM
  3. Tab order again
    By knutso in forum Windows Programming
    Replies: 9
    Last Post: 07-29-2003, 05:39 PM
  4. what is the significance of low order and high order bits
    By Shadow12345 in forum Windows Programming
    Replies: 1
    Last Post: 11-16-2002, 11:46 AM

Tags for this Thread