01010111 01100101 01101100 01100011 01101111 01101101 01100101
𓂜𓈖
𓂜𓈖
@uniqname
Aumni - A JP Morgan Chase company
1stdraftdesign
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
Code should be written to minimize the time it would take for someone else to understand it.
𓂜𓈖
Boswell, Dustin & Foucher, Trevor (2012). The Art of Readable Code. O'Reilly
𓂜𓈖
Jess Sawyer. (2024, August 8). Newspaper Reading Level. Originality.ai. https://originality.ai/blog/newspaper-reading-level
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
const activeUserNames = [];
for (i = 0; i < users.length; i++) {
if (users[i].active) {
activeUsers.push(users[i].name)
}
}
const activeUserNames = users
.filter(({ active }) => !!active)
.map(({ name }) => name)
const activeUserNames =
users.flatMap(({ active, name }) => !!active ? name : []);
𓂜𓈖
(tasks) => {
let val;
for (task of tasks) {
val = await task(val);
}
return val;
}
(tasks) => tasks.reduce(
(task, last) => last.then(task),
Promise.resolve()
)
𓂜𓈖
() => {}
function () {}
𓂜𓈖
𓂜𓈖
Better 1?
createPerson({ name: "Cory", title: "Architect", level: "Awesome" });
createPerson({
name: "Ryan",
title: "Engineering Manager",
level: "Wicked Awesome",
});
createPerson({
name: "Max",
title: "Senior Engineer",
level: "Freakin' Awesome",
});
createPerson({ name: "Kade", title: "Engineer", level: "Hella Awesome" });
createPerson({ name: "Richard", title: "Not Sure", level: "Kinda a bummer" });
createPerson({ name: "Cory", title: "Architect", level: "Awesome" });
createPerson({ name: "Ryan", title: "Engineering Manager", level: "Wicked Awesome" });
createPerson({ name: "Max", title: "Senior Engineer", level: "Freakin' Awesome" });
createPerson({ name: "Kade", title: "Engineer", level: "Hella Awesome" });
createPerson({ name: "Richard", title: "Not Sure", level: "Kinda a bummer" });
Or better 2?
(Rightly) Recommend in "The Art of Readable Code"
createPerson({ name: "Cory", title: "Architect", level: "Awesome" });
createPerson({
name: "Ryan",
title: "Engineering Manager",
level: "Wicked Awesome",
});
createPerson({
name: "Max",
title: "Senior Engineer",
level: "Freakin' Awesome",
});
createPerson({ name: "Kade", title: "Engineer", level: "Hella Awesome" });
createPerson({ name: "Richard", title: "Not Sure", level: "Kinda a bummer" });
createPerson({ name: "Cory", title: "Architect", level: "Awesome" });
createPerson({ name: "Ryan", title: "Engineering Manager", level: "Wicked Awesome" });
createPerson({ name: "Max", title: "Senior Engineer", level: "Freakin' Awesome" });
createPerson({ name: "Kade", title: "Engineer", level: "Hella Awesome" });
createPerson({ name: "Richard", title: "Not Sure", level: "Kinda a bummer" });
What Prettier does after your hard work to make things more readable.
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
𓂜𓈖
👍
👎
𓂜𓈖
𓆄𓅱
👍
👎
𓂜𓈖
𓆄𓅱
👍
👎
𓂜𓈖
be free from
Will be without
𓂜𓈖
[An] experiment exposed two groups of people to Chinese characters for short times. Participants were then told that these symbols represented adjectives and were asked to rate whether the symbols held positive or negative connotations. The symbols the participants had previously seen were consistently rated more positively than those they had not.
In a similar experiment, people were not asked to rate the connotations of the symbols, but to describe their mood after the experiment. Members of the group with repeated exposure to certain characters reported being in better moods than those without.
https://en.wikipedia.org/wiki/Mere-exposure_effect
𓂜𓈖
a phenomenon in which people tend to prefer familiar options over unfamiliar ones, even when the unfamiliar options may be better.
https://www.thebehavioralscientist.com/glossary/familiarity-bias
𓂜𓈖
👍
👎
🧠
🧑🏫
🧑🎓
This code is not readable.
This code is not readable.
This code is unfamiliar to me.
Why do you think this is better?
If you can't explain it simply, you probably don't understand it.
Someone at some point, probably not Einstein, but maybe Einstein?
Is it because it's more familiar to you?
If you want to enforce it, you need to be able to detect it.
If you think it's bad, prove it!
Be open
Ask questions
Suspend judgment
Embrace (some) experimentation
Be ready to teach
Be ready to be taught (you will be wrong)
Receive feedback gracefully
Isolate impact
Assuming you now understand the "grammar"
Does it clarify or obscure?
Does it hide details or hide bugs?
Can you scan or must you read?
Is it a complete encapsulation, or does it leak?
I'm with Richard Feldman when he asked:
people say...
I'm with Eric Elliott when he said:
people say...
I'm with the Authors of "The Art of Readable Code" when they advocate for flexible white line breaks and column alignment.
people say...
I mean, right? This clearly better?!?!
createPerson({ name: "Cory", title: "Architect", level: "Awesome" });
createPerson({
name: "Ryan",
title: "Engineering Manager",
level: "Wicked Awesome",
});
createPerson({
name: "Max",
title: "Senior Engineer",
level: "Freakin' Awesome",
});
createPerson({ name: "Kade", title: "Engineer", level: "Hella Awesome" });
createPerson({ name: "Richard", title: "Not Sure", level: "Kinda a bummer" });
createPerson({ name: "Cory", title: "Architect", level: "Awesome" });
createPerson({ name: "Ryan", title: "Engineering Manager", level: "Wicked Awesome" });
createPerson({ name: "Max", title: "Senior Engineer", level: "Freakin' Awesome" });
createPerson({ name: "Kade", title: "Engineer", level: "Hella Awesome" });
createPerson({ name: "Richard", title: "Not Sure", level: "Kinda a bummer" });
What Prettier does after you hard work to make things more readable.
Readable code and familiar code are very different things.
Come with data
Be open to data
Assert less
Ask more questions
You can't accurately judge until you accurately understand.
Boswell, Dustin & Foucher, Trevor (2012). The Art of Readable Code. O'Reilly
({ displayableStatus }) =>
displayableStatus === 'received'
? 'var(--blue400)'
: displayableStatus === 'processing'
? 'var(--purple400)'
: displayableStatus === 'complete'
? 'var(--green300)'
: 'var(--blue400)'
({ displayableStatus }) =>
displayableStatus === 'received' ? 'var(--blue400)'
: displayableStatus === 'processing' ? 'var(--purple400)'
: displayableStatus === 'complete' ? 'var(--green300)'
: 'var(--blue400)';
({ displayableStatus }) =>
displayableStatus === 'received'
? 'var(--blue400)'
: displayableStatus === 'processing'
? 'var(--purple400)'
: displayableStatus === 'complete'
? 'var(--green300)'
: 'var(--blue400)'
({ displayableStatus }) =>
displayableStatus === 'received'
? 'var(--blue400)'
: displayableStatus === 'processing'
? 'var(--purple400)'
: displayableStatus === 'complete'
? 'var(--green300)'
: 'var(--blue400)';
({ displayableStatus }) =>
displayableStatus === 'received' ? 'var(--blue400)'
: displayableStatus === 'processing' ? 'var(--purple400)'
: displayableStatus === 'complete' ? 'var(--green300)'
: 'var(--blue400)';
({ displayableStatus }) => {
if (displayableStatus === 'received') return 'var(--blue400)';
if (displayableStatus === 'processing') return 'var(--purple400)';
if (displayableStatus === 'complete') return 'var(--green300)';
return 'var(--blue400)'
}
({ displayableStatus }) => {
if (displayableStatus === 'received') {
return 'var(--blue400)';
}
if (displayableStatus === 'processing') {
return 'var(--purple400)';
}
if (displayableStatus === 'complete') {
return 'var(--green300)';
} else
return 'var(--blue400)'
}
({ displayableStatus }) => {
switch (displayableStatus) {
case 'received': { return 'var(--blue400)' };
case 'processing': { return 'var(--purple400)' };
case 'complete': { return 'var(--green300)' };
default: { return 'var(--blue400)' }
}
}
({ displayableStatus }) => {
switch (displayableStatus) {
case 'received': {
return 'var(--blue400)';
};
case 'processing': {
return 'var(--purple400)';
};
case 'complete': {
return 'var(--green300)';
};
default: {
return 'var(--blue400)'
}
}
}
({ displayableStatus }) => {
switch (displayableStatus) {
case 'received': { return 'var(--blue400)' };
case 'processing': { return 'var(--purple400)' };
case 'complete': { return 'var(--green300)' };
default: { return 'var(--blue400)' }
}
}
Any one of which I could make a decent argument are more "readable" than what Prettier does to chained ternaries.
Almost none of which will Prettier allow.
I think JavaScript deserves a proper pipeline operator where the result of the previous function gets passed as the sole argument to the next function, you know, like a normal pipeline operator.
So why do people hate them?
certain browser implementors
^
Some people are keen to steer people away from functional and point free style JavaScript becase of the "ease with which [developers] can allocate many many closures."
There are at least three problems with this.
My short answer?