SlideShare a Scribd company logo
Writing code for people
Alexey Ivanov, Evil Martians
Writing code for people
Evil Martians
Evil Martians
Writing code for people
Let's talk about
writing
—  Know how to write letters?
—  Know how to write words?
—  Know how to write sentences?
—  Do you write emails, Line messages, or tweets every day?
—  Published articles in magazines or books?
Do you know how to write?
7
Writing code is the
same
—  You open your code from one year ago and can't remember how it works.
—  You spend half of the day adding debug and console.log to functions
to see what they are doing.
—  You tried to read another person's code and can't understand it.
—  ^ Another person probably thought the same about your code too.
Have you been in these situations?
9
Most of programming tutorials and books teach how to write code that can
be understood by the computer and do some stuff with it.
Very few books and tutorials teach how to write code that other people can
read and understand.
This is a common situation
10
You write code once. But you and other people will be reading and modifying
it tens or even hundreds of times after that.
So it's crucial to write code that is readable, reusable, and refactorable.
But it's not a good situation
11
Writing code for people
Writing code for
people
As with any other skill, if you will be mindful of what you are writing and spend
enough time training, you will become better at this.
It's a skill that can be learned
14
1.  Writing the code — principles, rules, style guides, and linters.
2.  Reading the code — how to train yourself to become a better writer.
Talk structure
15
Writing the code
1.  Clean code.
2.  Easy to understand code.
3.  Code that shares context.
Writing the code
17
Clean code
—  Select one code style.
—  Automate it.
—  Forget about it.
Clean code
19
There are tons of existing style guides:
—  https://standardjs.com/
—  https://github.com/airbnb/javascript
—  https://google.github.io/styleguide/jsguide.html
—  Standard Prettier settings
Choose any of them. It's not important which one. Don't spend time on that.
Select a code style
CLEAN CODE
20
—  eslint for Javascript or TypeScript.
—  stylelint for CSS.
—  rubocop for Ruby.
—  prettier — tool that can automatically fix style for multiple languages.
Linters usually have excellent documentation about when and why to use
each rule.
Add linters
CLEAN CODE
21
—  eslint-config-airbnb
—  eslint-config-standard
—  stylelint-config-standard
The good thing about using a popular style guide is the fact that it is already
automated.
Add standard config for linters
CLEAN CODE
22
—  Add prettier and linter plugins to your editor.
—  Enable automatic fixing in prettier .
—  Add precommit hook that automatically format/lint your code.
—  Run your checks in CI (CircleCI or TravisCI will do).
Enable automatic linting and fixing
CLEAN CODE
23
Demo
Again, it's not important what style you choose. Toss a coin if you like. You
can always automatically reformat it later.
Forget about it
CLEAN CODE
25
Easy to
understand code
1.  Readability.
2.  Complexity.
3.  Reading flow.
Easy to understand code
27
Bad:
const yyyymmdstr = moment().format("YYYY/MM/DD");
Good:
const currentDate = moment().format("YYYY/MM/DD");
Use meaningful and pronounceable
variable names
READABILITY
28
Bad:
setTimeout(blastOff, 86400000);
Good:
const MILLISECONDS_IN_A_DAY = 86_400_000;
setTimeout(blastOff, MILLISECONDS_IN_A_DAY);
Use searchable names
READABILITY
29
Bad:
function createMenu(title, body, buttonText, cancellable) {
// ...
}
createMenu("Foo", "Bar", "Baz", true);
Function arguments (2 or fewer ideally)
READABILITY
30
Good:
function createMenu({ title, body, buttonText, cancellable })
// ...
}
createMenu({
title: "Foo", body: "Bar",
buttonText: "Baz", cancellable: true
});
Function arguments (2 or fewer ideally)
READABILITY
31
Bad:
function createFile(name, temp) {
if (temp) {
fs.create(`./temp/${name}`);
} else {
fs.create(name);
}
}
Don't use flags as function parameters
READABILITY
32
Good:
function createFile(name) {
fs.create(name);
}
function createTempFile(name) {
createFile(`./temp/${name}`);
}
Don't use flags as function parameters
READABILITY
33
—  Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin
⽇本語
—  https://github.com/ryanmcdermott/clean-code-javascript   ⽇本語 —
examples was from there.
—  https://github.com/ryanmcdermott/3rs-of-software-architecture
—  JS UX: Writing code for Humans by Lea Verou
Further reading
READABILITY
34
One of the sighs of the bad code is complexity:
—  Large functions that do multiple things at once.
—  Too many arguments for the function.
—  Multiple nested IFs or callbacks.
Complexity
35
You can automate detection of such things. For example with Eslint:
—   complexity  — Cyclomatic Complexity
—   max-depth
—   max-statements
—   max-nested-callbacks
Be careful. Following these rules blindly can produce harder to read code.
Automation
COMPLEXITY
36
—  How often do you go back and forth between functions and methods in the
file?
—  How many files do you need to open to understand how something works?
—  Are the files that you are switching between are close to each other or do you
need to go to different nested folders?
Sometimes it is better to break complexity rules to make the reading
flow easier.
Reading flow
37
dropdown/
locale/
en.json
jp.json
index.js
index.test.js
readme.md
styles.css
Place things close to each other
READING FLOW
38
Code that shares
context
Old code:
window.ga("send", {
hitType: "event",
eventCategory: "Videos",
eventAction: "play",
eventLabel: "Fall Campaign",
eventValue: 10
});
Replacing GA with GTM
EXAMPLE
40
New code:
window.dataLayer.push({
category: "Videos",
action: "play",
label: "Fall Campaign",
value: 10
});
Replacing GA with GTM
EXAMPLE
41
Solution:
const event = { /* ... */ }
const eventPlaceholder = {
label: undefined, value: underfined
};
window.dataLayer.push({ ...eventPlaceholder, ...event });
Replacing GA with GTM
EXAMPLE
42
1.  You can't just leave the code" as is" – next developer can delete it while
refactoring, and they spend eight more hours debugging it.
2.  You can't ask other people to review this code without telling them what it is
doing and why.
3.  Other people can't update and maintain this code.
But how do you share this knowledge?
43
/*
GTM sets all event fields as global variables inside itself,
so until we rewrite them, they will have old values. Because
label and value are optional fields, we need to unset them
for the next events explicitly. Relevant docs:
- https://developers.google.com/tag-manager/devguide
- https://support.google.com/tagmanager/answer/6164391?hl=en
*/
Use comments
44
Code can't explain why the program is being written, and the rationale for
choosing this or that method. Code cannot discuss the reasons certain
alternative approaches were taken.
Jeff Raskin
What is context?
“
45
For example:
/* A binary search turned out to be slower than the
Boyer-Moore algorithm for the data sets of interest,
thus we have used the more complex, but faster method
even though this problem does not at first seem
amenable to a string search technique. */
Jeff Raskin
What is context?
46
@media (--sm-scr) {
.input {
font-size: 16px; /* prevents iOS auto-scale on focus */
}
}
CSS example
47
React Source
GIT Source
—  The reader needs a context that can't be expressed using other means.
—  The code exists because of the environment issues. Browser bugs, for
example.
—  The ugly solution is chosen because of speed optimization reasons.
When to comment
50
Writing code for people
—  Code Tells You How, Comments Tell You Why by Jeff Artwood
—  The Art of Comments by Sarah Drasner
Links
52
1.  Clean code.
2.  Easy to understand code.
1.  Readability.
2.  Complexity.
3.  Reading flow.
3.  Code that shares context.
Summary of the first part
53
Reading the code
1.  Code reading.
2.  Code reviews.
3.  Pair Programming.
Reading the code
55
Code reading
Douglas Crockford — Goto There and Back Again starting from 27:15
Code reading
57
Crockford's method:
1.  Do it every day.
2.  Discuss approaches, patterns, and possible solutions.
3.  Don't judge. Don't use results as metrics.
Code reading
58
Who should read:
1.  Reading by the author — faster to do, better at describing context, but
fewer chances to find problems.
2.  Reading by the other person — slower, requires more steps, more useful
feedback on writing.
Code reading
59
You can use methodology from usability testings for the additional effect:
—  Think aloud. Make assumptions about what variables and functions will do.
—  Check if these assumptions were correct.
—  See how much time you spend on each block.
—  See how often you switch between files and sections inside the file.
Read more: Thinking Aloud: The #1 Usability Tool
Code reading
60
Read the code from open-source projects that you use together in the same
way:
—  You will have a better understanding of how they work.
—  You will see which approaches to writing code works and which don't.
Code reading
61
—  https://github.com/reduxjs/redux
—  https://github.com/mobxjs/mobx
—  webpack loaders
Some projects to start from
62
Code review
Principles of the clean code apply to commits and PRs as well:
—  Short, <200LOC PRs.
—  Do only one thing.
—  Describe the context.
Code review
64
If you have large PR — split them to the smaller parts:
1.  Refactoring filenames? Create PR.
2.  Changing the React component that is used in multiple places? Create PR.
3.  Making new utility for everyone to use? Create PR.
Split to many small PRs
CODE REVIEW
65
You can (and should) use commit messages and PR description to describe
the task's context:
1.  What was the task?
2.  Why did you choose to solve it in this way and not another?
Describe context
CODE REVIEW
66
Things that should be done before code review:
—  Discuss the PR process and decide who and how fast should review them.
—  Chose style guide and enable linters.
—  Discuss the new APIs before starting writing code for them.
Advance preparation
CODE REVIEW
67
1.  Split large PRs that need to be merged all at once in the separate commits
that only do one thing.
2.  Give each commit a meaningful name.
3.  Before pushing to upstream, make your commit history beautiful: Squash,
rename, and clean up your commits.
Can't split to different PRs?
CODE REVIEW
68
Writing code for people
Links:
—  http://ohshitgit.com/
—  https://chris.beams.io/posts/git-commit/
—  https://sethrobertson.github.io/GitBestPractices/
Code review
70
Pair programing
How to use to become a better writer:
—  Discuss the plan and make a basic structure.
—  Split tasks so both sides can program and not only listen.
—  Comment what you are trying to do now.
—  Give real-time feedback and ask questions.
Pair programing
72
Writing:
1.  Clean code.
2.  Easy to understand code.
1.  Readability.
2.  Complexity.
3.  Reading flow.
3.  Code that shares context.
Reading:
1.  Code reading.
2.  Code reviews.
3.  Pair Programming.
Summary of the talk
73
Alexey Ivanov, Evil Martians
Twitter: @iadramelk
Writing code for people
74

More Related Content

PDF
WordCamp US: Clean Code
PDF
Understanding, measuring and improving code quality in JavaScript
PPTX
Clean Code III - Software Craftsmanship
PDF
Euro python 2015 writing quality code
PDF
How To Become A Good C# Programmer
PDF
Clean Code V2
PPTX
Code quality
PPTX
Importance of the quality of code
WordCamp US: Clean Code
Understanding, measuring and improving code quality in JavaScript
Clean Code III - Software Craftsmanship
Euro python 2015 writing quality code
How To Become A Good C# Programmer
Clean Code V2
Code quality
Importance of the quality of code

What's hot (19)

PPTX
Clean Code I - Best Practices
PPTX
API workshop: Deep dive into Java
PPTX
Thinking of Documentation as Code [YUIConf 2013]
PPT
Clean Code summary
PDF
DEF CON 23 - Saif el-sherei and etienne stalmans - fuzzing
DOC
PDF
Software Analysis using Natural Language Queries
PDF
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
PDF
GPT-2: Language Models are Unsupervised Multitask Learners
PPTX
code documentation
PDF
Prefer Code to Comments
PPTX
Object Oriented Apologetics
PPTX
Writing High Quality Code in C#
PPTX
Clean Code II - Dependency Injection
PDF
Clean code
PDF
How to write maintainable code - Peter Hilton - Codemotion Amsterdam 2017
PDF
Inside Requirements
PDF
PPTX
API Documentation -- Presentation to East Bay STC Chapter
Clean Code I - Best Practices
API workshop: Deep dive into Java
Thinking of Documentation as Code [YUIConf 2013]
Clean Code summary
DEF CON 23 - Saif el-sherei and etienne stalmans - fuzzing
Software Analysis using Natural Language Queries
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
GPT-2: Language Models are Unsupervised Multitask Learners
code documentation
Prefer Code to Comments
Object Oriented Apologetics
Writing High Quality Code in C#
Clean Code II - Dependency Injection
Clean code
How to write maintainable code - Peter Hilton - Codemotion Amsterdam 2017
Inside Requirements
API Documentation -- Presentation to East Bay STC Chapter
Ad

Similar to Writing code for people (20)

PDF
How to write good quality code
PPTX
30% faster coder on-boarding when you have a code cookbook
PPTX
Best-Practices-for-Writing-Clean-Code.Presentation
PPTX
Linters for frontend code review
PDF
Meaningful code - BeCode Brussels - August 2018
PDF
Code Quality Makes Your Job Easier
PDF
Good Coding Practices with JavaScript
PDF
Clean Code. An Agile Guide to Software Craft Kameron H.
PPTX
Writing code for others
PDF
Clean Code. An Agile Guide to Software Craft Kameron H.
ODP
Documenting code yapceu2016
PDF
Clean Code. An Agile Guide to Software Craft Kameron H.
PDF
Chapter17 of clean code
PPS
CS101- Introduction to Computing- Lecture 44
PDF
Refactoring JavaScript turning bad code into good code First Edition Burchard
PDF
Managing and evolving JavaScript Code
PDF
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
PPTX
Improving Code Quality Through Effective Review Process
PDF
How to write maintainable code
PDF
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
How to write good quality code
30% faster coder on-boarding when you have a code cookbook
Best-Practices-for-Writing-Clean-Code.Presentation
Linters for frontend code review
Meaningful code - BeCode Brussels - August 2018
Code Quality Makes Your Job Easier
Good Coding Practices with JavaScript
Clean Code. An Agile Guide to Software Craft Kameron H.
Writing code for others
Clean Code. An Agile Guide to Software Craft Kameron H.
Documenting code yapceu2016
Clean Code. An Agile Guide to Software Craft Kameron H.
Chapter17 of clean code
CS101- Introduction to Computing- Lecture 44
Refactoring JavaScript turning bad code into good code First Edition Burchard
Managing and evolving JavaScript Code
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Improving Code Quality Through Effective Review Process
How to write maintainable code
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
Ad

More from Alexey Ivanov (6)

PDF
REST to GraphQL migration: Pros, cons and gotchas
PDF
Внутреннее устройство и оптимизация бандла webpack
PDF
CSS-в-JS, HTML-в-JS, ВСЁ-в-JS. Все гораздо проще, когда всё вокруг JavaScript
PDF
Будущее шаблонизаторов
PDF
ДАМП 2015 Екатеринбург
PDF
REST to GraphQL migration: Pros, cons and gotchas
Внутреннее устройство и оптимизация бандла webpack
CSS-в-JS, HTML-в-JS, ВСЁ-в-JS. Все гораздо проще, когда всё вокруг JavaScript
Будущее шаблонизаторов
ДАМП 2015 Екатеринбург

Recently uploaded (20)

PDF
Designing Intelligence for the Shop Floor.pdf
PPTX
Custom Software Development Services.pptx.pptx
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
Cost to Outsource Software Development in 2025
PDF
iTop VPN Crack Latest Version Full Key 2025
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PPTX
"Secure File Sharing Solutions on AWS".pptx
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PDF
Complete Guide to Website Development in Malaysia for SMEs
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PPTX
Computer Software and OS of computer science of grade 11.pptx
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PPTX
Cybersecurity: Protecting the Digital World
PPTX
Patient Appointment Booking in Odoo with online payment
PDF
Time Tracking Features That Teams and Organizations Actually Need
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PDF
How Tridens DevSecOps Ensures Compliance, Security, and Agility
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Designing Intelligence for the Shop Floor.pdf
Custom Software Development Services.pptx.pptx
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
Cost to Outsource Software Development in 2025
iTop VPN Crack Latest Version Full Key 2025
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
"Secure File Sharing Solutions on AWS".pptx
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Complete Guide to Website Development in Malaysia for SMEs
Why Generative AI is the Future of Content, Code & Creativity?
Computer Software and OS of computer science of grade 11.pptx
Weekly report ppt - harsh dattuprasad patel.pptx
Cybersecurity: Protecting the Digital World
Patient Appointment Booking in Odoo with online payment
Time Tracking Features That Teams and Organizations Actually Need
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
How Tridens DevSecOps Ensures Compliance, Security, and Agility
Embracing Complexity in Serverless! GOTO Serverless Bengaluru

Writing code for people

  • 1. Writing code for people Alexey Ivanov, Evil Martians
  • 7. —  Know how to write letters? —  Know how to write words? —  Know how to write sentences? —  Do you write emails, Line messages, or tweets every day? —  Published articles in magazines or books? Do you know how to write? 7
  • 8. Writing code is the same
  • 9. —  You open your code from one year ago and can't remember how it works. —  You spend half of the day adding debug and console.log to functions to see what they are doing. —  You tried to read another person's code and can't understand it. —  ^ Another person probably thought the same about your code too. Have you been in these situations? 9
  • 10. Most of programming tutorials and books teach how to write code that can be understood by the computer and do some stuff with it. Very few books and tutorials teach how to write code that other people can read and understand. This is a common situation 10
  • 11. You write code once. But you and other people will be reading and modifying it tens or even hundreds of times after that. So it's crucial to write code that is readable, reusable, and refactorable. But it's not a good situation 11
  • 14. As with any other skill, if you will be mindful of what you are writing and spend enough time training, you will become better at this. It's a skill that can be learned 14
  • 15. 1.  Writing the code — principles, rules, style guides, and linters. 2.  Reading the code — how to train yourself to become a better writer. Talk structure 15
  • 17. 1.  Clean code. 2.  Easy to understand code. 3.  Code that shares context. Writing the code 17
  • 19. —  Select one code style. —  Automate it. —  Forget about it. Clean code 19
  • 20. There are tons of existing style guides: —  https://standardjs.com/ —  https://github.com/airbnb/javascript —  https://google.github.io/styleguide/jsguide.html —  Standard Prettier settings Choose any of them. It's not important which one. Don't spend time on that. Select a code style CLEAN CODE 20
  • 21. —  eslint for Javascript or TypeScript. —  stylelint for CSS. —  rubocop for Ruby. —  prettier — tool that can automatically fix style for multiple languages. Linters usually have excellent documentation about when and why to use each rule. Add linters CLEAN CODE 21
  • 22. —  eslint-config-airbnb —  eslint-config-standard —  stylelint-config-standard The good thing about using a popular style guide is the fact that it is already automated. Add standard config for linters CLEAN CODE 22
  • 23. —  Add prettier and linter plugins to your editor. —  Enable automatic fixing in prettier . —  Add precommit hook that automatically format/lint your code. —  Run your checks in CI (CircleCI or TravisCI will do). Enable automatic linting and fixing CLEAN CODE 23
  • 24. Demo
  • 25. Again, it's not important what style you choose. Toss a coin if you like. You can always automatically reformat it later. Forget about it CLEAN CODE 25
  • 28. Bad: const yyyymmdstr = moment().format("YYYY/MM/DD"); Good: const currentDate = moment().format("YYYY/MM/DD"); Use meaningful and pronounceable variable names READABILITY 28
  • 29. Bad: setTimeout(blastOff, 86400000); Good: const MILLISECONDS_IN_A_DAY = 86_400_000; setTimeout(blastOff, MILLISECONDS_IN_A_DAY); Use searchable names READABILITY 29
  • 30. Bad: function createMenu(title, body, buttonText, cancellable) { // ... } createMenu("Foo", "Bar", "Baz", true); Function arguments (2 or fewer ideally) READABILITY 30
  • 31. Good: function createMenu({ title, body, buttonText, cancellable }) // ... } createMenu({ title: "Foo", body: "Bar", buttonText: "Baz", cancellable: true }); Function arguments (2 or fewer ideally) READABILITY 31
  • 32. Bad: function createFile(name, temp) { if (temp) { fs.create(`./temp/${name}`); } else { fs.create(name); } } Don't use flags as function parameters READABILITY 32
  • 33. Good: function createFile(name) { fs.create(name); } function createTempFile(name) { createFile(`./temp/${name}`); } Don't use flags as function parameters READABILITY 33
  • 34. —  Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin ⽇本語 —  https://github.com/ryanmcdermott/clean-code-javascript   ⽇本語 — examples was from there. —  https://github.com/ryanmcdermott/3rs-of-software-architecture —  JS UX: Writing code for Humans by Lea Verou Further reading READABILITY 34
  • 35. One of the sighs of the bad code is complexity: —  Large functions that do multiple things at once. —  Too many arguments for the function. —  Multiple nested IFs or callbacks. Complexity 35
  • 36. You can automate detection of such things. For example with Eslint: —   complexity  — Cyclomatic Complexity —   max-depth —   max-statements —   max-nested-callbacks Be careful. Following these rules blindly can produce harder to read code. Automation COMPLEXITY 36
  • 37. —  How often do you go back and forth between functions and methods in the file? —  How many files do you need to open to understand how something works? —  Are the files that you are switching between are close to each other or do you need to go to different nested folders? Sometimes it is better to break complexity rules to make the reading flow easier. Reading flow 37
  • 40. Old code: window.ga("send", { hitType: "event", eventCategory: "Videos", eventAction: "play", eventLabel: "Fall Campaign", eventValue: 10 }); Replacing GA with GTM EXAMPLE 40
  • 41. New code: window.dataLayer.push({ category: "Videos", action: "play", label: "Fall Campaign", value: 10 }); Replacing GA with GTM EXAMPLE 41
  • 42. Solution: const event = { /* ... */ } const eventPlaceholder = { label: undefined, value: underfined }; window.dataLayer.push({ ...eventPlaceholder, ...event }); Replacing GA with GTM EXAMPLE 42
  • 43. 1.  You can't just leave the code" as is" – next developer can delete it while refactoring, and they spend eight more hours debugging it. 2.  You can't ask other people to review this code without telling them what it is doing and why. 3.  Other people can't update and maintain this code. But how do you share this knowledge? 43
  • 44. /* GTM sets all event fields as global variables inside itself, so until we rewrite them, they will have old values. Because label and value are optional fields, we need to unset them for the next events explicitly. Relevant docs: - https://developers.google.com/tag-manager/devguide - https://support.google.com/tagmanager/answer/6164391?hl=en */ Use comments 44
  • 45. Code can't explain why the program is being written, and the rationale for choosing this or that method. Code cannot discuss the reasons certain alternative approaches were taken. Jeff Raskin What is context? “ 45
  • 46. For example: /* A binary search turned out to be slower than the Boyer-Moore algorithm for the data sets of interest, thus we have used the more complex, but faster method even though this problem does not at first seem amenable to a string search technique. */ Jeff Raskin What is context? 46
  • 47. @media (--sm-scr) { .input { font-size: 16px; /* prevents iOS auto-scale on focus */ } } CSS example 47
  • 50. —  The reader needs a context that can't be expressed using other means. —  The code exists because of the environment issues. Browser bugs, for example. —  The ugly solution is chosen because of speed optimization reasons. When to comment 50
  • 52. —  Code Tells You How, Comments Tell You Why by Jeff Artwood —  The Art of Comments by Sarah Drasner Links 52
  • 53. 1.  Clean code. 2.  Easy to understand code. 1.  Readability. 2.  Complexity. 3.  Reading flow. 3.  Code that shares context. Summary of the first part 53
  • 55. 1.  Code reading. 2.  Code reviews. 3.  Pair Programming. Reading the code 55
  • 57. Douglas Crockford — Goto There and Back Again starting from 27:15 Code reading 57
  • 58. Crockford's method: 1.  Do it every day. 2.  Discuss approaches, patterns, and possible solutions. 3.  Don't judge. Don't use results as metrics. Code reading 58
  • 59. Who should read: 1.  Reading by the author — faster to do, better at describing context, but fewer chances to find problems. 2.  Reading by the other person — slower, requires more steps, more useful feedback on writing. Code reading 59
  • 60. You can use methodology from usability testings for the additional effect: —  Think aloud. Make assumptions about what variables and functions will do. —  Check if these assumptions were correct. —  See how much time you spend on each block. —  See how often you switch between files and sections inside the file. Read more: Thinking Aloud: The #1 Usability Tool Code reading 60
  • 61. Read the code from open-source projects that you use together in the same way: —  You will have a better understanding of how they work. —  You will see which approaches to writing code works and which don't. Code reading 61
  • 64. Principles of the clean code apply to commits and PRs as well: —  Short, <200LOC PRs. —  Do only one thing. —  Describe the context. Code review 64
  • 65. If you have large PR — split them to the smaller parts: 1.  Refactoring filenames? Create PR. 2.  Changing the React component that is used in multiple places? Create PR. 3.  Making new utility for everyone to use? Create PR. Split to many small PRs CODE REVIEW 65
  • 66. You can (and should) use commit messages and PR description to describe the task's context: 1.  What was the task? 2.  Why did you choose to solve it in this way and not another? Describe context CODE REVIEW 66
  • 67. Things that should be done before code review: —  Discuss the PR process and decide who and how fast should review them. —  Chose style guide and enable linters. —  Discuss the new APIs before starting writing code for them. Advance preparation CODE REVIEW 67
  • 68. 1.  Split large PRs that need to be merged all at once in the separate commits that only do one thing. 2.  Give each commit a meaningful name. 3.  Before pushing to upstream, make your commit history beautiful: Squash, rename, and clean up your commits. Can't split to different PRs? CODE REVIEW 68
  • 72. How to use to become a better writer: —  Discuss the plan and make a basic structure. —  Split tasks so both sides can program and not only listen. —  Comment what you are trying to do now. —  Give real-time feedback and ask questions. Pair programing 72
  • 73. Writing: 1.  Clean code. 2.  Easy to understand code. 1.  Readability. 2.  Complexity. 3.  Reading flow. 3.  Code that shares context. Reading: 1.  Code reading. 2.  Code reviews. 3.  Pair Programming. Summary of the talk 73
  • 74. Alexey Ivanov, Evil Martians Twitter: @iadramelk Writing code for people 74