Questions to ask when programming?

Project X

Expert Member
Joined
May 16, 2006
Messages
1,615
Reaction score
1
When you programmers are coding how do you know what var's to add,how many to add etc More specifically for Delphi but i dont think that matters because programming is programming!!

I think that's my major problem, learning the code is not a problem but i never know when to use which code etc... so if i knew what Q'z to ask myself while im coding then maybe i would be better..
 
I just declare each variable as it's needed. I once had a habit of declaring five integers, five real, five strings and five arrays at the start of each program and deleting the unused ones once it's done.
 
When you programmers are coding how do you know what var's to add,how many to add etc More specifically for Delphi but i dont think that matters because programming is programming!!

I think that's my major problem, learning the code is not a problem but i never know when to use which code etc... so if i knew what Q'z to ask myself while im coding then maybe i would be better..

In terms of software development theory,

1) I'd say the first question is "what should the program do"? The answer to this is called a "user requirement specification"

2) Then, "how will it do this? This one's answer is a "functional design". You can refine this down to the point where the developer knows how the solution should be structured.

When you get down to the implementation of the design, you'll (hopefully) create a modularised structure consisting of various piece of code, separated into various subroutines, methods, procedures or events and possibly various physical code files. As each of these smaller chunks are written, you'll start seeing where variables are required, which should be used globally and which are reusable.

HTH
 
When I look back at things that a wrote a month or more back, I ask myself WTF was I thinking here? :confused: :D
 
I just declare each variable as it's needed. I once had a habit of declaring five integers, five real, five strings and five arrays at the start of each program and deleting the unused ones once it's done.

lol Maybe thats the best way to start:D
 
ok i once answer a Q in two ways..
The 1st using a case statement
the 2nd using an array and for loop..
Now in an exam or where ever which would be the best way to answer?
 
ok i once answer a Q in two ways..
The 1st using a case statement
the 2nd using an array and for loop..
Now in an exam or where ever which would be the best way to answer?

At school level I guess whichever works, I don't think they care too much about how you did it (I know our school didn't) ;)

The array and for loop will probably allow greater flexibility should the code be reused.
 
Well, the Delphi compiler warns when a variable is not used. I think with variable, the more important bit is the naming of the variables....poor style if its all X/A/Q/N etc. With delphi, try to avoid global variables too....bad style.

I usually just add/remove variables as I need them. You can plan it to a certain extent like flarkit says, but at the end of the day the dude sitting in front of the PC will code on the fly.

Case statements in Delphi are fairly restrictive...90% of the time I end up using an array (either static/variable array).
 
ok i once answer a Q in two ways..
The 1st using a case statement
the 2nd using an array and for loop..
Now in an exam or where ever which would be the best way to answer?

What was the question? I really all depends on that

I don't really understand what you mean though. A case (switch) statement is a control statement which directs program execution while using a loop to iterate through an array doesn't do the same thing at all?
 
Its on one of the examples in the book..
You have 5 types of perfumes in a radiogroup and people have to vote for the one they like.. Simple little code.
 
2 arrays would be more flexible, but the CASE STATEMENT would be quicker to code.
Arrays:
One array contains the Names of the purfumes:
ar1[0] = "Purfume 1's Name"
ar1[1] = "Purfume 2's Name"
ar1[2] = "Purfume 3's Name"
ar1[3] = "Purfume 4's Name"
ar1[4] = "Purfume 5's Name"
The other array contains the Votes:
ar2[0] = 0
ar2[1] = 1
ar2[2] = 3
ar2[3] = 0
ar2[4] = 5
With the array solution, when assigning the votes, you have to look at your user interface, and how it is designed. With arrays, the trick is to have a means of getting the index number or the Purfume name of the perfume choice from the interface. With a case statement, the trick would be getting the Perfume Name from their choice.

A system that utilises the array option would be more flexible, because you could change the contents of the array at will without changing the code that deals with the vote counting.

But, the array system also requires more code and loops and error checking.

Now, over time, you will begin to spot the systems that can be done using "Hard coding" (Case statements) vs the systems that must be done using Arrays.

Basically, if you're writing a system where data values will change, or code will be reused, then you're going to use the array route. But, when a quick answer is required, the case statement works fiine, and with copy and paste, you can duplicate case statements damn quickly, but then the catch is remembering to change every "hard coded" part of the copied case statement.

i.e. Depends on what you are creating.
 
Top
Sign up to the MyBroadband newsletter
X