Reusing Code-Programming Tip For Beginner's

Make a template that you can open in a new project for the controller.

Later you can start saving templates after working with LED's, serial communication, writing to EEPROM etc.

If nothing else just use the code you were working on last project to start new project.

That way you write less lines of new code to achieve the goal.



Comments

  • 11 Comments sorted by Date Added Votes
  • You may be summoning the famous JonnyMac in this thread, AKA King of Propellers (KoP) and King of BASIC Stamps (KoBS) and the master provisioner of programming templates.

    Ken Gracey

  • Thanks!

    In a way you can keep using the same program over and over again.

    Unless you change controller.

    Just saying 'Today with my processor and program I will control this.'


  • JonnyMacJonnyMac Posts: 6,090
    edited May 28 Vote Up0Vote Down
    As Ken points out, I am believer in using templates. I have attached programming templates for the BS1, BS2, and a couple for the Propeller. I have dozens of templates, usually tailored to a specific platform. At EFX-TEK we have several Propeller-based products, so most of my templates are focused there (yes, we release templates for our products so that our customers can hack them). The HC-8+ is our go-to controller so I have a lot of templates for it, most devoted to specific types of apps. I have attached the generic template which is where I start with custom projects for that board.
    Jon McPhalen
    Hollywood, CA
    It's Jon or JonnyMac -- please do not call me Jonny.

  • Point I am making for beginners is this .

    You will see things like this in tutorials and books.

    'Now change the code to have LED's blink on and off alternating'

    'Reusable code' 'Routines'

    You WILL get to the point where you reuse a lot of code.

    Just adding the parts that are new for the task at hand.


  • You


    just


    invented


    libraries?
    ◁ Stay OmmmmmmPtimistic! ▷ ◁ Facebook. ▷ ◁ Google. ▷ ◁ Microsoft. ▷ ◁ No Source – No Go! ▷ ◁ Please help: http://rosettacode.org/wiki/Category:Spin ▷ ◁ Why Asimov's Laws of Robotics Don't Work - Computerphile ▷ ◁ DNA is a four letter word. ▷
  • Hi

    I don't exactly use a template- but I take the source code for an old program- "save as" a new file name- comment out all code apart from copper plate- then start new code and use the commented out code to remember the syntax.

    Works for me.

    Later I can delete the commented out code


    Dave

  • Good point about 'save as'.

    As far as libraries.That's too advanced for beginner's.

    You have to see things from their viewpoint.

    The idea is to help not throw a bunch of stuff at them.

    The basic idea is that when when they see 'Now change the program to this' that will be

    important later. In various forms.


  • microcontrollerusermicrocontrolleruser Posts: 958
    edited May 28 Vote Up0Vote Down
    For beginners.

    Libraries are sections of code that perform a purpose.

    That you can paste into your program or call in a new program you write.

    Doing that way is less work than writing it all over again.

    Myself I prefer to write my own libraries.For a lot of reasons.

    You just save what you have done all along and you accumulate code you can use later.

    For beginners it is better to say 'Save code to use later in another program' than throw a new concept at them.



  • WhitWhit Posts: 3,970
    edited May 29 Vote Up0Vote Down
    @microcontrolleruser - great thread! I linked this thread to one I began. You might enjoy it - see http://forums.parallax.com/discussion/168430/becoming-a-better-programmer#latest

    @JonnyMac - thanks for posting your templates.
    Whit+

    "We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps leading us down new paths." - Walt Disney

  • Thank you Whit!

    Thank you Johnny!

    That is a good post of yours.

    About reusing code. I think everybody comes up with little variations of it.

    The basic concept is shared though.Cut and paste before editing.


  • WhitWhit Posts: 3,970
    edited May 29 Vote Up0Vote Down
    @microcontrolleruser - that is Jon or JonnyMac - thought I’d beat him to the punch! :-)

    See Jon's signature line...
    Whit+

    "We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps leading us down new paths." - Walt Disney
Sign In or Register to comment.