8 ms·
This kind of stuff is so common. For example closing <br /> with HTML, or using HTML comment marks with Javascript in SCRIPT tags. People just copy what other
by ars 12y ago
This kind of stuff is so common.
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?"
- cms07 12y agoIs <br /> really prone to that? I've only seen that in people actually trying to do XHTML.
- lelandbatey 12y agoIt is a really common thing for people to erroneously close void elements[0] that aren't supposed to have closing tags, or to give them contents when they can't have any. For example: <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. [0] - http://www.w3.org/TR/html5/syntax.html#void-elements http://www.w3.org/TR/html5/syntax.html#void-elements
- chias 12y agoThis is in reference to "<br />" not "</br>" 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.
- lelandbatey 12y agoWow that's odd. Also, PHP has a built in function for filtering filtering plain-text user input to create HTML? That's... not something I would have expected.
- nkozyra 12y agoSarcasm? PHP has a built-in function for any oddball thing you can think of.
- duskwuff 12y agoPersonal fav: gzgetss(). Reads a line from a gzip file handle and strips HTML tags from it. Why? I don't know! http://php.net/manual/en/function.gzgetss.php http://php.net/manual/en/function.gzgetss.php
- ars 12y agoIt's super useful. If you have a textarea for users to type paragraphs into you can use nl2br to output it more or less the same, but in HTML. (Be sure and escape the text before nl2br not after.)
- kedean 12y agoHe wasn't talking about closing void elements, he meant self-closing void tags, like <img/>, <br/>, and <hr/>. These were introduced by XHTML to fit with the idea that every tag needs to be closed. HTML5 does away with the requirement, but the HTML5 grammar does explicitly support self-closing tags (http://www.w3.org/TR/html5/syntax.html#self-closing-start-tag-state http://www.w3.org/TR/html5/syntax.html#self-closing-start-ta...). At this point, self-closing tags are more of a visual preference, as they have a negligable effect on parsing.
- userbinator 12y agoAt this point, self-closing tags are more of a visual preference, as they have a negligable effect on parsing. 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.
- ars 12y agoMinor correction: There will not be a second <br> in your second example. The </br> will be completely ignored.
- sirrocco 12y agoActually .. it wouldn't : http://jsfiddle.net/kv2tzb5n/ http://jsfiddle.net/kv2tzb5n/ (at least in chrome). Would you say this is a good moment to pass judgment on your programming abilities ?
- ars 12y ago> Would you say this is a good moment to pass judgment on your programming abilities ? Sure. Interestingly </hr> is ignored, but <br></br> is parsed as a block of some kind. I did not know this, so yes, you can judge me for it. I know you are poking me for what I said about self closing tags, but I stand by it. I've seen a lot of html, and it's one very easy way to find the bad programmers - they all self close <br>. I'm sure there are exceptions, but I have not come across any. It's a sign of a tutorial programmer (not exactly), maybe, more or a copy/paste programmer, who finds "blocks" of code that work, and just apply it everywhere. They tend to lack the deep fundamentals of how html works.
- ygra 12y agoIt's not parsed as a block of some kind. The standalone <br> is parsed as it should be, without surprises. The closing tag, however, is parsed as another <br> tag. This is usual HTML behaviour, though, and since HTML 5 thoroughly specified.
- xj9 12y agoI use self-closing tags for aesthetic reasons, even though I know they aren't HTML. I like the consistency. I suppose I should get with the times, though, if I am to be taken seriously.
- jontro 12y ago
- grrowl 12y agoThe ever-tolerant HTML browser will automatically fix it up. The irony is in that this XHTML syntax has bled back into some code styles in HTML, however inaccurate in that language, but since the introduction of JSX and React, the self-closing tag is required again (all tags must close, or self-close, to be able to parse the file at all)
- userbinator 12y agoIt's made worse by the fact that such information is getting increasingly difficult to find when someone actually does want to figure out the "why". Maybe it's just me, but I've found Google's search results to be much worse now than they used to be in terms of detail and specificity, for the same queries.
- lelandbatey 12y agoI feel like this is a side effect of so many people writing random blog posts and other things in an attempt to help others, but in the large it makes it less clear because there's such a long tail of documents that are useful (for some things), that people like, but that cannot answer underlying questions or point to where underlying questions can be answered. 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.
- userbinator 12y agoThe worst part is that lots of historical but valuable information is "falling through the gaps" as a result of being overwhelmed by the new and superficial. If archive.org had a real search engine, I'd probably use it more than Google.
- noobermin 12y agoReminds me of the theory for why some words in English have such odd spellings, that at times, scribes would make errors in their copying and since many scribes were illiterate, those errors would propagate and become part of English.
- TazeTSchnitzel 12y agoMonks had a lot of influence on spelling. In French, they abbreviated the "ls" at the end of some words to "x", thus "animals" becoming "animax" (later "animaux", as others added a "u" to make the spelling fit the pronunciation better).
- NamTaf 12y ago'Connexion' is the one I have come across most frequently, and most of that was when an old colleague leant me a book he got as a child about engineering feats from the late 1800s and early 1900s (up to about 1940). They still used the 'x' instead of 'ct' when writing it, though it was British.
- deanmen 12y agoconnexion reflects the Latin etymology -- it comes from the Latin word cōnexiō (junction)
- WalterBright 12y agoMany spellings can be traced back to specific print shops. "would could should", for example.
- kenjackson 12y agoThis is super interesting? Any pointers to good articles about this?
- an_ko 12y agoThere's even a term for it: http://en.wikipedia.org/wiki/Cargo_cult_programming http://en.wikipedia.org/wiki/Cargo_cult_programming
- bunderbunder 12y agoThat term irritates me. 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."
- asveikau 12y ago> the Dispose pattern in .NET, 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.
- samspot 12y agoThat closing slash was never really required. Sure your xhtml won't validate, but it probably wasn't going to anyway. xhtml was recommended in my formative years and I never really broke that habit. I still think input, img, br 'look better' this way. If I am not mistaken, it's not even that it's wrong. I suppose it's a waste of bytes though.
- ars 12y agoWhen I see programmers add useless things that do nothing I wonder about their level of knowledge. Do they know it does nothing and are adding it for looks? Or are they poor programmers who can only program by copy paste? 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.
- aorloff 12y agoOr, are they programmers who have been burned by the arcane few instances where the absence of those relics can still bite you ? (as yet a third, very small distinct class)
- sirrocco 12y agoReally? Is that what you judge a programmer by? I might be annoyed if I see something like what you're talking about, but I'll just point it out and forget about it. PS: I too am from the XHTML era :)
- ars 12y ago> Really? Is that what you judge a programmer by? 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.
- duskwuff 12y agoMy personal favorite example of this is <meta name="MSSmartTagsPreventParsing" content="true">. This meta tag was related to a Windows XP feature that was proposed, but never released due to user backlash. It's never done anything in any released browser.
- comex 12y agoA feature which, incidentally, was adopted in limited form by Apple 6 years later in iPhone Safari, which to this day detects strings of digits that look like phone numbers and makes them into links to call the number (without any [obvious?] distinction from normal links, even), without any backlash whatsoever. The email app does that plus dates and addresses. Admittedly it's not quite the same and circumstances differ, but looking back, that IE backlash really looks like an overreaction. (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...)
- aerique 12y agoDifference is that there's competition in the smartphone space and I can grab an Android / Jolla / Ubuntu phone where I can change my default browser. Apple did not have several years of monopoly behind it by burning away competition and never managed to become a monopoly. 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.
- duskwuff 12y agoAnd crucially, Apple is only using data detectors to create linkages with iOS internal services that aren't otherwise readily accessible to web sites: creating calendar items, dialing the phone, etc. They're not using it, as Microsoft did, to promote their own web sites and services. (Yes, I know you can technically access the phone with a tel: link. But very few web sites do this!)
- A_COMPUTER 12y agoI just got in the habit when XHTML was looking like the Next Thing, I was actually using it in a lot of stuff, XHTML died, and I never stopped doing it that way because I always felt it was more consistent than having some tags be self-closing and some not. Funny enough, I had been doing things using Thymeleaf templating the last couple years, and it does the HTML template as XML, so you have to close all your tags. I think that has to be some kind of procrastination achievement.
- smarterchild 12y agoVestigial structures! http://en.wikipedia.org/wiki/Vestigiality http://en.wikipedia.org/wiki/Vestigiality
- LeoPanthera 12y ago> or using HTML comment marks with Javascript in SCRIPT tags. 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.
- ygra 12y agoAs far as I know, in all browsers that know the script element, it's a non-issue. And even though Lynx won't evaluate JS, it should certainly understand the meaning of the script element. 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.
- TazeTSchnitzel 12y agoIt's not like Lynx development stopped the year JS came out!
- reitanqild 12y agoFor anyone who wasn't there then I think the space between br and / was added because of a parsing bug in Netscape 4 or something.