forked from soulteary/forever-coolshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path23.html
executable file
·416 lines (393 loc) · 41.3 KB
/
23.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
<!DOCTYPE html><!--[if IE 8]>
<html id="ie8" dir="ltr" lang="zh-CN"
prefix="og: https://ogp.me/ns#" >
<![endif]--><!--[if !(IE 8) ]><!--><html dir="ltr" lang="zh-CN" prefix="og: https://ogp.me/ns#"><!--<![endif]--><head><meta charset="UTF-8"/><title>酷壳 – CoolShell.cn - Part 23</title><link rel="stylesheet" type="text/css" href="/assets/all.min.css"/><link rel="shortcut icon" href="/assets/favicon.png"/></head>
<body class="home blog paged paged-23 group-blog">
<div id="page" class="hfeed site">
<header id="masthead" role="banner">
<div id="cc_spacer"></div>
<div class="site-header">
<div class="site-branding">
<a class="home-link" href="/" title="酷 壳 – CoolShell" rel="home">
<h1 class="site-title">酷 壳 – CoolShell</h1>
<h2 class="site-description">享受编程和技术所带来的快乐 – Coding Your Ambition</h2>
</a>
</div>
</div>
</header>
<div class="container">
<div class="row">
</div>
</div>
<div id="content" class="site-content">
<div class="container">
<div class="row">
<div id="primary" class="content-area col-md-12" style="margin-top: 40px;">
<main id="main" class="site-main" role="main">
<article id="post-5479" class="post-content post-5479 post type-post status-publish format-standard hentry category-misc category-tools tag-cheat-sheet tag-vim">
<header class="entry-header">
<span class="screen-reader-text">给程序员的VIM速查卡</span>
<h2 class="entry-title">
<a href="/articles/5479.html" rel="bookmark">给程序员的VIM速查卡</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/5479.html" title="09:07" rel="bookmark"><time class="entry-date" datetime="2011-09-16T09:07:05+08:00" pubdate="">2011年09月16日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/5479.html#comments" class="comments-link">73 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 118,233 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>前几天酷壳发布过“<a title="简明 Vim 练级攻略" href="/articles/5426.html" target="_blank">vim简明攻略</a>”,不知道大家练得怎么样了。如果你练了一下,那么这里这个速查卡就会对你有帮助了。以前本站也有过一个(<a title="Vim命令速查卡" href="/articles/150.html" target="_blank">vim速查卡</a>),不过其太简单了。我觉得这个很不错,很全,很直观。这个速查卡来自<strong><a href="http://michael.peopleofhonoronly.com/vim/" target="_blank">这里</a></strong>。其用颜色标注了级别:</p>
<ul>
<li><span style="background-color: #008000;"><span style="color: #ffffff;"> Green </span></span> = 存活级</li>
<li><span style="background-color: #ffff00;"> Yellow </span> = 感觉良好</li>
<li><span style="background-color: #ff8000;"> Orange </span> / <span style="background-color: #0000ff;"><span style="color: #ffffff;">Blue</span></span> = 高级</li>
<li><span style="background-color: #ff0000;"> Red </span> = 专家级</li>
</ul>
<p>下面的图片点击可以看大图:</p>
<figure id="attachment_5480" aria-describedby="caption-attachment-5480" style="width: 639px" class="wp-caption aligncenter"><a href="https://coolshell.cn/wp-content/uploads/2011/09/vim_cheat_sheet_for_programmers_print.png"><img decoding="async" class="size-large wp-image-5480 " title="给程序员的VIM速查卡" src="/uploads/2011/09/vim_cheat_sheet_for_programmers_print-1024x791.png" alt="给程序员的VIM速查卡" width="639" height="494" srcset="" sizes="(max-width: 639px) 100vw, 639px"/></a><figcaption id="caption-attachment-5480" class="wp-caption-text">给程序员的VIM速查卡(点击看大图)</figcaption></figure>
<p>你还可以下载<a href="http://michael.peopleofhonoronly.com/vim/vim_cheat_sheet_for_programmers_print.pdf" target="_blank">PDF版</a>的和<a href="http://michael.peopleofhonoronly.com/vim/vim_cheat_sheet_for_programmers_print.xlsx" target="_blank">Excel版</a>的,如果你是色盲的话,还有<a href="http://michael.peopleofhonoronly.com/vim/vim_cheat_sheet_for_programmers_colorblind.pdf" target="_blank">蓝色版PDF</a>的。如果你不是很喜欢的话,这里还有几个:</p>
<p> <a href="/articles/5479.html#more-5479" class="more-link">…</a></p><a href="/articles/5479.html#more-5479" class="more-link">
</a><p class="read-more"><a href="/articles/5479.html#more-5479" class="more-link"></a><a class="btn btn-default" href="/articles/5479.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-5479-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-5444" class="post-content post-5444 post type-post status-publish format-standard hentry category-misc category-progdesign category-proglanguage tag-api tag-bool tag-coding tag-design tag-programmer tag-58">
<header class="entry-header">
<span class="screen-reader-text">千万不要把 bool 设计成函数参数</span>
<h2 class="entry-title">
<a href="/articles/5444.html" rel="bookmark">千万不要把 bool 设计成函数参数</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/5444.html" title="15:35" rel="bookmark"><time class="entry-date" datetime="2011-09-08T15:35:18+08:00" pubdate="">2011年09月08日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/5444.html#comments" class="comments-link">94 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 63,375 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>我们有很多Coding Style 或 代码规范。但这一条可能会经常被我们所遗忘,就是我们经常会在函数的参数里使用bool参数,这会大大地降低代码的可读性。不信?我们先来看看下面的代码。</p>
<p>当你读到下面的代码,你会觉得这个代码是什么意思?</p>
<p><code data-enlighter-language="c" class="EnlighterJSRAW">widget->repaint(false);</code></p>
<p>是不要repaint吗?还是别的什么意思?看了文档后,我们才知道这个参数是immediate, 也就是说,false代表不立即重画,true代码立即重画。</p>
<p>Windows API中也有这样一个函数:InvalidateRect,当你看到下面的代码,你会觉得是什么意思?</p>
<p><code data-enlighter-language="c" class="EnlighterJSRAW">InvalidateRect(hwnd, lpRect, false);</code></p>
<p>我们先不说InvalidateRect这个函数名取得有多糟糕,我们先说一下那个false参数?invalidate意为“让XXX无效”,false是什么意思?双重否定?是肯定的意思?如果你看到这样的代码,你会相当的费解的。于是,你要去看一下文档,或是InvalidateRect的函数定义,你会看到那个参数是 <strong>BOOL</strong><em> bErase</em>,意思是,是否要重画背景。</p>
<p>这样的事情有很多,再看下面的代码,想把str中的”%USER%”替换成真实的用户名:</p>
<p><code data-enlighter-language="c" class="EnlighterJSRAW">str.replace("%USER%", user, false); // Qt 3</code></p>
<p>TNND,那个false是什么意思?不替换吗?还是别的什么意思,看了文档才知道,false代码大小写不敏感的替换。</p>
<p>其实,如果你使用枚举变量/常量,而不是bool变量,你会让你的代码更易读,如:</p>
<p> <a href="/articles/5444.html#more-5444" class="more-link">…</a></p><a href="/articles/5444.html#more-5444" class="more-link">
</a><p class="read-more"><a href="/articles/5444.html#more-5444" class="more-link"></a><a class="btn btn-default" href="/articles/5444.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-5444-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-5426" class="post-content post-5426 post type-post status-publish format-standard hentry category-misc category-tools tag-vim">
<header class="entry-header">
<span class="screen-reader-text">简明 Vim 练级攻略</span>
<h2 class="entry-title">
<a href="/articles/5426.html" rel="bookmark">简明 Vim 练级攻略</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/5426.html" title="08:27" rel="bookmark"><time class="entry-date" datetime="2011-09-07T08:27:26+08:00" pubdate="">2011年09月07日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/5426.html#comments" class="comments-link">610 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 1,323,974 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>vim的学习曲线相当的大(参看<a title="主流文本编辑器学习曲线" href="/articles/3125.html" target="_blank">各种文本编辑器的学习曲线</a>),所以,如果你一开始看到的是一大堆VIM的命令分类,你一定会对这个编辑器失去兴趣的。下面的文章翻译自《<a href="http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/" target="_blank">Learn Vim Progressively</a>》,我觉得这是给新手最好的VIM的升级教程了,没有列举所有的命令,只是列举了那些最有用的命令。非常不错。</p>
<p style="text-align: center;">——————————正文开始——————————</p>
<p>你想以最快的速度学习人类史上最好的文本编辑器VIM吗?你先得懂得如何在VIM幸存下来,然后一点一点地学习各种戏法。</p>
<p><a href="http://www.vim.org">Vim</a> the Six Billion Dollar editor</p>
<blockquote><p>Better, Stronger, Faster.</p></blockquote>
<p>学习 <a href="http://www.vim.org">vim</a> 并且其会成为你最后一个使用的文本编辑器。没有比这个更好的文本编辑器了,非常地难学,但是却不可思议地好用。</p>
<p>我建议下面这四个步骤:</p>
<ol>
<li>存活</li>
<li>感觉良好</li>
<li>觉得更好,更强,更快</li>
<li>使用VIM的超能力</li>
</ol>
<p>当你走完这篇文章,你会成为一个vim的 superstar。</p>
<p>在开始学习以前,我需要给你一些警告:</p>
<ul>
<li>学习vim在开始时是痛苦的。</li>
<li>需要时间</li>
<li>需要不断地练习,就像你学习一个乐器一样。</li>
<li>不要期望你能在3天内把vim练得比别的编辑器更有效率。</li>
<li>事实上,你需要2周时间的苦练,而不是3天。</li>
</ul>
<div> <a href="/articles/5426.html#more-5426" class="more-link">…<p></p>
</a><p class="read-more"><a href="/articles/5426.html#more-5426" class="more-link"></a><a class="btn btn-default" href="/articles/5426.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p></div>
<div id="post-ratings-5426-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-5388" class="post-content post-5388 post type-post status-publish format-standard hentry category-cplusplus category-misc category-proglanguage category-story tag-c tag-programmer tag-58">
<header class="entry-header">
<span class="screen-reader-text">C语言中史上最愚蠢的Bug</span>
<h2 class="entry-title">
<a href="/articles/5388.html" rel="bookmark">C语言中史上最愚蠢的Bug</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/5388.html" title="10:17" rel="bookmark"><time class="entry-date" datetime="2011-08-26T10:17:48+08:00" pubdate="">2011年08月26日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/5388.html#comments" class="comments-link">126 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 71,843 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>本文来自“<a href="http://www.elpauer.org/?p=971" target="_blank">The most stupid C bug ever</a>”,很有意思,分享给大家。我相信这样的bug,就算你是高手你也会犯的。你来看看作者犯的这个Bug吧。。</p>
<p>首先,作者想用一段程序来创建一个文件,如果有文件名的话,就创建真正的文件,如果没有的话,就调用?<a href="http://linux.die.net/man/3/tmpfile">tmpfile()</a>?创建临时文件。他这段程序就是HTTP下载的C程序。code==200就是HTTP的返回码。</p>
<pre data-enlighter-language="c" class="EnlighterJSRAW">else if (code == 200) { // Downloading whole file
/* Write new file (plus allow reading once we finish) */
g = fname ? fopen(fname, "w+") : tmpfile();
}</pre>
<p>但是这个程序,只能在Unix/Linux下工作,因为 Microsoft 的?<a href="http://msdn.microsoft.com/en-us/library/x8x7sakw.aspx">tmpfile()的实现</a>?居然选择了 C:\ 作为临时文件的存放目录,这对于那些没有管理员权限的人来说就出大问题了,在Windows 7下,就算你有管理员权限也会有问题。所以,上面的程序在Windows平台下需要用不同的方式来处理,不能直接使用Windows的tmpfile()函数。</p>
<p>于是作者就先把这个问题记下来,在注释中写下了FIXME:</p>
<pre data-enlighter-language="c" class="EnlighterJSRAW">else if (code == 200) { // Downloading whole file
/* Write new file (plus allow reading once we finish) */
// FIXME Win32 native version fails here because
// Microsoft's version of tmpfile() creates the file in C:\
g = fname ? fopen(fname, "w+") : tmpfile();
}</pre>
<p>然后,作者觉得需要写一个跨平台的编译:</p>
<pre data-enlighter-language="c" class="EnlighterJSRAW">FILE * tmpfile ( void ) {
#ifndef _WIN32
return tmpfile();
#else
//code for Windows;
#endif
}</pre>
<p>然后,作者觉得这样实现很不好,会发现名字冲突,因为这样一来这个函数太难看了。于是他重构了一下他的代码——写一个自己实现的tmpfile() – w32_tmpfile,然后,在Windows 下用宏定义来重命名这个函数为tmpfile()。(陈皓注:这种用法是比较标准的跨平台代码的写法)</p>
<p> <a href="/articles/5388.html#more-5388" class="more-link">…</a></p><a href="/articles/5388.html#more-5388" class="more-link">
</a><p class="read-more"><a href="/articles/5388.html#more-5388" class="more-link"></a><a class="btn btn-default" href="/articles/5388.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-5388-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-5353" class="post-content post-5353 post type-post status-publish format-standard hentry category-webdev category-progdesign category-netsecurity tag-password tag-web tag-320 tag-318">
<header class="entry-header">
<span class="screen-reader-text">你会做Web上的用户登录功能吗?</span>
<h2 class="entry-title">
<a href="/articles/5353.html" rel="bookmark">你会做Web上的用户登录功能吗?</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/5353.html" title="08:48" rel="bookmark"><time class="entry-date" datetime="2011-08-25T08:48:48+08:00" pubdate="">2011年08月25日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/5353.html#comments" class="comments-link">119 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 143,682 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>Web上的用户登录功能应该是最基本的功能了,可是在我看过一些站点的用户登录功能后,我觉得很有必要写一篇文章教大家怎么来做用户登录功能。下面的文章告诉大家这个功能可能并没有你所想像的那么简单,这是一个关系到用户安全的功能,希望大家能从下面的文章中能知道什么样的方法才是一个好的用户登录功能。<span style="color: #cc0000;"><strong>以下内容,转载时请保持原文一致,并请注明作者和出处</strong></span>。</p>
<h4>用户名和口令</h4>
<p>首先,我们先来说说用户名和口令的事。这并不是本站第一次谈论这个事了。<a title="如何管理并设计你的口令" href="/articles/2428.html" target="_blank">如何管理自己的口令</a>让你知道怎么管理自己的口令,<a title="破解你的口令" href="/articles/3801.html" target="_blank">破解你的口令</a>让你知道在现代这样速度的计算速度下,用穷举法破解你的口令可能会是一件很轻松的事。在这里我想告诉从开发者的角度上来做设计这个用户名和口令的事。下面一几件规则:</p>
<ul style="font-weight: bold;">
<li><span class="Apple-style-span" style="font-weight: normal;"><strong>限制用户输入一些非常容易被破解的口令</strong>。如什么qwert,123456, password之类,就像<a title="Twitter的禁用口令" href="/articles/2451.html" target="_blank">twitter限制用户的口令</a>一样做一个口令的黑名单。另外,你可以限制用户口令的长度,是否有大小写,是否有数字,你可以用你的程序做一下校验。当然,这可能会让用户感到很不爽,所以,现在很多网站都提供了UX让用户知道他的口令强度是什么样的(比如<a title="另类UX让你输入强口令" href="/articles/3877.html" target="_blank">这个有趣的UX</a>),这样可以让用户有一个选择,目的就是告诉用户——要想安全,先把口令设得好一点。</span></li>
</ul>
<ul style="font-weight: bold;">
<li><span class="Apple-style-span" style="font-weight: normal;"><strong>千万不要明文保存用户的口令</strong>。正如<a title="如何管理并设计你的口令" href="/articles/2428.html" target="_blank">如何管理自己的口令</a>所说的一样,很多时候,用户都会用相同的ID相同的口令来登录很多网站。所以,如果你的网站明文保存的话,那么,如果你的数据被你的不良员工流传出去那对用户是灾难性的。所以,用户的口令一定要加密保存,最好是用不可逆的加密,如MD5或是SHA1之类的有hash算法的不可逆的加密算法。CSDN曾明文保存过用户的口令。(另,对于国内公司的品行以及有关部门的管理方式,我不敢保证国内网站以加密的方式保存你的口令。我觉得,做为一个有良知的人,我们应该加密保存用户的口令)</span></li>
</ul>
<div> <a href="/articles/5353.html#more-5353" class="more-link">…<p></p>
</a><p class="read-more"><a href="/articles/5353.html#more-5353" class="more-link"></a><a class="btn btn-default" href="/articles/5353.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p></div>
<div id="post-ratings-5353-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-5292" class="post-content post-5292 post type-post status-publish format-standard hentry category-progdesign category-career category-story tag-program tag-programmer tag-58">
<header class="entry-header">
<span class="screen-reader-text">弱爆程序员的特征值</span>
<h2 class="entry-title">
<a href="/articles/5292.html" rel="bookmark">弱爆程序员的特征值</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/5292.html" title="10:04" rel="bookmark"><time class="entry-date" datetime="2011-08-23T10:04:06+08:00" pubdate="">2011年08月23日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/articles/author/sumtec" title="View all posts by sumtec" rel="author">sumtec</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/5292.html#comments" class="comments-link">69 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 60,080 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>【<strong><span style="color: #cc0000;">感谢网友</span><a title="由 sumtec 发布" href="/articles/author/sumtec" rel="author">sumtec</a><span style="color: #cc0000;">投递此文,很欢乐也有意思,与大家共勉</span></strong>】</p>
<p>首先说明:</p>
<p>1、以下特征是真实遇到过的,同事犯过的,乃至我自己也犯过的;<br/>
2、为了剧情需要,某些例子进行了一些夸张修饰等演绎创作,如无雷同,请勿生气;<br/>
3、如果你出现过以下症状之一,并不代表你就是弱爆了,但是如果你一直出现,乃至一说到这个大家就能联想到你,那么你就得小心了;<br/>
4、如果你是集这几个的大乘者,恭喜你,你已经找到了离开这个行业的充足理由了。</p>
<h4>好了,搞定!</h4>
<p>“那个Bug解决了吗?”</p>
<p>“好了,搞定!”</p>
<p>“这么快?”</p>
<p>正当你非常欣喜的时候,就传来了噩耗:刚才还能编译成功的,就失败了。(好吧,我们的集成编译尚未成功配置上,理论上这种事情应该会被退回。)又或者能编译成功,但是呢,原来明明能起作用的一个下拉框,突然发神经的不起作用了。最隐蔽的莫过于,一切正常,但是当你看到代码的时候,你就晕厥过去了。比如我们曾经发现了一个Bug,简单说就是每次用户点击某个东西,就会执行下面的这段C#代码:</p>
<p><code data-enlighter-language="csharp" class="EnlighterJSRAW">controlPropertyPanel.PropertyChanged += this.UpdatePropertyOnChanged;</code></p>
<p>这个Bug很明显会导致速度越来越慢,因为同一个更新操作会被更新N次,并且这个N会越来越大。其实这个Bug已经够弱了,但是后来居然被修改为:</p>
<p> <a href="/articles/5292.html#more-5292" class="more-link">…</a></p><a href="/articles/5292.html#more-5292" class="more-link">
</a><p class="read-more"><a href="/articles/5292.html#more-5292" class="more-link"></a><a class="btn btn-default" href="/articles/5292.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-5292-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-5265" class="post-content post-5265 post type-post status-publish format-standard hentry category-cplusplus category-proglanguage tag-c tag-c-11 tag-c0x">
<header class="entry-header">
<span class="screen-reader-text">C++11 中值得关注的几大变化(详解)</span>
<h2 class="entry-title">
<a href="/articles/5265.html" rel="bookmark">C++11 中值得关注的几大变化(详解)</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/5265.html" title="08:43" rel="bookmark"><time class="entry-date" datetime="2011-08-19T08:43:59+08:00" pubdate="">2011年08月19日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/5265.html#comments" class="comments-link">91 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 96,499 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>源文章来自前C++标准委员会的 <a href="http://www.softwarequalityconnection.com/author/dannykalev/">Danny Kalev</a> 的 <a href="http://www.softwarequalityconnection.com/2011/06/the-biggest-changes-in-c11-and-why-you-should-care/" target="_blank">The Biggest Changes in C++11 (and Why You Should Care)</a>,赖勇浩做了一个<a href="http://blog.csdn.net/lanphaday/article/details/6564162" target="_blank">中文翻译在这里</a>。所以,我就不翻译了,我在这里仅对文中提到的这些变化“<strong>追问为什么要引入这些变化</strong>”的一个探讨,<strong>只有知道为了什么,用在什么地方,我们才能真正学到这个知识</strong>。而以此你可以更深入地了解这些变化。所以,本文不是翻译。因为写得有些仓促,所以难免有问题,还请大家指正。</p>
<h4 class="color-programming">Lambda 表达式</h4>
<p>Lambda表达式来源于函数式编程,说白就了就是在使用的地方定义函数,有的语言叫“闭包”,如果 lambda 函数没有传回值(例如 <tt>void</tt> ),其回返类型可被完全忽略。 定义在与 lambda 函数相同作用域的变量参考也可以被使用。这种的变量集合一般被称作 closure(闭包)。我在这里就不再讲这个事了。表达式的简单语法如下,</p>
<p><code data-enlighter-language="c" class="EnlighterJSRAW">[capture](parameters)->return_type {body}</code></p>
<p>原文的作者给出了下面的例子:</p>
<pre data-enlighter-language="c" class="EnlighterJSRAW">int main()
{
char s[]="Hello World!";
int Uppercase = 0; //modified by the lambda
for_each(s, s+sizeof(s), [&Uppercase] (char c) {
if (isupper(c))
Uppercase++;
});
cout << Uppercase << " uppercase letters in: " << s <<endl;
}</pre>
<p>在传统的STL中for_each() 这个玩意最后那个参数需要一个“函数对象”,所谓函数对象,其实是一个class,这个class重载了operator(),于是这个对象可以像函数的式样的使用。实现一个函数对象并不容易,需要使用template,比如下面这个例子就是函数对象的简单例子(实际的实现远比这个复杂):</p>
<p> <a href="/articles/5265.html#more-5265" class="more-link">…</a></p><a href="/articles/5265.html#more-5265" class="more-link">
</a><p class="read-more"><a href="/articles/5265.html#more-5265" class="more-link"></a><a class="btn btn-default" href="/articles/5265.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-5265-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-5247" class="post-content post-5247 post type-post status-publish format-standard hentry category-webdev category-misc category-progdesign tag-sina tag-twitter tag-web tag-weibo">
<header class="entry-header">
<span class="screen-reader-text">国内微博和Twitter的最大不同</span>
<h2 class="entry-title">
<a href="/articles/5247.html" rel="bookmark">国内微博和Twitter的最大不同</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/5247.html" title="08:34" rel="bookmark"><time class="entry-date" datetime="2011-08-17T08:34:04+08:00" pubdate="">2011年08月17日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/5247.html#comments" class="comments-link">85 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 62,876 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>霍炬近两个月前写过一篇《<a href="http://blog.devep.net/virushuo/2011/06/26/microblogging.html">microblogging和微博信息架构产品差距和影响</a>》分析了国内微博和Twitter的差距,重点就是因为信息的平等性。我也一直在观察新浪微博,以及新浪和Twitter的一些功能上的差别。发现了一些东西,想在这里和大家分享一下。我的见解达不到像霍炬那样的层次,作为一个技术人员,我只能在产品功能上做些分析。欢迎大家指正。</p>
<h4>现实状况</h4>
<p>国内的微博就是新浪,Sohu微博,腾讯微博,以及饭否。我们不难发现:</p>
<ul>
<li>搜狐的和腾讯的就是Copy新浪的。在Following和Followed上大家都有自己所谓的“创新”</li>
<li>饭否是在Copy Twitter,这点太明显了,不过,抄在了表面,而且相当的怪。</li>
</ul>
<p>国内所有的这些以Twitter为蓝本干出来的这些东西,其和Twitter在核心功能上有这些差别:</p>
<ul>
<li>Twitter的Retweet一点信息都加不上,国内的微博的转发需要加上自己的评论,也就形自己的信息。</li>
<li>Twitter的Reply只会有一个@原来的人,国内的Reply也很相似,只是勾上转发后就会把Reply的东西以“<strong>//@XXX</strong>”的方式成为自己的信息。</li>
<li>饭否的做法比较怪,转发加原文(想做成新浪的样子),回复不加原文,只有@(Twitter)的样子,可见饭否的分裂。</li>
</ul>
<h4>SNS中的上下文</h4>
<p>这段时间,我一直在想,新浪为什么要做成这样,为什么不做成Twitter那样,或者,为什么Twitter做成那样而不是新浪这样?从表面上看上去,<strong>新浪的“<span style="color: #800000;">回复+转发</span>”会带被回的信息,而Twitter的回复不带上下文,Twitter上一些我fo的人的话题完全看不懂,不像新浪的还能看到上文</strong>。</p>
<p>老实说,在一开始,我还觉得新浪微博这种用法和技术上要比 Twitter 要强大,现在看来是我当时对Twitter并不熟悉。经过这段时间的观察。<strong>我恰恰发现新浪在转发和回复上都要带上原文其实是一件很没有技术含量的事</strong>。要说清这个事,请让我说一下评论和回复的事。</p>
<p> <a href="/articles/5247.html#more-5247" class="more-link">…</a></p><a href="/articles/5247.html#more-5247" class="more-link">
</a><p class="read-more"><a href="/articles/5247.html#more-5247" class="more-link"></a><a class="btn btn-default" href="/articles/5247.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-5247-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-5201" class="post-content post-5201 post type-post status-publish format-standard hentry category-misc tag-coding tag-programmer tag-refactory tag-58">
<header class="entry-header">
<span class="screen-reader-text">重构代码的7个阶段</span>
<h2 class="entry-title">
<a href="/articles/5201.html" rel="bookmark">重构代码的7个阶段</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/5201.html" title="08:42" rel="bookmark"><time class="entry-date" datetime="2011-08-16T08:42:35+08:00" pubdate="">2011年08月16日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/5201.html#comments" class="comments-link">77 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 60,924 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>你曾去想重构一个很老的模块,但是你只看了一眼你就恶心极了。文档,奇怪的函数和类的命名,等等,整个模块就像一个带着脚镣的衣衫褴褛的人,虽然能走,但是其已经让人感到很不舒服。面对这种情况,真正的程序员会是不会认输的,他们会接受挑战认真分析,那怕重写也在所不惜。最终那个模块会被他们重构,就像以前和大家介绍过的<a title="各种流行的编程风格" href="/articles/2058.html" target="_blank">那些令人销魂的编程方式</a>中的屠宰式编程一样。下面是重构代码的几个阶段,文章来自:<a href="https://norsedev.blogspot.com/2011/08/n-stages-of-refactoring.html" target="_blank">The 7 stages of refactoring</a>,下面的翻译只是意译。</p>
<p><strong>第一阶段 – 绝望</strong></p>
<p><strong></strong>在你开始去查看你想要重构的模块的,你会觉得好像很简单,这里需要改一个类,那里需要改两到三个函数,重写几个函数,看上去没什么大不了的,一两天就搞定了。于是你着手开始重构,然后当你调整重构了一些代码,比如改了一些命名,修理了一些逻辑,渐渐地,你会发现这个怪物原来体型这么大,你会看到与代码不符甚至含糊不清的注释,完全摸不着头脑的数据结构,还有一些看似不需要方法被调了几次,你还会发现无法搞清一个函数调用链上的逻辑。你感到这个事可能一周都搞不定,你开始绝望了。</p>
<p><strong>第二阶段 – 找最简单的做</strong></p>
<p><strong></strong>你承认你要重构的这个模块就是一个可怕的怪物,不是一两下就可以搞定的,于是你开始着干一些简单的事,比如重新命名一下几个函数,移除一些代码的阻碍,产生几个常量来消除magic number,等等,你知道这样做至少不会让代码变得更糟糕。</p>
<p><strong>第三阶段 – 再次绝望</strong></p>
<p><strong></strong>但是接下来的事会让你再次撞墙。你会发现那些代码的瑕疵是些不痛不痒的事,改正这些事完全于事无补,你应该要做的事就是重写所有的东西。但是你却没有时间这么干,而这些代码剪不乱理还乱,耦合得太多,让你再一次绝望。所以,你只能部分重写那些不会花太多时间的部分,这样至少可以让这些老的代码能被更多的重用。虽然不完美,但是至少可以试试。</p>
<p> <a href="/articles/5201.html#more-5201" class="more-link">…</a></p><a href="/articles/5201.html#more-5201" class="more-link">
</a><p class="read-more"><a href="/articles/5201.html#more-5201" class="more-link"></a><a class="btn btn-default" href="/articles/5201.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-5201-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-5202" class="post-content post-5202 post type-post status-publish format-standard hentry category-proglanguage tag-c tag-javascript tag-oop tag-ruby">
<header class="entry-header">
<span class="screen-reader-text">对象的消息模型</span>
<h2 class="entry-title">
<a href="/articles/5202.html" rel="bookmark">对象的消息模型</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/5202.html" title="10:37" rel="bookmark"><time class="entry-date" datetime="2011-08-15T10:37:13+08:00" pubdate="">2011年08月15日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/articles/author/todd" title="View all posts by Todd" rel="author">Todd</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/5202.html#comments" class="comments-link">42 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 27,146 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p><strong><span style="color: #cc0000;">[ ———— 感谢</span> <a href="http://www.cnblogs.com/weidagang2046/" target="_blank">Todd 同学</a> <span style="color: #cc0000;">投递本文,<a href="http://www.cnblogs.com/weidagang2046/archive/2011/08/14/2138059.html" target="_blank">原文链接</a> ———— ]</span></strong></p>
<h4><strong>C++对象模型</strong></h4>
<p>话题从下面这段C++程序说起,你认为它可以顺利执行吗?</p>
<pre data-enlighter-language="c" class="EnlighterJSRAW">//C++
class A {
public:
void Hello(const std::string& name) {
std::cout << "hello " << name;
}
};
int main(int argc, char** argv)
{
A* pa = NULL; //!!
pa->Hello("world");
return 0;
}</pre>
<p>试试的确可以顺利运行输出hello world,奇怪吗?其实并不奇怪,根据C++对象模型,类的非虚方法并不会存在于对象内存布局中,实际上编译器是把Hello方法转化成了类似这样的全局函数:</p>
<pre data-enlighter-language="c" class="EnlighterJSRAW">void A_Hello_xxx(A * const this, const std::string& name) {
std::cout << “hello “ << name;
}</pre>
<p>对象指针其实是作为第一个参数被隐式传递的,pa->Hello(“world”)实际上是调用的A_Hello_xxx(pa, “world”),而恰好A_Hello_xxx内部没有使用pa,所以这段代码得以顺利运行。</p>
<h4><strong>对象的消息模型</strong></h4>
<p>如果是研究C++对象模型,上面的讨论可以到此为止,不过这里我想从另一个层面来继续探讨这个问题。OOP的先驱人物Alan Kay在总结Smalltalk的OO特征时强调:</p>
<p> <a href="/articles/5202.html#more-5202" class="more-link">…</a></p><a href="/articles/5202.html#more-5202" class="more-link">
</a><p class="read-more"><a href="/articles/5202.html#more-5202" class="more-link"></a><a class="btn btn-default" href="/articles/5202.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-5202-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<nav class="navigation posts-navigation" role="navigation">
<h2 class="screen-reader-text">Posts navigation</h2>
<div class="nav-links">
<div class="row">
<div class="wp-pagenavi" role="navigation">
<span class="pages">第 23 / 74 页</span><a class="first" aria-label="First Page" href="/">« 首页</a><a class="previouspostslink" rel="prev" aria-label="上一页" href="/page/22.html">«</a><span class="extend">...</span><a class="smaller page" title="第 10 页" href="/page/10.html">10</a><span class="extend">...</span><a class="page smaller" title="第 19 页" href="/page/19.html">19</a><a class="page smaller" title="第 20 页" href="/page/20.html">20</a><a class="page smaller" title="第 21 页" href="/page/21.html">21</a><a class="page smaller" title="第 22 页" href="/page/22.html">22</a><span aria-current="page" class="current">23</span><a class="page larger" title="第 24 页" href="/page/24.html">24</a><a class="page larger" title="第 25 页" href="/page/25.html">25</a><a class="page larger" title="第 26 页" href="/page/26.html">26</a><a class="page larger" title="第 27 页" href="/page/27.html">27</a><a class="page larger" title="第 28 页" href="/page/28.html">28</a><span class="extend">...</span><a class="larger page" title="第 40 页" href="/page/40.html">40</a><a class="larger page" title="第 50 页" href="/page/50.html">50</a><a class="larger page" title="第 60 页" href="/page/60.html">60</a><a class="larger page" title="第 70 页" href="/page/70.html">70</a><span class="extend">...</span><a class="nextpostslink" rel="next" aria-label="下一页" href="/page/24.html">»</a><a class="last" aria-label="Last Page" href="/page/74.html">末页 »</a>
</div>
</div>
</div>
</nav>
</main>
</div>
</div>
</div>
</div>
</div>
</body></html>