SlideShare a Scribd company logo
1 of 51
How to Write Beautiful Code
Beautiful Code = Maintainable Code
©10/3/2015
STRIKE A BALANCE
How To
©10/3/2015
Clarity and Transparency
• Clarity is how easily a reader can deduce
what the code does.
• If code seems to do one thing but actually
does something else (or something more),
it's misleading.
• Transparent code does what it seems to
do.
©10/3/2015
FUN FACTOID
Jeff Dean writes directly in binary. He
then writes the source code as a
documentation for other developers.
©10/3/2015
Elegance
• There are many ways to write code that
works.
• However some ways are clumsy while
other ways are neat and graceful.
• Succinctness often adds elegance, but
excessive succinctness can reduce clarity.
• A code artist finds the balance.
©10/3/2015
Reducing Markup
Whenever possible,
avoid superfluous
parent elements when
writing HTML.
Many times this
requires iteration and
refactoring, but
produces less HTML.
<!-- Not so great -->
<span class="avatar">
<img src="...">
</span>
<!-- Better -->
<img class="avatar"
src="...">
©10/3/2015
FUN FACTOID
Jeff Dean's IDE doesn't do code
analysis, it does code appreciation.
©10/3/2015
Efficiency
• Writing code beautifully avoids
unnecessary use of server resources and
reduces page load metrics.
• TTFB: Time to First Byte
• TTI: Time to Interact
• Efficiency = Better SEO and CRO
©10/3/2015
FUN FACTOID
Jeff Dean was forced to invent
asynchronous APIs one day when
he optimized a function so that it
returned before it was invoked.
©10/3/2015
Aesthetics
• Artful code is easy on the eyes.
• Create code style guides & policies
upfront.
• Use post processing tools, such as
CSSCOMB & JSLint.
• Code must be reviewed regularly for
compliance with policies.
©10/3/2015
FUN FACTOID
Jeff Dean acquired Sawzall readability after
writing 58 lines of Sawzall code. As part of
his readability review, he pointed out a flaw
in the style guide which was promptly
corrected by the reviewer.
©10/3/2015
PERFECTION VS BUDGET
Keeping YOUR Balance
©10/3/2015
It’s not a one step process.
• It’s art. Not perfection.
• Perfection = Blown Budget = Angry Client
= Bad Business
• Over time your code base ends up
cleaner, brighter and more beautiful.
©10/3/2015
WHO IS JEFF DEAN?
So…
©10/3/2015
Just the facts, ma’am!
• Google Senior Fellow who designed a lot
of Google's biggest projects including the
main search infrastructure.
• Jeff pumped out elegant code like a
champagne fountain at a wedding.
• Effortless code is not the norm.
©10/3/2015
BY DEFINITION
Coding
©10/3/2015
HTML Elements
The HTML element is everything from the
start tag to the end tag.
<p>My first HTML paragraph.</p>
UPDATE: In HTML5 some elements are
self-closing.
©10/3/2015
HTML Attributes
• HTML elements can have attributes.
• Attributes provide additional information
about an element.
• They are specified in the start tag.
• Attributes come in name/value pairs like:
name="value“
Examples: <a href= <img src= alt=
©10/3/2015
Boolean Attributes
• HTML and XHTML boolean attributes
should not be confused with boolean
values.
• The presence of a boolean attribute on an
element = the true value, and the absence
of the attribute = the false value.
<input type=“text” name=“example” disabled>
©10/3/2015
CSS Selectors
• CSS selectors allow you to select and
manipulate HTML elements.
• Are used to "find" (or select) HTML
elements based on their id, class, type,
attribute, and more.
h1, h2, p {
text-align: center;
color: red;
}
©10/3/2015
CSS Declarations
A CSS rule set consists of a selector and a
declaration block.
©10/3/2015
CSS Property Values
• Color
• Background and Borders
• Basic Box
• Flexible Box
• Text
• Text Decoration
• Fonts
• Writing Modes
• Table
• Lists and Counters
• Animation
• Transform
• Basic User Interface
• Multi-column
• Paged Media
• Generated Content
• Filter Effects
• Image/Replaced Content
• Masking
• Speech
• Marquee
©10/3/2015
CSS Color Parameters
Can be specified in the following ways:
• Hexadecimal colors
• RGB colors
• RGBA colors
• HSL colors
• HSLA colors
• Predefined/Cross-browser color names
©10/3/2015
BY THE GOLDEN RULE
Coding
©10/3/2015
ENFORCE THESE GUIDELINES
AT ALL TIMES.
Whether working together or alone…
©10/3/2015
The Beautiful Code
Cheat Sheet
©10/3/2015
Syntax
• Use soft tabs with two spaces—they're the
only way to guarantee code renders the
same in any environment.
• Nested elements should be indented once
(two spaces).
• Always use double quotes, never single
quotes, on attributes.
• Don't include a trailing slash in self-closing
elements.
• Don’t omit optional closing tags (e.g. </li> or
</body>).
©10/3/2015
Example
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<img src="images/company-logo.png" alt="Company">
<h1 class="hello-world">Hello, world!</h1>
</body>
</html>
©10/3/2015
HTML5 doctype
Enforce standards mode & more consistent
rendering in every browser possible with this
simple doctype at the beginning of every HTML
page.
<!DOCTYPE html>
<html>
<head>
</head>
</html>
©10/3/2015
Language Attribute
Always include it. Why?
• It aids speech synthesis tools to determine
what pronunciations to use.
• It helps translation tools to determine what
rules to use.
<html lang="en-us">
©10/3/2015
IE Compatibility Mode
• Internet Explorer supports the use of a
document compatibility <meta> tag to
specify what version of IE the page should
be rendered as.
• Unless circumstances require otherwise,
it's most useful to instruct IE to use the
latest supported mode with edge mode.
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
©10/3/2015
Character Encoding
• This isn’t just for internationals!!!
• Using it, quickly & easily ensures proper
rendering of your content.
• When doing so, you may avoid using
character entities in your HTML.
<head>
<meta charset="UTF-8">
</head>
©10/3/2015
CSS & JavaScript Includes
Default: text/css
<!-- External CSS -->
<link rel="stylesheet"
href=“website.css">
<!-- In-document CSS -->
<style>
/* ... */
</style>
Default: text/javascript
<!-- JavaScript -->
<script
src="website.js"></scrip
t>
©10/3/2015
Attribute Order
For readability, use
this order:
• class
• id, name
• data-*
• src, for, type, href,
value
• title, alt
• role, aria-*
<a class="..." id="..."
data-toggle="modal"
href="#"> Example link
</a>
<input class="form-
control" type="text">
<img src="..." alt="...">
©10/3/2015
The Beautiful Code
Cheat Sheet
©10/3/2015
CSS Syntax
Proper Indention
Use soft tabs with two
spaces—they're the
only way to guarantee
code renders the
same in any
environment.
<head>
<meta charset="UTF-8">
</head>
©10/3/2015
CSS Syntax
Selectors
When grouping
selectors, keep
individual
selectors to a
single line.
/* Bad CSS */
.selector, .selector-secondary, .selector[type=text] {
/* Good CSS */
.selector,
.selector-secondary,
.selector[type="text"] {
©10/3/2015
CSS Syntax
Declarations
Include one
space before
the opening
brace of
declaration
blocks for
legibility.
/* Bad CSS */
.selector{
padding: 15px;
margin-bottom: 15px; }
/* Good CSS */
.selector {
padding: 15px;
margin-bottom: 15px;
}
©10/3/2015
CSS Syntax
Declarations
Place closing
braces of
declaration
blocks on a new
line.
/* Bad CSS */
.selector[type="text"] {
padding: 15px;
margin-bottom: 15px; }
/* Good CSS */
.selector[type="text"] {
padding: 15px;
margin-bottom: 15px;
}
©10/3/2015
CSS Syntax
Declarations
Include one
space after :
for each
declaration.
/* Bad CSS */
box-shadow:0px 1px 2px #CCC,inset 0 1px 0
#FFFFFF
/* Good CSS */
box-shadow: 0 1px 2px #ccc, inset 0 1px 0 #fff;
©10/3/2015
CSS Syntax
Declarations
End all
declarations
with a semi-
colon, including
the last one.
/* Bad CSS */
box-shadow:0px 1px 2px #CCC,inset 0 1px 0
#FFFFFF
}
/* Good CSS */
box-shadow: 0 1px 2px #ccc, inset 0 1px 0 #fff;
}
©10/3/2015
CSS Syntax
Property and
Color Values
Comma-
separated
property values
should include
a space after
each comma.
/* Bad CSS */
box-shadow:0px 1px 2px #CCC,inset 0 1px 0
#FFFFFF
}
/* Good CSS */
box-shadow: 0 1px 2px #ccc, inset 0 1px 0 #fff;
}
©10/3/2015
CSS Syntax
Property and
Color Values
Don't prefix
property values or
color parameters
with a leading zero.
/* Bad CSS */
margin:0px 0px 15px;
/* Good CSS */
margin-bottom: 15px;
©10/3/2015
CSS Syntax
Property and Color
Values
• Lowercase all hex
values, e.g., #fff.
• Use shorthand
hex values where
available, e.g., #fff
instead of #ffffff.
Why?
Lowercase letters are much
easier to discern when
scanning a document as they
tend to have more unique
shapes.
©10/3/2015
CSS Syntax
Zero Values
Avoid specifying
units for zero
values.
/* Bad CSS */
margin: 0px;
/* Good CSS */
margin: 0;
©10/3/2015
Declaration Order
Related property declarations should be
grouped together following the order:
– Positioning
– Box model
– Typographic
– Visual
©10/3/2015
Don't use @import
It is slower, adds extra
page requests, and can
cause other problems.
• Use multiple <link>
elements
• Compile your CSS
with a preprocessor
like Sass or Less into
a single file.
<!-- Avoid @imports -->
<style> @import url("more.css");
</style>
<!-- Use link elements -->
<link rel="stylesheet" href="core.css">
©10/3/2015
/* Comments */
Lastly, comment, comment, comment!
Keep in mind that Code is written &
maintained by people.
Ensure your code is descriptive, well
commented, and approachable by others.
©10/3/2015
/* Comments */
Great code comments convey context or
purpose. Do not simply reiterate a
component or class name.
©10/3/2015
/* Bad example */
/* Modal header */
.modal-header {
...
}
/* Good example */
/* Wrapping element for .modal-title and .modal-close */
.modal-header {
...
}
#1 CSS Resource
High-level advice and guidelines for
writing sane, manageable, scalable CSS:
http://cssguidelin.es/
CSS Guidelines is developed by Harry Roberts, a Consultant Front-end Architect from the UK.
©10/3/2015
Conclusion
When you learn to write code beautifully, you
will be compared to Jeff Dean, who…
…has to unoptimize his code so that
reviewers believe it was written by a human.
©10/3/2015

More Related Content

What's hot

A quick guide to Css and java script
A quick guide to Css and  java scriptA quick guide to Css and  java script
A quick guide to Css and java scriptAVINASH KUMAR
 
Chapter 2 introduction to html5
Chapter 2 introduction to html5Chapter 2 introduction to html5
Chapter 2 introduction to html5nobel mujuji
 
Is it time to start using HTML 5
Is it time to start using HTML 5Is it time to start using HTML 5
Is it time to start using HTML 5Ravi Raj
 
Designing for the web - 101
Designing for the web - 101Designing for the web - 101
Designing for the web - 101Ashraf Hamdy
 
Html 5 tutorial - By Bally Chohan
Html 5 tutorial - By Bally ChohanHtml 5 tutorial - By Bally Chohan
Html 5 tutorial - By Bally Chohanballychohanuk
 
SUGUK Cambridge - Display Templates & JSLink for IT Pros
SUGUK Cambridge - Display Templates & JSLink for IT ProsSUGUK Cambridge - Display Templates & JSLink for IT Pros
SUGUK Cambridge - Display Templates & JSLink for IT ProsPaul Hunt
 
The Future of the Web: HTML5
The Future of the Web: HTML5The Future of the Web: HTML5
The Future of the Web: HTML5Derek Bender
 
Web development basics (Part-1)
Web development basics (Part-1)Web development basics (Part-1)
Web development basics (Part-1)Rajat Pratap Singh
 
Web Development Basics: HOW TO in HTML
Web Development Basics: HOW TO in HTMLWeb Development Basics: HOW TO in HTML
Web Development Basics: HOW TO in HTMLDer Lo
 
Lightning Talk: Bending Markdown to Your Will with Your Static Site Generator
Lightning Talk: Bending Markdown to Your Will with Your Static Site GeneratorLightning Talk: Bending Markdown to Your Will with Your Static Site Generator
Lightning Talk: Bending Markdown to Your Will with Your Static Site GeneratorLeon Barnard
 
Css types internal, external and inline (1)
Css types internal, external and inline (1)Css types internal, external and inline (1)
Css types internal, external and inline (1)Webtech Learning
 
HTML, CSS and Java Scripts Basics
HTML, CSS and Java Scripts BasicsHTML, CSS and Java Scripts Basics
HTML, CSS and Java Scripts BasicsSun Technlogies
 
Spsbe using js-linkanddisplaytemplates
Spsbe   using js-linkanddisplaytemplatesSpsbe   using js-linkanddisplaytemplates
Spsbe using js-linkanddisplaytemplatesPaul Hunt
 
Intro to HTML, CSS & JS - Internship Presentation Week-3
Intro to HTML, CSS & JS - Internship Presentation Week-3Intro to HTML, CSS & JS - Internship Presentation Week-3
Intro to HTML, CSS & JS - Internship Presentation Week-3Devang Garach
 
BEM Methodology — @Frontenders Ticino —17/09/2014
BEM Methodology — @Frontenders Ticino —17/09/2014BEM Methodology — @Frontenders Ticino —17/09/2014
BEM Methodology — @Frontenders Ticino —17/09/2014vzaccaria
 

What's hot (19)

A quick guide to Css and java script
A quick guide to Css and  java scriptA quick guide to Css and  java script
A quick guide to Css and java script
 
HTML5 & CSS3
HTML5 & CSS3 HTML5 & CSS3
HTML5 & CSS3
 
Chapter 2 introduction to html5
Chapter 2 introduction to html5Chapter 2 introduction to html5
Chapter 2 introduction to html5
 
Is it time to start using HTML 5
Is it time to start using HTML 5Is it time to start using HTML 5
Is it time to start using HTML 5
 
Designing for the web - 101
Designing for the web - 101Designing for the web - 101
Designing for the web - 101
 
Html 5 tutorial - By Bally Chohan
Html 5 tutorial - By Bally ChohanHtml 5 tutorial - By Bally Chohan
Html 5 tutorial - By Bally Chohan
 
SUGUK Cambridge - Display Templates & JSLink for IT Pros
SUGUK Cambridge - Display Templates & JSLink for IT ProsSUGUK Cambridge - Display Templates & JSLink for IT Pros
SUGUK Cambridge - Display Templates & JSLink for IT Pros
 
The Future of the Web: HTML5
The Future of the Web: HTML5The Future of the Web: HTML5
The Future of the Web: HTML5
 
Web development basics (Part-1)
Web development basics (Part-1)Web development basics (Part-1)
Web development basics (Part-1)
 
Web Development Basics: HOW TO in HTML
Web Development Basics: HOW TO in HTMLWeb Development Basics: HOW TO in HTML
Web Development Basics: HOW TO in HTML
 
Lightning Talk: Bending Markdown to Your Will with Your Static Site Generator
Lightning Talk: Bending Markdown to Your Will with Your Static Site GeneratorLightning Talk: Bending Markdown to Your Will with Your Static Site Generator
Lightning Talk: Bending Markdown to Your Will with Your Static Site Generator
 
Css types internal, external and inline (1)
Css types internal, external and inline (1)Css types internal, external and inline (1)
Css types internal, external and inline (1)
 
HTML, CSS and Java Scripts Basics
HTML, CSS and Java Scripts BasicsHTML, CSS and Java Scripts Basics
HTML, CSS and Java Scripts Basics
 
Spsbe using js-linkanddisplaytemplates
Spsbe   using js-linkanddisplaytemplatesSpsbe   using js-linkanddisplaytemplates
Spsbe using js-linkanddisplaytemplates
 
Html Expression Web
Html Expression WebHtml Expression Web
Html Expression Web
 
HTML/CSS Lecture 1
HTML/CSS Lecture 1HTML/CSS Lecture 1
HTML/CSS Lecture 1
 
CSS
CSSCSS
CSS
 
Intro to HTML, CSS & JS - Internship Presentation Week-3
Intro to HTML, CSS & JS - Internship Presentation Week-3Intro to HTML, CSS & JS - Internship Presentation Week-3
Intro to HTML, CSS & JS - Internship Presentation Week-3
 
BEM Methodology — @Frontenders Ticino —17/09/2014
BEM Methodology — @Frontenders Ticino —17/09/2014BEM Methodology — @Frontenders Ticino —17/09/2014
BEM Methodology — @Frontenders Ticino —17/09/2014
 

Similar to How to Write Beautiful Code That is Maintainable and Efficient

IT230-Assignment 1 Solved.pdf
IT230-Assignment 1 Solved.pdfIT230-Assignment 1 Solved.pdf
IT230-Assignment 1 Solved.pdfDark179280
 
HTML5, CSS, JavaScript Style guide and coding conventions
HTML5, CSS, JavaScript Style guide and coding conventionsHTML5, CSS, JavaScript Style guide and coding conventions
HTML5, CSS, JavaScript Style guide and coding conventionsKnoldus Inc.
 
css and Input attributes
css and Input attributescss and Input attributes
css and Input attributesSiji P
 
html css intro sanskar , saurabh.pptx
html css intro  sanskar , saurabh.pptxhtml css intro  sanskar , saurabh.pptx
html css intro sanskar , saurabh.pptxSanskardubey24
 
WEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptxWEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptxkarthiksmart21
 
Structuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSStructuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSSanjoy Kr. Paul
 
Doing More with LESS for CSS
Doing More with LESS for CSSDoing More with LESS for CSS
Doing More with LESS for CSSTodd Anglin
 
Introduction to Web Development.pptx
Introduction to Web Development.pptxIntroduction to Web Development.pptx
Introduction to Web Development.pptxAlisha Kamat
 
Introduction to Web Development.pptx
Introduction to Web Development.pptxIntroduction to Web Development.pptx
Introduction to Web Development.pptxGDSCVJTI
 
Introduction to Web Development.pptx
Introduction to Web Development.pptxIntroduction to Web Development.pptx
Introduction to Web Development.pptxAlisha Kamat
 
Make Css easy : easy tips for css
Make Css easy : easy tips for cssMake Css easy : easy tips for css
Make Css easy : easy tips for cssshabab shihan
 
HTML email design and usability
HTML email design and usabilityHTML email design and usability
HTML email design and usabilityKeith Kmett
 
Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8RohanMistry15
 

Similar to How to Write Beautiful Code That is Maintainable and Efficient (20)

IT230-Assignment 1 Solved.pdf
IT230-Assignment 1 Solved.pdfIT230-Assignment 1 Solved.pdf
IT230-Assignment 1 Solved.pdf
 
HTML5, CSS, JavaScript Style guide and coding conventions
HTML5, CSS, JavaScript Style guide and coding conventionsHTML5, CSS, JavaScript Style guide and coding conventions
HTML5, CSS, JavaScript Style guide and coding conventions
 
Creative Guidelines
Creative GuidelinesCreative Guidelines
Creative Guidelines
 
css and Input attributes
css and Input attributescss and Input attributes
css and Input attributes
 
html css intro sanskar , saurabh.pptx
html css intro  sanskar , saurabh.pptxhtml css intro  sanskar , saurabh.pptx
html css intro sanskar , saurabh.pptx
 
WEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptxWEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptx
 
Html and html5 cheat sheets
Html and html5 cheat sheetsHtml and html5 cheat sheets
Html and html5 cheat sheets
 
DHTML
DHTMLDHTML
DHTML
 
css-tutorial
css-tutorialcss-tutorial
css-tutorial
 
css-tutorial
css-tutorialcss-tutorial
css-tutorial
 
Structuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSStructuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSS
 
Doing More with LESS for CSS
Doing More with LESS for CSSDoing More with LESS for CSS
Doing More with LESS for CSS
 
Introduction to Web Development.pptx
Introduction to Web Development.pptxIntroduction to Web Development.pptx
Introduction to Web Development.pptx
 
Introduction to Web Development.pptx
Introduction to Web Development.pptxIntroduction to Web Development.pptx
Introduction to Web Development.pptx
 
Introduction to Web Development.pptx
Introduction to Web Development.pptxIntroduction to Web Development.pptx
Introduction to Web Development.pptx
 
Make Css easy : easy tips for css
Make Css easy : easy tips for cssMake Css easy : easy tips for css
Make Css easy : easy tips for css
 
HTML
HTMLHTML
HTML
 
Lecture2 CSS1
Lecture2  CSS1Lecture2  CSS1
Lecture2 CSS1
 
HTML email design and usability
HTML email design and usabilityHTML email design and usability
HTML email design and usability
 
Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8
 

Recently uploaded

AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxellan12
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsThierry TROUIN ☁
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024APNIC
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirtrahman018755
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
Radiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsRadiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsstephieert
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts servicesonalikaur4
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersDamian Radcliffe
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With RoomVIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Roomishabajaj13
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$kojalkojal131
 

Recently uploaded (20)

AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with Flows
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girls
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Radiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsRadiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girls
 
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With RoomVIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
 

How to Write Beautiful Code That is Maintainable and Efficient

  • 1. How to Write Beautiful Code Beautiful Code = Maintainable Code ©10/3/2015
  • 2. STRIKE A BALANCE How To ©10/3/2015
  • 3. Clarity and Transparency • Clarity is how easily a reader can deduce what the code does. • If code seems to do one thing but actually does something else (or something more), it's misleading. • Transparent code does what it seems to do. ©10/3/2015
  • 4. FUN FACTOID Jeff Dean writes directly in binary. He then writes the source code as a documentation for other developers. ©10/3/2015
  • 5. Elegance • There are many ways to write code that works. • However some ways are clumsy while other ways are neat and graceful. • Succinctness often adds elegance, but excessive succinctness can reduce clarity. • A code artist finds the balance. ©10/3/2015
  • 6. Reducing Markup Whenever possible, avoid superfluous parent elements when writing HTML. Many times this requires iteration and refactoring, but produces less HTML. <!-- Not so great --> <span class="avatar"> <img src="..."> </span> <!-- Better --> <img class="avatar" src="..."> ©10/3/2015
  • 7. FUN FACTOID Jeff Dean's IDE doesn't do code analysis, it does code appreciation. ©10/3/2015
  • 8. Efficiency • Writing code beautifully avoids unnecessary use of server resources and reduces page load metrics. • TTFB: Time to First Byte • TTI: Time to Interact • Efficiency = Better SEO and CRO ©10/3/2015
  • 9. FUN FACTOID Jeff Dean was forced to invent asynchronous APIs one day when he optimized a function so that it returned before it was invoked. ©10/3/2015
  • 10. Aesthetics • Artful code is easy on the eyes. • Create code style guides & policies upfront. • Use post processing tools, such as CSSCOMB & JSLint. • Code must be reviewed regularly for compliance with policies. ©10/3/2015
  • 11. FUN FACTOID Jeff Dean acquired Sawzall readability after writing 58 lines of Sawzall code. As part of his readability review, he pointed out a flaw in the style guide which was promptly corrected by the reviewer. ©10/3/2015
  • 12. PERFECTION VS BUDGET Keeping YOUR Balance ©10/3/2015
  • 13. It’s not a one step process. • It’s art. Not perfection. • Perfection = Blown Budget = Angry Client = Bad Business • Over time your code base ends up cleaner, brighter and more beautiful. ©10/3/2015
  • 14. WHO IS JEFF DEAN? So… ©10/3/2015
  • 15. Just the facts, ma’am! • Google Senior Fellow who designed a lot of Google's biggest projects including the main search infrastructure. • Jeff pumped out elegant code like a champagne fountain at a wedding. • Effortless code is not the norm. ©10/3/2015
  • 17. HTML Elements The HTML element is everything from the start tag to the end tag. <p>My first HTML paragraph.</p> UPDATE: In HTML5 some elements are self-closing. ©10/3/2015
  • 18. HTML Attributes • HTML elements can have attributes. • Attributes provide additional information about an element. • They are specified in the start tag. • Attributes come in name/value pairs like: name="value“ Examples: <a href= <img src= alt= ©10/3/2015
  • 19. Boolean Attributes • HTML and XHTML boolean attributes should not be confused with boolean values. • The presence of a boolean attribute on an element = the true value, and the absence of the attribute = the false value. <input type=“text” name=“example” disabled> ©10/3/2015
  • 20. CSS Selectors • CSS selectors allow you to select and manipulate HTML elements. • Are used to "find" (or select) HTML elements based on their id, class, type, attribute, and more. h1, h2, p { text-align: center; color: red; } ©10/3/2015
  • 21. CSS Declarations A CSS rule set consists of a selector and a declaration block. ©10/3/2015
  • 22. CSS Property Values • Color • Background and Borders • Basic Box • Flexible Box • Text • Text Decoration • Fonts • Writing Modes • Table • Lists and Counters • Animation • Transform • Basic User Interface • Multi-column • Paged Media • Generated Content • Filter Effects • Image/Replaced Content • Masking • Speech • Marquee ©10/3/2015
  • 23. CSS Color Parameters Can be specified in the following ways: • Hexadecimal colors • RGB colors • RGBA colors • HSL colors • HSLA colors • Predefined/Cross-browser color names ©10/3/2015
  • 24. BY THE GOLDEN RULE Coding ©10/3/2015
  • 25. ENFORCE THESE GUIDELINES AT ALL TIMES. Whether working together or alone… ©10/3/2015
  • 26. The Beautiful Code Cheat Sheet ©10/3/2015
  • 27. Syntax • Use soft tabs with two spaces—they're the only way to guarantee code renders the same in any environment. • Nested elements should be indented once (two spaces). • Always use double quotes, never single quotes, on attributes. • Don't include a trailing slash in self-closing elements. • Don’t omit optional closing tags (e.g. </li> or </body>). ©10/3/2015
  • 28. Example <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <img src="images/company-logo.png" alt="Company"> <h1 class="hello-world">Hello, world!</h1> </body> </html> ©10/3/2015
  • 29. HTML5 doctype Enforce standards mode & more consistent rendering in every browser possible with this simple doctype at the beginning of every HTML page. <!DOCTYPE html> <html> <head> </head> </html> ©10/3/2015
  • 30. Language Attribute Always include it. Why? • It aids speech synthesis tools to determine what pronunciations to use. • It helps translation tools to determine what rules to use. <html lang="en-us"> ©10/3/2015
  • 31. IE Compatibility Mode • Internet Explorer supports the use of a document compatibility <meta> tag to specify what version of IE the page should be rendered as. • Unless circumstances require otherwise, it's most useful to instruct IE to use the latest supported mode with edge mode. <meta http-equiv="X-UA-Compatible" content="IE=Edge"> ©10/3/2015
  • 32. Character Encoding • This isn’t just for internationals!!! • Using it, quickly & easily ensures proper rendering of your content. • When doing so, you may avoid using character entities in your HTML. <head> <meta charset="UTF-8"> </head> ©10/3/2015
  • 33. CSS & JavaScript Includes Default: text/css <!-- External CSS --> <link rel="stylesheet" href=“website.css"> <!-- In-document CSS --> <style> /* ... */ </style> Default: text/javascript <!-- JavaScript --> <script src="website.js"></scrip t> ©10/3/2015
  • 34. Attribute Order For readability, use this order: • class • id, name • data-* • src, for, type, href, value • title, alt • role, aria-* <a class="..." id="..." data-toggle="modal" href="#"> Example link </a> <input class="form- control" type="text"> <img src="..." alt="..."> ©10/3/2015
  • 35. The Beautiful Code Cheat Sheet ©10/3/2015
  • 36. CSS Syntax Proper Indention Use soft tabs with two spaces—they're the only way to guarantee code renders the same in any environment. <head> <meta charset="UTF-8"> </head> ©10/3/2015
  • 37. CSS Syntax Selectors When grouping selectors, keep individual selectors to a single line. /* Bad CSS */ .selector, .selector-secondary, .selector[type=text] { /* Good CSS */ .selector, .selector-secondary, .selector[type="text"] { ©10/3/2015
  • 38. CSS Syntax Declarations Include one space before the opening brace of declaration blocks for legibility. /* Bad CSS */ .selector{ padding: 15px; margin-bottom: 15px; } /* Good CSS */ .selector { padding: 15px; margin-bottom: 15px; } ©10/3/2015
  • 39. CSS Syntax Declarations Place closing braces of declaration blocks on a new line. /* Bad CSS */ .selector[type="text"] { padding: 15px; margin-bottom: 15px; } /* Good CSS */ .selector[type="text"] { padding: 15px; margin-bottom: 15px; } ©10/3/2015
  • 40. CSS Syntax Declarations Include one space after : for each declaration. /* Bad CSS */ box-shadow:0px 1px 2px #CCC,inset 0 1px 0 #FFFFFF /* Good CSS */ box-shadow: 0 1px 2px #ccc, inset 0 1px 0 #fff; ©10/3/2015
  • 41. CSS Syntax Declarations End all declarations with a semi- colon, including the last one. /* Bad CSS */ box-shadow:0px 1px 2px #CCC,inset 0 1px 0 #FFFFFF } /* Good CSS */ box-shadow: 0 1px 2px #ccc, inset 0 1px 0 #fff; } ©10/3/2015
  • 42. CSS Syntax Property and Color Values Comma- separated property values should include a space after each comma. /* Bad CSS */ box-shadow:0px 1px 2px #CCC,inset 0 1px 0 #FFFFFF } /* Good CSS */ box-shadow: 0 1px 2px #ccc, inset 0 1px 0 #fff; } ©10/3/2015
  • 43. CSS Syntax Property and Color Values Don't prefix property values or color parameters with a leading zero. /* Bad CSS */ margin:0px 0px 15px; /* Good CSS */ margin-bottom: 15px; ©10/3/2015
  • 44. CSS Syntax Property and Color Values • Lowercase all hex values, e.g., #fff. • Use shorthand hex values where available, e.g., #fff instead of #ffffff. Why? Lowercase letters are much easier to discern when scanning a document as they tend to have more unique shapes. ©10/3/2015
  • 45. CSS Syntax Zero Values Avoid specifying units for zero values. /* Bad CSS */ margin: 0px; /* Good CSS */ margin: 0; ©10/3/2015
  • 46. Declaration Order Related property declarations should be grouped together following the order: – Positioning – Box model – Typographic – Visual ©10/3/2015
  • 47. Don't use @import It is slower, adds extra page requests, and can cause other problems. • Use multiple <link> elements • Compile your CSS with a preprocessor like Sass or Less into a single file. <!-- Avoid @imports --> <style> @import url("more.css"); </style> <!-- Use link elements --> <link rel="stylesheet" href="core.css"> ©10/3/2015
  • 48. /* Comments */ Lastly, comment, comment, comment! Keep in mind that Code is written & maintained by people. Ensure your code is descriptive, well commented, and approachable by others. ©10/3/2015
  • 49. /* Comments */ Great code comments convey context or purpose. Do not simply reiterate a component or class name. ©10/3/2015 /* Bad example */ /* Modal header */ .modal-header { ... } /* Good example */ /* Wrapping element for .modal-title and .modal-close */ .modal-header { ... }
  • 50. #1 CSS Resource High-level advice and guidelines for writing sane, manageable, scalable CSS: http://cssguidelin.es/ CSS Guidelines is developed by Harry Roberts, a Consultant Front-end Architect from the UK. ©10/3/2015
  • 51. Conclusion When you learn to write code beautifully, you will be compared to Jeff Dean, who… …has to unoptimize his code so that reviewers believe it was written by a human. ©10/3/2015