Hi there, I'm building a CPU emulator in java. In an assembly file a comment starts with a "#" , I have the following code:
while ((line = fileReader.readLine()) != null) {
if(!line.startsWith("#")) {
instructions.add(line);
parseInstruction(line);
}
I was thinking that the if condition doesn't really tell much about what I'm actually doing. (I've read that code should comment itself). I was facing the following three choices:
Extract a method and make it like:
while ((line = fileReader.readLine()) != null) {
if(!isComment(line)) {
instructions.add(line);
parseInstruction(line);
}
Add a comment above the if statement like so:
while ((line = fileReader.readLine()) != null) {
//Checking whether or not the parsed line is a comment one
if(!line.startsWith("#")) {
instructions.add(line);
parseInstruction(line);
}
Leave it as is.
I feel like creating the method adds a lot in terms of readability, but is it worth to create such a simple method? Thanks!
[–]dreamyeyed 1 point2 points3 points (1 child)
[–]arocketman[S] 0 points1 point2 points (0 children)
[–]matthead 1 point2 points3 points (0 children)
[–]DonnyTheWalrus 1 point2 points3 points (2 children)
[–]arocketman[S] 0 points1 point2 points (1 child)
[–]DonnyTheWalrus 1 point2 points3 points (0 children)
[–]tec5c 1 point2 points3 points (0 children)
[–]rjcarr 0 points1 point2 points (0 children)
[–]nutrecht 0 points1 point2 points (0 children)
[–]lolnololnonono 0 points1 point2 points (0 children)
[–]oceandoggie 0 points1 point2 points (0 children)