by ars · 11y ago · 0 comments
For example closing <br /> with HTML, or using HTML comment marks with Javascript in SCRIPT tags.
People just copy what other people have done, without trying to understand each part of it, so you have stuff that is just blindly copied from person to person to person until someone finally stops and says "What does this actually do?"
And even if you have XHTML doctype but do not server your document with XHTML MIME type browsers will treat it as HTML. So all "liking" to use XHTML syntax in HTML were just lucky that no mainstream browser bothered to implement this part of SGML handling correctly.
Nope, it's not. In HTML5 it's just optional. From the W3C standard:
>Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single "/" (U+002F) character. This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.
Writing XHTML without validating is sort of like writing Haskell without type-checking, isn't it? It seems like all the pain with none of the benefit.
It's been a while, so I'm not completely sure this is true, but I think any XHTML within an XSL document also had to be valid XML (that would also validate against the XHTML schema), so you couldn't get away with as much as you could with rendering a plain XHTML page.
Not sure if that was worth all the trouble.
[0] https://developer.mozilla.org/en-US/docs/SVG_In_HTML_Introdu...
Some things are obviously looks (useful looks, but still not required) - indents in C, or semi-colon in Javascript.
Other things are not. You say that the slash is just for the look, but since that's a rare position, I would advise not doing that - it makes you look bad to other programmers. Especially because unlike my other examples the slash has no useful purpose at all.
Nitpick, but that is required. The heuristic that places it for you is meant as an aide if you accidentally forget to add it. And it's not always right.
Linters will also flag your code when you don't include semicolons.
As for <br> vs. <br/>. I personally prefer <br/> because of consistency. Just like I'd write <img .. />, <link .. /> and so on.
And the one tag that has to be closed with no content: <script type=".." src=".."></script> can't be self closed anyway.
Self closing tags have no place in HTML.
PS: I too am from the XHTML era :)
If all I have is the HTML source code to go by, then yes, that's one of the things.
If I see useless self-closing tags then that starts them at a lower caliber of programmer, and the rest of the code better be really good to raise them back up.
This is because I assume that if they are closing the tags they never bothered to learn html properly, and are just copying online tutorials. Sure, not are all like that, but in absence of other information, I have to use what's in front of me.
> PS: I too am from the XHTML era :)
It's time to stop. People who learned Javascript 20 years ago also had to eventually learn to stop wrapping the scripts in HTML comments. Things change.
(I also remember reading, many years ago, a very angry post about how you couldn't fully remove Internet Explorer from Windows, because various OS components used it as a library to render their UIs, and how evil and anticompetitive it was for Microsoft to intermingle their products that way. Oh, how times change...)
There's a reason governments do not like monopolies and the markets cannot fix themselves by getting rid of them since the monopolies are not playing by the market's rules anymore.
(Yes, I know you can technically access the phone with a tel: link. But very few web sites do this!)
The current situation in programming is that, wherever you work and whatever you do, there is probably piles of boilerplate that you're told to follow. So much of it is just dealing with weird little quirks and shortcomings of a particular platform - I'm thinking here of the Dispose pattern in .NET, various cross-browser compatibility incantations in HTML, the good old Perl preamble, include guards. . . it creates an environment where it's not just natural to copy what you see others do, it's perfectly rational behavior. You could go the engaged skeptical route and figure out exactly what it all means and why you have to do it, but the answer is so frequently "because historical obnoxiousness you can't escape" that it's hard to blame anyone for thinking it's not worth the bother.
Contrast with actual cargo cults, which involved trying to mimic what others see in ways that not only miss the entire point, but fail to achieve the intended effect either. Oftentimes what gets dismissed as cargo cult programming is very different - the operating principle is, "Don't bother with the point because it's probably stupid; just copy others because it will (usually) achieve the intended effect without too much hassle."
Which is important. I have seen an awful lot in practice that you can't rely on GC to happen at all, or happen promptly if it does. Plus things like file handle leaks have even worse consequences in Windows than elsewhere. IDisposable is great to standardize manual cleanup across objects.
> include guards
Whose behavior is bleedingly obvious the first time you see it.
I am thinking if you believe these things are "cargo cult" (despite disagreeing with the term) you must be thinking of fairly mediocre programmers, who look at code and don't get curious about the explanations for things.
I've found the best solution is to try to find someone with whom you can have a discussion about what you don't understand and where you can find learning resources. Also, being able to find and read specifications can be very helpful.
If archive.org had a real search engine, I'd probably use it more than Google.
This still has a valid, if rare use. In browsers that don't understand javascript (such as lynx), it prevents the code from appearing in the page.
The comments were necessary in the very beginning when the script element was new and thus might have been treated like any other part of invalid HTML – doing a best effort in rendering.
<p> some paragraph </p>
<br></br>
<p> a second paragraph </p>
or: <p> some first paragraph </p>
<br><p> a second paragraph </p></br>
<p> a third thing </p>
Neither of those are valid, and the last one is interpreted as: <p> some first paragraph </p>
<br>
<p> a second paragraph </p>
<br>
<p> a third thing </p>
New users find behavior like this confusing all the time.The "/>" is syntax for a self-closing tag in xhtml (e.g. you were supposed to use <img src="" /> etc).
You see "<br />" a lot in php forums because these will often filter user input through the function nl2br whose purpose is to add HTML linebreaks wherever a person has a newline in their post. PHP's nl2br function by default inserts "<br />" unless you tell it specifically not to use xhtml-compatible linebreaks.
In fact they can be said to have no effect on parsing HTML itself, as the only time when self-closing makes any difference is when the tag's name isn't one that HTML defines - what the spec calls "foreign elements" (e.g. inline SVG or MathML). Those will close when their tag is self-closing, but the closing behaviour of HTML tags is hardcoded in the parser.