Before Coding

This is a discussion on Before Coding within the C++ Programming forums, part of the General Programming Boards category; Guys if you've read my previous posts you will find that I'm quite a determined, yet new programmer in C++. ...

  1. #1
    Registered User cyberCLoWn's Avatar
    Join Date
    Dec 2003
    Location
    South Africa
    Posts
    124

    Before Coding

    Guys if you've read my previous posts you will find that I'm quite a determined, yet new programmer in C++.

    Today I wanted to create a program but I found that I was unable to do it. I just find there are too many limitations, or I can't think of a way to work it out. I move things to functions only to find variables stop working. Arrays prove really hard and I truly suck at pointers.

    The thing is, I have read that you should not dive into the coding process. That's fine when I read it but in practise I don't know any other way. How do you guys plan your program before getting down to coding? Are there any guides to doing this? I feel I have the skills to pull off this certain program (coding wise) but it's all still in the air. I don't know how to implement it and I'd like to do it by myself.

    Any ideas?

  2. #2
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Make sure you know what you are truly making. Think about how to make it. Plan the flow of the program. Remember, the hard part isn't coding. The hardest part is the problem itself. Once you have the answer to a problem, you can easily translate it from English to Spanish, or even English to C++ easily .
    Do not make direct eye contact with me.

  3. #3
    Registered User cyberCLoWn's Avatar
    Join Date
    Dec 2003
    Location
    South Africa
    Posts
    124
    Yeah, but that's the problem. I don't know how to 'see' the problem. I'm not sure how to plan the project, which I think is where my biggest problem comes in.

  4. #4
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Well, look at the big picture. If you truly need help, ask someone here. You're bound to get some ideas on where to start.
    Do not make direct eye contact with me.

  5. #5
    Registered User cyberCLoWn's Avatar
    Join Date
    Dec 2003
    Location
    South Africa
    Posts
    124
    How do you plan ur programs before you code them?

  6. #6
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    I look at what I want to do. I look at what I'll need to acomplish the task. I look at the flow of the program, and plan the functions. Don't go for the big things first, start out with a skeleton and make the muscles around it .
    Do not make direct eye contact with me.

  7. #7
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    I think in terms of modules. I think of one module at a time. Remember, a function should only do one thing and one thing well. Then, I string together my functions in main.

    Try to decompose large problems into smaller modules that are more easily solved. For example, writing an ATM program might seem daunting, but writing a withdrawl function is not.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  8. #8
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I find I never plan well when I'm learning something new...I will learn a new concept and then just try to build off what I have to make my program...Never works :P

    Get out some paper and a pencil and start writing down whatever thoughts you have about it and then organize your thoughts into a design
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  9. #9
    Registered User cyberCLoWn's Avatar
    Join Date
    Dec 2003
    Location
    South Africa
    Posts
    124
    I must say I did try this for the first time and it helped quite a bit. I deleted the unsaved file I typed out the plan in by mistake but it did help while it was around. Hopefully in the future I'll become better at planning it. I guess with everything, it takes practise. Thanks for all the comments.

  10. #10
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    ...only to find variables stop working.
    Yeah, it sounds like you are on the right track in thinking about pointers. You may need to re-study variable "scope" and how functions "pass-by-value". When you pass a variable into a function, you are only passing-in a copy. So, any changes that the function makes are only made to the copy. You should play-around with pointers until you get more comfortable with them.

    You may not have studied structures yet, but it is quite common to have a structure that contains all of the variables you want to work-with. If you pass a pointer to that structure into your function, you can manipulate the original variables.

    PLANNING -
    [DISCLAIMER] - I haven't had any formal training or education on the subject, I work in a company that doesn't have procedures for this process, and I'm not a full-time programmer.

    I usually start-out by making a list of the things the program is supposed to do (in no particular order). At this point I might start researching the things that I don't know... Things like "How do I find the value of a particular pixel in a bitmap".

    Next, I'll make a rough (not-detailed) flow-chart showing what things the program needs to do, and in what sequence.

    Then, I'll write some psudo-code. I do this by making a program that is 99 percent comments. When this is done, I have good idea of what functions I need to write.

    Last, I'll start replacing the comments with code, or add code and "clean-up" the comments. This can be a little tricky, because you need to develop the code in a sequence that makes it possible to test-compile and test-run as you go along.

    When I'm writing the actual code, I'll be checking references (books and online), and maybe doing some more research.

    It is probably OK to just "jump-in" and start writing a very small program or one function. But, you usually need to do some planning in order to know exactly what that function needs to do!

    When planning and documentation is done the right way, (in "well-structured" organizations) the entire program is completely designed before any coding is started. The development sequence would be planned-out in advance. If more than one programmer is working on the project, each programmer would be assigned "blocks" from the flow chart. Every function will be fully documented before it's written, and code will be written for the sole purpose of testing each function!
    Last edited by DougDbug; 12-12-2003 at 04:52 PM.

  11. #11
    Gronkulator of Surds littleweseth's Avatar
    Join Date
    Oct 2003
    Posts
    68
    Normally i find i have about half a dozen aborted attepmts at planning, which i ignore anyway, and just jump into coding because when i am planning, i think ( wow! i could do that with a forever loop! cool....) and then jump in and code that wihle i think of it, etc. Results, eventually, in complete spaghetti code and problems that can only br solved with the delete key.

    Plan first
    Ph33r the sphericalCUBE

  12. #12
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    i only read the first post so someone might have already said this.
    when i start a new (middlesize/big)project this is how i go about things....
    paper and pen(eracable)

    list everything i want to do. not how to do it but what much be done

    this be an example from my current project
    ----
    dll for ts waterworks outline
    user creates/selects a cube. this becomes my partical box.
    user selects a a method for creating particals. e.g. a face where they are created.
    user selects how much gravity will be applied. direction included
    user selects partical props. eg life, volicty, direction, randimazation.

    user can select colision on/off.
    user can apply external forces. wind

    user can create/select a plane. this becomes a height map.
    user can select heightmap propertys. min/max height. color, reflection map, time delta.
    user can select colision on/off
    user can apply externam forces.

    Partical box outline:
    need a 3d box. example class_partical[x][y][z]
    need to keep track of how many particals are live.
    need to keep track of how many particals are TO BE created(based on time delta)
    need to update my phicks engin for 3d math.
    ----
    basicly you write out a todo list.
    the main thing is to keep is simple enough to see what you want to do and detailed enough to know what your talking about
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  13. #13
    Registered User
    Join Date
    Sep 2003
    Posts
    135

    Re: Before Coding

    Originally posted by cyberCLoWn
    Today I wanted to create a program but I found that I was unable to do it. I just find there are too many limitations, or I can't think of a way to work it out. I move things to functions only to find variables stop working. Arrays prove really hard and I truly suck at pointers.
    You've had some useful tips about planning already, but underlying your difficulty here is an obvious lack of understanding of arrays and pointers - as you acknowledge.

    Take some time out from your program to familiarise yourself with these. Go back to your reference book and read up on them, then create some small programs using arrays and pointers to reinforce your understanding, away from the distraction of your current program. Keep going till you feel really comfortable with them, they're bread and butter features that you need to thoroughly understand. It will be a good investment of your time. (And people here will help you if you get stuck).

    Once you have them covered you'll find it much easier to plan your current program.

  14. #14
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    It's easy to plan a program.
    step 1) Sit down and think about the problem.
    step 2) Decide how you want the data input, how you will manipulate it, and how to present it to the user.
    step 3) Write tons of code, and rewrite it constantly till you have what you want.
    step 4) Relax and enjoy, you're done.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  15. #15
    verbose cat
    Join Date
    Jun 2003
    Posts
    209

    Re: Before Coding

    Originally posted by cyberCLoWn
    Today I wanted to create a program but I found that I was unable to do it. I just find there are too many limitations, or I can't think of a way to work it out.
    ...
    The thing is, I have read that you should not dive into the coding process. That's fine when I read it but in practise I don't know any other way. How do you guys plan your program before getting down to coding?
    ...
    Any ideas?
    Think of building a house. You can't just walk up to an empty lot and build a house, you need to know things about it first. Will it be made of wood or brick, one or two stories, how many windows and doors will it have and how will the rooms be laid out? Once you've determined these things (for a house, that usually means drawing up the blueprints), you can collect the materials and build it.

    You might say, "I know what kind of house I want to build" and walk up to the site with some wood and nails in hand, but that means you've already made a few decisions about the house. You have already thought about whether it will be one or two stories, how many doors it will have and how the rooms will be laid out. (Or if you haven't, you'll find yourself going back and designing it later.) If you haven't designed it perfectly the first time (things are rarely perfect the first time) you may find yourself pulling nails out and ripping walls down to start them again because the floorplan you made doesn't leave enough room for what you wanted.

    Even a master builder has to draw up the blueprint to make sure the house is built properly. The master builder has experience with what works and what doesn't, so he will be able to design the house much faster than someone new to building houses, but in the end he still had to design it.

    Coding is similar. Even if you think that you're going to just jump into coding, you can't without some type of plan. If you start churning out C++ code, that means you've already made some decisions about the program (otherwise, how do you know what you're coding?). Others have just given you alot of good ideas, so just think about what you are trying to accomplish.

    In an ideal situation, you will design the entire program and then code it and it will work the way you planned. We rarely have an ideal situation however and you will find yourself designing part of the program (even if you think you're designing the entire program) and then begin coding it. After putting code down, you'll find something doesn't work, you didn't take some aspect into consideration, or you have to change something. Don't get paralyzed by trying to figure out every little detail of the program at first. As you work through the process of design-trial-design-trial... you will find what works best for you.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-20-2009, 05:22 PM
  2. pointer coding
    By princez90 in forum C Programming
    Replies: 2
    Last Post: 05-15-2008, 10:07 AM
  3. Coding Guideline ....!!
    By imfeelingfortun in forum Tech Board
    Replies: 8
    Last Post: 10-08-2006, 07:09 AM
  4. Coding Contest....
    By Koshare in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 10-14-2001, 04:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21