Thread: Patterns of writing CODES

  1. #1
    Banned
    Join Date
    Apr 2015
    Posts
    596

    Patterns of writing CODES

    Hi !
    when I code I see that my code looks messy and not organized , I mean it's vision of writing isn't convenient to whom reads my code, for example I've seen some codes following this pattern of writing variables sumSize and other patterns, where can I find like those patterns of coding to get my code looks fine and not messy ?

    I tried to search on google didn't find, maybe I'm not using the correct "term" for searching on that subject on google?

    thanks alot

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3

  4. #4
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Depending on your experience with C, this might help...

    Go to here and look at the "Patterns in C" section at the bottom.

    Another good place to start for some solutions (like a microcontoller controlling a vending machine) is by using a state machine. The "poor man's version" is using a switch statement, and is fine for lots of small control programmes... You can then use multiple switch statements and implement your own cooperative multitasking system.

    The thing that you need to remember when you do this is to not use blocking code... i.e.
    Code:
    while(i!=someNumber) 
    {
      Blah... 
    }
    becomes...
    Code:
    switch(state) 
    {
     ... 
      case state1:
        someNumber = 123;
        i=0;
        state = state2;
        break;
    
      case state2:
        Blah... 
        if (i==someNumber) 
          state=state3;
    
        break;
    
     ... 
    }
    ... The idea is that after each "Blah" you can have other state machines doing separate tasks.


    There are heaps of solutions for different problems, and better ways to implement a state machines

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Patterns to produce "meaningful" patterns
    By Aslaville in forum Tech Board
    Replies: 5
    Last Post: 03-14-2015, 12:46 AM
  2. Patterns and anti-patterns
    By Neo1 in forum C++ Programming
    Replies: 3
    Last Post: 10-23-2013, 05:30 PM
  3. Regarding Writing Self Codes??
    By shwetha_siddu in forum C Programming
    Replies: 3
    Last Post: 05-27-2008, 11:33 AM
  4. help for writing codes
    By sonturk in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2007, 07:08 PM

Tags for this Thread