SlideShare une entreprise Scribd logo
1  sur  47
代码的用户体验
别让我想,别让我猜,别让我烦
用户体验三要素
别让我想
别让我等
别让我烦
代码用户体验的三要素
 别让我想
 别让我猜
 别让我烦
用户体验一:别让我想
没有信息量的注释
没有信息量的变量名
没有信息量的常量
不够抽象的概念
平铺直叙的代码
How to do Do what
混乱的抽象层次
http:/song.ttpod.com/Lenka/Blue Skies.m4a?k=2348147 M4A
用户体验二:别让我猜
A name should tell you
why it exists, what it does,
and how it is used.
- Uncle Bob
变量名
 首字母缩写
 前缀名缩写
ServletOutputStream
RecordRecommend
方法名
void nextSong() void playNextSong()
Song nextSong()
类名
Conceptual Integrity
I contend that conceptual
integrity is the most
important consideration
in system design.
-Frederick Brooks
one concept:
multiple names
Strive for consistency in
naming. If you use two
names interchangeably,
someone else will be
mislead into believing
that there is a difference.
混合使用不同的名词
and I has
another name
called
“Control”.
Hi, my
name is
“Widget”.
混合使用不同的名词
Online
Media
Stream
Media
红心收藏
• Favorites
• Like
• Rate
• Mark
• Love
• Heart
• ……
混合使用不同的名词
混合使用全称和缩写
混合使用常量和字面量
one name:
multiple concepts
If you use same term for
two distinct concepts,
others will be even more
confused.
Sin Sin
Conceptual Integrity
We work hard to make
sure that each concept
in our application is
expressed just once in
our code.
-Dave Thomas
既做输入
又做输出
既做错误码
又做输出
Conceptual Integrity
Every thing is Fd.
• open( )
• read( )
• write( )
• close( )
用户体验三:别让我烦
无处不在的空指针检查
空指针捕获
空指针检查
NullPointerException
无处不在的空指针检查
空指针检查
空指针检查
无处不在的空指针检查
空指针检查
无处不在的空指针检查
无处不在的空指针检查
无处不在的空指针检查
内部代码
 避免产生空指针,并去掉null判断
 接口显式说明参数和返回值是否可为null
使用第三方库
 做防御性判断
http://www.juvenxu.com/2014/10/28/using-design-to-prevent-errors/
避免产生空指针
接口显式说明参数和返回值是否可能为空
10 months 18 years
写更少的代码
The Best API is no API at all.
-《The Little Manual of API Design》
The most readable code is
no code at all.
-《The Art of Readable Code》
使用更有表达力的语言
• 根据索引获取歌曲
• 根据名称获取歌曲
合理使用第三方提供的库
ignorable
ignored
熟悉你使用的库
reading code
writing code
Code should be written to
minimize the time it would
take someone else to
understand it.
-《The Art of Readable Code》
正确
稳定
易读
代码的用
户体验
产品的用
户体验
ranzhao2000
ranzhao2000@gmail.com
THANKS

Contenu connexe

Plus de AHAConference

What is business model
What is business modelWhat is business model
What is business modelAHAConference
 
精益产品开发实例
精益产品开发实例精益产品开发实例
精益产品开发实例AHAConference
 
一个互联网产品的成长史
一个互联网产品的成长史一个互联网产品的成长史
一个互联网产品的成长史AHAConference
 
Agile organization design workshop
Agile organization design workshopAgile organization design workshop
Agile organization design workshopAHAConference
 
What is business model
What is business modelWhat is business model
What is business modelAHAConference
 
Tdd thats-not-what-we-meant
Tdd thats-not-what-we-meantTdd thats-not-what-we-meant
Tdd thats-not-what-we-meantAHAConference
 
互联网产品演进中的组织适应
互联网产品演进中的组织适应互联网产品演进中的组织适应
互联网产品演进中的组织适应AHAConference
 
Odde conference effectiveteamv5-sc-1
Odde conference effectiveteamv5-sc-1Odde conference effectiveteamv5-sc-1
Odde conference effectiveteamv5-sc-1AHAConference
 

Plus de AHAConference (10)

What is business model
What is business modelWhat is business model
What is business model
 
精益产品开发实例
精益产品开发实例精益产品开发实例
精益产品开发实例
 
一个互联网产品的成长史
一个互联网产品的成长史一个互联网产品的成长史
一个互联网产品的成长史
 
Agile organization design workshop
Agile organization design workshopAgile organization design workshop
Agile organization design workshop
 
What is business model
What is business modelWhat is business model
What is business model
 
Tdd thats-not-what-we-meant
Tdd thats-not-what-we-meantTdd thats-not-what-we-meant
Tdd thats-not-what-we-meant
 
Mc aha-20150416
Mc aha-20150416Mc aha-20150416
Mc aha-20150416
 
互联网产品演进中的组织适应
互联网产品演进中的组织适应互联网产品演进中的组织适应
互联网产品演进中的组织适应
 
Nmonecis aha
Nmonecis   ahaNmonecis   aha
Nmonecis aha
 
Odde conference effectiveteamv5-sc-1
Odde conference effectiveteamv5-sc-1Odde conference effectiveteamv5-sc-1
Odde conference effectiveteamv5-sc-1
 

代码的用户体验

Notes de l'éditeur

  1. 产品的用户体验 yes 代码的用户体验 no