Don’t waste time writing HTML and CSS
When you've worked with front-end development for a while, you start thinking about effectiveness. So without further ado, here's my four best ways to be a more effective front-end developer. Feel free to add more ideas as comments!
1. Do you need HTML or CSS for this?#
Lots of times when I get stranded on hard problem and sit back, I realize that I really shouldn't be trying to use CSS to solve all layout problems. Assuming a rounded corner box will have to scale in all directions (up to 8 images!), when it really is fixed width and height (1 image), is an indescribable waste of everyone's time. Look closely at the design you're trying to implement: does it really have to be as flexible and scalable as you think? Shifting to that mindset saves me hours of work per day.
One thing that many developers forget is that not all designers care for exact pixels. If something is really hard to develop, walk over to their table and suggest a change. You'll soon start to notice that designers are real people too, and that they have as much flexibility as you do. It's just as easy to call them up, so don't let shyness waste your time.
2. Try to set properties once#
When you know you have to do something (see above), try to do things once. This is really tricky in both HTML and CSS, languages that have no variables, and generally makes code reuse a pain. But it is possible.
With CSS; set widths of elements once, and trust inner elements to fill their parent. That's the default behavior of block level elements, and you can set display: block, or width: 100% on most other elements. Don't set heights at all if you can avoid them, and let elements expand to fill their containers. Combine similar CSS selectors to avoid typing things twice, and make new ones for common properties when few properties differ. Use floats and clearing instead of absolute positioning, and you'll won't have to micromanage positions all the time.
With HTML, make sure that you really know the template language. I've fighted with ASP.NET, JSP, JSTL, Smarty, WordPress Themes, RHTML, and Django's Templating Language, and now know enough about all of them to be productive. You should never have to type the same structure out twice, even in HTML. If your template language have loops, if-clauses and includes you really have no excuse to copy large chunks of HTML around. Refactor your HTML and make your own life easy.
3. Learn your text editor#
When code reuse isn't possible, use search/replace in your favorite text editor.
Replacing all instances of one HTML tag name with another is about replacing "element>" with "element2>" (without the opening bracket). That way you replace both opening and ending tags at once. Check to see if your editor supports regular expressions in its search/replace tool. If it does you can save lots of time by learning it. Matching a HTML tag is "<[^>]+>", a starting angel bracket, one or more non-brackets, followed by an ending angel bracket. Naive regexps can make you match the starting bracket of one tag and the end of another, which makes for a mess.
There's lots of little tricks like that, if you learn them you save massive amounts of time.
4. Make sure your environment supports you#
There's more than the text editor that you have to work with. One essential part of front-end development is trial and error. It sounds silly but no matter what your skill is, sometimes you must resort to trying and testing your way to a solution. With HTML and CSS, this means being able to quickly make a change, switch window, and see that change in the browser. If that cycle takes more that 5 seconds, you're losing valuable time.
Don't use a virtual machine (even if it's only for IE6) that you can't quickly Alt-Tab out of. If you're stuck using one, you need to have the text editor on that machine too. It's worth your time fixing it.
Don't accept build processes that makes you wait more than 5-10 seconds before you see your changes. With trial and error coding you will then waste 50% of your capacity doing nothing. Most often you can bypass this by copying just the HTML and CSS to the right place, without touching other source-code. I've managed to do this in all kinds of crappy environments, and it's always worth it.
So.
I hope some of the above can help you save some time each day. The little things add up you know. What's your best time-saver?
Comments
By: trobrock (#1)
By: Jrf (#2)
One remark about the regex and matching more than you want:
This can be easily avoided. You rightly point out that regexes are greedy. To make a regex non-greedy, add an '?' after the repetition qualifier.
For your example:
<.+> is greedy
<.+?> is the non-greedy version
By: Jrf (#3)
I hope the example is still clear enough even though the regex has been cut in half.
By: Charlie Park (#4)
By: Charlie Park (#5)
By: Emil Stenström (#6)
@Charlie Park: ah, I knew I forgot about one important point. I also have a CSS structure I use.
By: James Socol (#7)
And like Emil and @Charlie Park, I have a similar CSS structure that I use to avoid breaking things. It saves a lot of time.
By: Don’t waste time writing HTML and CSS | WhiteSandsDigital.com (#8)
By: Heather (#9)
By: Stephen (#10)
By: zcorpan (#11)
Looks fine in Opera, Firefox 3 and IE7.
By: James Socol (#12)
By: Emil Stenström (#13)
@Heather: Sorry for the headline! Thanks for the linkback :)
By: James Socol (#14)
By: Rasmus Kaj (#15)
And I'd like to reverse the first item! :-)
Most of a site can and should be developed in plain html+css. When that is no longer practical, some xslt/jsp/php/etc and/or javascript can be usefull. In extreme cases, even flash can have its points.
Lots of sites seems to use flash and/or giant javascript toolboxes for no actual reason. That's fine for a playground project, but a real project for a real client should be built up from the usecase, not down from the cool widget ...
Despite this, a good text and sound advice. Thanks! :-)
By: Tyler (#16)
Many good tips for increasing productivity. One suggestion with tip #4 is to get a second monitor. Having side by side monitors has made me close to 30% more efficient. It's difficult to work without 2 monitors now.
Tyler,
http://www.whatdivs.com
By: David McNorton (#17)
By: ask (#18)
By: Emil Stenström (#19)
@Rasmus Kaj: For the special case of expert users I agree with you. But for most other cases, people don't have any idea of how to resize the browser window, so they will get too long lines.
@Tyler, ask: Good tips!
By: Rasmus Kaj (#20)
Too many sites specify a content width in pixels, and a tiny font. A user who finds tiny fonts uncomfortable soon learns to change the font size (ctrl +), but then many layouts break down.
By: Johan (#21)
- Reusing code blocks
By: Justin Ferrara (#22)
By: chrisco (#23)
Found your blog through a link on the Geek Meet Stockholm page. Glad I found it :)
Thanks,
Chris
BuzzPal.com/Team
PS: I am looking for concept development / user experience / user interaction design type folks. Let me know if you know any good ones or send them my way. Thanks.
By: Emil Stenström (#24)
By: James Socol (#25)
overflow: hidden
, I suppose. (The New York Times' site always comes to mind.)Two things which are, in my experience, true: people change the text size, and lots of people still use IE6 and Firefox 2.
Maybe you can choose to ignore the needs of that audience. I can't. Especially in light of the Target vs NFB settlement in this country.
By: Emil Stenström (#26)
By: James Socol (#27)
I'm not worried about default behavior. Hopefully the design properly handles all the text at its default size (or you can manually hyphenate). I'm worried about what happens when you hit
ctrl +
.By: Emil Stenström (#28)
By: James Socol (#29)
By: Emil Stenström (#30)
By: James Socol (#31)
Now, maybe you can say the risk of law suits is minimal, or you're too small to care, or you just don't care. But if you use
em
s, it will scale by itself, so it can't zoom "too much."By: Emil Stenström (#32)
We seem to also have different ideas about how to make a scaling layout. It's not just about throwing some ems in there. But we're not getting anywhere with this discussion, so lets just concentrate on something else. Thanks!
By: Denver Web Development (#33)
By: Anonymous (#34)
By: Justin (#35)
thanks,
makingcolor staff
By: Case pariuri (#36)
The Anonymous above me gave an excellent advice, ty for sharing it mate!