0

I have a really really long lines for blur function. when I pass it to style50 it asks me to change code style to this:

for (int j = 1; j < width - 1 ; j++)
    {
        image[i][j].rgbtRed = round((copy[i - 1][j - 1].rgbtRed + copy[i - 1][j].rgbtRed + copy[i - 1][j + 1].rgbtRed + copy[i][j -
                                     1].rgbtRed + copy[i][j].rgbtRed + copy[i][j + 1].rgbtRed + copy[i + 1][j - 1].rgbtRed + copy[i + 1][j].rgbtRed + copy[i + 1][j +

                                             1].rgbtRed) / 9.0);
        image[i][j].rgbtGreen = round((copy[i - 1][j - 1].rgbtGreen + copy[i - 1][j].rgbtGreen + copy[i - 1][j + 1].rgbtGreen + copy[i][j -
                                       1].rgbtGreen + copy[i][j].rgbtGreen + copy[i][j + 1].rgbtGreen + copy[i + 1][j - 1].rgbtGreen + copy[i + 1][j].rgbtGreen + cop
                                       y[i +
                                         1][j + 1].rgbtGreen) / 9.0);
        image[i][j].rgbtBlue = round((copy[i - 1][j - 1].rgbtBlue + copy[i - 1][j].rgbtBlue + copy[i - 1][j + 1].rgbtBlue + copy[i][j -
                                      1].rgbtBlue + copy[i][j].rgbtBlue + copy[i][j + 1].rgbtBlue + copy[i + 1][j - 1].rgbtBlue + copy[i + 1][j].rgbtBlue + copy[i +
                                              1][j
                                                      + 1].rgbtBlue) / 9.0);
    }

is that a bug or really the code is more readable in this way?
I think following code is more readable than that:

image[i][j].rgbtRed = round((copy[i - 1][j - 1].rgbtRed + copy[i - 1][j].rgbtRed + copy[i - 1][j + 1].rgbtRed + copy[i][j -1].rgbtRed + copy[i][j].rgbtRed + copy[i][j + 1].rgbtRed + copy[i + 1][j - 1].rgbtRed + copy[i + 1][j].rgbtRed + copy[i + 1][j +1].rgbtRed) / 9.0);
image[i][j].rgbtGreen = round((copy[i - 1][j - 1].rgbtGreen + copy[i - 1][j].rgbtGreen + copy[i - 1][j + 1].rgbtGreen + copy[i][j - 1].rgbtGreen + copy[i][j].rgbtGreen + copy[i][j + 1].rgbtGreen + copy[i + 1][j - 1].rgbtGreen + copy[i + 1][j].rgbtGreen + copy[i + 1][j + 1].rgbtGreen) / 9.0);
image[i][j].rgbtBlue = round((copy[i - 1][j - 1].rgbtBlue + copy[i - 1][j].rgbtBlue + copy[i - 1][j + 1].rgbtBlue + copy[i][j - 1].rgbtBlue + copy[i][j].rgbtBlue + copy[i][j + 1].rgbtBlue + copy[i + 1][j - 1].rgbtBlue + copy[i + 1][j].rgbtBlue + copy[i + 1][j + 1].rgbtBlue) / 9.0);

although it is very long but we know what happened in the code.

0

From the style guide

Line Length

By convention the maximum length of a line of code is 80 characters long in C, with that being historically grounded in standard-sized monitors on older computer terminals, which could display 24 lines vertically and 80 characters horizontally. Though modern technology has obsoleted the need to keep lines capped at 80 characters, it is still a guideline that should be considered a “soft stop,” and a line of 100 characters should really be the longest you write in C, else readers will generally need to scroll. If you need more than 100 characters, it may be time to rethink either your variable names or your overall design!

So, no, it should not be considered a bug. It seems that style50 is suggesting line breaks to shorten the lines. IMO neither version is "readable" (perhaps "rethink your overall design"?). Your grade, your choice.

2
  • I agree. My suggestion (although I haven't tested it) is to split lines at logical points and indent appropriately. You can run it through style50 to see what it says about your changes, but anytime one has to scroll to see the whole line, it's bad. A person should be able to see an entire line of code on the screen, split or not, so that they can grasp the entire concept of the line at once.
    – Cliff B
    Aug 31 at 21:35
  • I agree too. but my problem is that it even suggests a line break inside an index of array! Sep 1 at 4:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .