Aberhart-school / abe-site

The website of William Aberhart high school
http://schools.cbe.ab.ca/b829/aberhart/
GNU General Public License v3.0
6 stars 8 forks source link

Limit line length? #157

Closed thirstyice closed 8 years ago

thirstyice commented 8 years ago

Should we add a guideline to limit non-link lines to ~80 characters? It would make the code easer to read without horizontal scrolling. Example:

<!DOCTYPE html>
<!--
 Comments would be included in the character limit, so this comment gets cut off
 here
-->
<html>
    <body>
        <div>
            <div>
                <div>
                    <div>
                        <p>
                            Indents count towards the limit, so this line is cut
                            here
                        </p>

                        <p>Single line paragraphs are still ok</p>

                        <p>But multi-line paragraphs with the p element on the
                            same lines (like this) are not</p>

                        <p>
                            A link can be inline, like <a href="short">this,</a>
                            but if it would make the line too long
                            <a href= "reallyverysuperblyfantasticallyextremelylonglinklikemorethaneightycharacterskindoflonglongimtalkinglooooooooooooooooooong">
                                it should be on a seperate line
                            </a>
                            Medium links can occupy their own line with
                            <a href="asortofmediumlengthoflink">inline tags</a>
                            provided that they dont exceede the limit

                            And, like for paragraphs <a href="notgood"> inline
                            tags </a> on different lines are bad
                        </p>
                        <p>
                            Finally, common sense should be employed.
                            A 10-letter word that is 2 characters over the limit
                            is fine.
                            As a general rule though, if there is any whitespace
                            past 80 characters, it should be a new line. Even one
                            word.
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>
nemeulenbroek commented 8 years ago

How would you enforce this though? Would it be automated?

nemeulenbroek commented 8 years ago

Also, when you get divs that are indented at different distances as the website expands, it would begin to look very odd and may be extremely hard to maintain. My simple rule of thumb is to line break when there's a sentence that ends

thirstyice commented 8 years ago

If you have 20 nested divs then you should probably think about revising your code structure. As for enforcement, it would be an honour system, the same as the guidelines for indenting. We would fix any errors we come across, as we do now.

nemeulenbroek commented 8 years ago

But whereas indenting is easy to visually identify and is a coding standard across most programming platforms, the 80 character limit is hard to identify without a proper text editor. Also, as websites get more complicated, there are cases where heavily nested divs will appear. I have has to implement some myself where there are no other options. To be perfectly honest, I think putting a line break after every sentence (or if the sentences are like 2 words long, at the coder's discretion) is acceptable as it's still readable and generally, if a sentence goes off screen, it's probably a run on sentence or within something heavily nested anyways

thirstyice commented 8 years ago

Tabs vs spaces is also difficult to identify without a proper text editor. Thankfully for both problems, I have a proper text editor. Plus, this is a general rule. Common sense can (and should) be employed.

nemeulenbroek commented 8 years ago

Yes, but tabs verses spaces is a problem only in languages like python where the indent type is important. Also, there are more contributors coming in and out modifying things who may not be using the same text editor as you, and so it should be acomodating to those new contributors, especially those with less experience

thirstyice commented 8 years ago

What code editor can't draw an 80 character line? The issue here is not a code problem, it's a readability problem, same as tabs vs spaces. Also what about this sentence: <p>For more information click <a href="http://webdesign.about.com/od/dreamweaver/ig/Dreamweaver-Options/Customize-Code-Format.htm">here,</a><a href="http://stackoverflow.com/questions/1248895/is-there-an-eclipse-line-width-marker#answer-27212402">here,</a> or <a href="https://books.google.ca/books?id=zcUd2sY3CbAC&pg=PA96&lpg=PA96&dq=dreamweaver+80+column+line&source=bl&ots=h2ZimkfGBv&sig=pQ3tnZ88AxfO4gav_ClmLhuXMaA&hl=en&sa=X&ved=0CCoQ6AEwAmoVChMIkoPK6cu7yAIVSS2ICh2hSQxB#v=onepage&q=dreamweaver%2080%20column%20line&f=false">here</a></p>

8 words long, 542 characters.

nemeulenbroek commented 8 years ago

Yes, but this isn't an automated process, and as such would be a time consuming one to manually check and see if all lines are less than 80 characters long. For sentences like that, that would be where you use common sense and line break it like you have

thirstyice commented 8 years ago

City of Calgary bylaw states that "No owner or occupier of a Premises shall allow grass or other Herbaceous Plants on the Premises to exceed a height of 15 centimetres." That doesn't mean that they hire a crew to go around with a ruler inspecting everyone's lawn.

nemeulenbroek commented 8 years ago

Yes, but by your proposed standard, we would have to do this as we're coding, which is what I was pointing out. It will be extremely tedious to check the character count on the line every other second while you're coding and then backtracking if you're over 80 with one word. It's like setting the speed limit to 30 on a highway. Everyone has to constantly watch their speedometer in an attempt not to exceed the limit cause there could be an officer around the corner and they don't want to get in trouble.

thirstyice commented 8 years ago

It's not like it's that hard to tell where column 80 is using any good text editor (as argued above). And nobody is going around keeping track of how many words go over the limit (as argued above).

nemeulenbroek commented 8 years ago

Then my argument is what's the point of implementing it if it's not going to be enforced?

thirstyice commented 8 years ago

To encourage people to limit their line length

gjwehnes commented 8 years ago

Even though setting the line length to 80 characters couldn't be enforced 100%, it is still IMO worth specifying it as a coding convention. 95% compliance would still be of benefit to the readability of the code.

This is much like variable naming conventions (or white space, as alluded to previously with the Python example); you cannot completely enforce good usage, but we can still fight the good fight in maintaining order and structure in our code.

I will clean code as I come across it.

thirstyice commented 8 years ago

Added