 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
janicethorne via JavaKB.c Guest
|
Posted: Fri Apr 21, 2006 2:12 pm Post subject: Arrays again - I must be dumb |
|
|
Hello:
Please tell me that all of you have had the same mental block when you all
first learned java! I am trying to complete this assignment and am totally
lost. Any help is really appreciated.
I am supposed to create two classes. One holds the methods and the other
implements them. The methods are supposed to pull in 5 numbers from a file
(args[0]), calculate the average and output to a file. The main method is
supposed to instantiate them. This can't be as hard as I am making it. Please
take a look at the code below and tell me what I am doing wrong. Thank you
for all of your help and patience.
JT
import java.text.*;
import java.io.*;
public class Program10a {
public static void main (String[] args) throws IOException {
average myAve = new average();
BufferedReader inFile = new BufferedReader(new FileReader(args[0]));
PrintWriter outFile = new PrintWriter(new FileWriter(args[1]));
myAve.knowAverage();
myAve.getNumbers(numbers);
outFile.println("Your numbers are " + myAve.printIt());
outFile.println("The average is " + myAve.knowAverage());
outFile.println(average.testData(double numbers));
inFile.close();
outFile.close();
}//end main
public class average {
int count = 0;
double nmbrs;
double ave = 0.0;
double[] numbers = new double[5];
public double getNumbers();
double numbers = Double.parseDouble(inline.Substring(0, inLine.length()));
return numbers; }
//adds numbers
public void addMe(double numbers) {
count++;
nmbrs = nmbrs + numbers;
}
//gets count of numbers
public int knowCount() {
return count;
}
//gets average
public double knowAverage() {
ave = nmbrs / count;
return ave;
}
//print all numbers on a line with spaces between them
public static void printIt(double numbers) {
for (int index = 0; index < numbers.length; index++)
outFile.print(Double.parseDouble(numbers[index])+ " ");
}
//loops through data and performs a test
public double testData(double numbers, double ave) {
for (int index = 0; index < numbers.length; index++)
If (data[index] < ave)
outFile.println(Double.parseDouble(numbers[index]) + " is less than the
average.");
If (data[index] > ave)
outFile.println(Double.parseDouble(numbers[index]) + " is greater than the
average.");
Else
outFile.println(Double.parseDouble(numbers[index]) + "
is equal to the average.");
}//end test data
}//end average
}//end Program10a
--
"The man who does not read good books has no advantage over the man who
cannot read them."
Message posted via http://www.javakb.com |
|
| Back to top |
|
 |
Thomas Weidenfeller Guest
|
Posted: Fri Apr 21, 2006 3:12 pm Post subject: Re: Arrays again - I must be dumb |
|
|
janicethorne via JavaKB.com wrote:
| Quote: | Please tell me that all of you have had the same mental block when you all
first learned java! I am trying to complete this assignment and am totally
lost. Any help is really appreciated.
|
http://home.earthlink.net/~patricia_shanahan/beginner.html
| Quote: | I am supposed to create two classes. One holds the methods and the other
implements them.
|
Your terminology is flawed. What should "class holds a method" be? May I
suggest you straighten out your terminology, e.g. by re-reading your
assignment.
| Quote: | The methods are supposed to pull in 5 numbers from a file
|
Pull? You mean read from a file. As a general hint, it simplifies
understanding and communication if you stick with standard terms. Sounds
like a small thing? Well, being able to pay attention to details is an
essential skill in programming.
| Quote: | (args[0]), calculate the average and output to a file. The main method is
supposed to instantiate them.
|
Them? Who are them? The above mentioned methods? Methods are not
instantiated. Again, you might want to work on your terminology.
| Quote: | This can't be as hard as I am making it. Please
take a look at the code below and tell me what I am doing wrong.
|
I won't look at it, for the following reasons:
a) You failed to adequately explain what the program should do
b) You failed to explain what (wrong) result your code produces, and why
you think it's wrong
c) It is your homework, not ours.
/Thomas
--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/ |
|
| Back to top |
|
 |
janicethorne via JavaKB.c Guest
|
Posted: Fri Apr 21, 2006 3:12 pm Post subject: Re: Arrays again - I must be dumb |
|
|
Thomas:
Thank you for your help and your encouragement. It is people like you who
make me want to succeed as a programmer.
JT
--
"The man who does not read good books has no advantage over the man who
cannot read them."
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-setup/200604/1 |
|
| Back to top |
|
 |
Hendrik Maryns Guest
|
Posted: Fri Apr 21, 2006 3:12 pm Post subject: Re: Arrays again - I must be dumb |
|
|
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
janicethorne via JavaKB.com schreef:
| Quote: | Hello:
Please tell me that all of you have had the same mental block when you all
first learned java! I am trying to complete this assignment and am totally
lost. Any help is really appreciated.
I am supposed to create two classes. One holds the methods and the other
implements them. The methods are supposed to pull in 5 numbers from a file
(args[0]), calculate the average and output to a file. The main method is
supposed to instantiate them. This can't be as hard as I am making it. Please
take a look at the code below and tell me what I am doing wrong. Thank you
for all of your help and patience.
JT
import java.text.*;
import java.io.*;
public class Program10a {
public static void main (String[] args) throws IOException {
average myAve = new average();
BufferedReader inFile = new BufferedReader(new FileReader(args[0]));
PrintWriter outFile = new PrintWriter(new FileWriter(args[1]));
myAve.knowAverage();
myAve.getNumbers(numbers);
outFile.println("Your numbers are " + myAve.printIt());
outFile.println("The average is " + myAve.knowAverage());
outFile.println(average.testData(double numbers));
|
This will not work. Leave out ‘double’. At least try to interpret the
compiler error messages and correct the syntax errors.
| Quote: | inFile.close();
outFile.close();
}//end main
|
I see no reason to make this an embedded class. Give it its separate
source file.
| Quote: | public class average {
|
Naming conventions tell you to start names of classes with a capital
letter. Please adhere to them.
| Quote: | int count = 0;
double nmbrs;
double ave = 0.0;
double[] numbers = new double[5];
|
Why 5?
| Quote: | public double getNumbers();
|
This cannot compile. The ; should be a {.
| Quote: | double numbers = Double.parseDouble(inline.Substring(0, inLine.length()));
|
What is inLine? Did you split up the file in lines? Where?
Double.parseDouble looks for one number. I suppose you have a file with
a number on each line. You will have to loop through it, invoking
parseDouble over and over again.
So something like:
// determine the number of doubles first
double[] numbers = new double[nbOfDoubles];
for(int i=0; i<numbers.length; i++){
numbers[i] = Double.parseDouble(inFile.readLine())
//I don’t know the syntax, have a look in File
}
It would all be easier with a resizable List<Double>, then you don’t
have to determine the size of the array first.
| Quote: | return numbers; }
//adds numbers
public void addMe(double numbers) {
count++;
nmbrs = nmbrs + numbers;
}
//gets count of numbers
public int knowCount() {
return count;
}
//gets average
public double knowAverage() {
ave = nmbrs / count;
return ave;
}
//print all numbers on a line with spaces between them
public static void printIt(double numbers) {
|
You want numbers to be declared as an array. The syntax is double[]:
public static void printIt(double[] numbers)
| Quote: | for (int index = 0; index < numbers.length; index++)
outFile.print(Double.parseDouble(numbers[index])+ " ");
}
|
But why not make it an instance method and use the array of doubles you
would have made an instance field anyway?
| Quote: | //loops through data and performs a test
Again, double[] numbers
public double testData(double numbers, double ave) {
for (int index = 0; index < numbers.length; index++)
If (data[index] < ave)
|
if should be with small i
| Quote: | outFile.println(Double.parseDouble(numbers[index]) + " is less than the
average.");
If (data[index] > ave)
|
bis
I’d suggest using brackets to make it more clear what belongs to which if.
| Quote: | outFile.println(Double.parseDouble(numbers[index]) + " is greater than the
average.");
Else
|
As should else. Are you sure you are learning Java? It is with
capitals in some other languages...
| Quote: | outFile.println(Double.parseDouble(numbers[index]) + "
is equal to the average.");
}//end test data
}//end average
}//end Program10a
|
HTH,
H.
- --
Hendrik Maryns
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQFESO3Ne+7xMGD3itQRAnmHAJ4pbEEy5nohUsifnhdMGUfUkkxyCQCfR8Cb
//FQHLJuGhEq4L5Yz8OppWo=
=H8Zc
-----END PGP SIGNATURE----- |
|
| Back to top |
|
 |
Monique Y. Mudama Guest
|
Posted: Fri Apr 21, 2006 5:12 pm Post subject: Re: Arrays again - I must be dumb |
|
|
On 2006-04-21, janicethorne via JavaKB.com penned:
| Quote: | Hello:
Please tell me that all of you have had the same mental block when you all
first learned java! I am trying to complete this assignment and am totally
lost. Any help is really appreciated.
I am supposed to create two classes. One holds the methods and the other
implements them. The methods are supposed to pull in 5 numbers from a file
(args[0]), calculate the average and output to a file. The main method is
supposed to instantiate them. This can't be as hard as I am making it. Please
take a look at the code below and tell me what I am doing wrong. Thank you
for all of your help and patience.
JT
|
I'm confused by how you describe the assigment. By "class that holds
the methods" do you mean an Interface?
There's some confusing stuff in the code, too. You have a member
variable called numbers that's an array, but then getNumbers() returns
a double, not an array -- why would you call a double "numbers" when
it's only one number?
Also, you instantiate inFile, but you never use it .. you just close
it. In getNumbers(), you have a class called inline that you never
declared or instantiated.
Those are a few leads on how to fix this code. If you want help with
your homework, most people here would prefer it if you asked a very
specific question ("Using this code, I get this specific compiler
error at line X; does anyone see why?") rather than vaguely asking for
help.
| Quote: |
import java.text.*;
import java.io.*;
public class Program10a {
public static void main (String[] args) throws IOException {
average myAve = new average();
BufferedReader inFile = new BufferedReader(new FileReader(args[0]));
PrintWriter outFile = new PrintWriter(new FileWriter(args[1]));
myAve.knowAverage();
myAve.getNumbers(numbers);
outFile.println("Your numbers are " + myAve.printIt());
outFile.println("The average is " + myAve.knowAverage());
outFile.println(average.testData(double numbers));
inFile.close();
outFile.close();
}//end main
public class average {
int count = 0;
double nmbrs;
double ave = 0.0;
double[] numbers = new double[5];
public double getNumbers();
double numbers = Double.parseDouble(inline.Substring(0, inLine.length()));
return numbers; }
//adds numbers
public void addMe(double numbers) {
count++;
nmbrs = nmbrs + numbers;
}
//gets count of numbers
public int knowCount() {
return count;
}
//gets average
public double knowAverage() {
ave = nmbrs / count;
return ave;
}
//print all numbers on a line with spaces between them
public static void printIt(double numbers) {
for (int index = 0; index < numbers.length; index++)
outFile.print(Double.parseDouble(numbers[index])+ " ");
}
//loops through data and performs a test
public double testData(double numbers, double ave) {
for (int index = 0; index < numbers.length; index++)
If (data[index] < ave)
outFile.println(Double.parseDouble(numbers[index]) + " is less than the
average.");
If (data[index] > ave)
outFile.println(Double.parseDouble(numbers[index]) + " is greater than the
average.");
Else
outFile.println(Double.parseDouble(numbers[index]) + "
is equal to the average.");
}//end test data
}//end average
}//end Program10a
|
--
monique
Help us help you:
http://www.catb.org/~esr/faqs/smart-questions.html |
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Fri Apr 21, 2006 8:12 pm Post subject: Re: Arrays again - I must be dumb |
|
|
On Fri, 21 Apr 2006 16:35:57 +0200, Hendrik Maryns
<hendrik_maryns (AT) despammed (DOT) com> wrote, quoted or indirectly quoted
someone who said :
| Quote: | This will not work. Leave out ‘double’. At least try to interpret the
compiler error messages and correct the syntax errors.
|
see http://mindprod.com/jgloss/compileerrormessages.html
for help figuring out what various error message really mean.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching. |
|
| Back to top |
|
 |
Greg R. Broderick Guest
|
Posted: Sat Apr 22, 2006 5:12 pm Post subject: Re: Arrays again - I must be dumb |
|
|
"janicethorne via JavaKB.com" <u16040@uwe> wrote in
news:5f1c5d967b589@uwe:
Hi Janice:
I've a few other comments sprinkled liberlally through the code below. The
others have hit a lot of the substantiative issues, I've tried to not simply
duplicate what they've said.
[grb] where I work, we used to do this in our code, found that it resulted
in code that was unnecessarily cluttered-looking, more difficult than
necessary to read. We are still in the process of going back through our
large volume of source code and removing them.
I'd recommend that you don't even _start_ this! :-)
| Quote: | public class average {
|
[grb] class names should begin with an uppercase character.
[grb] here you're saving typing two characters, and have made the field name
not immediately-readable. I'd recommend not trying to save the typing of two
characters and renaming the field to "number", because this is something that
anyone who reads the English language can immediately understand. A non-
array variable cannot contain multiple values, so the plural in the variable
name isn't correct.
| Quote: | double ave = 0.0;
double[] numbers = new double[5];
|
[grb] generic variable names such as 'count', 'numbers' usually betray a
lack of understanding of what the program is going to do -- write the
software so that you will be able to pick it up in six months and understand
it without difficulty! Write the software so that someone else can pick it
up and understand it without difficulty.
| Quote: | public double getNumbers();
double numbers = Double.parseDouble(inline.Substring(0,
inLine.length()));
return numbers; }
//adds numbers
public void addMe(double numbers) {
count++;
nmbrs = nmbrs + numbers;
}
|
[grb] your methods are named strangely, and your use of 'numbers' as a
parameter hides the class' double array field, which often isn't a good
programming practice.
| Quote: | //gets count of numbers
public int knowCount() {
return count;
}
|
[grb] if the method gets the count, then name the method 'getCount()'! :-)
| Quote: | //gets average
public double knowAverage() {
ave = nmbrs / count;
return ave;
}
|
[grb] if the method gets the average, then name the method 'getAverage()'!
:-)
| Quote: | //print all numbers on a line with spaces between them
public static void printIt(double numbers) {
for (int index = 0; index < numbers.length; index++)
outFile.print(Double.parseDouble(numbers[index])+ " ");
}
|
[grb] you are never putting values into the double array 'numbers' class
field in the code, so you won't be able to get values out of the 'numbers'
array. I'd recommend modifying the 'addMe()' method to remedy this.
| Quote: | //loops through data and performs a test
public double testData(double numbers, double ave) {
for (int index = 0; index < numbers.length; index++)
If (data[index] < ave)
outFile.println(Double.parseDouble(numbers[index]) + " is less
than the average.");
If (data[index] > ave)
outFile.println(Double.parseDouble(numbers[index]) + " is
greater than the average.");
|
[grb] it makes your code a lot more readable if you indent continuation
lines.
| Quote: | Else
outFile.println(Double.parseDouble(numbers
[index]) + " is equal to the average.");
|
[grb] it makes your code a lot more readable if you use a consistent
indentation, and if you use spaces instead of tabs to indent.
| Quote: | }//end test data
}//end average
}//end Program10a
|
Cheers
GRB
--
---------------------------------------------------------------------
Greg R. Broderick [rot13] terto (AT) oynpxubyvb (DOT) qlaqaf.bet
A. Top posters.
Q. What is the most annoying thing on Usenet?
--------------------------------------------------------------------- |
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Sat Apr 22, 2006 6:12 pm Post subject: Re: Arrays again - I must be dumb |
|
|
On Sat, 22 Apr 2006 10:34:05 -0500, "Greg R. Broderick"
<terto (AT) oynpxubyvb (DOT) qlaqaf.bet> wrote, quoted or indirectly quoted
someone who said :
| Quote: | double nmbrs;
[grb] here you're saving typing two characters, and have made the field name
not immediately-readable. I'd recommend not trying to save the typing of two
characters and renaming the field to "number", because this is something that
anyone who reads the English language can immediately understand. A non-
array variable cannot contain multiple values, so the plural in the variable
name isn't correct.
|
The other problem is there are great many ways to abbreviate. This can
lead to bugs where you abbreviate one way in one part of a program and
another in another. Even if they are detected at compile time, they
still waste your time correcting them.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching. |
|
| Back to top |
|
 |
Mishagam Guest
|
Posted: Sun Apr 23, 2006 1:12 am Post subject: Re: Arrays again - I must be dumb |
|
|
Generally it looks like janicethorne couldn't decide if he works with
one double number or array of double numbers. I also think he received a
lot of style advices that look inappropriate on this stage. I think it
is easier for me to provide possibly working one number version that
write more:
Hendrik Maryns wrote:
| Quote: | -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
janicethorne via JavaKB.com schreef:
Hello:
Please tell me that all of you have had the same mental block when you all
first learned java! I am trying to complete this assignment and am totally
lost. Any help is really appreciated.
I am supposed to create two classes. One holds the methods and the other
implements them. The methods are supposed to pull in 5 numbers from a file
(args[0]), calculate the average and output to a file. The main method is
supposed to instantiate them. This can't be as hard as I am making it. Please
take a look at the code below and tell me what I am doing wrong. Thank you
for all of your help and patience.
JT
import java.text.*;
import java.io.*;
public class Program10a {
public static void main (String[] args) throws IOException {
average myAve = new average();
BufferedReader inFile = new BufferedReader(new FileReader(args[0]));
PrintWriter outFile = new PrintWriter(new FileWriter(args[1]));
myAve.knowAverage();
myAve.getNumbers(numbers);
Here numbers is undefined, so we (and compiler) even cannot know if this |
is one number or array.
| Quote: |
outFile.println("Your numbers are " + myAve.printIt());
Your methods printIt(), and so on write to outFile instead of returning |
string, so you cannot use them like that.
| Quote: | outFile.println("The average is " + myAve.knowAverage());
outFile.println(average.testData(double numbers));
This will not work. Leave out ‘double’. At least try to interpret the
compiler error messages and correct the syntax errors.
inFile.close();
outFile.close();
}//end main
I see no reason to make this an embedded class. Give it its separate
source file.
public class average {
Naming conventions tell you to start names of classes with a capital
letter. Please adhere to them.
int count = 0;
double nmbrs;
double ave = 0.0;
double[] numbers = new double[5];
Why 5?
public double getNumbers();
This cannot compile. The ; should be a {.
double numbers = Double.parseDouble(inline.Substring(0, inLine.length()));
What is inLine? Did you split up the file in lines? Where?
Double.parseDouble looks for one number. I suppose you have a file with
a number on each line. You will have to loop through it, invoking
parseDouble over and over again.
So something like:
// determine the number of doubles first
double[] numbers = new double[nbOfDoubles];
for(int i=0; i<numbers.length; i++){
numbers[i] = Double.parseDouble(inFile.readLine())
//I don’t know the syntax, have a look in File
}
It would all be easier with a resizable List<Double>, then you don’t
have to determine the size of the array first.
return numbers; }
//adds numbers
public void addMe(double numbers) {
count++;
nmbrs = nmbrs + numbers;
}
//gets count of numbers
public int knowCount() {
return count;
}
In Java this method will be almost always called getCount(). It is one |
of many places where Java becomes better language by removing
unnecessary choices.
| Quote: |
//gets average
public double knowAverage() {
ave = nmbrs / count;
return ave;
}
//print all numbers on a line with spaces between them
public static void printIt(double numbers) {
You want numbers to be declared as an array. The syntax is double[]:
public static void printIt(double[] numbers)
for (int index = 0; index < numbers.length; index++)
outFile.print(Double.parseDouble(numbers[index])+ " ");
Double.parseDouble() method is used incorrectly. You want to use |
Double.toString() here.
| Quote: | }
But why not make it an instance method and use the array of doubles you
would have made an instance field anyway?
//loops through data and performs a test
Again, double[] numbers
public double testData(double numbers, double ave) {
for (int index = 0; index < numbers.length; index++)
If (data[index] < ave)
if should be with small i
outFile.println(Double.parseDouble(numbers[index]) + " is less than the
average.");
If (data[index] > ave)
bis
I’d suggest using brackets to make it more clear what belongs to which if.
outFile.println(Double.parseDouble(numbers[index]) + " is greater than the
average.");
Else
As should else. Are you sure you are learning Java? It is with
capitals in some other languages...
outFile.println(Double.parseDouble(numbers[index]) + "
is equal to the average.");
}//end test data
}//end average
}//end Program10a
HTH,
H.
- --
Hendrik Maryns
I provided fixed version here. I am new to this newsgroup so please |
excuse me if this isn't advised behavior here:
import java.io.*;
public class Program10a {
// outFile has to be field to be accessible to Average
static PrintWriter outFile = null;
public static void main(String[] args) throws IOException {
Average myAve = (new Program10a()).new Average();
BufferedReader inFile = new BufferedReader(new
FileReader(args[0]));
outFile = new PrintWriter(new FileWriter(args[1]));
double[] numbers = myAve.getNumbers(inFile.readLine());
double ave = myAve.knowAverage();
outFile.println("Your numbers are ");
myAve.printIt();
outFile.println("The average is " + myAve.knowAverage());
myAve.testData(numbers, ave);
//inFile.close();
outFile.close();
}// end main
public class Average {
int count = 0;
double sum = 0;
double ave = 0.0;
double[] numbers = new double[5];
/**
* will work for <= 5 numbers
*
* @param s
* @return
*/
public double[] getNumbers(String s) {
String[] ss = s.split(" ");
for (int i = 0; i < ss.length; i++) {
numbers[i] = Double.parseDouble(ss[i]);
addMe(numbers[i]);
}
return numbers;
}
// adds numbers
public void addMe(double numbers) {
count++;
sum = sum + numbers;
}
// gets count of numbers
public int knowCount() {
return count;
}
// gets average
public double knowAverage() {
ave = sum / count;
return ave;
}
// print all numbers on a line with spaces between them
public void printIt() {
for (int index = 0; index < numbers.length; index++)
outFile.print("" + Double.toString(numbers[index]) + " ");
}
// loops through data and performs a test
public void testData(double[] numbers, double ave) {
for (int index = 0; index < numbers.length; index++) {
if (numbers[index] < ave) {
outFile.println(Double.toString(numbers[index])
+ " is less than the average.");
} else if (numbers[index] > ave) {
outFile.println(Double.toString(numbers[index])
+ " is greater than the average.");
} else {
outFile.println(Double.toString(numbers[index])
+ "is equal to the average.");
}
}
}// end test data
}// end average
}// end Program10a
> |
|
| Back to top |
|
 |
Monique Y. Mudama Guest
|
Posted: Sun Apr 23, 2006 3:12 am Post subject: Re: Arrays again - I must be dumb |
|
|
On 2006-04-23, Mishagam penned:
| Quote: | I provided fixed version here. I am new to this newsgroup so please
excuse me if this isn't advised behavior here:
|
Generally, if someone looks like they are trying to complete a
homework assignment, we try not to give them the whole answer.
Providing clues helps them learn, whereas if they get the whole thing
written for them, they may not take the time to understand.
--
monique
Help us help you:
http://www.catb.org/~esr/faqs/smart-questions.html |
|
| Back to top |
|
 |
Greg R. Broderick Guest
|
Posted: Sun Apr 23, 2006 2:12 pm Post subject: Re: Arrays again - I must be dumb |
|
|
Mishagam <noemail (AT) provider (DOT) com> wrote in news:5Dz2g.1160$n13.356
@tornado.southeast.rr.com:
| Quote: | I also think he received a lot of style advices that look inappropriate
on this stage.
|
A LOT of professional software development revolves around programming
style. A class file can be absolutely correct, but if its style renders
the code unreadable and unmaintainable, then the code is worthless -- 75
percent of the cost of software over its lifetime is in maintenance. If
your code isn't maintainable, it is crap and I won't be recommending to
hire you! :-)
c.f. http://mindprod.com/jgloss/unmain.html
Coding habits (including style) are established early. The time to help a
potential software developer to learn good coding style (rendering them
potentially more employable) is early, at the same time that they're
learning the language and there are few or no bad habits to unlearn.
Cheers
GRB
--
---------------------------------------------------------------------
Greg R. Broderick [rot13] terto (AT) oynpxubyvb (DOT) qlaqaf.bet
A. Top posters.
Q. What is the most annoying thing on Usenet?
--------------------------------------------------------------------- |
|
| Back to top |
|
 |
Mishagam Guest
|
Posted: Sun Apr 23, 2006 4:12 pm Post subject: Re: Arrays again - I must be dumb |
|
|
Greg R. Broderick wrote:
| Quote: | Mishagam <noemail (AT) provider (DOT) com> wrote in news:5Dz2g.1160$n13.356
@tornado.southeast.rr.com:
I also think he received a lot of style advices that look inappropriate
on this stage.
A LOT of professional software development revolves around programming
style. A class file can be absolutely correct, but if its style renders
the code unreadable and unmaintainable, then the code is worthless -- 75
percent of the cost of software over its lifetime is in maintenance. If
your code isn't maintainable, it is crap and I won't be recommending to
hire you! :-)
c.f. http://mindprod.com/jgloss/unmain.html
Coding habits (including style) are established early. The time to help a
potential software developer to learn good coding style (rendering them
potentially more employable) is early, at the same time that they're
learning the language and there are few or no bad habits to unlearn.
Cheers
GRB
I think style is not so urgent if you program doesn't work at all, has |
error on each line, and you don't know what to do. |
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Sun Apr 23, 2006 6:12 pm Post subject: Re: Arrays again - I must be dumb |
|
|
On Sun, 23 Apr 2006 15:42:05 GMT, Mishagam <noemail (AT) provider (DOT) com>
wrote, quoted or indirectly quoted someone who said :
| Quote: | I think style is not so urgent if you program doesn't work at all, has
error on each line, and you don't know what to do.
|
The whole point of style is to help you write programs that are
readable. Whenever I have to deal with someone else's code, I clean
up the cosmetic/style stuff first to get the clutter out the way to
let the meaning of the program shine through. It seems logical that
technique should also work for the newbie.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching. |
|
| Back to top |
|
 |
Mishagam Guest
|
Posted: Sun Apr 23, 2006 11:12 pm Post subject: Re: Arrays again - I must be dumb |
|
|
Roedy Green wrote:
| Quote: | On Sun, 23 Apr 2006 15:42:05 GMT, Mishagam <noemail (AT) provider (DOT) com
wrote, quoted or indirectly quoted someone who said :
I think style is not so urgent if you program doesn't work at all, has
error on each line, and you don't know what to do.
The whole point of style is to help you write programs that are
readable. Whenever I have to deal with someone else's code, I clean
up the cosmetic/style stuff first to get the clutter out the way to
let the meaning of the program shine through. It seems logical that
technique should also work for the newbie.
I often also change style (or tempted to change style) to my liking |
first. This is more often possible and advisable if you either program
alone or use Java, because Java has standard style dictated by SUN
conventions.
On the C, on other side, each organization if not each programmer has
it's (his) own conventions, and I doubt that starting by changing style
is advisable in these circumstances. |
|
| Back to top |
|
 |
Rhino Guest
|
Posted: Mon Apr 24, 2006 12:12 am Post subject: Re: Arrays again - I must be dumb |
|
|
"Greg R. Broderick" <terto (AT) oynpxubyvb (DOT) qlaqaf.bet> wrote in message
news:Xns97AE58EA6EBE9tnalzrqrfcrnxrnflarg (AT) io (DOT) blackholio.dyndns.org...
| Quote: | Mishagam <noemail (AT) provider (DOT) com> wrote in news:5Dz2g.1160$n13.356
@tornado.southeast.rr.com:
I also think he received a lot of style advices that look inappropriate
on this stage.
A LOT of professional software development revolves around programming
style. A class file can be absolutely correct, but if its style renders
the code unreadable and unmaintainable, then the code is worthless -- 75
percent of the cost of software over its lifetime is in maintenance. If
your code isn't maintainable, it is crap and I won't be recommending to
hire you! :-)
c.f. http://mindprod.com/jgloss/unmain.html
Coding habits (including style) are established early. The time to help a
potential software developer to learn good coding style (rendering them
potentially more employable) is early, at the same time that they're
learning the language and there are few or no bad habits to unlearn.
I agree that style is very important but I don't think you can force newbies |
into a particular style until they have some idea of what they are doing. If
they don't know what the statements in the language do yet, it can really be
frustrating for someone to criticize their style too. I think they need to
get a basic understanding of the language and the concepts behind loops,
flow of control and so forth before you should start pressuring them to
adopt a good style.
Knowing exactly when they have reached the right point in their learning of
Java is not that easy and I'm sure each of us would put that point in a
slightly different place.
I also think that style evolves fairly constantly over time. Some basic
elements of Java style, like using capital letters at the start of class
names and lower case letters at the start of method names, should probably
be adopted very early on by a newbie. But other things, like how much work
to do in a method and when to create a new class, things which are more
design-oriented, evolve over the course of your work with the language as
you learn more about OO design. You certainly don't want to criticize a
newbie's design choices too early in the process of learning Java and you
certainly can't assume that they have already mastered OO design before they
start learning Java.
In the multi-pronged effort to learn what the statements in Java does, how
to design OO programs - and probably how the business he is in works - I
think a premature emphasis on style just undermines the confidence of the
newbie. Learning something complicated like Java is hard enough without
making the student feel inadequate because he doesn't use a professional
style in his first few programs.
--
Rhino |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|