An empirical study on the use of CSS Preprocessors Davood Mazinanian Nikolaos Tsantalis Department of Computer Science and Software Engineering Concordia.

Slides:



Advertisements
Similar presentations
Web Pages Week 10 This week: CSS Next week: CSS – Part 2.
Advertisements

Layout using CSS. Using multiple classes In the head:.important{font-style:italic;}.title{color:red;} In the body: Here's a type of paragraph that is.
Discovering Refactoring Opportunities in Cascading Style Sheets Davood Mazinanian Nikolaos Tsantalis Ali Mesbah Concordia University, Montréal, Canada.
Recognizing the Benefits of Using CSS 1. The Evolution of CSS CSS was developed to standardize display information CSS was slow to be supported by browsers.
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
Cascade Style Sheet Demo. Cascading Style Sheets Cascading Style Sheets (CSS) is a simple mechanism for adding style (e.g., fonts, colors, spacing) to.
“Cascading Style Sheets” for styling WWW information DSC340 Mike Pangburn.
An empirical study on the use of CSS Preprocessors Davood Mazinanian - Nikolaos Tsantalis Department of Computer Science and Software Engineering Concordia.
AD Intermediate Computer Graphics | spring 2008 | Daria Tsoupikova | School of Art and Design | UIC CSS Cascading Style Sheets.
XP 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
Working with Cascading Style Sheets. 2 Objectives Introducing Cascading Style Sheets Using Inline Styles Using Embedded Styles Using an External Style.
CSS (Cascading Style Sheets): How the web is styled Create Rules that specify how the content of an HTML Element should appear. CSS controls how your web.
Working with Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of a document.
Cascading Style Sheets CS3505. What are CSS? Method for adding style attributes consistently to HML tags Cascading because styles are applied in order.
XP Tutorial 7New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks.
Using Styles and Style Sheets for Design
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
CS134 Web Design & Development Cascading Style Sheets (CSS) Mehmud Abliz.
Davood Mazinanian, Nikolaos Tsantalis Concordia University, Montreal CSER FALL 2013 MEETING 1 An Empirical Study of Duplication in Cascading Style Sheets.
INTRODUCTION TO CSS. TOPICS TO BE DISCUSSED……….  Introduction Introduction  Features of CSS Features of CSS  Creating Style Sheet Creating Style Sheet.
CSS PREPROCESSORS Michael and Miles. Overview What are CSS Preprocessors Why use them? What is LESS and how to use LESS example What is SASS and how to.
SASS & LESS Syntactically Awesome StyleSheets Dynamic StyleSheet Language Svetlin Nakov Technical Trainer Software University
1 CSS-PREPROCESSORS as a way to speed up the process of interfaces developing and achieve Customer goals DMITRY SHURSHILIN AUGUST 3, 2015.
Introduction to CSS. Why CSS? CSS Provides Efficiency in Design and Updates CSS relatively easy to use Can give you more flexibility and control Faster.
CNIT 132 – Week 4 Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of.
Copyright © Osmosys O S M O S Y SO S M O S Y S D e p l o y i n g E x p e r i e n c e & E x p e r t i s e™ CSS Training.
 HTML, CSS, JavaScript – enormously successful  SASS has all the tools we need! INTRO.
Martin Kruliš by Martin Kruliš (v1.0)1.
Understanding CSS Cascading Style Sheets control the presentation of content in HTML pages Style Sheets separate formatting from the content –Styles defined.
HTML 5 AND CSS Dr Mohd Soperi Mohd Zahid Semester /16.
XP Tutorial 7New Perspectives on HTML and XHTML, Comprehensive 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
CSS Introductions. Objectives To take control of the appearance of a Web site by creating style sheets. To use a style sheet to give all the pages of.
WebD Introduction to CSS By Manik Rastogi.
CSS.
Working with Cascading Style Sheets
Migrating CSS to Preprocessors by Introducing Mixins
Simple theme creation using Sass
4.01 Cascading Style Sheets
Google fonts CSS box model
The Box Model in CSS Web Design – Sec 4-8
Unit 3 - Review.
Advanced Web Page Styling
>> The “Box” Model
Cascading Style Sheets
Box model.
Cascading Style Sheets (Layout)
Web Systems & Technologies
>> CSS Layouts.
Web Development & Design Foundations with HTML5 7th Edition
Chapter 7 Page Layout Basics Key Concepts
Web Development & Design Foundations with HTML5 8th Edition
Web Development & Design Foundations with HTML5
CSS.
Basics of Web Design Chapter 7 Page Layout Basics Key Concepts
6 Layout.
CSS PreProcessors MIS 424.
CSS Borders and Margins.
CSS Box Model.
>> Dynamic CSS Selectors
Software Refactoring Group
Web Development & Design Foundations with H T M L 5
Cascading Style Sheets™ (CSS)
Web Development & Design Foundations with HTML5
HTML / CSS Mai Moustafa Senior Web Designer eSpace eSpace.
Web Development & Design Foundations with HTML5
CSS and Class Tools.
Cascading Style Sheets
4.01 Cascading Style Sheets
Presentation transcript:

An empirical study on the use of CSS Preprocessors Davood Mazinanian Nikolaos Tsantalis Department of Computer Science and Software Engineering Concordia University – Montreal, Canada

Cascading Style Sheets (CSS) div { color: gray; } Declaration … … … … … … … … HTML document SelectorValueProperty Limitations: Lack of variables, functions, etc. Duplication is pervasive! 2 / 25

CSS Preprocessors Transpilers that add the missing features Variables, functions, loops, conditionals, mathematical operations, etc. Ruby-like syntax (*.sass) CSS-like syntax (*.scss) 3 / 25

Motivation Automatic migration (CSS to Preprocessors) Refactoring recommendation (Preprocessors) Suggest preprocessor language improvements 4 / 25

Experiment design Subjects 5 / websites (*.sass) (*.less) 50 (*.scss) 1,266 preprocessor files

Feature #1: Variables Goal: reduce styling errors, improve maintainability 1px solid #EDEDEE; ….ui.menu { … … }.ui.table { … … }.ui.menu { … border: 1px solid #EDEDEE; … }.ui.table { … border: 1px solid #EDEDEE; … } Preprocessor From Semantic-UI (version 1.6.2) CSS 6 / 25

RQ1 How developers use variables? Scope of variables PreprocessorGlobal (%)Local (%)Total Less956 (95.79)42 (4.21)998 Sass917 (84.67)166 (15.33)1,083 SCSS1,387 (88.34)183 (11.66)1,570 Total3,260 (89.29)391 (10.71)3,651 7 / 25

RQ1 How developers use variables? Value types 8 / 25

RQ1 Conclusions When migrating to variables: Prefer global (89.3%) to local variables (10.7%) Favor variables with color values (46%) 9 / 25

Feature #2: Nesting Goal: improve organization, understandability.navbar-toggle { position: relative; float: right; … &:focus { outline: 0; } ….icon-bar { display: block; width: 22px; … } … } PreprocessorCSS From Bootstrap (version 3.3.1).navbar-toggle { position: relative; float: right; … }.navbar-toggle:focus { outline: 0; } ….navbar-toggle.icon-bar { display: block; width: 22px; … } … 10 / 25

RQ2: How developers use nesting Nesting can be applied to special selectors Combinators (A B, A>B, A+B, A~B) Pseudo elements (a::before) Pseudo classes (a:hover) 78.5% of all selectors were nestable Out of those nestable selectors, 78% were actually nested 11 / 25 nestable selectors

RQ2: How developers use nesting Nesting depth 12 / 25

RQ2 Conclusions Nesting must be supported in migration techniques It’s a popular feature (78% of selectors are nested) Mostly for shallow nesting hierarchies (depth 1 or 2) 13 / 25

Feature #3: Mixins Goal: improve reusability and readability From Bootstrap CSS library (version 3.3.1) div.content { font: 13px Tahoma; padding: 5px;.border(2px, 4px, 3px) { table { margin: 5px;.border(1px, { border: black; outline: ridge } div.content { font: 13px Tahoma; padding: 5px; border: solid 2px black; border-radius: 4px; outline: ridge black 3px; } table { margin: 5px; border: solid 1px black; border-radius: 3px; outline: ridge black 0; } PreprocessorCSS 14 / 25

RQ3 How developers use mixins? Mixin reuse Number of mixin calls 15 / 25

RQ3 How developers use mixins? Mixin reuse Number of mixin calls Wilcoxon Signed-Rank Test (p-value: ) #Mixins called more than once > #Mixins called only once 16 / 25

RQ3 How developers use mixins? Size of mixins (#declarations) 17 / 25

RQ3 How developers use mixins? Number of mixin parameters 18 / 25

RQ3 How developers use mixins? Mixin parameter reuse 89% of vendor-specific properties reuse at least one parameter 19% of the parameters were reused across non-vendor-specific 2px) { /* Webkit */ /* Mozilla */ /* W3C */ } 19 / 25

RQ3 Conclusions Mixins can be useful for: Eliminating duplication (63% two or more mixin calls) Decomposing long selectors (37% one mixin call) When migrating to mixins: Small size (median = 3 declarations) Small number of parameters (median = 1) Include vendor-specific properties (42%) Preprocessors can be extended with: Built-in mixins for vendor-specific properties 20 / 25

Feature #4: Extend Goal: improve reusability.dropdown-menu { min-width: 220px; border: none; margin-top: 9px;... }.select2-drop { min-width: 220px; border: none; margin-top: 9px;... visibility: visible;... }.dropdown-menu { min-width: 220px; border: none; margin-top: 9px;... }.select2-drop { &:extend(.dropdown-menu); visibility: visible;... } Preprocessor CSS From Flat-UI (version 2.2.2) 21 / 25

RQ4: How developers use extend No usages in the Less dataset ~5 usages per file for Sass/SCSS Extend can be replaced with mixins with no parameters!.dropdown-menu { min-width: 220px; border: none; margin-top: 9px; }.select2-drop { min-width: 220px; border: none; margin-top: 9px; visibility: visible; … } CSS.mixin() { min-width: 220px; border: none; margin-top: 9px; }.dropdown-menu {.mixin(); }.select2-drop {.mixin(); visibility: visible; … } Preprocessor 22 / 25

RQ4: How developers use extend Extend vs. no-parameter mixin 23 / 25

RQ4 Conclusions When migrating to preprocessors: Prefer no-parameter mixins to extend Extend might break the presentation semantics Preprocessor transpilers can be extended to: Warn the developers when using extend carelessly! 24 / 25

Current and future work Current work Automatic extraction of mixins Challenges: parameterizing differences, ranking opportunities, checking presentation preservation Future work Conduct developer surveys for validation How does preprocessor code evolve over time? Visit for data + codehttp://users.encs.concordia.ca/~d_mazina/papers/SANER'16/ 25 / 25

RQ4: How developers use extend Breaking the presentation by using Extend! table { float: left; &:extend(.zeroSpacing) } table { margin: 2px; }.zeroSpacing { margin: 0; padding: 0; } table { float: left; } table { margin: 2px; }.zeroSpacing, table { margin: 0; padding: 0; } Preprocessor CSS 26

Motivation Credits: css-tricks.com/poll-results-popularity-of-css-preprocessors/ 27

Experiment design Analyzed preprocessor files 28