CSS syntax naming conventions

My next Stack Exchange Challenge post will most likely be about the Programmers SE. One part of the challenge is to actually ask a question I have on the topic. The question I came up with (to be honest, this has been bothering me for months now) took quite some time to write down carefully. So, as I don’t have my next SE Challenge post ready yet, I decided to cross-post my question here on my blog as well.

The Question: what are the practical considerations for the syntax in class and id values?

Note that I’m not asking about the semantics, i.e. the actual words that are being used, as for example described in this blogpost. There are a lot of resources on that side of naming conventions already, in fact obscuring my search for practical information on the various syntactical bits: casing, use of interpunction (specifically the - dash), specific characters to use or avoid, etc.

To sum up the reasons I’m asking this question:

  • The naming restrictions on id and class don’t naturally lead to any conventions
  • The abundance of resources on the semantic side of naming conventions obscure searches on the syntactic considerations
  • I couldn’t find any authorative source on this
  • There wasn’t any question on SE Programmers yet on this topic

Some of the conventions I’ve considered using:

CSS naming conventions
CSS naming conventions
  1. UpperCamelCase, mainly as a cross-over habit from server side coding
  2. lowerCamelCase, for consistency with JavaScript naming conventions
  3. css-style-classes, which is consistent with naming of css properties (but can be annoying when Ctrl+Shift+ArrowKey selection of text)
  4. with_under_scores, which I personally haven’t seen used much
  5. alllowercase, simple to remember but can be hard to read for longer names
  6. UPPERCASEFTW, as a great way to annoy your fellow programmers (perhaps combined with option 4 for readability)

And probably I’ve left out some important options or combinations as well. So: what considerations are there for naming conventions, and to which convention do they lead?

Episode 1: Cooking Stack Exchange Challenge

Cooking Stack Exchange
Cooking Stack Exchange

Last week I announced the little Stack Exchange Challenge that I’d designed for myself. In this post I will be doing the first episode, featuring the Cooking Stack Exchangesite. This post should be the first in a series. I’ll try to stick to a format, though it may evolve a little over the episodes.

Important note: in all cases, I try to go through the site and actually contribute as a well-behaved member of the community. I’d love to be able to ask questions, answer some, and will up and downvote if it seems appropriate; but only if it is appropriate! Afterwards, I’ll summarize:

  • The questions I may have asked.
  • The answers I may have given.
  • Some questions that I found interesting and subsequently upvoted.
  • Noteworthy “community wiki” questions and answers.
  • A conclusion.

So, let’s move on to the Cooking site.

Current Statistics

First up, the current “fun facts” for this particular sub-site:

Fact Cooking.SE
Questions 5,336
Questions with no upvoted answers 56 (1.05%)
FAQ (questions with most links) 1,617
Top 3 questions 134 votes, 72 votes, 59 votes
Questions active last hour 3
All-time rep for top 3 users 27.6k, 23.4k, 19.1k
Meta questions 386

Not the biggest SE site, but still a decent volume of knowledge.

Photo's for the dishwasher-fish-recipe
Photo’s for the dishwasher-fish-recipe

My Questions

To be honest, my choice to do Cooking SE for the first episode was because I wanted to answer a particular question. When I wanted to do so it turned out that I needed to have earned at least 10 rep before I was even allowed to answer that question. Not to worry though, there were two actual questions I still had from my own cooking experiments in the past few weeks, so I came up with these:

My Answers

This section was the reason I picked Cooking SE first: I was very eager to provide an answer with empirical evidence for one particular question:

My wife and I were laughing uncontrollably when it turned out the experiment was successful. It was extremely fun to write this particular answer. Afterwards, I felt the urge to thank the creators of Stack Exchange, and so I did via Twitter. To my surprise and excitement @CodingHorror a.k.a. Jeff Atwood almost immediately retweeted this to his 65,000 (!) followers. What followed were several retweets, favorites, upvotes for the answers, and wonderful direct responses about my answer. This made me realize: I love the interwebs!

Interesting questions

There were several very interesting questions on this site for a home chef. Don’t expect any recipes (which are probably subjective and thus off-topic), but do expect very practical tips. Some questions I enjoyed:

Community Wiki

At first sight, there was just one real “ultimate list” question that caught my eye:

Conclusion

The Q&A format of Stack Exchange seems perfect for a particular type of cooking questions. Once you’re used to the fact that things like recipe-requests are off-topic you’ll start to appreciate the practical aspect of this site.

Probably because it’s a sister site to things like Stack Overflow, several top users note in their  bio that they’re “fulltime computer guy, part-time amateur chef“. That probably means I’m going to have a lot of fun there!

Stack Exchange Challenge

My new hobby: the great Stack Exchange sites.

In the 90’s most of my questions on software development were either answered by friends and family, trial and error, or books. I’ve always loved reading books on this topic. Most of my books have some particular animal on the cover, from the company with a man on a mission. In addition to books, the new millenium lured me to the Google Groups on C#. It seems at the time of writing this only a “new” Google Groups exists, which is a good thing: even though I enjoyed reading and posting there very much, the spam drove me (and many others) away.

Of course, just Google Search remained a very decent source for answers to development questions. In recent years, the search results have slowly started to point to one particular site: Stack Overflow. The various interesting sister sites quickly grabbed my attention.

I can highly recommend looking at the sites they have, and joining some of the discussions. Overall, the communities seemed very friendly to me as long as you put effort and thought in your questions and answers. Personally, I’m seriously considering to set myself up for a challenge and investigate one site a time, with perhaps a blog post on my findings. Now where shall I begin?

Shredder

Shredder, nemesis of the TMNT!
Shredder, nemesis of the TMNT!

Trading my three year old PC for a bottle of whisky (or is it whiskey?) to a friend seems like a great deal. With several work-related files left on my computer, it felt like a great opportunity to try out a shredding tool. So I figured I’d just Google for the popular choice and try it out.

Then I got submerged in a whirlpool of information. Some folks linked to “non geek perspectives”, for example this article on 4 file shredder tools. Others gave walls of text on the technical details. I was in fact hoping to find some article on the Dutch hardware.info site on this topic. In the end the Stack Exchange site for “power users” gave me the most info through a dedicated file-shredding-tag.

And there, finally: a great list of shredding options! Options all around: bootable CDs, hidden Windows 7 tools, as well as a  great post on Scott Hanselman’s blog. For some reason one of the answers with almost the least amount of answers caught my attention.

So I downloaded a bootable ISO of Ubuntu and fired it up. First I tried the “basic” suggestion:

The terminal screen just sat there, with a blinking caret. Apparently I’d entered a staring contest. After some time I decided to hit the enter key a few times in the console: the caret moved. After a minute of pondering I tried CTRL+C: and the operation got cancelled. I’d lost the staring competition, that’s for sure.

Now, this staring contest had taken about one hour. So I decided to try the second suggestion:

No dice. Utterly confising console error messages. Since I’m mot quite a Linux guru like these guys, I did some more searching around. Finally I found some more detailed instructions on hdparm. First I had to unfreeze my drive, and I had to set a password (though I don’t quite grasp why). Then the moment of truth…

Ever since I’ve been in yet another staring contest with Ubuntu. Only this time I’m gonna win, or die trying!


Update: after over two hours the staring contest is over… and won! The console returns to normal. At first, it seems Ubuntu can still browse the drives. But, after a reboot, there is not a single file, folder or partition to be found anymore!

CSS first-letter drop caps

A little while ago this interesting Stack Overflow question caught my attention. The question is about drop caps: a typographical gimmick where the first letter of a paragraph is very big and prominent. In older texts this could be even more than “prominent”, for example this page from an old Dutch Bible:

Drop caps in an old Dutch Bible
Drop caps in an old Dutch Bible

Of course, the CSS pseudo-selector :first-letter seems perfect to achieve this effect on the web. The question on Stack Overflow used that as a starting point, and is about a particular situation where IE wouldn’t render correctly. While trying to find a solution to that particular problem I found out things were not so simple, and posted this answer. The answer basically came down to “no way to get it right in all browsers”. With rather “standard” CSS rules, various browsers gave varying results:

Rendering of drop caps in various browsers
Various browsers render drop caps differently

Not very satisfying at all! After thinking about this some more, I decided to try and at least get a “minimal” example of drop caps working in all current browsers. To keep things “minimal” my first try will:

  • Not bother with padding for now (just set them all at zero);
  • Not bother (yet) with browsers <IE9;
  • Stick to the basic 26 characters from the latin alphabet;
  • Stick with uppercase versions of those characters.

It took some time, but I did come up with decent results. You can show the example html file on my blog, or view it as a jsfiddle. The example contains a reset style and some coloring so you can see the results clearly. However, the nitty gritty is in this bit of CSS:

This actually gives acceptable and mostly consistent results. Here’s a screenshot of how this renders in up to date versions of my browsers (all on Windows 7):

Drop caps experiment in IE9
IE9
Drop caps experiment in Chrome
Google Chrome
Drop caps experiment in Opera
Opera
Drop caps experiment in Firefox
Firefox

Great! However, one browser is still not playing nice. No, not everyone’s “favorite” browser IE is acting weird, but Firefox is! Have a closer look at the left (:first-letter) rendering in Firefox: the height of the drop cap isn’t what we want it to be. However, some searching on Google leads to a related Stack Overflow question as well as this question, ultimately leading me to a bug from 2007 in Firefox. Guess it can’t be done easily then.

End of the road? Perhaps. But perhaps also a great opportunity to try and create a jQuery plugin that creates drop caps…

Eye love you

At work I spend most of my time looking at a computer screen. At home I also spend most of my time looking at a computer screen. Basically: I spend a lot of time looking at a computer screen. Recently I’ve been looking for ways to make this as pleasant as possible. So far I’ve come up with the following:

  • I’ve installed bias lighting after reading this.
  • From the same article I found out Windows 7 has a built-in screen setup procedure in the media center app (it turns out LCD factory settings are on “eye scorching brightness”).
  • Work in progress: getting a new set of hi-res screens at work. See point 9 on The Joel Test.
  • Changing my monospace font to one in this top 10 list. Courier New is apparently almost as bad as Comic Sans.
  • I’m also experimenting with inverted color schemes for my programming tools: C# and JavaScript disguised as Ruby!

In the next few months there will be more changes to my setup, most likely. First up would be a second LCD, although I can’t seem to decide if I want the exact same monitor twice, or perhaps a different one next to my HD one. Either way, so far these changes were more than welcome: can’t imagine how I got along without them.

Interested? Go for it! Show your eyes some love!

Programming music

Lying is useless: I’m addicted… to music. Just about whatever I do, I will have music in the background. Especially when I’m working on the computer: programming, photo-shopping, video-editing, gaming all require music.

Different activities and varying times of day require different types of music for me. Luckily, I enjoy just about all kinds of music. The growing popularity of Spotify has driven both di.fm and last.fm radio from my favorites, and allows me to pick just about anything I want to hear.

This brings us back to the topic of this post then (hope no-one was expecting a guide on how to program music on some device), music for programming duties! I realized I put on certain types of music whenever I’m in a certain type of zone. So here’s a go at my music choice per programming task.

Task Music Genre
Creating C# interfaces, designing server side code Dubstep or Classical Music
C# code (or any server side code, for that matter) Any album that’s very familiar, e.g. Homework
Database design & SQL queries (SELECTs) Electro, Hardstyle, or even some old Gabber tunes
SQL UPDATEs and DELETEs Ambient or downbeat
CSS and HTML (skinning and the like) 90s dance or dirty house
Debugging a difficult problem Classical music or Gregorian chants
Creating wireframes More dubstep
Excel formulas and VBA macros Death Metal or Industrial Powernoise
Footnote: recently ghettofunk has been a great fallback for any programming task. Stickybuds!

Hopefully I’ll be able to look back at this post some time in the future and create an updated overview. Perhaps this will even inspire someone to up a music-programming cross table of their own. If you do: let me know!

Re-discovering JavaScript

Around 1995 I started creating web pages. HTML was my friend, and analogous to the story of Adam and Eve, a companion called CSS was created. I considered HTML to be the robust male of the relationship, and CSS giving the beautiful female touch to my web pages.

Then Darkness came.

A brand new player invaded my perfect little web world and tried to make it into a love triangle. Enter JavaScript. At first this new technique looked awesome to me. I knew Turbo C++ 3.0  (with a nice DOS look and feel) as well as Visual Basic, and was eager to add some dynamic features to my web pages.

Oh how I underestimated the complexity. I knew no patterns, none of my code had ever been reviewed by others, and I tried to figure out everything with trial and error. Plus: I didn’t understand the DOM at all. So I ended up writing stuff like this:

The above snippet must have cost me a week to figure out. I was so frustrated I wanted to ban JavaScript from my pages as much as possible, which is exactly what I did when I learned to use Perl to add dynamic features to web sites.

More than a decade passed, but Darkness was still looming. I tried to stay in the Light with my happy couple HTML and CSS (only tolerating incidental guest appearances by JavaScript). I even turned to WinForms programming in .NET so I wouldn’t have to face the Darkness.

But then my ASP.NET days came, and it turned out: JavaScript was here to stay. However, my second encounter with JavaScript was mediated by jQuery, which had powers rivaling those of Dr. Phil himself. That library makes JavaScript feel like the love child of HTML and CSS, with a dynamic twist.

And so, JavaScript is getting a second chance. Any leftover JavaScript frustrations were explained in this presentation: I started to use JavaScript without ever learning it. So I picked up the corresponding book by Douglas Crockford, which shall be followed by The Definitive Guide. Hopefully this will allow me to Learn to Stop Worrying and Love the Bomb.


Foot note: at the time of writing, the piece of JavaScript code in this post is still running in production, in a Web Shop created in the 90’s, using Perl 5, HTML4, CSS2, and a hint of JavaScript…

Content is King

After having several months of fun with various Social Media, I found Twitter to be the best one for me. Took me a while before I understood why. It’s the quick fire-and-forget blogging “flavor” that I enjoy. Not only is it fun to fire some thoughts onto the web myself, but also to see other people’s thoughts, jokes, and other random goodness.

At the same time I was trying out Twitter I also took up a blogging project, using my World of Warcraft addiction to generate content. Because it’s true:

Content is king!

So after finishing that blogging project with my final episode (an Interactive Youtube Adventure), I sort of landed in a void. Without any more content: what was I to blog about? Besides: who’d want to read what I have to say?

The answer is: who cares!? You can also just blog for your own pleasure (or to overcome your fear of writing). So that’s exactly what I’ll do!