February 28, 2004
How Not To Get Hated In Web Programming
I have a lot of work to do this weekend. Work that isn't being made easier by the fact that the last people to work on the pages I'm adding to and using as templates decided to go easy on the prep work. By using only the visual editing interfaces in Dreamweaver, and doing a half-buttock job with their CSS, they've guaranteed a miserable time for anyone who goes in after them.
This individual, whose name I don't know, has been getting roundly cursed for days now. If you wish to avoid this terrible fate, and don't mind putting up with HTML jargon, read on.
CSS
Cascading style sheets were intended to be a glorious advance that saved web programmers from having to labor with the tedium of coloring and sizing text with font tags. But guess what? It's no big help when you just tediously color and/or size text with individual in-line style tags.
And future programmers will want to strangle you if for any reason you should write code that nests a font tag inside of a bold tag inside of a span tag inside of a heading tag. Or, at any rate, you can be sure that if I was the next programmer to come along, that's what I'd want to do.
There are these things called external style sheets. Use them. One file per site is usually sufficient. One style per directory is as many as should reasonably be permitted, but only to allow the laziness of using the exact same relative link.
Not only does a universal style help the coder, it helps the visitor. Not everyone coming to your site has a firm grasp on the mechanics of internet use. They may not be entirely clear about the difference between their default search engine and their browser. And that's perfectly fine, because specialization of knowledge is the key to wealth and high culture. Your job as a web programmer is to make things easy on visitors.
Maintaining a consistent style, a uniform look and feel throughout the site reinforces the idea that your entire site is of a piece. That the pages are related to each other, and should be considered as such. If you want to break this sense of continuity, there's no better way than to alter text and color styles from page to page.
And a final external style sheet commandment: Write your CSS in notepad, or similar plain text editor. Do not succumb to the temptation of creating one through pulldown menus. It really is easier to change later because you can look at all your styles laid out on one screen, formatted for your convenience, and cut and paste across them.
Use Existing Tags Whenever Possible
HTML has six heading tags. Six. It's inconceivable that any website needs more heading styles than that. And if you think your site needs more, you're just out of your mind. I can be candid with you because you aren't employing me, so let me repeat.
NO ONE needs more than six heading styles.
You'll probably even have leftovers, and these can also be useful. When doing search engine optimization, the first thing a decent SEO contractor will tell you about coding a page is that heading tags are important. After the URL, the page title (the one found in the head tag that displays at the top of the browser window), and the text of inbound links, search engines look for text in heading tags. The most weight goes to H1, then H2, etc. Use no more than necessary, but don't waste that boost.
When you create your external style sheet, instead of inventing heading tags, modify the existing ones. You can set all the variables just the way you would otherwise. To cover regular text, define your overall font by creating an entry for the body tag. But if you don't want to adjust things at the body tag, make sure that p, li, table, & blockquote tags at the very least have CSS font styles applied to them.
This takes care of the vast majority of text in HTML pages. Every page done thereafter will require only the site template, maybe the occasional font color tweak, and the sort of basic HTML that can be picked up in a weekend.
Making New Styles
Don't get creative, here. Name new styles as plainly and boringly as possible. Don't add unecessary styles just because you think you might someday, maybe, kinda, sorta, might need green italicized 15 point Times New Roman. If you think that last sentence didn't scan well, you should look at the code I've been trying to untangle.
When in doubt, don't. Don't bother making styles that code for only one attribute, because in that case, it's probably easier to use inline code.
Using WYSIWYG Interfaces
Unless you have first gone into the code and made sure that it's tidy and readable, don't create professional pages in WYSIWYG. Edit them, add to them, pull in a template and go to town, but don't rely on them to create readable HTML.
A special note about MS Frontpage: This program is the very devil. Just opening an HTML file in Frontpage changes it. Side effects may range from gibberish tags and formatting to files that can no longer be opened by other editing software. This is not a blanket condemnation of MS software, because their developer suite contains a very good web programming interface called InterDev which is every bit as respectable as Dreamweaver.
You don't have to write all your code in Notepad, but you should know how.
If you don't take direct responsibilty for your code, you'll have only yourself to kick when something goes wrong and you realize that you've got a mess on your hands. Alternately, you might be the recipient of the curses of a strange web programmer doomed to clean up after you.
Now, bugger it, I've got to go clean up after someone.
Posted by natasha at February 28, 2004 01:47 PM | TrackBackYou are the reson this country is in the fix it is in now. All the problems bush is encountering is because of the clinton years. If you would research first before mouthing off ,you wouldn't seem so ignorant. Clinton cut the military personnel and spending in half. He cut and gutted the CIA and the FBI. If you were a smart AMerican you would know that the democratic platform is that of the SDS from the 1960's. A socialistic and communistic form of government. Research research research!!!
Posted by: trace on February 28, 2004 03:37 PMi know how this stuff goes. i spent a bunch of time at one of my jobs redoing a corporate internet site that had been originally created in frontpage & some other web editor. it was loaded with inconsistencies, mistakes, and huge blocks of code that apparently did nothing -- not to mention incomprehensible style names. we won't even get into what the site looked like. or the bad copy.
i hope you get through all of the crap you're having to deal with quickly.
Posted by: Magpie on February 28, 2004 05:34 PMOne of my peeves with HTML is that it doesn't have a <section> container or the like, which means you have to manually tweak all the heading levels when you reorganize your site. It also contributed to the trend in the Bad Old Days of people using <hx> for decoration.
The W3C has long since given up on preserving semantic information, it seems, and now they're just trying to get people to use HTML as merely a presentation language, albeit in a syntactically correct manner. This is why I still use dir and menu, in defiance of their deprecated status.
Aside from my personal site (which I haven't updated in forever, and really need to do), which I plan to switch over, all my HTML is autogenerated anyway, which allows me to do nice things like ensure correct closing tags and the like with a minimum of effort. I have some nice macros to autogenerate the appropriate heading levels, and use CSS in a human-readable and semantically useful manner.
I have to say that I couldn't disagree more with the idea of using Notepad. I've used Wordpad to edit HTML before and it's all right, but Notepad is just way too bare-bones (freaks out if you open a Unix- (and probably Mac-) generated text file, for example) to be of any use. I like XEmacs myself, but I usually use a stripped down HTML mode.
Posted by: vsync on February 29, 2004 01:39 PMMore thoughts on sectioning: LATEX has the same problem as HTML, with \section, \subsection, and \subsubsection. Enabling or disabling numbering is done by appending '*' to the individual command, not document-wide (although I suppose you could redefine the commands to their non-numbered equivalents, but that's ugly).
Both languages also have the problem that section contents are inferred, not specified. So there's the problem of:
<h3>section name</h3>
<p>content</p>
<hr/>
<address>contact info</address>
Here, contact info would be inferred to be under the h3. I suppose you could do <h1>Contact Info</h1>, but that's ugly unless you do <h1 class="contact">… (hmm, that's an idea).
I seem to recall that one browser — can't remember which, but I'm thinking it was Mosaic — allowed you to view an outline of the document, generated from the heading tags, and jump to sections. That was cool.
BTW, you might check out the latest Mozilla Firefox as a tool to help solve some of your woes. Right-click & "view selection source" as well as the DOM Inspector are great tools for parsing information out of third-party pages.
Posted by: vsync on February 29, 2004 01:59 PMAnd future programmers will want to strangle you if for any reason you should write code that nests a font tag inside of a bold tag inside of a span tag inside of a heading tag. Or, at any rate, you can be sure that if I was the next programmer to come along, that's what I'd want to do.You're right. When I moved from Blogger to Movable Type with an entirely different design, I hated myself for all the experimental inline styles I used. After I imported the old entries I found a significant number of them were unreadable because of text color/background color clashes.
Posted by: P6 on March 1, 2004 03:18 PM