Slashdot Mirror


CSS Selectors as Superpowers

An anonymous reader writes "Simon St. Laurent writes in praise of CSS selectors: 'After years of complaints about Cascading Style Sheets, many stemming from their deliberately declarative nature, it's time to recognize their power. For developers coming from imperative programming styles, it might seem hard to lose the ability to specify more complex logical flow. That loss, though, is discipline leading toward the ability to create vastly more flexible systems, a first step toward the pattern matching model common to functional programming.'"

7 of 190 comments (clear)

  1. Completely agree by Chrisq · · Score: 5, Informative

    Anyone who has used JQuery will know how their power exceeds the original intention

  2. Re:!Like by LizardKing · · Score: 5, Informative

    Bollocks. CSS was designed to separate styling from structure in web pages. It does this admirably, and only needs to be a declarative language to do so. This prevents a lot of "clever" hacks that including conditional or flow statements would have encouraged. It's the same reason why statically typed languages are better than dynamic ones - since the tooling and compile time checks can be much more comprehensive and optimisation is easier - but clueless twats prefer the dynamic ones, since they don't understand the downsides or foolishly think they are so good they wont screw up. Improved programmer productivity claims for including flow statements in CSS (or using dynamic languages) are crap as well, since while a programmer might find it easier to cobble together something that just about works, chances are very high that it will be harder to maintain.

  3. Re:!Like by dingen · · Score: 5, Informative

    You have no idea what you're talking about. CSS (and HTML for that matter) have *nothing* to do with programming. CSS is merely a way for designers to code a layout, nothing more, nothing less.

    I do agree CSS could have been a lot better and there are definitely some errors which needs fixing, but the general idea of separating mark up and layout is a sound one and selectors is one of CSS' best features.

    --
    Pretty good is actually pretty bad.
  4. Re:!Like by Anonymous Coward · · Score: 2, Informative

    If that's what you think, then you don't understand why CSS and HTML are separate languages. The implementation is by no means perfect, but its a very good example of Separation of Concerns (separating content from presentation, and in javascript's case, both of those from application logic), something that all too many 'programmers' don't seem to have any idea about. Then again if you're one of those programmers who see SOLID principles as over-engineering then I can understand why you might think that its an 'additional unnecessary third layer'.

  5. Re:Is this a joke? by dingen · · Score: 3, Informative

    Javascript is much more a functional programming language than a procedural one. It's by no means as pure as Haskell, but this also allows it to be useful.

    I suggest you read up on some of the articles by Douglas Crockford, who does an awesome job of explaining the true nature of Javascript to the world. This is a good starting point.

    If you don't believe Javascript is indeed a functional programming, here is a Google Talk by the same Douglas Crockford explaining how to do monads in Javascript: http://www.youtube.com/watch?v=b0EF0VTs9Dc

    --
    Pretty good is actually pretty bad.
  6. Re:No , sorry. by Anonymous Coward · · Score: 1, Informative

    I haven't seen somebody be so wrong here in years. Just about everything you said is bunk or outright bullshit.

    dingen's bullshit claim: You're crazy.

    WRONG. The GP's assertions are completely true, completely correct, and show a very high degree of sanity.

    dingen's bullshit claim: CSS and HTML are completely unrelated languages and technologies.

    WRONG. CSS and HTML are extremely intertwined and heavily related. Anyone who knows their history knows that they arose and evolved as a result of one another's flaws.

    dingen's bullshit claim: None is a hack on top of another.

    WRONG. CSS is a hack upon HTML, and HTML's evolution has been affected by the hack that is CSS. They're both hacks upon one another, over time.

    dingen's bullshit claim: HTML describes the structure of a document, CSS defines how things look.

    WRONG. HTML does affect the appearance of the document, and CSS does influence the structure. In any moderately complex web page, you'll need to consider both at the same time if you want to achieve anything like the desired outcome.

    dingen's bullshit claim: It's that simple.

    WRONG. If you had any real world web development experience, you'd know how utterly wrong this claim is.

    dingen's bullshit claim: They require a different syntax because they are used for different things.

    WRONG. They can both be represented using s-expressions. It's just that the original designers screwed up by not choosing this natural syntax, and none of the major players have chosen to right this wrong.

    dingen's bullshit claim: And they're both very successful at what they're trying to do.

    WRONG. They're essentially the only options available. That's not a sign of "success". Given all the problems people have with them, it's proper to classify them as failures.

    dingen's bullshit claim: Sure there are problems, sure there are things wrong with it, but show me something perfect.

    WRONG. There aren't just "problems". The technologies entirely consist of problems, and entirely exhibit problems. The only type of "perfection" they attain is being perfectly imperfect.

    dingen's bullshit claim: There are two types of languages you know: ones everybody complains about and ones nobody uses.

    WRONG. Wrong, Bjarne. There are languages that smart people use, just because they don't have to constantly complain about them. Python is a good example. JavaScript is not. And HTML and CSS aren't even programming languages, so what you quoted doesn't even apply here!

    dingen's bullshit claim: I have no idea what you mean by "embedded Javascript", but Javascript is the programming language of the web.

    WRONG. No, C and C++ are the programming languages of the Web. They power the operating systems, web servers, database systems, networking devices, high-level server-side programming languages, web browsers, and even the JavaScript implementations used today. JavaScript is a minor client-side player, at best.

    dingen's bullshit claim: Contrary to HTML and CSS, Javascript is a "real" programming language by any definition.

    WRONG. JavaScript is not a programming language. It's a stretch to even call it a scripting language. It's clearly lacking too many critical features to be considered a real programming language.

    dingen's bullshit claim: Without it web applications would not be possible and the web would merely be a document system.

    WRONG. This is by far the most incorrect thing you have said so far. Surprisingly capable web applications existed before JavaScript was first released in 1995, and even well after that, when people were still using browsers that did not support JavaScript. Furthermore, there's nothing stopping browser developers from embedding other languages in their browsers. I suppose you've never used VBScript with Internet Explorer. JavaScrip

  7. Re:CSS should be a programming language by Jason+Levine · · Score: 5, Informative

    Css has been around for 16 years and it still lacks the ability to easily declare a completely separate layout based on display height or width, something like "If width is less than _x_, use this css, else this" or "set width equal to - 30". If you want those things now, you have to use javascript, and it's sometimes pretty awkward - like calculating the width of an element filled with content prior to displaying it.

    Actually, you can do that. I do it all the time when I use responsive web design. Here's some sample CSS code:

    @media screen and (min-width: 501px) and (max-width: 750px) { /* Put styles in here to reformat the page for larger tablets or small desktop resolutions */
    }

    @media screen and (max-width: 500px) { /* Put styles in here to reformat the page for mobile devices and small tablets */
    }

    @media print { /* Put all of your styles in here to format the page for printing. */
    }

    There is no JavaScript at work here. If you loaded a page utilizing this code in Chrome or FireFox (or IE10), disabled JavaScript, and resized the browser to make it smaller, you'd see the page slowly transform from a desktop version to a tablet version to a mobile version. (A good example of this is the Boston Globe's website: http://www.bostonglobe.com/ ). I can set styles for HTML elements and override them if certain conditions are met (max-width is between 2 values, screen resolution is a certain amount, print vs screen, etc). It might not be "if-then" statements, but it has the same effect.

    --
    My sci-fi novel, Ghost Thief, is now available from Amazon.com.