Connect with us

Programming starting point

Discussion in 'Microcontrollers, Programming and IoT' started by NMNeil, Sep 11, 2017.

  1. NMNeil

    NMNeil

    109
    10
    Oct 3, 2014
    A very general question.
    When you have come to the point in a project where you need to write code, how do you begin. By that I mean do you start by using pencil and paper or do you dive straight in with a software package like flow code?
    For the younger members of the forum, pencils and paper are old technology, both derived from wood and requiring no batteries; Google them:D
     
  2. vead

    vead

    473
    14
    Nov 27, 2011
    Its all depend on how do you apply logic's. my best advice write on paper what you want and how do you achieve via program. These two things should be always run in your mind. think which condition may be apply. programming is simple instructions which we can write in any language to run on hardware device. can you implement your idea on paper to blink LED for 1 seconds.
     
  3. Rixen

    Rixen

    98
    23
    Feb 16, 2016
    I often start by pouring myself a glass of scotch.
     
  4. kellys_eye

    kellys_eye

    4,281
    1,144
    Jun 25, 2010
    I'm allowed to use my blunt crayons and soft paper (under supervision) to scribble a nice flowchart, coloured-in of course, before getting approval from my nurse to translate this into punched cards before being returned to my padded room.

    Back in the real world.... the flowchart still applies - even if it's just a simple list of steps that first come to mind - before checking that the wheel hasn't already been invented by someone else while I wasn't looking.

    I'm not a professional code writer and suspect that few really are so we'll each approach this from slightly different directions but quite often it involves using something that currently exists and making modifications - even if they are substantial modifications - that would probably be better served by starting from scratch.

    When the code gets compiled and there isn't any errors thrown up, then the celebration cake is baked.

    Most times I'm left frikken starving......
     
  5. Researchers

    Researchers

    5
    0
    Sep 22, 2017
    I think firstly draw a flow chart of all statement sequentially that have been execute. Now write the code for every statement in the same. I am sure you got simplified code for your project.
     
  6. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,192
    2,694
    Jan 21, 2010
    The first thing you need to know is what the program needs to do.

    The next thing is what the inputs and outputs are.

    One you've got that, if you don't have a good idea in your head about how to do it, the next step is research.

    After that, take a look at what is already written. Maybe you don't have to write anything at all. Maybe you just have to modify something a little. Maybe there are existing libraries which can do some of the heavy lifting.

    Next, choose your method of planning. It may be flowcharts, structure diagrams, or even pseudo code. Whatever it is, know what stepwise refinement is, and use it where appropriate.

    This planning may identify edge cases and decision points that should drive your testing. With a microcontroller you're not likely to use a test harness, but you can still note what needs to be tested.

    Once your chosen method of planning has taken you to a level you can code, you can start coding.

    After coding comes the iterative testing process, which, depending on your application may need to be a formal documented step.

    At this point, after gathering your documentation, you have a version you can deploy.

    Even if it's just a home project, gather that documentation. When you come back to it in possibly several year's time, you'll thank your past self.
     
  7. BobK

    BobK

    7,642
    1,662
    Jan 5, 2010
    I hate to say it, but, as a professional programmer for some 47 years, I thought I should weigh in. I think about the structure of the program in my head until enough of it is clear. Then I sit down with the tool I am using (currently Eclipse and Java, or MPLAB X and C), and start writing code. I have not done anything on paper in years, nor even detailed specs, and never have used any flowcharting tools.

    When I really was programming with punched cards, the process was quite different.

    Edit: Okay, I will admit that I sometimes draw pictures on a white board before starting programming.

    Bob
     
    Minder likes this.
  8. Javi12Alvares

    Javi12Alvares

    1
    0
    Oct 12, 2017
    When i was just starting programing at my first job i also was drawwing pictures on a white board before starting doing something, and now i do the same sometimes.






    [mod edit -- advertising removed]
     
  9. Irv

    Irv

    112
    30
    Jun 7, 2017
    Unlike BobK, I'm a relative newcomer, only been programming for 45 years. And I agree, very seldom has a flowchart been of help. Making a neat one takes me more time than writing the working code. Pseudo-code often helps clarify things, however. The closer it is to plain english that a non-programmer can understand, the better chance you'll have of spotting errors and omissions.
    It always surprises me when people write code which doesn't work, and ask for help, and then cannot explain in plain language what they expect the program to do.
     
  10. NMNeil

    NMNeil

    109
    10
    Oct 3, 2014
    Thanks to you all.
    I'll break out the crayons and Scotch.
     
  11. pgib8

    pgib8

    99
    22
    Jul 26, 2015
    i start by installing the tools and get to the point where i can even load a program onto the chip. next i work on the startup code, ensuring proper clock selection and what not. that's how i start.
    after that i take it one step at a time. we're probably talking about embedded programming here, so pick out one of your pieces of hardware and get that to work, then onto the next.
    I usually don't start writing the actual application until i got all hardware drivers figured out.
     
  12. Minder

    Minder

    2,871
    594
    Apr 24, 2015
    Basically the lazy method, I don't wish to re-invent the wheel, so what I do is to accumulate any code or methods that is close to my projects that have been posted out there on the web, including any app notes by the micro manuf etc.
    I then use these as a basis for modifying and writing the code needed for that application.
    M.
     
  13. NMNeil

    NMNeil

    109
    10
    Oct 3, 2014
    I have both a PICKit3 and AVR programmer with MPLAB X and ATMEL STUDIO. Undecided which one to use at the moment, either PIC16F630 or the ATTINY 2313, as mine is a very simple project only needing digital i/o and one timer.
     
  14. fnelson

    fnelson

    3
    0
    Nov 28, 2017
    The first and fundamental step is to make sure that I properly understand the technology which I'll be using for creating that program (I also take few tutorials, read some educational resources if necessary).

    Then, in most cases, I draw the most basic conteptual design of system, its transformation process, inputs and outputs. After that, I use some UML diagram to create logical design in more detail (level of details depends on situation).

    After all of above is done, I start to write some code.

    So, I'd say that programming is more 'writing and sketching on paper or some software tool' that 'real coding'.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-