tag:blogger.com,1999:blog-61808941012745057942024-03-20T01:14:32.539-07:00@Avi's - By Avi EtzioniI write about technology, about culture, and about a software-engineer's life.
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-6180894101274505794.post-30134607514305614052015-03-21T11:01:00.000-07:002015-03-21T11:32:35.018-07:007 Shell Commands You Must Know When Digging Through Log Files<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPMhKyFBLVkOKKqipIuEaEecG_Rw05Jw93R3htZfcrlUmmVUKAJWN7jkreUFSVs2HoaIHkm8G6lPkrKgvzUyQ7_OIJb_Q9YHZxivkJg_uYcRSN6VHUC204_DHAZzt5NG0v0Xq3l9bTVjrD/s1600/terminal-icon-osx.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPMhKyFBLVkOKKqipIuEaEecG_Rw05Jw93R3htZfcrlUmmVUKAJWN7jkreUFSVs2HoaIHkm8G6lPkrKgvzUyQ7_OIJb_Q9YHZxivkJg_uYcRSN6VHUC204_DHAZzt5NG0v0Xq3l9bTVjrD/s1600/terminal-icon-osx.png" height="280" width="320" /></a></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">We've all been there - staring through tons of log lines and trying to find a needle in a hay stack, trying to make some sense in all those log lines. I've recently noticed that a lot of people I work with are familiar with only a basic set of commands, usually only 'tail' and 'grep' (and also - only very very basic use of those commands) which makes it hard for them to dig through log files and find what they're really looking for.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">In this post, I'll share some of the command-line tools I love to use when digging through log files. I will only brief through the basics, the more advanced stuff could be found in the <i>man</i> pages.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Hope you'll find it useful. Feel free to add your own in the comments section.</span><br />
<span style="color: red; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b><br /></b></span>
<span style="color: red; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Clicking on any of the examples will lead you to the awesome tool <a href="http://explainshell.com/" target="_blank">explainshell</a> that explains what linux commands actually do.</b></span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">0. <i>cat</i> - Show me what you've got</span></h3>
<div>
<a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?tail" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: small;" target="_blank">cat man page</a></div>
<div>
<br /></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Well, the use of <i>cat</i> is usually so simple that I thought of not putting it here at all. But I decided, for the record, to add it here. So we'll use <i>cat</i> to print file content to the screen. Yes, it has more options, but that's the most common one. So I think that'll do for now :)</span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></h3>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">1. <i>tail</i> - Wait for it...</span></h3>
<a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?tail" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: small;" target="_blank">tail man page</a><br />
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The first one (aside from <i>cat</i> which is not counted) is the famous <i>tail</i> command that most people use. I actually very rarely use the 'tail' command. I would much rather use the <span style="color: #45818e; font-style: italic;">less </span>as you'll see below. The <i>tail</i> command, in its naive use, allows us to print to the standard output the last X lines from a file as follows:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><a href="https://www.blogger.com/blogger.g?blogID=6180894101274505794#less"><br /></a></span></div>
<div style="background-color: gainsboro; border: 2px solid;">
<a href="http://explainshell.com/explain?cmd=tail+-n10+mylog.log" target="_blank">tail -n10 mylog.log</a></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">This will print out the last 10 lines of the file <b>mylog.log</b>.</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">But What most people use it for is to stream log files (or other streams of messages) to the standard output using:</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div style="background-color: gainsboro; border: 2px solid;">
<a href="http://explainshell.com/explain?cmd=tail+-f+mylog.log" target="_blank">tail -f mylog.log</a></div>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">That's usually very helpful. But I would usually rather use <i>less</i> (with shift +F) instead as you'll see next. When I do use <i>tail</i> usually is when I want to pipe it to <i>grep</i> and see only specific lines:</span><br />
<br />
<div style="background-color: gainsboro; border: 2px solid;">
<a href="http://explainshell.com/explain?cmd=tail+-f+mylog.log+%7C+grep+some_string">tail -f mylog.log | grep some_string</a></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">This will stream only the log lines that contain <i>some_string</i> in them which is not as convenient to do with <i>less.</i></span><br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></h3>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">2. <i>less</i> - Less is more</span></h3>
<div>
<a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?less" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: small;" target="_blank">less man page</a></div>
<div>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><i>less</i> lets you navigate through a large input file. Unlike text-editors (like <i>vi</i> for example), <i>less</i> does not read the entire file before starting up which makes it faster to load. There are loads of features for <i>less</i> but I'll give here a few basic ones which will get you up and running quickly:</span></div>
<div>
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Shift + f: Will throw you to the end of the file and let you watch the stream of lines as more lines are added to the file/stream. So if you have a log file that is being filled with log lines, you'll see those log lines written, just like with "<i>tail -f"</i>. The big advantage over <i>tail </i>in my opinion is the option to use <i>Ctrl+C</i> to stop the stream and perform searches on it. <i>tail </i>just prints stuff to the terminal so you can't use search commands like you can do with <i>less </i>and that's why I would more commonly use <i>less</i> with <i>shift+f</i> and not <i>tail.</i></span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>/ - </i>Typing /<i> </i>allows you to then type a search term. <i>less</i> will now allow you to browse through all of the places in which this search term appears either with typing <i>n</i> to find the next appearance of the term or <i>Shift+n</i> to find the previous appearance.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>?</i> - Typing <i>?</i> does the exact opposite of <i>/. </i>It will search a term backwards (this also means that <i>n</i> will search for the term in the lines above the line you're at and <i>Shift+n</i> will search for the lines after the line you're at).</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>Shift + G</i> - Will take you to the last line of the file. It goes well with combination with <i>?</i> - if you want to search the latest place a phrase appeared just browse to the end of the file with <i>Shift+G</i> and then type <i>?</i> and the phrase.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>Line number + g</i> - Typing a number of line and then <i>g</i> will bring you to the specific line. I usually use it to go to the first line (typing 1g) and then using <i>/</i> to find the first time a phrase appears.</span></li>
</ol>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">There are, of course, a lot more options to <i>less</i> but that pretty much covers the basics.</span></div>
</div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">3. <i>grep</i> - Is it here?</span></h3>
</div>
<div>
<a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?grep" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: small;" target="_blank">grep man page</a></div>
<div>
<br /></div>
<div>
<i style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">grep</i><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> is a very useful command for finding only relevant lines. Basically, the easiest and probably most common pattern would be this one:</span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="background-color: gainsboro; border: 2px solid;">
<span style="color: #0000ee;"><a href="http://explainshell.com/explain?cmd=grep+string+mylog.log">grep phrase mylog.log</a></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">This pattern finds all the lines that contain the word '<i>phrase</i>' in the file <i>mylog.log</i>. Of course you can use file pattern such mylog.log*<i> </i>to search in all the <i>mylog.log</i> files. Again, grep has tons of options you can use but here are the ones I find most useful to start with:</span><br />
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>-v</i> - Adding <i>-v</i> finds all the lines that <b>don't</b> contain the phrase, instead of the ones that do.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>-c</i> - Count the number of matching (or non-matching if you use <i>-v</i>) lines.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>-e</i> - Allows to provide a regexp instead of a a plain phrase.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>-i</i> - Ignore case.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>-r</i> - Allows recursive search inside the directory tree.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>-n</i> - Prints the line number in the file in which the phrase was found</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>-A</i> 3 - Prints the 3 lines right after the match (of course, you can use other numbers and not only 3 :) ).</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>-B 3</i> - </span><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Prints the 3 lines right before the match.</span></li>
</ol>
<div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></h3>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">4. <i>awk</i> - Make it look better</span></h3>
</div>
<div>
<a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?awk" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: small;" target="_blank">awk (or gawk) man page</a></div>
<div>
<br /></div>
<div>
<i style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">awk</i><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"> could, by itself, fill a full blog-post. But this is a post for only the basics. So, I would usually use <i>awk</i> by piping with something like <i>grep</i> or <i>tail. awk</i> basically allows you to manipulate the input. The basic use I usually use awk for is to pretty-print the relevant data I grep-ed from the log line, and I believe an example would be easier to understand here. Let's say we have a file <i>mylog.log</i> that this is its content:</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div style="background-color: gainsboro; border: 2px solid;">
User Avi has id of 49240924<br />
Some unneeded data<br />
Some unneeded data<br />
Some unneeded data<br />
User George has id of 895042<br />
Some unneeded data<br />
Some unneeded data<br />
User Elaine has id of 90348235<br />
Some unneeded data<br />
Some unneeded data<br />
User Jerry has id of 9235239<br />
Some unneeded data<br />
Some unneeded data<br />
User Kramer has id of 94023920<br />
Some unneeded data<br />
Some unneeded data<br />
Some unneeded data</div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">I want to extract only those lines that contain a user name and the user's id. Using 'grep' would make it easy to extract the lines:</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div style="background-color: gainsboro; border: 2px solid;">
<b>~ $ <a href="http://explainshell.com/explain?cmd=grep+%22has+id+of%22+mylog.log" target="_blank">grep "has id of" mylog.log</a></b><br />
User Avi has id of 49240924<br />
User George has id of 895042<br />
User Elaine has id of 90348235<br />
User Jerry has id of 9235239<br />
User Kramer has id of 94023920</div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">But still I won't be able to have a clear mapping, user to id. I won't be able, for example to copy the result to a CSV file easily enough nor will I be able to further manipulate it with a few commands we'll learn below. But luckily, I have <i>awk</i> for the rescue:</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div style="background-color: gainsboro; border: 2px solid;">
<b>~ $ <a href="http://explainshell.com/explain?cmd=grep+%22has+id+of%22+mylog.log+%7C+awk+%7B%27print+%242%22%3A+%22%246%27%7D" target="_blank">grep "has id of" mylog.log | awk {'print $2": "$6'}</a></b><br />
Avi: 49240924<br />
George: 895042<br />
Elaine: 90348235<br />
Jerry: 9235239<br />
Kramer: 94023920</div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">In this case, I used awk to re-print the results from the grep using the <i>print</i> command. The $2 and $6 mark the 2nd and 6th token respectively of each line resulted from the grep assuming each token is separated by a space.</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">In order to change the delimiter from space to something else you could use the <i>-F</i> option and provide some other separator.</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">As I mentioned, there are tons of uses to <i>awk</i> besides what I showed here like printing lower/upper-case, substring, split and more but those are beyond the scope of this post. It is important, however, to know that those options exist, in case you ever find yourself in need of using them.</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">5. <i>uniq</i> - The only one</span></h3>
</div>
</div>
</div>
</div>
</div>
<div>
<a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?uniq" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: small;" target="_blank">uniq man page</a></div>
<div>
<br /></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><i>uniq</i> allows you to play with repeating lines. So, for example, if we take the example file from 'awk' we can print it and avoid the repetitions of the line "Some unneeded data":</span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<div style="background-color: gainsboro; border: 2px solid;">
<b>~ $ </b><span style="color: #0000ee;"><b><u><a href="http://explainshell.com/explain?cmd=cat+mylog.log+%7C+uniq" target="_blank">cat mylog.log | uniq</a></u></b></span><br />
User Avi has id of 49240924<br />
Some unneeded data<br />
User George has id of 895042<br />
Some unneeded data<br />
User Elaine has id of 90348235<br />
Some unneeded data<br />
User Jerry has id of 9235239<br />
Some unneeded data<br />
User Kramer has id of 94023920<br />
Some unneeded data</div>
<div>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">As you can see, the <i>uniq</i>-ness is reset whenever a non identical line is found. </span> <span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Here are the main extra features of <i>uniq</i>:</span><br />
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>-c</i> - Adding the <i>-c </i>switch will print the number of repetitions before each line.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>-d</i> - Will print only the lines that repeat more than once.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>-u</i> - Will print only the lines that do not repeat more than once.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>-i</i> - Ignore case</span></li>
</ol>
<div>
</div>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">6. <i>sort</i> - From A to Z</span></h3>
</div>
</div>
<div>
<a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?sort" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: small;" target="_blank">sort man page</a></div>
<div>
<br /></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Well, I guess it's easy to figure out what this command does. <i>sort</i> will sort its input and print it sorted to the standard output. Of course it goes well by piping with previous commands. For example, it might be a great tool after using <i>awk</i> to print a specific detail from a log line and print it sorted. For example, if we again take the example file from the <i>awk</i> command and add <i>sort </i>to the result we'll get the user ids sorted by names:</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<div style="background-color: gainsboro; border: 2px solid;">
<b>~ $ <a href="http://explainshell.com/explain?cmd=grep+%22has+id+of%22+mylog.log+%7C+awk+%7B%27print+%242%22%3A+%22%246%27%7D+%7C+sort" target="_blank">grep "has id of" mylog.log | awk {'print $2": "$6'} | sort</a></b><br />
Avi: 49240924<br />
Elaine: 90348235<br />
George: 895042<br />
Jerry: 9235239<br />
Kramer: 94023920</div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Another useful way of using <i>sort</i> would be by combining it with "<i>uniq -c</i>" if you want to sort by number of line repetitions.</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Most useful options of </span><i style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">sort</i><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">:</span><br />
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>-f</i> - Ignore case (because <i>-i</i> is such a cliche already).</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>-r</i> - Reverse order.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>-n</i> - Sort according to numeric value</span></li>
</ol>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Again, there are more options to <i>sort</i> which you can find in the man page.</span></div>
<div>
<br /></div>
</div>
<div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">7. <i>xargs</i> - Now, let's do something else</span></h3>
</div>
</div>
<div>
<a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?xargs" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: small;" target="_blank">xargs man page</a></div>
<div>
<br /></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">And what if, all of the data you extract is just needed as an input for another command? <i>xargs</i> is meant for building and executing commands from the standard input. How is it done? Well, by piping usually. Again, an example would be much easier here. Let's take a different example file - mylog2.log:</span></div>
<div>
<br /></div>
<div style="background-color: gainsboro; border: 2px solid;">
<b>User Avi has id of 49240924</b><br />
<b>User George has id of 895042</b><br />
<b>User Elaine has id of 90348235</b><br />
<b>User Jerry has id of 9235239</b><br />
<b>User Kramer has id of 94023920</b><br />
<b>User 49240924 presses the green button</b><br />
<b>User 49240924 presses the yellow button</b><br />
<b>User 895042 presses the red button</b><br />
<b>User 9235239 presses the green button</b><br />
<b>User 49240924 presses the green button</b><br />
<b>User 94023920 presses the red button</b></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Now, we want to find every action that 'Avi' took. Problem is - we know the name of the user, Avi, but the logs are written with the user id and not its name. Let's combine everything we have learned so far to get the desired output.</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">We first want to get the user's id:</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div style="background-color: gainsboro; border: 2px solid;">
<b>~ $ <a href="http://explainshell.com/explain?cmd=grep+%22User+Avi%22+mylog2.log" target="_blank">grep "User Avi" mylog2.log</a></b><br />
<b>User Avi has id of 49240924</b></div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">We already know how to print only the id without the prefix:</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div style="background-color: gainsboro; border: 2px solid;">
<b>~ $ <a href="http://explainshell.com/explain?cmd=grep+%22User+Avi%22+mylog2.log+%7C+awk+%7B%27print+%246%27%7D" target="_blank">grep "User Avi" mylog2.log | awk {'print $6'}</a></b><br />
<b>49240924</b></div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Now, we want to grep all the log lines that contain this id but we don't want to enter the id manually, so instead we'd use <i>xargs</i> as follows:</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div style="background-color: gainsboro; border: 2px solid;">
<b>~ $ <a href="http://explainshell.com/explain?cmd=grep+%22User+Avi%22+mylog2.log+%7C+awk+%7B%27print+%246%27%7D+%7C+xargs+-I+user-id+grep+user-id+mylog2.log" target="_blank">grep "User Avi" mylog2.log | awk {'print $6'} | xargs -I user-id grep user-id mylog2.log</a></b><br />
<b>User Avi has id of 49240924</b><br />
<b>User 49240924 presses the green button</b><br />
<b>User 49240924 presses the yellow button</b><br />
<b>User 49240924 presses the green button</b></div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">The switch -I defines a parameter named <i>user-id</i> which can later be used in the <i>grep command</i> and assigned with the value of the result from the piping to the <i>awk</i> command, in this case - the user id. If you want to take it one step further and get rid of the line "User Avi has id of 49240924" you can use "<i>grep -v" as follows:</i></span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><i><br /></i></span>
<br />
<div style="background-color: gainsboro; border: 2px solid;">
<b>~ $ <a href="http://explainshell.com/explain?cmd=grep+%22User+Avi%22+mylog2.log+%7C+awk+%7B%27print+%246%27%7D+%7C+xargs+-I+user-id+grep+user-id+mylog2.log+%7C+grep+-v+%22has+id%22" target="_blank">grep "User Avi" mylog2.log | awk {'print $6'} | xargs -I user-id grep user-id mylog2.log | grep -v "has id"</a></b><br />
<b>User 49240924 presses the green button</b><br />
<b>User 49240924 presses the yellow button</b><br />
<b>User 49240924 presses the green button</b><br />
<b><br /></b></div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">And now we get only the actions that the user Avi made.</span><br />
<br /></div>
<div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">That's it!</span></h3>
</div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">So, that's what I usually use when digging through log files. There is tons of more options and possibilities for those tools and also there are other tools that I left out because I wanted to focus on the absolute must in my opinion. I hope you enjoyed and learned that the world has more to offer than just <i>tail</i> and <i>grep.</i></span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><i><br /></i></span></div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Feel I left something too important out? Want to add something or correct me? Please feel free to leave your comment!</span></div>
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;"><br /></span></span></h3>
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;"><br /></span></span></h3>
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;">Find me on Twitter: </span><a href="https://twitter.com/AviEtzioni" style="color: #888888; font-weight: normal; text-decoration: none;">@AviEtzioni</a></span></h3>
<br />
<div>
<b>More interesting posts from this blog:</b><br />
<b><br /></b></div>
<div class="widget-content">
<div class="OUTBRAIN" data-src="http://avietzioni.blogspot.co.il/2013/11/welcome.html" data-widget-id="AR_1">
</div>
<script type="text/javascript">var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(ob,h);})();</script>
<script src="http://widgets.outbrain.com/outbrainLT.js" type="text/javascript"></script></div>
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.com2tag:blogger.com,1999:blog-6180894101274505794.post-15162289704786395092014-11-03T12:53:00.002-08:002014-11-13T12:47:06.920-08:00IoT Hackathon @ Journey 2014<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">A few weeks ago, my friend Alon Herbst told me about the first Israeli IoT (Internet of Things) hackathon that was organized and sponsored by Texas Instruments, IBM and Pitango VC. 3 days of developing end-to-end IoT applications, or what I heard when he told me about it - "3 days of vacation in order to work even harder than a normal day". Sounds very tempting indeed...</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">But after some discussion I agreed to go under one condition - "we're going there to win!".</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">We discussed some ideas and agreed that we need something that is both technological and can make a "show" on the demo day. After some ideas that revolved around babies and dogs (those things that steal the show) we decided to go with a sport training app. An app that will automatically sense your workout, figure out which exercise you do, how well you do it, how many repetitions, will track progress and will engage through gamification.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">For the "show"-factor we agreed upon bringing a winners podium and medals for the demo and do a little contest.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">The Hackathon itself</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">We arrived at Afeka collage where the hackathon was held and started to work day and night. </span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">While Alon was working on a motion analyzer algorithm (you won't believe how difficult it is to figure out a simple exercise repetition from a motion sensor and make it work in 3 days!), I worked on creating a fully real-time app that will connect to the motion detection sensors and demonstrate a real-time live competition between a few competitors. A third friend joined us and worked on the hardware stuff of configuring TI's CC3200 board to talk with IBM's cloud. For the gicky readers, here's our architecture (taken from our presenation):</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiE9cRuMDXCyFYxROkcBIu88uAXJmedfRq51FlqZ9mm2rcWwcDa5Yasv0GYvGunQCYlevxzE6_YfKF7cEUoaAdeJQh9aZOjd0iR64py2QhSkDCqH90L21A1nHOPh47DmnkcOhfz00rBeThn/s1600/Slide06.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiE9cRuMDXCyFYxROkcBIu88uAXJmedfRq51FlqZ9mm2rcWwcDa5Yasv0GYvGunQCYlevxzE6_YfKF7cEUoaAdeJQh9aZOjd0iR64py2QhSkDCqH90L21A1nHOPh47DmnkcOhfz00rBeThn/s1600/Slide06.jpg" height="480" width="640" /></a></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">And here's a screenshot of the app:</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimOTUF3Tiy-AyXR1PCmjgvLK3I4rRmlfy_EudEWF_GuO6Nd_vn4o5akiTN8cdWYhbdhZpSVqX6yx58tPwYjs845aaQODEBeWitAZSPWGf8w9-rlK_6B3uwpUw_31lncxxHeqrD5KXTgCFc/s1600/Screen+Shot+2014-11-01+at+12.53.40+AM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimOTUF3Tiy-AyXR1PCmjgvLK3I4rRmlfy_EudEWF_GuO6Nd_vn4o5akiTN8cdWYhbdhZpSVqX6yx58tPwYjs845aaQODEBeWitAZSPWGf8w9-rlK_6B3uwpUw_31lncxxHeqrD5KXTgCFc/s1600/Screen+Shot+2014-11-01+at+12.53.40+AM.png" height="310" width="640" /></a></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Amazingly, after 3 days this worked!! We had 2 contestants that wore the sensors and the push-up counters counted it live.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Our little show with the medals and the winners podium helped setting up the mood and we indeed won the hackathon, together with <a href="http://www.globes.co.il/news/article.aspx?did=1000981384">3 more groups </a>that built smart lighting-poles, health-monitoring for the elders and Wifi->BLE->IR connectors, and went up to the final stage. That's when the real hard work began.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h4>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">JournEY conference 2014</span></h4>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Well, the final of the hacakthon was part of the prestigious annual JournEY conference held by E&Y (Ernst & Young). This was a much more formal event and as such we had to meet a presentation coacher, to shoot a demo-video for case things go wrong, do a lot of rehearsals and basically align with the major league. </span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Here's the demo for the case things go wrong (unfortunately, we had to use it on the real stage):</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/FaFPicqXwf8?feature=player_embedded' frameborder='0'></iframe></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">After tons of work, the big day arrived. Instead of the plain-old-presentation that everyone is already used to, we decided to take the "show" one step further and performed a skit on stage in which I was the lazy person who can't finish his workout and Alon joins and motivates me to build this app to help me perform my workout and increase my engagement.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/vgkFnNRSthk?feature=player_embedded' frameborder='0'></iframe></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Everything went well. Well, almost everything. When we did the push-up contest, the WiFi broke down and the push-ups were not counted. Although it was kind of embarrassing, at the end of the contest the numbers did show up on the screen (in my mind I reminded myself that Bill Gates had a blue-screen when presenting Windows 98 and he lived. This is nothing...). And even though we were afraid it would cost us the victory we did win at the end. Well, we had to win, that was my agreement with Alon for going ;)</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqcX0d_YW5eInID0yOHZHssFfH5Txt1kygEJ4-hbfDRf1PODftrWVStpiZNfPIXIACwRMls5eQgxHiiryeip2qaj05y1L8urWtjLxyjSF06SEiD1Fb7c8a5Jk4SmfGMQL4QVGVgbcypNdF/s1600/1926042_10152482047366033_8875658146152612633_o.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqcX0d_YW5eInID0yOHZHssFfH5Txt1kygEJ4-hbfDRf1PODftrWVStpiZNfPIXIACwRMls5eQgxHiiryeip2qaj05y1L8urWtjLxyjSF06SEiD1Fb7c8a5Jk4SmfGMQL4QVGVgbcypNdF/s1600/1926042_10152482047366033_8875658146152612633_o.jpg" height="426" width="640" /></a></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">This hackathon was just an amazing experience and I thank TI, IBM & Pitango VC for organizing it and also to our hosts at "Afeka" collage and of course E&Y that gave us a very respectable stage to show-off on. And our names were even <a href="http://www.globes.co.il/news/article.aspx?did=1000983032">mentioned on Globes</a>.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">I can't wait for the next hackathon ;)</span><br />
<br />
<br /></div>
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;">Find me on Twitter: </span><a href="https://twitter.com/AviEtzioni" style="color: #888888; font-weight: normal; text-decoration: none;">@AviEtzioni</a></span></h3>
<br />
<div>
<b>More interesting posts from this blog:</b><br />
<b><br /></b></div>
<div class="widget-content">
<div class="OUTBRAIN" data-src="http://avietzioni.blogspot.co.il/2013/11/welcome.html" data-widget-id="AR_1">
</div>
<script type="text/javascript">var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(ob,h);})();</script>
<script src="http://widgets.outbrain.com/outbrainLT.js" type="text/javascript"></script></div>
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.com0tag:blogger.com,1999:blog-6180894101274505794.post-66531753804098538012014-09-13T09:40:00.001-07:002014-09-30T00:42:56.435-07:00Clean Code With Builders<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">To anyone who says that software engineering is not an art I say "Have you heard about design patterns?". Design patterns are like poetry to a software engineer. I never meant to write a post about them because tons of posts and books were already published on those. But following a <a href="http://avietzioni.blogspot.co.il/2014/01/hands-on-effective-refactoring-of.html">talk</a> I gave this week I understood that people are not familiar with the ways the "Builder" pattern can help them create a cleaner code.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<div style="text-align: justify;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://cdn.marketplaceimages.windowsphone.com/v8/images/7365f8fe-36ce-418b-8600-7decb016d24e?imageType=ws_icon_large" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="http://cdn.marketplaceimages.windowsphone.com/v8/images/7365f8fe-36ce-418b-8600-7decb016d24e?imageType=ws_icon_large" /></a></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">What Is The Builder Pattern?</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><i>You can skip this part if you're familiar with the Builder pattern for creating immutable objects.</i></span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><i><br /></i></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">The "Builder" pattern helps us, not surprisingly, to build objects. It is often used for building immutable objects. For example, let's say we have this class:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<pre style="background: #f9f9f9; color: #080808;"><span style="color: #a71d5d; font-style: italic;">public</span> <span style="color: #a71d5d; font-style: italic;">class</span> <span style="color: #bf4f24;">Student</span> {
<span style="color: #a71d5d; font-style: italic;">private</span> <span style="color: #a71d5d; font-style: italic;">final</span> <span style="color: #a71d5d; font-style: italic;">String</span> givenName;
<span style="color: #a71d5d; font-style: italic;">private</span> <span style="color: #a71d5d; font-style: italic;">final</span> <span style="color: #a71d5d; font-style: italic;">String</span> lastName;
<span style="color: #a71d5d; font-style: italic;">private</span> <span style="color: #a71d5d; font-style: italic;">final</span> <span style="color: #a71d5d; font-style: italic;">int</span> averageGrade;
<span style="color: #a71d5d; font-style: italic;">private</span> <span style="color: #a71d5d; font-style: italic;">final</span> <span style="color: #a71d5d; font-style: italic;">int</span> age;
<span style="color: #a71d5d; font-style: italic;">public</span> <span style="color: #bf4f24;">Student</span> (<span style="color: #a71d5d; font-style: italic;">final</span> <span style="color: #a71d5d; font-style: italic;">String</span> <span style="color: #234a97;">givenName</span>, <span style="color: #a71d5d; font-style: italic;">final</span> <span style="color: #a71d5d; font-style: italic;">String</span> <span style="color: #234a97;">lastName</span>,
<span style="color: #a71d5d; font-style: italic;">int</span> <span style="color: #234a97;">averageGrade</span>, <span style="color: #a71d5d; font-style: italic;">int</span> <span style="color: #234a97;">age</span>) {
<span style="color: #234a97;">this</span><span style="color: #794938;">.</span>givenName <span style="color: #794938;">=</span> givenName;
<span style="color: #234a97;">this</span><span style="color: #794938;">.</span>lastName <span style="color: #794938;">=</span> lastName;
<span style="color: #234a97;">this</span><span style="color: #794938;">.</span>averageGrade <span style="color: #794938;">=</span> averageGrade;
<span style="color: #234a97;">this</span><span style="color: #794938;">.</span>age <span style="color: #794938;">=</span> age;
}
<span style="color: #5a525f; font-style: italic;">// Rest of the class is only getters with no setters here</span>
} </pre>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Then, if we want to split the assembly of the fields from the actual construction, we can use a builder in the following manner:</span><br />
<br />
<pre style="background: #f9f9f9; color: #080808;"><span style="color: #a71d5d; font-style: italic;">public</span> <span style="color: #a71d5d; font-style: italic;">class</span> <span style="color: #bf4f24;">Student</span> {
<span style="color: #a71d5d; font-style: italic;">private</span> <span style="color: #a71d5d; font-style: italic;">final</span> <span style="color: #a71d5d; font-style: italic;">String</span> givenName;
<span style="color: #a71d5d; font-style: italic;">private</span> <span style="color: #a71d5d; font-style: italic;">final</span> <span style="color: #a71d5d; font-style: italic;">String</span> lastName;
<span style="color: #a71d5d; font-style: italic;">private</span> <span style="color: #a71d5d; font-style: italic;">final</span> <span style="color: #a71d5d; font-style: italic;">int</span> averageGrade;
<span style="color: #a71d5d; font-style: italic;">private</span> <span style="color: #a71d5d; font-style: italic;">final</span> <span style="color: #a71d5d; font-style: italic;">int</span> age;
<span style="color: #a71d5d; font-style: italic;">public</span> <span style="color: #bf4f24;">Student</span> (<span style="color: #a71d5d; font-style: italic;">final</span> <span style="color: #a71d5d; font-style: italic;">String</span> <span style="color: #234a97;">givenName</span>, <span style="color: #a71d5d; font-style: italic;">final</span> <span style="color: #a71d5d; font-style: italic;">String</span> <span style="color: #234a97;">lastName</span>,
<span style="color: #a71d5d; font-style: italic;">int</span> <span style="color: #234a97;">averageGrade</span>, <span style="color: #a71d5d; font-style: italic;">int</span> <span style="color: #234a97;">age</span>) {
<span style="color: #234a97;">this</span><span style="color: #794938;">.</span>givenName <span style="color: #794938;">=</span> givenName;
<span style="color: #234a97;">this</span><span style="color: #794938;">.</span>lastName <span style="color: #794938;">=</span> lastName;
<span style="color: #234a97;">this</span><span style="color: #794938;">.</span>averageGrade <span style="color: #794938;">=</span> averageGrade;
<span style="color: #234a97;">this</span><span style="color: #794938;">.</span>age <span style="color: #794938;">=</span> age;
}
<span style="color: #5a525f; font-style: italic;">// Rest of the class is only getters with no setters here</span>
<span style="color: #a71d5d; font-style: italic;">public</span> <span style="color: #a71d5d; font-style: italic;">static</span> <span style="color: #a71d5d; font-style: italic;">class</span> <span style="color: #bf4f24;">StudentBuilder</span> {
<span style="color: #a71d5d; font-style: italic;">private</span> <span style="color: #a71d5d; font-style: italic;">String</span> givenName;
<span style="color: #a71d5d; font-style: italic;">private</span> <span style="color: #a71d5d; font-style: italic;">String</span> lastName;
<span style="color: #a71d5d; font-style: italic;">private</span> <span style="color: #a71d5d; font-style: italic;">int</span> averageGrade;
<span style="color: #a71d5d; font-style: italic;">private</span> <span style="color: #a71d5d; font-style: italic;">int</span> age;
<span style="color: #a71d5d; font-style: italic;">public</span> <span style="color: #bf4f24;">StudentBuilder</span>() { }
<span style="color: #a71d5d; font-style: italic;">public</span> <span style="color: #a71d5d; font-style: italic;">StudentBuilder</span> <span style="color: #bf4f24;">withGivenName</span>(<span style="color: #a71d5d; font-style: italic;">final</span> <span style="color: #a71d5d; font-style: italic;">String</span> <span style="color: #234a97;">givenName</span>) {
<span style="color: #234a97;">this</span><span style="color: #794938;">.</span>givenName <span style="color: #794938;">=</span> givenName;
<span style="color: #794938;">return</span> <span style="color: #234a97;">this</span>;
}
<span style="color: #5a525f; font-style: italic;">// The rest of the 'with' setters look the same...</span>
<span style="color: #a71d5d; font-style: italic;">public</span> <span style="color: #a71d5d; font-style: italic;">Student</span> <span style="color: #bf4f24;">build</span>() {
<span style="color: #794938;">return</span> <span style="color: #794938;">new</span> <span style="color: #a71d5d; font-style: italic;">Student</span>(givenName, lastName, averageGrade, age);
}
}
}
</pre>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">This way we have a mutable inner class <i>StudentBuilder</i> which gathers the fields we need for the immutable class and when the time has come to create the immutable object we just call <i>build()</i> and we get the immutable object already fully constructed.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">So what does that have to do with clean code?</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Express Yourself With Builders</span></h3>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">I'm sure you have seen a pattern similar to that in the past:</span><br />
<pre style="background: #f9f9f9; color: #080808;"><span style="color: #a71d5d; font-style: italic;">StudentGrades</span> grades <span style="color: #794938;">=</span> <span style="color: #794938;">new</span> <span style="color: #a71d5d; font-style: italic;">StudentGrades</span>();
grades<span style="color: #794938;">.</span>setStudentId(<span style="color: #811f24; font-weight: 700;">97</span>); <span style="color: #5a525f; font-style: italic;">// The student id in the DB</span>
grades<span style="color: #794938;">.</span>setMath(<span style="color: #811f24; font-weight: 700;">84</span>);
grades<span style="color: #794938;">.</span>setEnglish(<span style="color: #811f24; font-weight: 700;">92</span>);
grades<span style="color: #794938;">.</span>setChemistry(<span style="color: #811f24; font-weight: 700;">75</span>);
grades<span style="color: #794938;">.</span>setLiteratue(<span style="color: #811f24; font-weight: 700;">88</span>);
grades<span style="color: #794938;">.</span>setGymnastic(<span style="color: #811f24; font-weight: 700;">55</span>);
grades<span style="color: #794938;">.</span>setBiology(<span style="color: #811f24; font-weight: 700;">76</span>);
grades<span style="color: #794938;">.</span>setHistory(<span style="color: #811f24; font-weight: 700;">81</span>);
</pre>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">What we'll usually try to do next is something that will wrap these lines into a single line like this:</span><br />
<pre style="background: #f9f9f9; color: #080808;"><span style="color: #a71d5d;">private</span> <span style="color: #a71d5d;">StudentGrades</span> createStudentGrades (<span style="color: #a71d5d;">int</span> id, <span style="color: #a71d5d;">int</span> math, <span style="color: #a71d5d;">int</span> english,
<span style="color: #a71d5d;">int</span> chemistry, <span style="color: #a71d5d;">int</span> literature,
<span style="color: #a71d5d;">int</span> gymnastic, <span style="color: #a71d5d;">int</span> biology, <span style="color: #a71d5d;">int</span> history) {
<span style="color: #a71d5d;">StudentGrades</span> grades <span style="color: #794938;">=</span> <span style="color: #794938;">new</span> <span style="color: #a71d5d;">StudentGrade</span>();
grades<span style="color: #794938;">.</span>setStudentId(id); <span style="color: #5a525f;">// The student id in the DB</span>
grades<span style="color: #794938;">.</span>setMath(math);
grades<span style="color: #794938;">.</span>setEnglish(english);
grades<span style="color: #794938;">.</span>setChemistry(chemistry);
grades<span style="color: #794938;">.</span>setLiteratue(literature);
grades<span style="color: #794938;">.</span>setGymnastic(gymnastic);
grades<span style="color: #794938;">.</span>setBiology(biology);
grades<span style="color: #794938;">.</span>setHistory(history);
<span style="color: #794938;">return</span> grades;
}
</pre>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">And indeed this will make the whole clutter of code into a one-liner:</span><br />
<pre style="background: #f9f9f9; color: #080808;"><span style="color: #a71d5d;">StudentGrades</span> grades <span style="color: #794938;">=</span> createStudentGrades(<span style="color: #811f24; font-weight: 700;">97</span>, <span style="color: #811f24; font-weight: 700;">84</span>, <span style="color: #811f24; font-weight: 700;">92</span>, <span style="color: #811f24; font-weight: 700;">75</span>, <span style="color: #811f24; font-weight: 700;">88</span>, <span style="color: #811f24; font-weight: 700;">55</span>, <span style="color: #811f24; font-weight: 700;">76</span>, <span style="color: #811f24; font-weight: 700;">81</span>);</pre>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Well, this is great. Much less verbose. But without looking back on the <i>createStudentGrades </i>method, will you be able to tell what 75 stands for? Or 88?</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">This pattern is very hard to read. You have to scroll back and forth or at least open the tooltip of the method to understand what each number says.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Using the builder pattern can help us create something that is less verbose than the original version of the code (the one with the oh so many lines) and a bit more descriptive than this one liner. We'll create a builder for <i>StudentGrades</i> as follows:</span><br />
<pre style="background: #f9f9f9; color: #080808;"><span style="color: #5a525f; font-style: italic;">// This doesn't have to be inner class now. It's not the immutability that we need the builder for. It's the readability</span>
<span style="color: #a71d5d; font-style: italic;">public</span> <span style="color: #a71d5d; font-style: italic;">StudentGradesBuilder</span> {
<span style="color: #a71d5d; font-style: italic;">int</span> id;
<span style="color: #a71d5d; font-style: italic;">int</span> math;
<span style="color: #a71d5d; font-style: italic;">int</span> english;
<span style="color: #a71d5d; font-style: italic;">int</span> chemistry;
<span style="color: #a71d5d; font-style: italic;">int</span> literature;
<span style="color: #a71d5d; font-style: italic;">int</span> gymnastic;
<span style="color: #a71d5d; font-style: italic;">int</span> biology;
<span style="color: #a71d5d; font-style: italic;">int</span> history;
<span style="color: #a71d5d; font-style: italic;">private</span> StudentGradesBuilder() {
<span style="color: #5a525f; font-style: italic;">// Making the constructor private in order to enforce construction</span>
<span style="color: #5a525f; font-style: italic;">// with the readable static construction method.</span>
}
<span style="color: #a71d5d; font-style: italic;">public</span> <span style="color: #a71d5d; font-style: italic;">StudentGradesBuilder</span> studentGrades() {
<span style="color: #794938;">return</span> <span style="color: #794938;">new</span> <span style="color: #a71d5d; font-style: italic;">StudentGradesBuilder</span>();
}
<span style="color: #a71d5d; font-style: italic;">public</span> <span style="color: #a71d5d; font-style: italic;">StudentGradesBuilder</span> forUser(<span style="color: #a71d5d; font-style: italic;">int</span> id) {
<span style="color: #234a97;">this</span><span style="color: #794938;">.</span>id <span style="color: #794938;">=</span> id;
<span style="color: #794938;">return</span> <span style="color: #234a97;">this</span>;
}
<span style="color: #a71d5d; font-style: italic;">public</span> <span style="color: #a71d5d; font-style: italic;">StudentGradesBuilder</span> withHistory(<span style="color: #a71d5d; font-style: italic;">int</span> history) {
<span style="color: #234a97;">this</span><span style="color: #794938;">.</span>history <span style="color: #794938;">=</span> history;
<span style="color: #794938;">return</span> <span style="color: #234a97;">this</span>;
}
<span style="color: #5a525f; font-style: italic;">// Rest of setters</span>
<span style="color: #a71d5d; font-style: italic;">public</span> <span style="color: #a71d5d; font-style: italic;">StudentGrades</span> build() {
<span style="color: #a71d5d; font-style: italic;">StudentGrades</span> grades <span style="color: #794938;">=</span> <span style="color: #794938;">new</span> <span style="color: #a71d5d; font-style: italic;">StudentGrade</span>();
grades<span style="color: #794938;">.</span>setStudentId(id);
grades<span style="color: #794938;">.</span>setMath(math);
grades<span style="color: #794938;">.</span>setEnglish(english);
grades<span style="color: #794938;">.</span>setChemistry(chemistry);
grades<span style="color: #794938;">.</span>setLiteratue(literature);
grades<span style="color: #794938;">.</span>setGymnastic(gymnastic);
grades<span style="color: #794938;">.</span>setBiology(biology);
grades<span style="color: #794938;">.</span>setHistory(history);
<span style="color: #794938;">return</span> grades;
}
}
</pre>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Now we can construct <i>StudentGrades</i> in a verbal, yet concise manner:</span><br />
<pre style="background: #f9f9f9; color: #080808;"><span style="color: #5a525f; font-style: italic;">// Static importing of StudentGradesBuilder.studentGrades() method</span>
<span style="color: #5a525f; font-style: italic;">// allows to call it directly which makes it readable like an English sentence</span>
<span style="color: #a71d5d; font-style: italic;">StudentGrades</span> studentGrades <span style="color: #794938;">=</span> studentGrades()<span style="color: #794938;">.</span>forUser(<span style="color: #811f24; font-weight: 700;">97</span>)<span style="color: #794938;">.</span>withMath(<span style="color: #811f24; font-weight: 700;">84</span>)
.withEnglish(<span style="color: #811f24; font-weight: 700;">92</span>)<span style="color: #794938;">.</span>withChemistry(<span style="color: #811f24; font-weight: 700;">75</span>)
.withLiterature(<span style="color: #811f24; font-weight: 700;">88</span>)<span style="color: #794938;">.</span>withGymnastic(<span style="color: #811f24; font-weight: 700;">55</span>)
.withBiology(<span style="color: #811f24; font-weight: 700;">76</span>)<span style="color: #794938;">.</span>withHistory(<span style="color: #811f24; font-weight: 700;">81</span>)
.build();
</pre>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">This can be read almost as an English sentence "studentGrades for user 97 with math 84...."</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Don't know about you - but I really like it this way. This make me feel I read a sentence rather then trying to decrypt the meaning of a random group of numbers.</span></div>
<div>
<br />
<b><br /></b></div>
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;">Find me on Twitter: </span><a href="https://twitter.com/AviEtzioni" style="color: #888888; font-weight: normal; text-decoration: none;">@AviEtzioni</a></span></h3>
<br />
<div>
<b>More interesting posts from this blog:</b><br />
<b><br /></b></div>
<div class="widget-content">
<div class="OUTBRAIN" data-src="http://avietzioni.blogspot.co.il/2013/11/welcome.html" data-widget-id="AR_1">
</div>
<script type="text/javascript">var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(ob,h);})();</script>
<script src="http://widgets.outbrain.com/outbrainLT.js" type="text/javascript"></script></div>
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.com3tag:blogger.com,1999:blog-6180894101274505794.post-72803083451585109982014-09-05T15:57:00.001-07:002014-09-05T15:58:55.935-07:00Elephant Carpaccio - Use Case<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">In my <a href="http://avietzioni.blogspot.co.il/2014/07/cooking-elephant-carpaccio.html">previous post</a> I talked about a technique called "Elephant Carpaccio" for splitting large projects and epics to smaller, measurable and valuable stories and tasks.</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">I would like to share now an example for a real-life scenario and show how to apply the carpaccio technique for this scenario.</span><br />
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
</span><br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Our example case</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Let's say we're working on an enterprise product. We started with one language in our UI - English. And now the company's salespersons say we're missing great deals due to our lack of support in a multi lingual interface. And now your PO asks your team to implement this new feature.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Let's try to think about this feature request. Where do we start? What is most important? And one of the most important questions of all - how long will it take?!</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br />It's obvious we can't just run and implement such a feature because it probably requires some infrastructure to support a generic addition of new languages and most probably this addition of a new multi-language support will require a lot of changes in a lot of places.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Ask questions</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">A good start I found useful for me is to first ask questions. Many questions. It will be very beneficial to include a few people (at least the team and a product representative) in the discussions and let everybody ask questions. Here are some questions that you will probably want to answer before running and implementing the feature:</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Will the users of the product be able to change the language whenever they want? Or is it set on the system level for all users?</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Where in the UI will the user change the language?</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Do we need to support also things like error messages in our translations? Or is it ok to leave them in English?</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Should we support any RTL (Right-To-Left) languages?</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">If we support RTL languages - should the entire UI be viewed in an RTL direction?</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Should the language selection be persisted or is it ok to always start a user session in English and allow the user to change?</span></li>
</ol>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Make assumptions</span></h3>
</div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Asking these questions will help both product and R&D to understand where the value for this feature lies and what can be delayed for a later version/sprint.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">After the value is clear, you can prioritize and create user stories. Each user story must deliver <u>some</u> value to the user and be estimated according to the efforts and risks that are assumed to be put into it:</span></div>
<div>
<br /></div>
<div>
<ol><ol>
</ol>
</ol>
<h3>
<b style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><span style="color: #3d85c6; font-size: large;">Story #1 - Support Spanish in a specific UI menu:</span></b></h3>
<ol><ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>DoD (Definition of Done)</b>: The user will have a language selection list. When the user selects Spanish, a specific menu will be changed to Spanish</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Assumptions:</b></span></li>
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">The language is not persisted and the next time the user will log-in the system will be in English again.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Only one menu should be translated when choosing Spanish</span></li>
</ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b><a href="http://programmers.stackexchange.com/questions/36810/whats-the-best-explanation-of-what-story-points-are">Story points</a> - 8:</b> This is a hard story - we need to create the infrastructure.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Tasks:</b></span></li>
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Infrastructure design. (1 day - net, after design review and discussions)</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">UI addition (0.5 day - just adding the language list widget is easy. It can be done while waiting for feedback on the design)</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Implementing infrastructure - storage of language codes, maybe failover (if a message doesn't exist in Spanish we'd like to fall back to English), a generic API for converting message codes to locale strings, etc... (4 days)</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Change the UI menu to use the converter API (0.5 day)</span></li>
</ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Value</b>: After this story there's a robust infrastructure and an already working spanish menu. The value addition is huge both in the user/product experience it adds and the easement of now changing other places.</span></li>
</ol>
</ol>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Story #2 - Support Spanish in whole of the UI (No error support yet)</span></h3>
<div>
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>DoD:</b> All UI texts will be in spanish</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Assumptions:</span></li>
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">No support for errors (exceptions)</span></li>
</ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Story points - 5: </b>This is not hard but requires a lot of tedious work of replacing any string to the translation API call. This also requires a lot of time from QA to make sure everything is replaced correctly.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Tasks</b>: Just replacing string with the translated text (2 days + 3-4 QA days)</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Value:</b> After this story we can see a UI that's in a different language and get the main multi-language experience.</span></li>
</ol>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Defining other languages</span></h3>
</div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">After the previous stories are done we can, in fact, add languages in a very low development (and even QA) costs. If the infrastructure is built correctly it will require no more then adding a file or a DB records with the translated strings. We can now choose 2 methods for splitting the stories:</span></div>
<div>
<ul>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>All other languages once </b>- Due the easiness of adding a new language splitting each language to its own story would be an overhead so all the languages could be combined into a 2-3 story-points story. <b>Better approach</b></span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Adding languages one at a time</b> - in case other languages are not given in advance, splitting the stories into 1 story-points stories is also fine.</span></li>
</ul>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Future features</span></h3>
</div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">After we finished the main feature, and we no longer loosing deals it's much easier to prioritize the remaining features like translating error codes, and support RTL and so on. We lowered the pressure from the business side, we provided a huge amount of value.<br />If these features that haven't made the cut are important enough - they will be waiting at the head of the backlog stack. If not, they will be pushed down the backlog which probably means that they were not that valuable to begin with.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">This example is of course very specific and was born out of former projects I worked on. I hope I managed to give you the idea of how to do such tasks. Mastering Carpaccio takes time, but will benefit you a lot.</span><br />
<br /></div>
<ol><ol><ol>
</ol>
</ol>
</ol>
</div>
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;">Find me on Twitter: </span><a href="https://twitter.com/AviEtzioni" style="color: #888888; font-weight: normal; text-decoration: none;">@AviEtzioni</a></span></h3>
<br />
<div>
<b>More interesting posts from this blog:</b><br />
<b><br /></b></div>
<div class="widget-content">
<div class="OUTBRAIN" data-src="http://avietzioni.blogspot.co.il/2013/11/welcome.html" data-widget-id="AR_1">
</div>
<script type="text/javascript">var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(ob,h);})();</script>
<script src="http://widgets.outbrain.com/outbrainLT.js" type="text/javascript"></script></div>
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.com0tag:blogger.com,1999:blog-6180894101274505794.post-41245974356418334522014-07-13T11:26:00.001-07:002014-09-05T15:59:35.909-07:00Cooking an elephant carpaccio<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;"><b>Disclaimer</b>: No elephants or other animals were harmed during the writing of this post.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Make me an elephant</span></h3>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">What if I asked you to make me an elephant? Can you tell me how long would it take you? Can you guarantee that under this time estimation you gave me you will be able to create a great elephant, with all the capabilities and characteristics an elephant possesses?</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://media-cache-ak0.pinimg.com/736x/e9/f0/1c/e9f01c2b7d2414559cf4b6804f556a50.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://media-cache-ak0.pinimg.com/736x/e9/f0/1c/e9f01c2b7d2414559cf4b6804f556a50.jpg" height="380" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: xx-small;">Image taken from <a href="http://www.pinterest.com/pin/20195898298814935/">here</a></span></td></tr>
</tbody></table>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Tackle this huge story</span></h3>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Ok, so us, software engineers, are not that good at creating elephants. We'll leave this to the lady elephants to cook new elephants. But we aim to be good at creating software.<br />Tackling a large story may be very puzzling. Both from our (developers) perspective and from the product manager's eyes.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">How many times have you started working on such an enormous story and found out that there were a lot of holes in your complete mega-design? How many times have you been mistaken in your estimations? How many times have you found out that large portion of your code is not in use or not what the customer/product described?</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">It's hard for us to plan every little detail in the system ahead. There are a lot of unknowns down the road, which will be careless of us to presume we know, and will make it difficult for us to give an honest estimation. Also it's not easy for the product as well to define every little detail given all these unknowns.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Elephant carpaccio</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Elephant carpaccio is a technique that helps us tackle such a big problem. Instead of trying to create an entire elephant, we can try breaking the manufacturing process to small stories. Each such story must stand on its own - meaning, provide <u>some</u> (some == more than 0) value to our users and be independently testable (meaning - no need to wait for other parts of the story to end in order to test it).</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">In an elephant carpaccio we'll try to follow a simple pattern:</span><br />
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Create a very thin flow</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Thicken this flow by each time adding another layer or sub-feature to it.</span></li>
</ol>
<div>
<br /></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Creating the initial flow</span></h3>
</div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">In order to find this main flow we better ask ourselves what is the main problem we try to solve. We can then map the main use-case. The one that solves a large portion of the problem. Then we can decide this will be the flow.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">It's important to understand that this is ok to state that this flow will not stand on its own for releasing to the market. If we would to design an ATM, our main flow would probably be - <u>withdraw money.</u> But we can't send it to production without making sure the flow is transactional, secured, audited in the bank's books and so on. But creating the really basic flow of withdrawing money, in a very naive way (maybe even without checking if the customer has sufficient funds in his account) will already give an enormous value and a great starting point.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Thickening the flow</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">After we understand the initial flow we're in a much better position to split the story. In this point we need to ask ourselves some questions to understand the more smaller details by which we can split the story. I'll give example on how we do it in my <a href="http://avietzioni.blogspot.co.il/2014/09/elephant-carpaccio-use-case.html">next post</a>.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Focus, Build, Increase Trust</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Sometimes in the work of engineers with product we encounter a lot of trust issues (if you speak Hebrew, take 5 minutes to hear from a former colleague of mine about this in <a href="http://youtu.be/UtQS2vsFClM">this ignite talk</a> or read her <a href="http://moranshimron.blogspot.co.il/2014/03/drop-your-weapons.html">blog-post</a>, in English, instead). Product managers often feel they do not exactly understand where the engineering are in the process and whether things go as they wanted. The engineers are not always aligned with the vision the product managers lead to. It sometimes makes them scatter to the less important areas of the feature, the ones that are a nice-to-have (for example - having an ultra beautiful button is important in an ATM, but less important than having the functionality to withdraw money).</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">By working with small portions we allow product to define the priorities of the work by having the engineering focused and aligned with what's really important. The engineers, when the carpaccio is done right, know exactly what they should do <u>now</u>. They're (usually) not distracted because they work in a very small units of work. It also allows product to change requirements on the way because the engineering process starts with the certainties and the most important things. We can change the rest of the plan as we continue to progress.<br />When combining such story-splitting techniques with other agile methodologies like sprints, dailies and so on, we can create a better communication between product and engineering, improve trust and improve the productivity of the team as a whole.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">My Rules of Thumb for Carppacioing</span></h3>
<div>
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Split an epic to stories in such a way that each story would provide value. Any value.<br />How you define value you ask? Value is defined as something that you can show to a user and (s)he would actually care and be able to give you feedback about it. </span><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: large;">(A new button that doesn't do anything <u>yet</u> is value; A new table in the DB is not).</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Repeat bullet #1 for each story you created and try to split it some more until you're absolutely certain you can't or that further splitting would just increase the overhead of implementing it too much.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">In your sprint planning split each story to very short tasks. These tasks do not need to provide user value. They can and should be very small but not too small (less than 0.5 day is probably too small) in order to not increase overhead.</span></li>
</ol>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
</div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">For those of you who would like to deepen your understanding on the subject I would suggest <a href="http://www.slideshare.net/larsthorup/elephant-carpaccio"> Lars Thorup's presentation on the subject</a> which I found very interesting and concise.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Also, in my <a href="http://avietzioni.blogspot.co.il/2014/09/elephant-carpaccio-use-case.html">next post</a> I'll give a more detailed example of the carpaccio method. Stay tuned...</span></div>
<br />
<br />
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;">Find me on Twitter: </span><a href="https://twitter.com/AviEtzioni" style="color: #888888; font-weight: normal; text-decoration: none;">@AviEtzioni</a></span></h3>
<br />
<div>
<b>More interesting posts from this blog:</b><br />
<b><br /></b></div>
<div class="widget-content">
<div class="OUTBRAIN" data-src="http://avietzioni.blogspot.co.il/2013/11/welcome.html" data-widget-id="AR_1">
</div>
<script type="text/javascript">var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(ob,h);})();</script>
<script src="http://widgets.outbrain.com/outbrainLT.js" type="text/javascript"></script></div>
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.com0tag:blogger.com,1999:blog-6180894101274505794.post-68494967698526331112014-05-23T03:02:00.001-07:002015-10-27T10:02:59.722-07:00So Long Spring XMLs... (@Configuration class quick start guide)<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>This post is based on a tech-talk I gave in Outbrain</i></span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">This time I decided to dedicate the post to something a bit more technical than my usual posts. In this post I will try to show those of you that use XMLs to define their Java Spring application context, how to use a method which I find much more convenient for most cases - the spring @Configuration class.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">When Spring just started, the only way to configure the wirings of an application, was to use XMLs which defined the dependencies between different beans. As Spring had continued to develop, 2 more methods were added to configure dependencies - the annotation method and the @Configuration method.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: small;">What is this @Configuration class?</span></h3>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">You can think of a @Configuration class just like XML definitions, only defined by code. Using code instead of XMLs allows some advantages over XMLs which made me switch to this method:</span><br />
<br />
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>No typos </b>- You can't have a typo in code. The code just won't compile</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Compile time check (fail fast)</b> - With XMLs it's possible to add an argument to a bean's constructor but to forget to inject this argument when defining the bean in the XML. Again, this can't happen with code. The code just won't compile</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>IDE features come for free</b> - Using code allows you to find usages of the bean's constructor to find out easily the contexts that use it; It allows you to jump back and forth between beans definitions and basically everything you can do with code, you get for free.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Feature flags</b> - In Outbrain we use feature-flags a lot. Due to the continuous-deployment culture of the company, a code that is pushed to the trunk can find itself in production in a matter of minutes. Sometimes, when developing features, we use feature flags to enable/disable certain features. This is pretty easy to do by defining 2 different implementations to the same interface and decide which one to load according to the flag. When using XMLs we had to use the <i>alias</i> feature which makes it not intuitive enough to create feature-flags. With @Configuration, we can create a simple <i>if</i> clause for choosing the right implementation.</span></li>
</ol>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: small;">Our example case</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">So, let's start with a simple example of a Spring XML, and migrate it to Spring @Configuration class:</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="background-color: gainsboro; border: 2px solid;">
<pre><span style="color: #004a43;"><?</span><span style="color: maroon; font-weight: bold;">xml</span><span style="color: #004a43;"> </span><span style="color: #074726;">version</span><span style="color: #808030;">=</span><span style="color: #0000e6;">"</span><span style="color: #7d0045;">1.0</span><span style="color: #0000e6;">"</span><span style="color: #004a43;"> </span><span style="color: #074726;">encoding</span><span style="color: #808030;">=</span><span style="color: #0000e6;">"</span><span style="color: #0000e6;">UTF-8</span><span style="color: #0000e6;">"</span><span style="color: #004a43;">?></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">beans</span> <span style="color: #666616;">xmlns</span><span style="color: #808030;">=</span><span style="color: #0000e6;">"</span><span style="color: #666616;">http</span><span style="color: purple;">:</span><span style="color: maroon; font-weight: bold;">//</span><span style="color: #5555dd;">www.springframework.org</span><span style="color: #40015a;">/schema/beans</span><span style="color: #0000e6;">"</span>
<span style="color: #666616;">xmlns</span><span style="color: purple;">:</span><span style="color: #074726;">xsi</span><span style="color: #808030;">=</span><span style="color: #0000e6;">"</span><span style="color: #666616;">http</span><span style="color: purple;">:</span><span style="color: maroon; font-weight: bold;">//</span><span style="color: #5555dd;">www.w3.org</span><span style="color: #40015a;">/2001/XMLSchema-instance</span><span style="color: #0000e6;">"</span>
<span style="color: #666616;">xsi</span><span style="color: purple;">:</span><span style="color: #074726;">schemaLocation</span><span style="color: #808030;">=</span><span style="color: #0000e6;">"</span><span style="color: #666616;">http</span><span style="color: purple;">:</span><span style="color: maroon; font-weight: bold;">//</span><span style="color: #5555dd;">www.springframework.org</span><span style="color: #40015a;">/schema/beans</span><span style="color: #0000e6;"> </span><span style="color: #666616;">http</span><span style="color: purple;">:</span><span style="color: maroon; font-weight: bold;">//</span><span style="color: #5555dd;">www.springframework.org</span><span style="color: #40015a;">/schema/beans/spring-beans-3.0.xsd</span><span style="color: #0000e6;">"</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">import</span> <span style="color: #274796;">resource</span><span style="color: #808030;">=</span><span style="color: #0000e6;">"</span><span style="color: #0000e6;">another-application-context.xml</span><span style="color: #0000e6;">"</span><span style="color: #a65700;">/></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">bean</span> <span style="color: #274796;">id</span><span style="color: #808030;">=</span><span style="color: #0000e6;">"</span><span style="color: #0000e6;">someBean</span><span style="color: #0000e6;">"</span> <span style="color: #274796;">class</span><span style="color: #808030;">=</span><span style="color: #0000e6;">"</span><span style="color: #0000e6;">avi.etzioni.spring.configuration.SomeClassImpl</span><span style="color: #0000e6;">"</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">constructor-arg</span> <span style="color: #274796;">value</span><span style="color: #808030;">=</span><span style="color: #0000e6;">"</span><span style="color: #0000e6;">${some.interesting.property}</span><span style="color: #0000e6;">"</span> <span style="color: #a65700;">/></span>
<span style="color: #a65700;"></</span><span style="color: #5f5035;">bean</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">bean</span> <span style="color: #274796;">id</span><span style="color: #808030;">=</span><span style="color: #0000e6;">"</span><span style="color: #0000e6;">anotherBean</span><span style="color: #0000e6;">"</span> <span style="color: #274796;">class</span><span style="color: #808030;">=</span><span style="color: #0000e6;">"</span><span style="color: #0000e6;">avi.etzioni.spring.configuration.AnotherClassImpl</span><span style="color: #0000e6;">"</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">constructor-arg</span> <span style="color: #274796;">ref</span><span style="color: #808030;">=</span><span style="color: #0000e6;">"</span><span style="color: #0000e6;">someBean</span><span style="color: #0000e6;">"</span><span style="color: #a65700;">/></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">constructor-arg</span> <span style="color: #274796;">ref</span><span style="color: #808030;">=</span><span style="color: #0000e6;">"</span><span style="color: #0000e6;">beanFromSomewhereElse</span><span style="color: #0000e6;">"</span><span style="color: #a65700;">/></span>
<span style="color: #a65700;"></</span><span style="color: #5f5035;">bean</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"></</span><span style="color: #5f5035;">beans</span><span style="color: #a65700;">></span></pre>
</div>
<div>
<br /></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: small;"><br /></span></h3>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: small;">Step 1: Migrate <beans> to @Configuration</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">In XMLs the highest tag in the hierarchy is <beans>. This tag will be replaced with a class, annotated with @Configuration</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="background-color: gainsboro; border: 2px solid;">
<pre>@Configuration
<span style="color: maroon; font-weight: bold;">public</span> <span style="color: maroon; font-weight: bold;">class</span> ByeXmlApplicationContext <span style="color: purple;">{</span>
<span style="color: purple;">}</span></pre>
</div>
<h3>
<span style="color: #3d85c6; font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><span style="font-size: small;"><br /></span></span></h3>
<h3>
<span style="color: #3d85c6; font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><span style="font-size: small;">Step 2: Create a method for each Bean</span></span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Each <bean> tag in the XML will be replaced with a method that's annotated with @Bean annotation. Usually it would be a better practice for the method to return an interface type as follows:</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="background-color: gainsboro; border: 2px solid;">
<pre>@Configuration
<span style="color: maroon; font-weight: bold;">public</span> <span style="color: maroon; font-weight: bold;">class</span> ByeXmlApplicationContext <span style="color: purple;">{</span>
<span style="color: #808030;">@</span>Bean(name = "someBean")
<span style="color: maroon; font-weight: bold;">public</span> SomeClass getSomeClass<span style="color: #808030;">(</span><span style="color: #808030;">)</span> <span style="color: purple;">{</span>
<span style="color: maroon; font-weight: bold;">return</span> <span style="color: maroon; font-weight: bold;">new</span> SomeClassImpl<span style="color: #808030;">(</span><span style="color: red;">someInterestingProperty</span><span style="color: #808030;">)</span><span style="color: purple;">;</span>
<span style="color: purple;">}</span>
<span style="color: #808030;">@</span>Bean(name = "anotherBean")
public AnotherClass getAnotherClass<span style="color: #808030;">(</span><span style="color: #808030;">)</span> <span style="color: purple;">{</span>
<span style="color: maroon; font-weight: bold;">return</span> <span style="color: maroon; font-weight: bold;">new</span> AnotherClassImpl<span style="color: #808030;">(</span>getSomeClass<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: red;">beanFromSomewhereElse</span><span style="color: #808030;">)</span><span style="color: purple;">;</span>
<span style="color: purple;">}</span>
<span style="color: purple;">}</span><span style="color: purple;">
</span></pre>
</div>
<div>
<pre><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>A few things to notice:</b></span></pre>
<pre><ul style="line-height: 1em;">
<li style="line-height: 13px;"><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Each method is defined to return an interface type. In the method body we create the concrete class.</span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; line-height: 13px;">The name that's defined in the <i>@Bean</i> annotation is the same as the id that is defined in the XML for the beans.</span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; line-height: 13px;"> The bean <i>anotherBean</i> is injected with <i>someBean</i> in the XML. In the scenario here, we just call the <i>getSomeClass()</i> method. This doesn't create another bean, this just uses the bean <i>someBean</i> (the same as it was in the XML).</span></li>
</ul>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">We notice that we're missing the property someInterestingProperty and the bean beanFromSomewhereElse.</span></pre>
<h3>
<span style="color: #3d85c6; font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: small;">Step 3: Import other XMLs or other @Configuration classes</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The bean </span><i style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">beanFromSomewhereElse </i><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">comes from a different XML file named </span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>another-application-context.xml</i> and which was imported in the original XML. In order to use it, we need to import this XML here as well. To do so, we'll just annotate the class with the annotation <i>@ImportResource</i> as follows:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="background-color: gainsboro; border: 2px solid;">
<pre>@ImportResource("another-application-context.xml")
@Configuration
<span style="color: maroon; font-weight: bold;">public</span> <span style="color: maroon; font-weight: bold;">class</span> ByeXmlApplicationContext <span style="color: purple;">{</span>
</pre>
<span style="color: purple;"> . . .</span>
<br />
<div>
<span style="color: purple;">}</span><br />
<span style="color: purple;"><br /></span>
<span style="color: purple;">
</span>
</div>
</div>
<div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">That's in fact equivalent to the <import resource=""/> tag in the XML format.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
</span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">If this bean resides in another @<i>Configuration</i> class you can use a different annotation <i>@Import</i> to import it:</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div style="background-color: gainsboro; border: 2px solid;">
<pre>@Import(OtherConfiguration.class)
@Configuration
<span style="color: maroon; font-weight: bold;">public</span> <span style="color: maroon; font-weight: bold;">class</span> ByeXmlApplicationContext <span style="color: purple;">{</span>
<span style="color: #808030;">.</span><span style="color: #808030;">.</span><span style="color: #808030;">.</span>
<span style="color: purple;">}</span></pre>
</div>
<h3>
<span style="font-weight: normal;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span></h3>
<h3>
<span style="font-weight: normal;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">In order to complete the picture, here's how you can import a @Configuration class from an XML configuration file:</span></span></h3>
<h3>
<pre style="background-color: gainsboro; border: 2px solid; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: small;"><span style="color: #a65700; font-weight: normal;"><</span><span style="color: #5f5035;">context:annotation-config</span><span style="color: #a65700;">/></span>
<span style="color: #a65700; font-weight: normal;"><</span><span style="color: #5f5035;">bean</span> <span style="color: #274796;">class</span><span style="color: #808030;">=</span><span style="color: #0000e6;">"some.package</span><span style="color: #0000e6;">.ByeXmlApplicationContext</span><span style="color: #0000e6;">"/</span><span style="color: #a65700;">></span></span></pre>
</h3>
<h3>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-weight: normal;">The </span><i style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-weight: normal;"><context:annotation-config/> </i><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-weight: normal;">needs to be defined once in the context in order to make spring aware to </span><i style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-weight: normal;">@Configuration</i><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-weight: normal;"> classes</span></h3>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-weight: normal;"><br /></span></div>
<h3>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: #3d85c6; font-size: small;">Step 4: Import beans from other XMLs (or @Configuration class, or @Component etc... classes)</span></span></h3>
</div>
</div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">In order to use beans that were not defined in this <i>@Configuration</i> class we can either declare a private member annotated with <i>@Autowired</i> and <i>@Qualifier</i> as follows:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="background-color: gainsboro; border: 2px solid;">
<pre> <span style="color: #808030;">@</span>Autowired
<span style="color: #808030;">@</span>Qualifier<span style="color: #808030;">(</span>value <span style="color: #808030;">=</span> <span style="color: #0000e6;">"beanFromSomewhereElse"</span><span style="color: #808030;">)</span>
<span style="color: maroon; font-weight: bold;">private </span><span style="color: maroon; font-weight: bold;">final</span> StrangeBean beanFromSomewhereElse<span style="color: purple;">;</span></pre>
</div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">This member can now be used to construct the bean <i>anotherBean.</i></span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Another option is to declare a method argument to</span> <span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><i>getAnotherClass()</i> as follows:</span>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div style="background-color: gainsboro; border: 2px solid;">
<pre><span style="color: #808030;"> @</span>Bean<span style="color: #808030;">(</span>name <span style="color: #808030;">=</span> <span style="color: #0000e6;">"anotherBean"</span><span style="color: #808030;">)</span>
public AnotherClass getAnotherClass<span style="color: #808030;">(</span><span style="color: #808030;">@</span>Qualifier <span style="color: #808030;">(</span>value <span style="color: #808030;">=</span> <span style="color: #0000e6;">"beanFromSomewhereElse"</span><span style="color: #808030;">)</span></pre>
<pre> <span style="color: maroon; font-weight: bold;">final</span> StrangeBean beanFromSomewhereElse<span style="color: #808030;">)</span> <span style="color: purple;">{</span>
<span style="color: maroon; font-weight: bold;">return</span> <span style="color: maroon; font-weight: bold;">new</span> AnotherClassImpl<span style="color: #808030;">(</span>getSomeClass<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> beanFromSomewhereElse<span style="color: #808030;">)</span><span style="color: purple;">;</span>
<span style="color: purple;">}</span></pre>
</div>
</div>
</div>
<pre><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">I usually prefer the first method as it is less verbose. But of course, that's just a matter of taste.</span></pre>
<pre><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Just remember - the beans you import must be loaded to the application context - either by @Import or @ImportResource from this class, or using any other method from anywhere else (XML, @Configuration or annotations).</span></pre>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: small;">Step 5: Import properties</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">So, we still need to import somehow the property <i>someInterestingProperty</i> which was defined in the XML using <i>${some.interesting.property}</i>. Well, that will be very similar to autowiring a bean, but instead of the @<i>Qualifier</i> annotation, we'll use the <i>@Value</i> annotation:</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="background-color: gainsboro; border: 2px solid;">
<pre>@Autowired
@Value("$<span style="color: purple;">{</span>some<span style="color: #808030;">.</span>interesting<span style="color: #808030;">.</span>property<span style="color: purple;">}</span>")
<span style="color: maroon; font-weight: bold;">private</span> <span style="color: maroon; font-weight: bold;">final</span> String someInterestingProperty;</pre>
<pre></pre>
<pre><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"></span></pre>
</div>
<div>
<br />
You can also use a <i>SpEL</i> (<b>Sp</b>ring <b>E</b>xpression <b>L</b>anguage) expressions with <i>@Value</i>.</div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: small;"><br /></span></h3>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: small;">Step 6: Import @Configuration from web.xml</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">At the final step, we would like to be able to import an entire application-context without using any XMLs. If we have a web app, this can be done by declaring the class in the web.xml as follows:</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="background-color: gainsboro; border: 2px solid;">
<pre><span style="color: #a65700;"><</span><span style="color: #5f5035;">servlet</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">servlet-name</span><span style="color: #a65700;">></span>my-dispatcher<span style="color: #a65700;"></</span><span style="color: #5f5035;">servlet-name</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">servlet-class</span><span style="color: #a65700;">></span>org.springframework.web.servlet.DispatcherServlet<span style="color: #a65700;"></</span><span style="color: #5f5035;">servlet-class</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">init-param</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">param-name</span><span style="color: #a65700;">></span>contextClass<span style="color: #a65700;"></</span><span style="color: #5f5035;">param-name</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">param-value</span><span style="color: #a65700;">></span>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
<span style="color: #a65700;"></</span><span style="color: #5f5035;">param-value</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"></</span><span style="color: #5f5035;">init-param</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">init-param</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">param-name</span><span style="color: #a65700;">></span>contextConfigLocation<span style="color: #a65700;"></</span><span style="color: #5f5035;">param-name</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">param-value</span><span style="color: #a65700;">></span>some.package.ByeXmlApplicationContext<span style="color: #a65700;"></</span><span style="color: #5f5035;">param-value</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"></</span><span style="color: #5f5035;">init-param</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"><</span><span style="color: #5f5035;">load-on-startup</span><span style="color: #a65700;">></span>1<span style="color: #a65700;"></</span><span style="color: #5f5035;">load-on-startup</span><span style="color: #a65700;">></span>
<span style="color: #a65700;"></</span><span style="color: #5f5035;">servlet</span><span style="color: #a65700;">></span></pre>
</div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Summary</span></h3>
</div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">As you can see - spring @Configuration classes can be a powerful tool in defining your application context. But with great power comes great responsibility. Code is much easier to abuse than XMLs. It's easy to make complexed @Configuration classes. Try to think of the @Configuration class as a more flexible XMLs and behave them as if they were XMLs:</span></div>
<div>
<ul>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Split to different @Configuration classes and don't put all of your beans in one class</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Give meaningful names and even decide on a naming convention</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Avoid</b> <b>any logic inside the </b><b>@Configuration classes</b>. Aside maybe for things like feature-flags.</span></li>
</ul>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
</div>
<div>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Of course, I just gave here the basics. The internet is full of resources about using @Configuration classes. And of course, y</span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">ou are more than welcome to contact me for any further help. I'll do my best to assist.</span></div>
<br />
<br />
<br />
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;">Find me on Twitter: </span><a href="https://twitter.com/AviEtzioni" style="color: #888888; font-weight: normal; text-decoration: none;">@AviEtzioni</a></span></h3>
<br />
<br />
<div>
<b>More interesting posts from this blog:</b><br />
<b><br /></b></div>
<div class="widget-content">
<div class="OUTBRAIN" data-src="http://avietzioni.blogspot.co.il/2013/11/welcome.html" data-widget-id="AR_1">
</div>
<script type="text/javascript">var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(ob,h);})();</script>
<script src="http://widgets.outbrain.com/outbrainLT.js" type="text/javascript"></script></div>
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.com20tag:blogger.com,1999:blog-6180894101274505794.post-87442330311007676822014-04-11T00:36:00.001-07:002014-04-12T07:06:19.546-07:00My Reversim Summit Experience<div style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; text-align: left;">
<div class="separator" style="clear: both; text-align: center;">
</div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8ywUqCqL-WudGvRvjgciDiVadq9wiCrtehW8QZzZd1rKYzw2mdO3E2QouQ82No518JfA2a6M5_k3G27hyb6ALKURJwvvQgVqsgEwHp7ChQYquN5fUX1Zv3dAZYMlQV5cjoW48t1msUFR6/s1600/reversim-logo-white+copy.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8ywUqCqL-WudGvRvjgciDiVadq9wiCrtehW8QZzZd1rKYzw2mdO3E2QouQ82No518JfA2a6M5_k3G27hyb6ALKURJwvvQgVqsgEwHp7ChQYquN5fUX1Zv3dAZYMlQV5cjoW48t1msUFR6/s1600/reversim-logo-white+copy.jpg" height="150" width="320" /></a><a href="http://www.reversim.com/"><span style="font-size: large;">Reversim</span></a><span style="font-size: large;"> is an Israeli podcast that speaks about technology and the software world. In 2013 they organized the first Reversim summit - an event dedicated to sharing knowledge between tech companies. After last year's success, in February 2014 a second summit was held. The tickets were over faster than the Led-Zeppelin or the israeli Kaveret reunions (I guess that the free-entrance made it easy for people to just register and save their spot quickly, but I think that was not the main reason).</span></div>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">This year I got the opportunity to present my <a href="http://avietzioni.blogspot.co.il/2013/12/code-review-just-do-it-part-1-feedback.html">code-review talk</a>, which I gave in Outbrain a few month ago, in front of people from other companies. For those of you who missed it, here it is:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/z8dYrdD2uB0?feature=player_embedded' frameborder='0'></iframe></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">It was very interesting to speak with people after the talk and hear their opinions about code-review, the challenges they faced and the tips they looked for.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Aside from that, there were so many great lectures and things to enjoy in the summit. For me, the most inspiring lecture was <a href="http://youtu.be/A8XBLLCA6MU">Iris Shoor's lecture</a> that talked about how she converted her dev team to marketers. Her last year's presentation inspired me when I worked on my interview exercise for Outbrain, so I knew that I want to hear this year's talk. </span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Another great talk was <a href="http://youtu.be/pfru6Oflx5I">Oren Ellenbogen's talk: Engineering your culture- how to keep your engineers happy</a>. Oren analyzed the qualities engineers look for in a work place and the importance of hiring the people that fit the qualities the company can offer.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Of course, I still need to catch up all the talks I couldn't attend. I believe I'm about to find a lot more interesting talks.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Aside for the regular talks, I really enjoyed the open-space about "Why do we work so hard and move so slowly?". Probably a question that each developer has asked himself/herself sometime. It was very interesting to hear the different opinions and observations to this question. For example, a lot of people talked about all the "non-working" stuff they have to do - answering emails, attend meetings, fix bugs and so on. One of the conclusions that the group reached to was that these things are also work, they also help us progress. A lot of engineers feel that progress == writing code, and not consider other valuable tasks as work which makes them feel they move too slowly.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Also we talked about the importance of <a href="http://avietzioni.blogspot.co.il/2013/11/my-retrospective-about-my-retrospective.html">retrospecting</a> and measuring your work and other stuff like technical-debt, methodologies and so on.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Also, let us not forget a lot of other fun activities like the ignite talks in which people tried to pass on an idea in 5 minutes, the band (with the Pizza & Beer) and the (in)famous "Hall of Shame" where people exposed their most glorified failures in their career.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">So, bottom-line - I really enjoyed this summit, both as a speaker and as a listener. I would recommend other colleagues to catch the videos on youtube. I'm already waiting for next year!</span>
<br />
<br />
<br />
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;">Find me on Twitter: </span><a href="https://twitter.com/AviEtzioni" style="color: #888888; font-weight: normal; text-decoration: none;">@AviEtzioni</a></span></h3>
<div>
<br />
<br /></div>
<div>
<b>More interesting posts from this blog:</b><br />
<b><br /></b></div>
<div class="widget-content">
<div class="OUTBRAIN" data-src="http://avietzioni.blogspot.co.il/2013/11/welcome.html" data-widget-id="AR_1">
</div>
<script type="text/javascript">var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(ob,h);})();</script>
<script src="http://widgets.outbrain.com/outbrainLT.js" type="text/javascript"></script></div>
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.com0tag:blogger.com,1999:blog-6180894101274505794.post-46280227917308249402014-02-08T03:11:00.000-08:002014-02-08T07:24:02.239-08:00The Best Programming Language<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">This post is not about Java vs .Net or Python vs Ruby or any other programming language in particular. This post is about the programming <i style="font-weight: bold;">language</i> that is common to all of them. We call these technologies <i style="font-weight: bold;">languages</i> but in fact all of them are written in English (well aside for <a href="http://en.wikipedia.org/wiki/Non-English-based_programming_languages">a few</a>). But unlike English article or blog post, programs are often very hard to read. In this post I want to share with you how I try to keep my code readable and maintainable.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Inflation of comments</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">When I started to program professionally, more than ten years ago, I felt it was pretty hard for me to get into others' code. I was having a hard time reading it. I wanted to make sure my code wouldn't look like that. So, as we often do, I made sure my code was filled with tons of comments. Let me demonstrate with an example (code taken from my <a href="http://avietzioni.blogspot.co.il/2014/01/hands-on-effective-refactoring-of.html">refactoring hands-on post</a>, comments added for this post)</span><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: large;">:</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2NggwxGpnfW9nENTb0oAb_TyIKl07uhVwiAFlW_tvLfwR-xxpKT9qn06AgXmklvOnsWfJcMRJolP8H4PAmr_iZz24A9DMExUcpPgftrUoTho16BDNhQrR19c1AC9W0eOmB50Mm9sDLUkN/s1600/Commented.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2NggwxGpnfW9nENTb0oAb_TyIKl07uhVwiAFlW_tvLfwR-xxpKT9qn06AgXmklvOnsWfJcMRJolP8H4PAmr_iZz24A9DMExUcpPgftrUoTho16BDNhQrR19c1AC9W0eOmB50Mm9sDLUkN/s1600/Commented.png" height="582" width="640" /></a></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">That's not the whole class but it pretty much reflects the idea. Now, take a second and try to figure out what this code does more or less.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">I bet you didn't read the comments. And if you did, that's only because I have been writing about comments from the beginning of this section. Most of the times we are blind to comments, we ignore them. Especially if there are many of them and we're already used to them stating the obvious. Do I really need a comment stating that this is <b>THE</b> item Dao?</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhytl3ka3mbeGG4x_t4aIVpfq4pcshyphenhyphen3HqNDcAfgyiAD_5pg7QfdVSDdHYNUa0gd1E3Q7rHVCC8j-BuODQ5xcQNkkfHFOv7mFXvhF10iYdpow-9cGitsodz3daNErXzx1jbJ1IrIfR7jb_I/s1600/itemdao.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhytl3ka3mbeGG4x_t4aIVpfq4pcshyphenhyphen3HqNDcAfgyiAD_5pg7QfdVSDdHYNUa0gd1E3Q7rHVCC8j-BuODQ5xcQNkkfHFOv7mFXvhF10iYdpow-9cGitsodz3daNErXzx1jbJ1IrIfR7jb_I/s1600/itemdao.png" height="58" width="320" /></a></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">All of the comments in this code are pretty much the same, stating the obvious. This is not readable code, this is cluttered code that needs to be maintained twice - once for the code itself and once for the comments. Problem is - comments tend to rot. We don't <b>have</b> to maintain them, the computer doesn't care what they say, the computer only cares about the code. So, we tend to neglect them. I bet most of you didn't even find the copy-paste mistake hidden in the comments.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Deflation of comments</span></h3>
</div>
<div>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">After I realized that I was inflating comments, I started to deflate them. I wanted my code to feel that when there's a comment, it must be read, it's important. I eliminated all of, what I call, "The Duh" comments.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://envirodad.com/wp-content/uploads/2012/03/well_duh.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://envirodad.com/wp-content/uploads/2012/03/well_duh.jpg" height="288" width="320" /></a></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">I only added comments when I really needed to explain what I was doing. For example, what I like to call "The <i>eeeefff</i> if" (because it's such a code-smell):</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEl2pE8lRNwfkFt04Fj2S4XZSvE6493cXegXG811jgux-rp6_7xP3r8_sQfIIUfpMKrmSfz72iH2JLR0UNxJ9s-KMecEPIGwuNoIN4MTaMATln73C58pJDObxg8-0Or9hub5oZEtKI-3t4/s1600/If.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEl2pE8lRNwfkFt04Fj2S4XZSvE6493cXegXG811jgux-rp6_7xP3r8_sQfIIUfpMKrmSfz72iH2JLR0UNxJ9s-KMecEPIGwuNoIN4MTaMATln73C58pJDObxg8-0Or9hub5oZEtKI-3t4/s1600/If.png" height="114" width="640" /></a></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">No way you can understand what this if-clause checks on the first read. You'll have to read it at least twice, and usually 3-4-5 times, to be certain you understand the code. In this kind of scenarios I had usually put a comment that stated what this clause was supposed to do: "Checks if the document has a title or if we can extract a title" (for the sake of the example - let's assume we can extract a title from video/image). Ok, that's a bit clearer now, but we need to consider two things:</span></div>
<div>
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">People will still, most likely, try to read the code before the comment (assuming they won't ignore it completely).</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Even after reading the comment, it is still not clear why we are so certain we can extract a title. The <i>if</i> is complicated, and we can't be sure the comment is aligned with the code and hasn't rotten yet (at least without checking the source-control history).</span></li>
</ol>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">We'll get back to this example later.</span></div>
</div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">/* No comment */</span></h3>
<div>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">At the last stage (so far...) in my journey for writing readable code I realized, with the help of <i>Uncle Bob</i><b style="font-style: italic;"> </b>in his book <a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882">Clean Code</a>, that I should make my code readable <u>without</u> comments. This may sound extreme at first, "A code that is readable without any comments?", well... yes. Aside for some very specific cases, you should aspire to avoid comments in your code and just write code that is readable on its own.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://ooshi.net/shop/media/catalog/product/cache/1/thumbnail/600x600/9df78eab33525d08d6e5fb8d27136e95/n/o/no_comment.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://ooshi.net/shop/media/catalog/product/cache/1/thumbnail/600x600/9df78eab33525d08d6e5fb8d27136e95/n/o/no_comment.png" height="320" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Writing code in English</span></h3>
<div>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">If you manage to write code with each line looking like a sentence in English, each method is a paragraph telling about a very specific subject of the big picture, and each class tells only one aspect of the story - you will not need almost any comments, and your code will be readable. And also as a beneficial side effect, well-designed and maintainable. <i>Uncle Bob</i> compares this type of code to a newspaper where you have articles (classes) with headers (high-level method abstraction), sub-headers and text which both represent different levels of implementation details.</span></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">The two main ways in my opinion to achieve such code are:</span><br />
<br />
<ol>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: large;">Descriptive naming</span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: large;">English-like sentences</span></li>
</ol>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Descriptive naming</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">There's just so much to say about descriptive naming which makes it a topic for another post. I'll just give a few pointers for good naming:</span><br />
<br />
<ul>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Give clear descriptive names which can be used in English-like sentences (will be described in the next paragraph)</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Avoid using abbreviations</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Stick to conventions</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Avoid making the reader scroll up/down the page to figure out what a variable/method/class is meant for. With good naming, usually no scrolling will be needed.</span></li>
</ul>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Giving names to things is amongst the programmer's most difficult tasks. I suggest that when you write the code, start with any name (even <i>foo</i> for a method), and improve it as you go along (but before you commit or ask for review).</span></div>
</div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></h3>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">English like sentences</span></h3>
</div>
<div>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Try to maintain the reading flow of your code-lines. Make them look like English sentences. For example:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvSi2uJYrsRs6PdbIrKTq6lzvcPoDNCHccMClypKxqYe7kyJe4n08xovKSSXiG_Qu95v7eB_PcysnjMCocpAQXrXbNh8X1-YcPsuo52YkMDnPXUayQ1PA2DYEPzyICI8h8WWbkekJp4Q9i/s1600/hasclients.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvSi2uJYrsRs6PdbIrKTq6lzvcPoDNCHccMClypKxqYe7kyJe4n08xovKSSXiG_Qu95v7eB_PcysnjMCocpAQXrXbNh8X1-YcPsuo52YkMDnPXUayQ1PA2DYEPzyICI8h8WWbkekJp4Q9i/s1600/hasclients.png" height="102" width="640" /></a></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">You can read the if sentence like an English sentence "if store has client - currentClient". That is far more readable than doing something like:</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh41SRT-cJzAaQIoA171ou6i5P4eTNS7UiZR1AvJjpIIZ6jln2M2oVxngKXDy_02r7qms4c9uxc19sLjfb32vqnV87Rj6xolR7TSRkF-hOOE4Dp7WXHIZwAdbsX4pyC23aZv8Mu9td-WfZY/s1600/messy_has_clients.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh41SRT-cJzAaQIoA171ou6i5P4eTNS7UiZR1AvJjpIIZ6jln2M2oVxngKXDy_02r7qms4c9uxc19sLjfb32vqnV87Rj6xolR7TSRkF-hOOE4Dp7WXHIZwAdbsX4pyC23aZv8Mu9td-WfZY/s1600/messy_has_clients.png" height="66" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">The same goes for the ugly "if" we saw before. We can extract it to a private method in the <i>Document</i> class that simplifies the question in a form of an English sentence "if doc has title":</span><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidSb8ggIqdgUbW-iWJtqk5JyCTqHUbmlQF-KGSrQn7FmIhAVpFm_1xcr6ntu2zbVVlPSfnLchnlf8o7xmfdIYxeITtr9DgtZ8ue42Agd59uE3I76HG8p2y35Q4tLtn_IoUF1sejxkr0LrR/s1600/doc1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidSb8ggIqdgUbW-iWJtqk5JyCTqHUbmlQF-KGSrQn7FmIhAVpFm_1xcr6ntu2zbVVlPSfnLchnlf8o7xmfdIYxeITtr9DgtZ8ue42Agd59uE3I76HG8p2y35Q4tLtn_IoUF1sejxkr0LrR/s1600/doc1.png" height="211" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The new if form</td></tr>
</tbody></table>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">The <i>Document</i> object will encapsulate the answer to the question by calling two private methods that each simplifies another aspect of the question: </span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8tnXqOFxfiMVXr3vYt7pDWTWAh5Lls0yEtiQxqufRufDrmt1U2zuF1c7I3uF4Z8C3wQ7EDhGDIw7yCNo3mMhtbh89d9EoYUTT3Tj2vO5zWORRJoNFyI9eK5r3jeHPefrWGEWYaeIiw2De/s1600/doc1.png" imageanchor="1" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8tnXqOFxfiMVXr3vYt7pDWTWAh5Lls0yEtiQxqufRufDrmt1U2zuF1c7I3uF4Z8C3wQ7EDhGDIw7yCNo3mMhtbh89d9EoYUTT3Tj2vO5zWORRJoNFyI9eK5r3jeHPefrWGEWYaeIiw2De/s1600/doc1.png" height="217" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Each part of the question is simplified in its own method</td></tr>
</tbody></table>
</div>
<div>
<br /></div>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">This way completely abstracts for the readers the question <i>"has title?"</i> and its two sub-questions - "already has a title?" or "can a title be extracted?" The proximity of the methods in the code also counts, but I won't get into that in this post.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Is it ever ok to use comments?</span></h3>
<div>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Of course! Comments are needed for java docs, they are needed to explain a nasty hack, explain why you preferred one algorithm over the other (when it's not obvious) or add a <i>TODO</i> comment (but if it stays there for more than a few days - it's also a code-smell). Also, each rule has its exception and sometimes comments may be needed to explain the code. But try to make it the exception, and not the norm, to use comments to explain yourself.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Further Reading</span></h3>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">This post was longer than most of my posts and I haven't even started to scratch the tip of the iceberg on the subject. I invite you to read Uncle Bob's </span><span style="font-size: large;"><a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Clean Code</a> </span><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">in order to improve your code-writing skills. Also, don't hesitate to contact me (via Twitter, Linked-in or just leave a comment here) for more help on the subject.</span>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: large;">I also invite you to send me code examples with explanation comments (even if we don't know each other yet) and we'll try to figure out together how to remove them and create a clean, readable code instead.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;">Find me on Twitter: </span><a href="https://twitter.com/AviEtzioni" style="color: #888888; font-weight: normal; text-decoration: none;">@AviEtzioni</a></span></h3>
<div>
<br />
<br /></div>
<div>
<b>More interesting posts from this blog:</b><br />
<b><br /></b></div>
<div class="widget-content">
<div class="OUTBRAIN" data-src="http://avietzioni.blogspot.co.il/2013/11/welcome.html" data-widget-id="AR_1">
</div>
<script type="text/javascript">var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(ob,h);})();</script>
<script src="http://widgets.outbrain.com/outbrainLT.js" type="text/javascript"></script></div>
</div>
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.com14tag:blogger.com,1999:blog-6180894101274505794.post-10385238007361777702014-01-06T14:03:00.000-08:002014-02-08T03:20:53.738-08:00Hands On: Effective Refactoring of Legacy Code<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">In my <a href="http://avietzioni.blogspot.co.il/2013/12/refactoring-invest-in-your-future.html">previous post</a> I talked about refactoring. At the end of it I promised to give a hands-on tutorial on refactoring.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">The last two weeks at Outbrain were great fun when we had our "Quality Time". In this quality time we invested two whole weeks in reducing our technical debt. As part of this quality time, people gave tech-talks about quality. As a fan of code-quality and continuous improvement I gave a talk about my team's first <a href="http://avietzioni.blogspot.co.il/2013/11/my-retrospective-about-my-retrospective.html">retrospective</a> and another talk which was a hands-on tutorial on refactoring legacy code. Here it is, I hope you'll enjoy it. </span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span><iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/S5tXoJYBli8" width="420"></iframe><br />
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">This talk is based on <a href="http://youtu.be/_NnElPO5BU0">Testing and Refactoring Legacy Code</a> which I really liked so I decided to translate it to Hebrew and change it to include common smells in Outbrain's legacy code. </span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;">Find me on Twitter: </span><a href="https://twitter.com/AviEtzioni" style="color: #888888; font-weight: normal; text-decoration: none;">@AviEtzioni</a></span></h3>
<div>
<br />
<br /></div>
<div>
<b>More interesting posts from this blog:</b><br />
<b><br /></b></div>
<div class="widget-content">
<div class="OUTBRAIN" data-src="http://avietzioni.blogspot.co.il/2013/11/welcome.html" data-widget-id="AR_1">
</div>
<script type="text/javascript">var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(ob,h);})();</script>
<script src="http://widgets.outbrain.com/outbrainLT.js" type="text/javascript"></script></div>
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.com0tag:blogger.com,1999:blog-6180894101274505794.post-11328765506191106922013-12-27T06:47:00.001-08:002014-02-08T03:22:23.437-08:00Refactoring - Invest in your future<h3>
<span style="color: #3d85c6; font-size: large;">Legacy code</span></h3>
<div>
<span style="font-size: large;"><i><br /></i></span></div>
<div>
<span style="font-size: large;"><i>Legacy code -</i> This phrase gives most of us the shivers. We imagine legacy code as a messy, unreadable, complicated, written-with-old-technology-and-conventions code. We embrace the dreadful phrase "if it works - don't touch it". We try to avoid as much as possible touching this horrible thing called <i>Legacy code</i>.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://elearning.industriallogic.com/gh/albums/shared/images/benefits/hazardsBig.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="474" src="https://elearning.industriallogic.com/gh/albums/shared/images/benefits/hazardsBig.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Smelly code: Picture taken from <a href="https://elearning.industriallogic.com/gh/submit?Action=AlbumContentsAction&album=recognizingSmells&devLanguage=CSharp">here</a></td></tr>
</tbody></table>
<br /></div>
<h3>
<span style="color: #3d85c6; font-size: large;">What exactly is legacy code?</span></h3>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">I tried to get an answer to this question. Is it a code written using old technology? A code written by somebody who doesn't work for the company anymore? A code that is very fragile or complicated?</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Well, I guess all of the above are correct. But I believe code becomes legacy code the moment it is too intimidating to be changed. No matter what the reason is. If you wrote a new feature today, which took you a lot of mental energy and time, and tomorrow you'll be afraid to change it, then I've got news for you - you have a new-born-healthy-two-days-old legacy code. Congratulations!!!</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-size: large;">Refactoring</span></h3>
<div>
<span style="color: #3d85c6; font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">As time passes, our code becomes harder and harder to understand and maintain. The developers who touch the code come-and go, functionality evolves which causes much more flows that serve an ever-growing demand of use-cases to appear, technologies change but each of them leaves its signature on the code-base. </span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Refactoring is our way, as engineers, to clean up the mess. Some people think that refactoring is a matter of aesthetics. While this may be true, aesthetics is merely a mean to an end - making the code </span><span style="font-size: large;">more easily-maintainable and </span><span style="font-size: large;">more readable to others. And when I say others, I also mean - the future you. You are the one who most likely will read this code in the foreseeable future, and I bet you prefer not to struggle with it.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<h3>
<span style="font-size: large;"><span style="color: #3d85c6;">Invest in your future</span></span></h3>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">A lot of engineers fail to realize that refactoring is an investment. You invest in order to save much more later. Every minute that is spent trying to understand the code, is a minute wasted. If the code is read by different people, in different times, and each of them struggles to understand it because it's complicated - that's a lot of time wasted. If only one of them would break the habbit and invest in a one time effort for a better future - a lot of development time would be spared and could be invested in new features.</span></div>
<div>
<span style="font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="font-size: large;"><br /></span></div>
<h3>
<span style="font-size: large;"><span style="color: #3d85c6;">The fear factor</span></span></h3>
<div>
<br /></div>
<div>
<span style="font-size: large;">And still, people, mostly, but certainly not exclusively, juniors, afraid of refactoring. And I have to admit, there are good reasons to be afraid. How do you start to read this code? It's so complicated and full of variables and branches and try-catches and too many lines of-code and code-duplications.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">It's also very intimidating to refactor when the person who wrote most parts of the code does not work with you anymore. Or maybe it was you who wrote it but you just can't remember why the hell you did it this way, but you're sure there was a reason.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-SVhPOyeYIA4/UBBCfbq-pSI/AAAAAAAATtM/w_oKXtl6Iwc/w800-h800/Screen+Shot+2012-07-25+at+1.57.27+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-SVhPOyeYIA4/UBBCfbq-pSI/AAAAAAAATtM/w_oKXtl6Iwc/w800-h800/Screen+Shot+2012-07-25+at+1.57.27+PM.png" height="320" width="240" /></a></div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="color: #3d85c6; font-size: large;"><b>Eliminating the fear factor</b></span></div>
<div>
<span style="color: #3d85c6; font-size: large;"><b><br /></b></span></div>
<div>
<span style="font-size: large;">Luckily we have so many tools in our disposal that, when you think about it, completely reduce the amount of fear one should have when refactoring.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><b>You can always revert back</b> to the way things were before the change using the source control.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<b><span style="font-size: large;">Tests are key for an efficient refactor process</span><span style="font-size: large;">. </span></b><span style="font-size: large;">You need to have tests that test the code. If you don't have tests (or don't have enough) - write tests before starting to refactor. Not only will it improve your confidence that you don't break anything while refactoring, but it will also help </span><span style="font-size: large;">you</span><span style="font-size: large;"> to better understand the code. </span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><b>Try to find ways to control and monitor your changes</b>. For example, in Outbrain, we use feature flags in order to control new features. When we want to implement a new change, we create a flag that instructs the service on whether to use the new feature or not. This can be easily used for refactoring. And of course, it helps reverting in no-time. Just turn-off the feature and you're back to the way you were before the change. We also monitor a lot of metrics in every part of the flow. Usually, I can easily monitor the behaviour of a flow and see if anything changes. Even if you don't have advanced monitoring tools, you could utilize the log for monitoring the changes. Find your way to control and monitor the changes, this will greatly ease your fear.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><b>Suspect comments</b>. Comments are d</span><span style="font-size: large;">eceiving. They lead you to think that the code does something which it may or may not do. Computers don't understand comments, they just read the code. You should trust the code. If there are comments, use them as a guidance, but be very suspicious about them. Comments rot much faster than code. Also try to write code that is readable without comments when you refactor.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><b>Take baby steps</b>. Don't ever ever ever try to make too many changes at once. Always do one simple change and try to test it. You should allow yourself to be certain what was the exact change that caused problems. Don't make a project out of it. Refactoring is not a "all or nothing" deal. Every change you make, even the tiniest one, is blessed.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><b>Boy scouts rule</b>. Aside from taking baby steps, try to embrace the boy scouts rule - always leave the place cleaner than it was when you got there. While you work, do minor refactorings all the time. It's pretty easy and doesn't take a lot of time or effort. If everybody does that, the accumulating affect will create a much more robust code-base.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><b>Invest only where necessary.</b> If you see an ugly code which is very rarely touched, don't refactor it (aside from, maybe, very minor refactorings). It's not worth the effort. Invest in places to which you come back again and again. </span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><b>Use refactoring to learn</b>. You already need to change and extend a piece of code. While refactoring you make the code readable <u>for yourself</u>. You start with minor refactoring, and bit-by-bit you unravel the code and learn how to extend it as you go.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<br /></div>
<h3>
<span style="color: #3d85c6; font-size: large;">What's the worst that could happen?</span></h3>
<div>
<span style="color: #3d85c6; font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">When I started working at Outbrain, I had an on-boarding with Ori Lahav, Co-Founder of Outbrain. Ori told us to embrace the phrase "What's the worst that could happen?" and told us to not let fears limit our progress.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">When you refactor you should think exactly that - what's the worst that could happen? If you're not touching an extremely sensitive component, then it's no biggy. If you do refactor a sensitive component, there are probably, and hopefully, enough tests around it, and monitoring, and backups, and failover mechanisms and so on. And, of course, you'll take baby-steps and test and monitor the change carefully. So go ahead and refactor. What's the worst that could happen??</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://howtosavetheworld.ca/images/wile-e-coyote.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://howtosavetheworld.ca/images/wile-e-coyote.jpg" height="240" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">What's the worst that could happen?</td></tr>
</tbody></table>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">My next post will include a video tutorial that shows how to refactor a piece of legacy-code using TDD. Hope you already can't wait!</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;">Find me on Twitter: </span><a href="https://twitter.com/AviEtzioni" style="color: #888888; font-weight: normal; text-decoration: none;">@AviEtzioni</a></span></h3>
<div>
<br />
<br /></div>
<div>
<b>More interesting posts from this blog:</b><br />
<b><br /></b></div>
<div class="widget-content">
<div class="OUTBRAIN" data-src="http://avietzioni.blogspot.co.il/2013/11/welcome.html" data-widget-id="AR_1">
</div>
<script type="text/javascript">var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(ob,h);})();</script>
<script src="http://widgets.outbrain.com/outbrainLT.js" type="text/javascript"></script></div>
</div>
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.com0tag:blogger.com,1999:blog-6180894101274505794.post-30012029620641344042013-12-20T07:19:00.000-08:002014-02-08T03:22:57.196-08:00Code Review - Just Do It! (Part 3 - What's Your Excuse?)<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">In my last 2 posts I talked about code-review as a great <a href="http://avietzioni.blogspot.co.il/2013/12/code-review-just-do-it-part-1-feedback.html">feedback tool</a>, and after that I tried to give <a href="http://avietzioni.blogspot.co.il/2013/12/code-review-just-do-it-part-2-whats-in.html">some numbers and reasons</a> as to why you should do it. If you got up to this post, you probably a bit more convinced about code-review. And yet, people tend to give me (and themselves) a lot of excuses as to why they shouldn't code-review. </span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">This final post about code-review, will be dedicated to the various excuses and their refutation.</span><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">It takes too much time</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">The first excuse is the one I most strongly refuse to accept. Saying that code-review takes too much time implicitly implies that it's a waste of time. In my opinion, a software-engineer's work is to provide quality code in order to allow future maintenance of the software. A lot of other things take time - like talking about and writing designs, like monitoring our app and let us not forget automatic tests that require us a lot of time as well.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Code review is not a waste of time - it's an investment of time</b> that will later save us much more time.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">I'm not familiar with the code</span></h3>
<div>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">I relate to this excuse more as more of a "reason" or "concern". That's true, it's harder to review code that you're not familiar with. But it's much easier than you'd might expect. It's so easy to spot code-smells - too many branching in a method, long methods/classes that do much more than they should, bad-namings, irrelevant and misleading comments, etc...</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Let's look at the following code:</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzHxwECc5Ijc5WvgKXXDWBlR-7iBd27rPNEK1N0OvcWBigZVBTJZltqWUfBmMX7Le8A7_ka6Cl-gXGmGJnXhRErpPCgaT58f6o6cbCww6wPclTnR8mF9CF7Qyv2sh8HRU5nKBy98eh-vP1/s1600/sb.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzHxwECc5Ijc5WvgKXXDWBlR-7iBd27rPNEK1N0OvcWBigZVBTJZltqWUfBmMX7Le8A7_ka6Cl-gXGmGJnXhRErpPCgaT58f6o6cbCww6wPclTnR8mF9CF7Qyv2sh8HRU5nKBy98eh-vP1/s1600/sb.jpg" height="269" width="320" /></span></a></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Almost every java developer would see that concatenating over and over will cause the heap to be filled with unused objects and the GC to work harder (let's assume no compiler-optimization). These examples (maybe a bit less trivial) happen a lot, and they need you to spot them.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Another great insight you can provide would be in a form of a question. "Did you run tests?", "How does this change affect other components?" and so on. These insights are very valuable. When we code, we don't always remember the full-picture around our feature, and it's great to have someone reminding us (before we discover the issues the hard way).</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></h3>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">It's too subjective</span></h3>
<div>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">That's true. Code-reviews are subjective. And yet, researches show an average of 82% of agreement amongst reviewers. This means that in 82% of the times, it's not <i>that</i> subjective. Also, you could always add more reviewers to help you decide when there is a difference of opinions. And lastly, <b>you don't have to agree</b>, but at least hear what others have to say. It might be useful.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">It's just a minor change</span></h3>
<div>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Oh, what a devious excuse is this one. No matter if we're totally noobs in software-engineering, or we're experts with 20 years of experience, we fall for this one time after time. We just wanted to change a little string, maybe even a log line and <b>BOOM (!!!)</b>, an exception is thrown. Let's take this "minor" example:</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1USv-RXbxcQtxh3nvRKRnYiOSLFWOQbsT6vrM-qm4_tP1n68gRKGqlgHiwJGKP_zBxFJM1eXUZoBLH9o3_EbuAPohiXAlXyqIWnFPuekXBK51VLhUJic_vyy5HIpt17vr6n9rW6d6_vM1/s1600/Untitled+2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1USv-RXbxcQtxh3nvRKRnYiOSLFWOQbsT6vrM-qm4_tP1n68gRKGqlgHiwJGKP_zBxFJM1eXUZoBLH9o3_EbuAPohiXAlXyqIWnFPuekXBK51VLhUJic_vyy5HIpt17vr6n9rW6d6_vM1/s1600/Untitled+2.jpg" height="30" width="640" /></a></span></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">
</span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">
</span>
<br />
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Won't it be sad when the NullPointerException will be thrown?</span></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">
</span>
<br />
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">In our line of work, even this minor change can cause problems. Problems that could easily be avoided during a code-review.</span></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">
</span>
<br />
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">
</span>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">
</span>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">
<span style="color: #3d85c6;">JUST DO IT</span><br />
<div>
<span style="color: #3d85c6;"><br /></span></div>
<div>
If you've come this far, I hope I managed to convince you that code-review is something you should embrace in your organization. The best way to start is just doing it. Stop making excuses as to why it won't work and just start. The rest will follow.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUmlA7ZhX6SXV2hrNuM9yUOretERkF8sOxuxnWntM2U7lDj7rcvBzjnSy4m9g1xbkQzwnTWcFyqbqSIgUTMMfJw1Hh2joVpATg5ZdS6sLPHAz3T7cH694Y1uCB-HD4MazsK-ZiLmefyOF3/s1600/just+do+it.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUmlA7ZhX6SXV2hrNuM9yUOretERkF8sOxuxnWntM2U7lDj7rcvBzjnSy4m9g1xbkQzwnTWcFyqbqSIgUTMMfJw1Hh2joVpATg5ZdS6sLPHAz3T7cH694Y1uCB-HD4MazsK-ZiLmefyOF3/s1600/just+do+it.jpg" height="426" width="640" /></a></div>
<br /></div>
<div>
<br /></div>
<div>
Hope you enjoyed and learned from this 3-posts-long topic. In my next post I'll talk about refactoring of legacy code. Stay tuned ;)<br />
<br /></div>
<br />
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;">Find me on Twitter: </span><a href="https://twitter.com/AviEtzioni" style="color: #888888; font-weight: normal; text-decoration: none;">@AviEtzioni</a></span></h3>
<div>
<br /></div>
<div>
<b>More interesting posts from this blog:</b><br />
<b><br /></b></div>
<div class="widget-content">
<div class="OUTBRAIN" data-src="http://avietzioni.blogspot.co.il/2013/11/welcome.html" data-widget-id="AR_1">
</div>
<script type="text/javascript">var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(ob,h);})();</script>
<script src="http://widgets.outbrain.com/outbrainLT.js" type="text/javascript"></script></div>
</span></div>
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.com0tag:blogger.com,1999:blog-6180894101274505794.post-23911135555901531232013-12-13T03:39:00.001-08:002014-02-08T03:23:28.338-08:00Code Review - Just Do It! (Part 2 - What's in it for me??)<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">In my <a href="http://avietzioni.blogspot.co.il/2013/12/code-review-just-do-it-part-1-feedback.html">previous post</a>, I talked about code-review as one of the great mechanisms we have to provide and accept feedback during our coding-process. In this post I'll try to talk about what you </span><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: large;">will </span><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: large;">really gain by code-reviewing.</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br /></span>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Code Review (ha!) What is it good for?? (Absolutely something!)</span></h3>
<div>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">When I try to convince people they should apply and use code-review, I tend to encounter lots of excuses. Well, perhaps it would be too accusing to say excuses, so let's say "concerns". Before addressing the various excuses (I mean, concerns) for not applying code-review as part of the development cycle, let's try and figure out why you <u>should</u> do code-review and <u>what you gain from it</u>. In my next post, I'll talk about the different excuses for refraining from it.</span></div>
<h3>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></h3>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Defect types </span></h3>
</div>
<div>
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span>
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Let's try and understand what are the common defect-types code-review can reveal; I</span><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">n a research conducted in the University of Helsinki ("Defect Detection Efficiency: Test Case Based vs. Exploratory Testing") they tried to identify the types of issues found in a review. We can group those issues into three groups:</span></span></div>
<div>
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Functional</b> - The code doesn't do what it supposed to</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Maintainability</b> - The code structure would be hard to maintain (classes that do too much, code style, strong coupling and so on...)</span></li>
<li><b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">False positives</span></b></li>
</ol>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">While one might think that the functional problems are the main problems found in a code review, turns out these problems comprise only 21% of the problems found in a review. It means that usually, when you reviewing code, the code actually works exactly how the author claims it works. The majority of the problems are the maintainability problems which comprise 71% of the problems. This means that by code-reviewing you help keeping your code clean, maintainable and defend it from rotting. </span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzaGqF3x6zuVUNzTZuzdn1gCMSAe5BlNsOt5spW5xo8cnfp8vyFbj9EnrA-HEwMCC6_JMJFVTcW4CJRvNtKY3ZJKceQK1vvbluzyV-8t4XG2_4qqBeiquk4jbGCV8JOS_MjVR3MW7UQw73/s1600/Issues.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-size: large;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzaGqF3x6zuVUNzTZuzdn1gCMSAe5BlNsOt5spW5xo8cnfp8vyFbj9EnrA-HEwMCC6_JMJFVTcW4CJRvNtKY3ZJKceQK1vvbluzyV-8t4XG2_4qqBeiquk4jbGCV8JOS_MjVR3MW7UQw73/s1600/Issues.png" height="212" width="400" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Defect Reduction</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">I tried to the dig around the web for numbers of defect reduction for different methods. I wasn't able to find any concrete scientific numbers, but I did find some less-official estimations. But between <u>pair-programming</u> (15%-50% of defect reduction), unit-tests (30%-60%) and code-review meeting (45%-50%) - I found the method I like most, the <u>asynchronous code-review</u> (in which you send the diff of your changes to your peers and they respond on their own time), to be considered as the most affective one with <u style="font-weight: bold;">60%-65%</u> of defect reduction.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Still not sure?</span></h3>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Even when the numbers are so solid, people often can't see what they can gain, personally, from code-reviewing. Let's take a moment to talk about that.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Why should I seek this feedback?</span></h3>
<h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Better code inspection</b></span><br />
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Before I publish my changes to review, I usually take a few minutes and read it again. Ensure I haven't left out any commented code or tweaks I had done while working, making sure the variables and methods are named with readable names, and so on. I do it because I know people will dig through my code, and I don't want to embarrass myself with poor quality code. This alone, helps me find issues even before the actual code review.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Get feedback from unbiased eyes</b></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Your code does not necessarily do what you think it does. It's also not as readable as you might expect it to be. Having someone that was not part of the code-writing, inspecting your code, reveals the true readability, and true purpose of your code.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Find your problems sooner than later</b></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">I've already met a lot of people that prefer ignoring their problems. And why won't they? You're about to finish a feature you have been working on for a few days, you can't wait for it to be committed and deployed, and now you're getting all sorts of feedbacks and comments that require you to make changes to this state-of-the-art piece of code. But the fact is that the problems aren't going anywhere. You should embrace feedback and fix your problems as soon as you find them, while your mind is still on this mission. Fixing it later will cost you more as you will try to remember and understand the things you did, and why you did them.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">You'll commit and deploy your code, don't worry. You'll be even more proud of it after you have fixed the issues.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Learn new stuff</b></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">You'd be surprised about what your peers can teach you. From a simple review you can learn about design patterns, quality-patterns, performance issues, design issues and a whole lot of other stuff. Try to learn from your peers, it's important in our line of work.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Teach the others</b></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">And your peers can also learn a lot from you, if you just give them the chance. By conducting code-review, they get a chance to see how you do stuff. And they'll most probably love to learn from you.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Why should I provide feedback to others?</span></h3>
<div>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<b style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><span style="font-size: large;">Improve code-reading skills</span></b></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">One of the most important skills for a programmer is the ability to read other people's code. Practice code-review and you'll see how it allows you to get into new-code in no-time.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Learn new stuff</b></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">I already mentioned it in the previous section. This is your chance to learn how your peers work. Learn from it!</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Better understanding of the code</b></span></div>
<div>
<br /></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">By consistently reviewing your peers work, you'll learn what happens outside your zone. You'll get a complete view of the system you're working on, which will allow you to understand the affect of your code on all of the system.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Common goal</b></span></div>
<div>
<br /></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">People tend to forget it. Your peer's success, is your organization's success which means <u>your success!</u> Help your peers improve their work, and your organization will become more successful, which you can only benefit from.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Let your voice be heard</b></span></div>
<div>
<br /></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">How many times have you looked into others code and thought to yourself "what the hell they were thinking"? This is your time to prevent it! Let people know how you think things should be done. Not always will it work, but when it will, the future reader of the code (which might be <u>you</u>) will thank you for not letting things deteriorate.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span>
<br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">What about the organization?</span></h3>
</div>
</div>
<div>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Organizations that encourage code-review will benefit greatly from the process. By creating more capable employees (which learn new-stuff all the time and improve their code-reading skills), by having a process the encourages knowledge-sharing. Also, new employees won't clutter the code due to their lack of understanding on how things work in the organization. The quality of the product will increase - allowing faster development of new feature and less bugs that the customers will have to face.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Lastly, code-review encourages <u>discussion</u>. An organization that wants to move forward should allow discussions and criticizing the process. Discussion is one of the most fruitful ways of taking the organization forward.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<br /></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Hope I convinced you a bit more about code-review. In the next post I will cover the excuses I tend to hear as to why not to perform code-review. Stay tuned....</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;">Find me on Twitter: </span><a href="https://twitter.com/AviEtzioni" style="color: #888888; font-weight: normal; text-decoration: none;">@AviEtzioni</a></span></h3>
<div>
<br />
<br /></div>
<div>
<b>More interesting posts from this blog:</b><br />
<b><br /></b></div>
<div class="widget-content">
<div class="OUTBRAIN" data-src="http://avietzioni.blogspot.co.il/2013/11/welcome.html" data-widget-id="AR_1">
</div>
<script type="text/javascript">var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(ob,h);})();</script>
<script src="http://widgets.outbrain.com/outbrainLT.js" type="text/javascript"></script></div>
</div>
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.com0tag:blogger.com,1999:blog-6180894101274505794.post-26630138652763842642013-12-06T13:21:00.001-08:002014-02-08T03:23:48.726-08:00Code Review - Just Do It! (Part 1 - Feedback)<span style="font-size: large;">I cannot over-estimate how important I think code-quality is. And yet, some people believe that code-review is not for them. Perhaps they think it takes too long, or they're too good for being reviewed by other team members.</span><br />
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Recently I gave a talk about the importance of the code review in my opinion. You can find it here:</span><br />
<span style="font-size: large;"><br /></span></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: large;"><iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/NeV1tP1IfoM?feature=player_embedded' frameborder='0'></iframe></span></div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">For those of you who don't speak hebrew, or prefer to just read instead of watching the video, I'll try to summarize here. I split the lecture into 3 different posts, don't forget to follow up for the next posts.</span><br />
<span style="font-size: large;"><br /></span></div>
<div>
<h3>
<span style="color: #3d85c6; font-size: large;">
Review - Not only for developers</span></h3>
</div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">I guess it wouldn't come to you as a complete surprise that review was not invented by or for the software engineering industry. Students at the university ask peers to review their work and sometime even pay good money for getting a professional review. Authors and journalist wouldn't dream of releasing their writings without them being reviewed by someone (usually more than one). And even this blog is reviewed by native English speakers to make sure I don't write in Hebrish (an un-understandable mixture of Hebrew and English).</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">How can that be that not all of the software-engineers think their work should be reviewed?</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-size: large;">
Feedback is all around us</span></h3>
<div>
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">I have worked in agile methodologies for more than 3 years already. When we try to be agile we try to seek feedback in every step of the way in order to solve problems as soon as possible. In the "Lean Start Up" book, by Eric Ries, it's described as <a href="http://lean.st/principles/build-measure-learn">"The Feedback Loop"</a>.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://lean.st/images/startup-feedback-loop1.png?1315940898" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-size: large;"><img border="0" src="http://lean.st/images/startup-feedback-loop1.png?1315940898" height="320" width="307" /></span></a></div>
</div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">During our work, we encounter a lot of feedback loops. I tried to map the main feedback loops on my work at Outbrain. I found 6 main feedback loops during a feature's development from when its requirements are passed from the PM to the development team and until it's released:</span><br />
<span style="font-size: large;"><br /></span></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo9-K7WXgEg4v3Z-pVHpIQo5wBTezSYg4a-EEMEfa2NmowWkRguHDsSjGZ1L61EL3aHCLiAW2Q6hl5wd6Nn7qBrj8tObfzWcFA16ddUrfWTbFKXMn0_aAP9D6TC2NUhKCAPHi8t-wkOXT6/s1600/Untitled.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-size: large;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo9-K7WXgEg4v3Z-pVHpIQo5wBTezSYg4a-EEMEfa2NmowWkRguHDsSjGZ1L61EL3aHCLiAW2Q6hl5wd6Nn7qBrj8tObfzWcFA16ddUrfWTbFKXMn0_aAP9D6TC2NUhKCAPHi8t-wkOXT6/s1600/Untitled.png" height="320" width="192" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: large; text-align: left;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: large; text-align: left;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">We start with writing a design, usually followed by a review and feedback from our peers. When we feel comfortable with the design, we start coding. And, while we code, the IDE warns us about errors in an extremely short feedback cycle. We then use automation tests to get feedback on whether we break the code, and when the code is committed it goes through a build process which provides us with a feedback on how our code is integrated in the system.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">After the code is released, we have a great monitoring system in Outbrain to monitor the features affect (on the users or on the server load, or any other KPI). Lastly, when things go wrong, we conduct a take-in to make sure we learn from our mistakes.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Looking at all of those great feedbacks, we can group those into two groups. The first group would be "Automatic Feedback" and the second would be "Human Feedback" as described in this picture:</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUmwByxLr-_jfuw4aqLx-Y_5DtVBoahyphenhyphen4mDjthF-FVDPgO6q-ScyBmRnQAPG4DakHDx7Ffm5sT6gXaom_jG2iKDSqOHglntie8vXtZXb1Fdlqp_ZleIBhZDgriZVgpgcCbJlIQ5PpboezZ/s1600/Untitled2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-size: large;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUmwByxLr-_jfuw4aqLx-Y_5DtVBoahyphenhyphen4mDjthF-FVDPgO6q-ScyBmRnQAPG4DakHDx7Ffm5sT6gXaom_jG2iKDSqOHglntie8vXtZXb1Fdlqp_ZleIBhZDgriZVgpgcCbJlIQ5PpboezZ/s1600/Untitled2.png" height="320" width="312" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Interesting observations on these two groups would be that the "Automatic Feedback" group exposes symptoms, whereas the "Human Feedback" group exposes problems.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">This actually means that we start our coding process by asking feedback, and only after we're done, and the feature's out, we try to learn from our mistakes. During the time between these two human interactions, we're pretty much on our own. Adding a code-review cycle gives us another opportunity to get human feedback and improve our code before it's committed/deployed.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">In my next post, I'll try to convince you that code review is great for the reviewer, the reviewee and of course - the organization.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">To be continued...</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;">Find me on Twitter: </span><a href="https://twitter.com/AviEtzioni" style="color: #888888; font-weight: normal; text-decoration: none;">@AviEtzioni</a></span></h3>
<div>
<br />
<br /></div>
<div>
<b>More interesting posts from this blog:</b><br />
<b><br /></b></div>
<div class="widget-content">
<div class="OUTBRAIN" data-src="http://avietzioni.blogspot.co.il/2013/11/welcome.html" data-widget-id="AR_1">
</div>
<script type="text/javascript">var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(ob,h);})();</script>
<script src="http://widgets.outbrain.com/outbrainLT.js" type="text/javascript"></script></div>
</div>
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.com0tag:blogger.com,1999:blog-6180894101274505794.post-49149606090415514252013-11-29T08:17:00.000-08:002014-02-08T03:24:20.622-08:00My Retrospective About My Retrospective<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Business as (too) usual</span></h3>
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Back when I was working for my previous employer, we used SCRUM as our development methodology. As part of this methodology we used to end every sprint (3 weeks of work) with a retrospective.</span></span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">During the retrospective, the team would sit down together and discuss what had been done well and what had not.</span><br />
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">This was a recurring ceremony in which the team-leader guided us into talking about the painful pain points (along with the good things we've done - we don't want to be ALL negative). We used to discuss various issues; a lot of those times it was done with a lot of enthusiasm, maybe even some arguing.</span></span><br />
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
</span><br />
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Let's make things more exciting</span></h3>
<div>
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">During one of our 1x1s, my team-leader told me that he felt like we had to shake the dust from the retrospective process a bit, make it more exciting and, more importantly, more productive. His suggestion was to have a rotation between team members and let each of us lead a retrospective. We were encouraged to freshen things up, any way we deemed fit.</span></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">What should I do?</span></h3>
<div>
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">I started thinking about what I wanted to do when it was my turn to lead a retrospective. Should it be around one specific topic? Should it be a game? Should I stick with the original format?</span></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">I decided to think about what was bothering me in our retrospective process. It was a sort of a retrospective with myself about our retrospective.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">I narrowed it down to 3 issues:</span></div>
<div>
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Priorities:</b> I realized that we don't always address the most important issues. We let our emotions, instead of our common-sense, affect the topics we discuss. Instead of finding 1 or 2 things that can improve us best, we discussed things that really annoyed us. We could not always change these things , or know that the change would have a great impact on the team or productivity, even if it happened.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Not everyone's voice can be heard</b>: Some people are more passionate when they speak, some are shy and some are more verbal and can convince others. It's hard to let everyone be equally heard and it was really important for me to try.</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Action items</b>: We all want to change the world, or at least our organization, for the best. But we have to be realistic and set feasible goals that, in each sprint, would improve us a little more. </span></li>
</ol>
</div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">So I decided to create a flow in my retrospective which will allow everyone to speak their minds, and will lead to an extremely focused set of 2-3 feasible and improving action items.</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">So that's what I did</span></h3>
<div>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h4>
</h4>
<h4>
</h4>
<h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">
Step 0: Preparations</span></h4>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">I booked a room with a big erasable board. Before the team arrived I wrote down all of the stories we worked on during this sprint with different colors (in order to make it very clear where we were at the end of this sprint):</span><br />
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
</span><br />
<ul>
<li><span style="color: lime; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>GREEN - ACCEPTED</b></span></li>
<li><b><span style="color: orange; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">ORANGE - IN PROGRESS</span></b></li>
<li><b><span style="color: red; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">RED - NOT STARTED</span></b></li>
</ul>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">I put some papers and pens on the table for the team to use later on.</span><br />
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
</span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgeiZYIE2NeJUAaO6VArfOY_Z-Ec-rGIrx2XnBZjBisfAxmbEJMQ0_YfBmziKgpriycDXKJF9xDwKNb6Xx1bnmc701znaqcsZQxdjY4E49G7MM-U6tWrRXbV41HuebjIL93dzcwL8H-2ta/s1600/Slide1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgeiZYIE2NeJUAaO6VArfOY_Z-Ec-rGIrx2XnBZjBisfAxmbEJMQ0_YfBmziKgpriycDXKJF9xDwKNb6Xx1bnmc701znaqcsZQxdjY4E49G7MM-U6tWrRXbV41HuebjIL93dzcwL8H-2ta/s1600/Slide1.jpg" height="240" width="320" /></span></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">This is how the board looked like when the team arrived</span></b></td></tr>
</tbody></table>
<h4>
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></b></h4>
<div>
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></b></div>
<h4>
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Step 1: Map the problems</span></b></h4>
<div>
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">I asked the team (myself included) to take 3-5 minutes and write down the four impediments which bothered them most. After all were finished we took turns in reading our notes and then wrote each of those on the board, near the stories that were already written there. Everyone could speak their minds about what was bothering them, without interruptions.</span></span><br />
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
</span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc5EV-0VlHrHejsSIjihpMJ1Fqt9EtICriBxJtBEqXAtlHYKVUNge0XOEzpsRWPx2hulOF_0_VtX0MpTaoKbt-vq0FfuQQjYUYFGhLaXvdbpFlrZyt8_nDhv45x7t46SkjvZUckC6eF1i5/s1600/Slide2.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc5EV-0VlHrHejsSIjihpMJ1Fqt9EtICriBxJtBEqXAtlHYKVUNge0XOEzpsRWPx2hulOF_0_VtX0MpTaoKbt-vq0FfuQQjYUYFGhLaXvdbpFlrZyt8_nDhv45x7t46SkjvZUckC6eF1i5/s1600/Slide2.jpg" height="240" width="320" /></span></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">In Step 1 we added our painful impediments</span></b></td></tr>
</tbody></table>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">
Step 2: Suggest solutions</span></h4>
<div>
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Pointing what's wrong or what's painful is fairly easy. Coming up with a solution to the problem, may sometimes be a bit more complicated. I, again, asked everybody to write down their suggested solutions to the impediments that were raised. When finished we took turns of reading the solutions and wrote down these suggestions on the board as well. This uncovered two interesting issues:</span></span></div>
<div>
<ol>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Unsurprisingly - some of the problems had the same solution</span></li>
<li><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">For some of the problems we couldn't find a solution with a good ROI (ROI<b> = R</b>eturn <b>O</b>f <b>I</b>nvestment: Meaning - all the solutions we found weren't worth their effort) </span></li>
</ol>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">This step made us focus on a smaller set of problems and their solutions. And again, everyone had their chance to suggest solutions.</span><br />
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
</span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZFbe9bBeArQILHRWZRKT3zoh_CQaPFWnpfHPROxWocSamP4VBY9IQS4dIWlYRazJA6Ilo0fcgjmEQRAQ_iYKzJ1g61p4SBbJv_wfZcGm5lnkmt0ypR0D2634UKAOPvkl-wX3YFP_DphO_/s1600/Slide3.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZFbe9bBeArQILHRWZRKT3zoh_CQaPFWnpfHPROxWocSamP4VBY9IQS4dIWlYRazJA6Ilo0fcgjmEQRAQ_iYKzJ1g61p4SBbJv_wfZcGm5lnkmt0ypR0D2634UKAOPvkl-wX3YFP_DphO_/s1600/Slide3.jpg" height="240" width="320" /></span></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Lastly - we added our suggested solutions</span></b></td></tr>
</tbody></table>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
</div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<h4>
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Step 3: Let's vote!</span></b></h4>
</div>
<div>
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Lastly, I told the team that each team member gets 10 points. Those points were used for voting on the solutions that were suggested in the previous step. Each team member was allowed to distribute the points in any way (s)he wanted to. At the end, the top 3 solutions were chosen as our action items for the next sprint.</span></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h4>
</h4>
<h4>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">
Step 4: Leave with a good taste</span></h4>
<div>
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Before wrapping up I asked everyone to say what they thought was good during the sprint. I wanted the retrospective to end with a positive note. Also, it's important to preserve what we do well.</span></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></h3>
<h3>
<span style="color: #3d85c6; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">Conclusion</span></h3>
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
</span><br />
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">After the retrospective, I again did a little retrospective with myself. I tried to figure out if I managed to address the 3 problems I tried to face at the beginning. The democratic nature of the retrospective allowed everyone's voice to be heard, as I wanted, and prevented unnecessary arguments about the priorities. Also, at the end, we had to vote on <u>some</u> action items. Having time to think about what's really important and what we can really change, made us choose action items that were feasible. Those action items were tracked during the next sprint - I sent an email that sums up the retrospective right after this meeting. During the sprint I sent a reminder when we encountered an issue that was brought up in the retrospective. Finally, before the next retrospective I sent an email describing our decisions from the previous retrospective and whether we applied the action items or not. At the next retrospective we made sure we followed on those action items, but that's another team member's story to tell :)</span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;">A word of thanks to Gal Zellermayer, my team-leader at the time, who pushed me into thinking out of the box and conduct this retrospective.</span><br />
<span style="font-size: large;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<br />
</span><br />
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: large;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;">Find me on Twitter: </span><a href="https://twitter.com/AviEtzioni" style="color: #888888; font-weight: normal; text-decoration: none;">@AviEtzioni</a></span></span></h3>
<span style="font-size: large;">
<div>
<br />
<br /></div>
<div>
<b>More interesting posts from this blog:</b><br />
<b><br /></b></div>
<div class="widget-content">
<div class="OUTBRAIN" data-src="http://avietzioni.blogspot.co.il/2013/11/welcome.html" data-widget-id="AR_1">
</div>
<script type="text/javascript">var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(ob,h);})();</script>
<script src="http://widgets.outbrain.com/outbrainLT.js" type="text/javascript"></script></div>
</span></div>
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.com13tag:blogger.com,1999:blog-6180894101274505794.post-43752660153694653052013-11-01T07:27:00.000-07:002016-06-10T05:23:38.431-07:00Welcome!I'm not sure when was the exact moment in which I knew I wanted to become a software-engineer. My first "Hello World!" was at the age of 10. But it wasn't until I was 18 that I started to actually work in this profession.<br />
<br />
At first I was a bit intimidated by the assumption that software-engineer's work is usually lonely. You sit by the computer and code. By yourself. And, considering myself a people's person, it made me rethink whether this line of work was for me.<br />
<br />
Over the years I have come to the realization that software-engineering is not lonely. Quite the opposite. Software-engineering is about people almost as much as it is about technologies. Only great teams build amazing products.<br />
<br />
In this blog I write about technology and culture. I hope you will enjoy it.
<br />
<br />
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span>
<br />
<h3 style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;">
<span style="font-size: medium;"><span style="color: blue; font-weight: normal;">Find me on Twitter: </span><a href="https://twitter.com/AviEtzioni" style="color: #888888; font-weight: normal; text-decoration: none;">@AviEtzioni</a></span></h3>
<div>
<br />
<br /></div>
<div>
<b>More interesting posts from this blog:</b><br />
<b><br /></b></div>
<div class="widget-content">
<div class="OUTBRAIN" data-src="http://avietzioni.blogspot.co.il/2013/11/welcome.html" data-widget-id="AR_1">
</div>
<script type="text/javascript">var h=document.getElementsByTagName("script")[0];h.parentNode.insertBefore(ob,h);})();</script>
<script src="http://widgets.outbrain.com/outbrainLT.js" type="text/javascript"></script></div>
Avihttp://www.blogger.com/profile/13093979883101224479noreply@blogger.com0