I’m taking another crack at learning java with the aim of getting a job. as I write code, I sometimes find it quite difficult to navigate my code using the formatting I often see in tutorials. something I’ve found that helps me is dividing up chunks of codes with long commented dashed lines (example below).
it really helps but I’m concerned that this is generally against professional best practices or not. I find it visually appealing but will companies or other coders?
//package declaration
package word_builder; // declares the package to be used in testPackage
//----------------------------------------------------------------------------------------------------------------------
//imports
import java.util.Scanner;
//----------------------------------------------------------------------------------------------------------------------
public class rootSuffixCombine{ // creates the rootSuffix class to contain rootSuffix method
//----------------------------------------------------------------------------------------------------------------------
//methods
public static void rootSuffix(){ // method for combining just a root and a suffix
//----------------------------------------------------------------------------------------------------------------------
// initial prompt and scanner creation
System.out.println("Do you want to make a word?");
Scanner partTaker = new Scanner(System.in);
String answer = partTaker.nextLine();
//----------------------------------------------------------------------------------------------------------------------
//variable initialization to start loops
int x = 1;
int y = 1;
//----------------------------------------------------------------------------------------------------------------------
// outer while loop for taking user input to either continue with program or end it
while (x == 1){
//----------------------------------------------------------------------------------------------------------------------
// affirmative case (continues program, prints results, then asks if you want to make another)
if (answer.equalsIgnoreCase("yes")){ // sets answer and ignores case
//----------------------------------------------------------------------------------------------------------------------
System.out.print("please input "root": "); // takes the root
String root = partTaker.nextLine();
System.out.print("please input "suffix": "); // takes the suffix
String suffix = partTaker.nextLine();
//----------------------------------------------------------------------------------------------------------------------
// main output
System.out.println("The word you created is: " + """ + root.concat(suffix) + """);
//----------------------------------------------------------------------------------------------------------------------
//resets loop in case user wants to make another word
y = 1;
//----------------------------------------------------------------------------------------------------------------------
// second while loop for creating more words
while (y == 1){
//----------------------------------------------------------------------------------------------------------------------
// prompts for second word
System.out.println("Do you want to make another word?");
answer = partTaker.nextLine();
//----------------------------------------------------------------------------------------------------------------------
//affirmative case
if (answer.equalsIgnoreCase("yes")) {
//ends second loop
y = 0;}
//----------------------------------------------------------------------------------------------------------------------
// negative case
else if (answer.equalsIgnoreCase("no")) { //ignores case
// closes second loop
break;}
//----------------------------------------------------------------------------------------------------------------------
//handling non-standard answers
else{
System.out.println("sorry, i dont understand");
//resets loop
x = 1;
y = 1;}}}
// end of second loop
//----------------------------------------------------------------------------------------------------------------------
// negative case (main loop)
else if (answer.equalsIgnoreCase("no")) {
System.out.println("OK, shutting down.");
break;} //ends loop
//----------------------------------------------------------------------------------------------------------------------
// catches non-standard response and repeats initial question until "yes" or "no" is given
else{
System.out.println("I dont understand, try again.");
answer = partTaker.nextLine();}}}
//----------------------------------------------------------------------------------------------------------------------
// main, which runs the method(S)
public static void main(String[] args){
rootSuffix();}}
//----------------------------------------------------------------------------------------------------------------------
//END
with a semi-long page of code, does this come off as messy?
Using commented dashes to divide up code chunks
I’m taking another crack at learning java with the aim of getting a job. as I write code, I sometimes find it quite difficult to navigate my code using the formatting I often see in tutorials. something I’ve found that helps me is dividing up chunks of codes with long commented dashed lines (example below).
it really helps but I’m concerned that this is generally against professional best practices or not. I find it visually appealing but will companies or other coders?
with a semi-long page of code, does this come off as messy?
KanagawaPunk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Filed under: softwareengineering - @ 11:16
Thẻ: comments, java
« How to Create a Menu with List Sliding Animation ⇐ More Pages ⇒ Backslash escape characters in zsh string for use as a path argument »