-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode_kata_seven.html
More file actions
428 lines (348 loc) · 20.5 KB
/
code_kata_seven.html
File metadata and controls
428 lines (348 loc) · 20.5 KB
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
417
418
419
420
421
422
423
424
425
426
427
428
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" id="typepad-standard" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="http://www.typepad.com/" />
<meta name="description" content="The last couple of kata have been programming challenges; let’s move back into mushier, people-oriented stuff this week. This kata is about reading code critically—our own code. Here’s the challenge. Find a piece of code you wrote last year sometime...." />
<link rel="stylesheet" href="http://codekata.pragprog.com/styles.css?v=6" type="text/css" media="screen" />
<link rel="stylesheet" href="http://static.typepad.com/.shared:v20110929.01-0-gb92b083:typepad:en_us/themes/common/print.css" type="text/css" media="print" />
<link rel="alternate" type="application/atom+xml" title="Posts on 'CodeKata' (Atom)" href="http://codekata.pragprog.com/atom.xml" />
<link rel="alternate" type="application/rss+xml" title="Posts on 'CodeKata' (RSS 1.0)" href="http://codekata.pragprog.com/index.rdf" />
<link rel="alternate" type="application/rss+xml" title="Posts on 'CodeKata' (RSS 2.0)" href="http://codekata.pragprog.com/rss.xml" />
<script type="text/javascript">
var TPApp = {};
TPApp.app_uri = "http://www.typepad.com/";
</script>
<script type="text/javascript" src="http://static.typepad.com/.shared:v20110929.01-0-gb92b083:typepad:en_us/js/yui/yahoo-dom-event.js,/js/app/thumbnail-gallery-min.js,/js/sixatrack-loader.js,/js/app/flyouts-min.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['t2._setAccount', 'UA-225723-36']);
_gaq.push(['t2._setDomainName', 'none']);
_gaq.push(['t2._setAllowLinker', true]);
_gaq.push(['t2._setCustomVar', 1, 'Blog', '6a00d83451c41c69e200d8341c84fe53ef', 3]);
_gaq.push(['t2._setCustomVar', 2, 'Page Type', 'Individual', 3]);
_gaq.push(['t2._trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<title>CodeKata: Kata Seven: How'd I Do?</title>
<link rel="start" href="http://codekata.pragprog.com/" title="Home" />
<link rel="prev" href="http://codekata.pragprog.com/2007/01/kata_eight_conf.html?no_prefetch=1" title="Kata Eight: Conflicting Objectives" />
<link rel="next" href="http://codekata.pragprog.com/2007/01/kata_six_anagra.html?no_prefetch=1" title="Kata Six: Anagrams" />
<!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<rdf:Description
rdf:about="http://codekata.pragprog.com/2007/01/kata_seven_howd.html"
trackback:ping="http://www.typepad.com/services/trackback/6a00d83451c41c69e200d83572af1a69e2"
dc:title="Kata Seven: How'd I Do?"
dc:identifier="http://codekata.pragprog.com/2007/01/kata_seven_howd.html"
dc:description="The last couple of kata have been programming challenges; let’s move back into mushier, people-oriented stuff this week. This kata is about reading code critically—our own code. Here’s the challenge. Find a piece of code you wrote last year sometime...."
dc:creator="Dave Thomas"
dc:date="2007-01-28T17:54:31-06:00" />
</rdf:RDF>
-->
</head>
<body class="layout-two-column-right">
<div id="container">
<div id="container-inner" class="pkg">
<!-- banner -->
<div id="banner">
<div id="banner-inner" class="pkg">
<h1 id="banner-header"><a href="http://codekata.pragprog.com/" accesskey="1">CodeKata</a></h1>
<h2 id="banner-description">
How to Become a Better Developer
</h2>
</div>
</div>
<div id="pagebody">
<div id="pagebody-inner" class="pkg">
<div id="alpha">
<div id="alpha-inner" class="pkg">
<!-- content nav -->
<p class="content-nav">
<a href="http://codekata.pragprog.com/2007/01/kata_eight_conf.html">« Kata Eight: Conflicting Objectives</a> |
<a href="http://codekata.pragprog.com/">Main</a>
| <a href="http://codekata.pragprog.com/2007/01/kata_six_anagra.html">Kata Six: Anagrams »</a>
</p>
<!-- entry -->
<h2 class="date-header">January 28, 2007</h2>
<div class="entry-author-dave_thomas entry-type-post entry" id="entry-15481452">
<h3 class="entry-header">Kata Seven: How'd I Do?</h3>
<div class="entry-content">
<div class="entry-body">
<p>
The last couple of kata have been programming challenges; let’s move
back into mushier, people-oriented stuff this week.
</p>
</div>
<a id="more"></a>
<div class="entry-more">
<p>
This kata is about reading code critically—our own code. Here’s
the challenge. Find a piece of code you wrote last year sometime. It should
be a decent sized chunk, perhaps 500 to 1,000 lines long. Pick code which
isn’t still fresh in your mind.
</p>
<p>
Now we need to do some acting. Read through this code three times. Each
time through, pretend something different. Each time, jot down notes on the
stuff you find.
</p>
<ul>
<li>The first time through, pretend that the person who wrote this code is the
best programmer you know. Look for all the examples of great code in the
program.
</li>
<li>The second time through, pretend that the person who wrote this code is the
worst programmer you know. Look for all the examples of horrible code and
bad design.
</li>
<li>The third (and last) time though, pretend that you’ve been told that
this code contains serious bugs, and that the client is going to sue you to
bankruptcy unless you fix them. Look for every potential bug in the code.
</li>
</ul>
<p>
Now look at the notes you made. What is the nature of the good stuff you
found? Would you find similar good stuff in the code you’re writing
today. What about the bad stuff; are similar pieces of code sneaking in to
your current code too. And finally, did you find any bugs in the old code?
If so, are any of them things that that you’d want to fix now that
you’ve found them. Are any of them systematic errors that you might
still be making today?
</p>
<h2>Moving Forward By Looking Back</h2>
<p>
Perhaps you’re not like me, but whenever I try this exercise I find
things that pleasantly surprise me and things that make me cringe in
embarrassment. I find the occasional serious bug (along with more frequent
less but serious issues). So I try to make a point of looking back at my
code fairly frequently.
</p>
<p>
However, doing this six months after you write code is not the best way of
developing good software today. So the underlying challenge of this kata is
this: how can we get into the habit of critically reviewing the code that
we write, as we write it? And can we use the techniques of reading code
with different expectations (good coder, bad coder, and bug hunt) when
we’re reviewing our colleagues code?
</p>
</div>
</div>
<div class="entry-footer">
<p class="entry-footer-info">
<span class="post-footers">Posted at 05:54 PM </span> <span class="separator">|</span> <a class="permalink" href="http://codekata.pragprog.com/2007/01/kata_seven_howd.html">Permalink</a>
</p>
<!-- technorati tags -->
<!-- post footer links -->
</div>
</div>
<div class="trackbacks">
<a id="trackback"></a>
<h3 class="trackbacks-header">TrackBack</h3>
<div class="trackbacks-info">
<p>TrackBack URL for this entry:<br /><span class="trackbacks-link">http://www.typepad.com/services/trackback/6a00d83451c41c69e200d83572af1a69e2</span></p>
<p>Listed below are links to weblogs that reference <a href="http://codekata.pragprog.com/2007/01/kata_seven_howd.html">Kata Seven: How'd I Do?</a>:</p>
</div>
<div class="trackbacks-content">
</div>
</div>
<a id="comments"></a>
<div class="comments" id="all-comments">
<h3 class="comments-header">Comments</h3>
<div class="comments-content" id="comments-content">
<!-- comment list --><a id="c6a00d83451c41c69e20147e0256b62970b"></a>
<div class="comment comment-odd comment-has-avatar" id="comment-6a00d83451c41c69e20147e0256b62970b">
<div class="comment-avatar">
<img id="comment-6a00d83451c41c69e20147e0256b62970b-avatarimg" src="http://graph.facebook.com/100000637122711/picture?type=square" alt="Kiranpulsar2007" width="50" height="50" at:flyout-userxid="6p0147e0255fde970b" at:flyout-enabled="yes" />
</div>
<div class="comment-content" id="comment-6a00d83451c41c69e20147e0256b62970b-content">
<span id="comment-6a00d83451c41c69e20147e0256b62970b-content"><p>hi sir am kiran from india </p>
<p>i finished my masters of computer applications in the year 2009 still am not got any job in software development ...am very weak in programming language and coding skills how can i improve my coding skills and programming skills</p>
<p>please suggest me to improve my carrer in coding skills</p>
<p>please kindly reply to me</p>
</div>
<p class="comment-footer">
Posted by:
<a rel="nofollow" target="_blank" title="http://profile.typepad.com/kiranpulsar2007" href="http://profile.typepad.com/kiranpulsar2007">Kiranpulsar2007</a> |
<a href="http://codekata.pragprog.com/2007/01/kata_seven_howd.html?cid=6a00d83451c41c69e20147e0256b62970b#comment-6a00d83451c41c69e20147e0256b62970b">November 25, 2010 at 07:49 AM</a>
</p>
</div><a id="c6a00d83451c41c69e20133f1c8d192970b"></a>
<div class="comment comment-even comment-has-avatar" id="comment-6a00d83451c41c69e20133f1c8d192970b">
<div class="comment-avatar">
<img id="comment-6a00d83451c41c69e20133f1c8d192970b-avatarimg" src="http://static.typepad.com/.shared:v20110929.01-0-gb92b083:typepad:en_us/default-userpics/17-50si.gif" alt="Dave Aronson" width="50" height="50" />
</div>
<div class="comment-content" id="comment-6a00d83451c41c69e20133f1c8d192970b-content">
<span id="comment-6a00d83451c41c69e20133f1c8d192970b-content"><p>I once read something somewhat like:</p>
<p>- The novice comments nothing.<br />
- The apprentice comments everything.<br />
- The journeyman comments why he did things that way.<br />
- The master comments why he DIDN'T do things ANOTHER way.</p></span>
</div>
<p class="comment-footer">
Posted by:
<a rel="nofollow" target="_blank" title="http://www.davearonson.com" href="http://www.davearonson.com">Dave Aronson</a> |
<a href="http://codekata.pragprog.com/2007/01/kata_seven_howd.html?cid=6a00d83451c41c69e20133f1c8d192970b#comment-6a00d83451c41c69e20133f1c8d192970b">June 25, 2010 at 03:22 PM</a>
</p>
</div><a id="c105229112"></a>
<div class="comment comment-odd comment-by-owner comment-has-avatar" id="comment-105229112">
<div class="comment-avatar">
<img id="comment-6a00d83451c41c69e200e550a0fc848834-avatarimg" src="http://up4.typepad.com/6a00d83451c41c69e200e55005ede28834-50si" alt="Dave Thomas" width="50" height="50" at:flyout-userxid="6p00d83451c41c69e2" at:flyout-enabled="yes" />
</div>
<div class="comment-content" id="comment-105229112-content">
<span id="comment-105229112-content"><p>Harvey:</p>
<p>I personally write comments (and hope to see comments in the code I read) that describe why non-obvious code is the way it is. I expect to see the code itself to be clear enough to document what it does.</p>
<p>The exception is with public APIs, where I use comments to document the interface, and tools to extract and format those comments into generally usable (say) HTML pages.</p>
<p><br />
Dave</p></span>
</div>
<p class="comment-footer">
Posted by:
<a rel="nofollow" target="_blank" title="http://profile.typepad.com/pragdave" href="http://profile.typepad.com/pragdave">Dave Thomas</a> |
<a href="http://codekata.pragprog.com/2007/01/kata_seven_howd.html?cid=105229112#comment-6a00d83451c41c69e200e550a0fc848834">February 29, 2008 at 11:43 AM</a>
</p>
</div><a id="c105223516"></a>
<div class="comment comment-even comment-has-avatar" id="comment-105223516">
<div class="comment-avatar">
<img id="comment-6a00d83451c41c69e200e5508c2a688833-avatarimg" src="http://static.typepad.com/.shared:v20110929.01-0-gb92b083:typepad:en_us/default-userpics/05-50si.gif" alt="Harvey Flaisher" width="50" height="50" />
</div>
<div class="comment-content" id="comment-105223516-content">
<span id="comment-105223516-content"><p>Hello Dave:</p>
<p>I hope I am posting this in the right place. What is your opinion on in-code comments. I have done this all my career and cant imagine anyone discouraging it. Yet, on my current project, there is a Java developer who discourages this. </p>
<p>Your opinion?</p></span>
</div>
<p class="comment-footer">
Posted by:
Harvey Flaisher |
<a href="http://codekata.pragprog.com/2007/01/kata_seven_howd.html?cid=105223516#comment-6a00d83451c41c69e200e5508c2a688833">February 29, 2008 at 11:02 AM</a>
</p>
</div>
</div>
</div>
<!-- comment-form-atp -->
<p class="comments-closed">
The comments to this entry are closed.
</p>
</div>
</div>
<div id="beta">
<div id="beta-inner" class="pkg">
<!-- sidebar -->
<div class="module-syndicate module">
<div class="module-content">
<a href="http://codekata.pragprog.com/atom.xml">Subscribe to this blog's feed</a>
</div>
</div>
<!-- user photo -->
<div class="module-photo module">
<div class="module-content"><img src="http://pragdave.blogs.pragprog.com/.a/6a00d83451c41c69e200e55005ede28834-150wi" alt="My Photo" /></div>
</div>
<div class="module-typelist module">
<h2 class="module-header">Other links</h2>
<div class="typelist-plain module-content">
<ul class="module-list">
<li class="module-list-item"><div class="typelist-note-label"><a href="http://pragdave.pragprog.com">My Blog</a></div><div class="typelist-note">Dave's blog, which stuff on Ruby, Rails, general programming, careers, and other stuff.</div></li>
<li class="module-list-item"><div class="typelist-note-label"><a href="http://pragmaticprogrammer.com/">The Pragmatic Programmers</a></div><div class="typelist-note">Where it all started! Have a look at the books we're publishing on all sorts of programming topics. If you liked the kata, you might also like <a href="http://www.pragmaticprogrammer.com/titles/fr_quiz/">The Best of Ruby Quiz</a>.</div></li>
</ul>
</div>
</div>
<div class="module-archives module">
<h2 class="module-header"><a href="http://codekata.pragprog.com/archives.html">Archives</a></h2>
<div class="module-content">
<ul class="module-list">
<li class="module-list-item"><a href="http://codekata.pragprog.com/2007/01/index.html">January 2007</a></li>
</ul>
</div>
</div>
<div class="module-typelist module">
<h2 class="module-header">The Kata</h2>
<div class="module-content">
<ul class="module-list">
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/code_kata_one_s.html">1. Supermarket Pricing</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_two_karate.html">2. Karate Chop</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_three_how_.html">3. How Big, How Fast?</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_four_data_.html">4. Data Munging</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_five_bloom.html">5. Bloom Filters</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_six_anagra.html">6. Anagrams</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_seven_howd.html">7. How'd I Do?</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_eight_conf.html">8. Conflicting Objectives</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_nine_back_.html">9. Back to the CheckOut</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_ten_hashes.html">10. Hashes vs. Classes</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_eleven_sor.html">11. Sorting it Out</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_twelve_bes.html#more">12. Best Sellers</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_thirteen_c.html">13, Counting Code Lines</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_fourteen_t.html">14. Tom Swift Under Milk Wood</a></li>
<li class="module-list-item"><a title="" href="http://www.codekata.com/2007/01/code_kata_fifte.html">15. Playing With Bits</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_sixteen_bu.html#more">16. Business Rules</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_seventeen_.html">17. More Business Processing</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_eighteen_t.html">18. Transitive Dependencies</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_nineteen_w.html">19. Word Chains</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_twenty_klo.html">20. Klondike</a></li>
<li class="module-list-item"><a title="" href="http://codekata.pragprog.com/2007/01/kata_twenty_one.html">21. Simple Lists</a></li>
</ul>
</div>
</div>
<div class="module-widget module" id="widget-Lijit_lijit_wijit">
<div class="module-content">
<script type="text/javascript" src="http://www.lijit.com/informers/wijits?username=pragdave&js=1"></script><a style='color: #999' href='http://www.lijit.com' id='lijit_wijit_pvs_link'>Lijit Search</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
<!--
var extra_happy = Math.floor(1000000000 * Math.random());
document.write('<img src="http://www.typepad.com/t/stats?blog_id=633036&user_id=2226312&page=' + escape(location.href) + '&referrer=' + escape(document.referrer) + '&i=' + extra_happy + '" width="1" height="1" alt="" style="position: absolute; top: 0; left: 0;" />');
// -->
</script>
<!-- Start Quantcast tag -->
<script type="text/javascript" src="http://edge.quantserve.com/quant.js"></script>
<script type="text/javascript">_qoptions = { tags:"typepad.extended" }; _qacct="p-fcYWUmj5YbYKM"; quantserve();</script>
<noscript>
<a href="http://www.quantcast.com/p-fcYWUmj5YbYKM" target="_blank"><img src="http://pixel.quantserve.com/pixel/p-fcYWUmj5YbYKM.gif?tags=typepad.extended" style="display: none" border="0" height="1" width="1" alt="Quantcast"/></a>
</noscript>
<!-- End Quantcast tag -->
<!-- Blogside Toolbar -->
<script type="text/javascript">
var TPToolbar = {
src: "http://www.typepad.com/services/toolbar?blog_id=6a00d83451c41c69e200d8341c84fe53ef&asset_id=6a00d83451c41c69e200d83572af1a69e2&atype=Individual&to=http%3A%2F%2Fcodekata.pragprog.com%2F2007%2F01%2Fkata_seven_howd.html&autofollowed=0",
asset_xid: "6a00d83451c41c69e200d83572af1a69e2",
bookmarklet_uri: "http://static.typepad.com/.shared/js/qp/loader-combined-min.js"
};
var TYPEPAD___bookmarklet_domain = "http://www.typepad.com/";
</script>
<script type="text/javascript" src="/.shared/js/toolbar/blogside-toolbar-combined-min.js"></script>
<!-- End Blogside Toolbar -->
<!-- Begin comScore Tag -->
<script>
document.write(unescape("%3Cscript src='" + (document.location.protocol == "https:" ? "https://sb" : "http://b") + ".scorecardresearch.com/beacon.js'%3E%3C/script%3E"));
</script>
<script>
COMSCORE.beacon({
c1: 2,
c2: "6035669",
c3: "",
c4: "http://codekata.pragprog.com/2007/01/kata_seven_howd.html",
c5: "",
c6: "",
c15: ""
});
</script>
<noscript>
<img src="http://b.scorecardresearch.com/b?c1=2&c2=6035669&c3=&c4=http%3A%2F%2Fcodekata.pragprog.com%2F2007%2F01%2Fkata_seven_howd.html&c5=&c6=&c15=&cv=1.3&cj=1" style="display:none" width="0" height="0" alt="" />
</noscript>
<!-- End comScore Tag -->
</body>
</html>
<!-- ph=1 -->