Blackout for SOPA and PIPA.
Click to learn more
Posterous theme by Cory Watilo

Filed under: Featured

Jailing bugs

Media_https3amazonaws_iaewo
Handling bugs is never an easy task. Some are not even meant to be logged while some can not be fixed without blowing up the whole system. Some of the books I've read described great ways to deal with defects. Most suggest to record them to a DTS, write some reproduction steps and wait for the programmer team to fix it. This approach works well and gives a good numbers to generate trends. I might be a bit obsessed with automation and TDD though, so I've started using something else.

What is a bug in this context?

A bug is a piece of behavior that doesn't work as expected from the user's point of view. The key points in the definition above are that we're only talking about defects that can be reproduced from the user interface only. Why? Because no one cares about the unseen.

So you've caught a bug!

Great! You probably have some notes about how to recreate the defect. You are aware of what it should be doing instead of what it is doing now. You'll probably record it to a bug tracker, but try this:

Create an automated test!

All levels of testing require inputs and expectations. Even the smallest micro-test that drive core methods rely on expected output from a known input. In the current scenario you'll have steps as inputs and you have expectations how your user interface should respond to those. For a primitive demonstration lets look at the following bug report:

Description:

A logged in user of the system cannot change the registered e-mail address!

Steps to reproduce:

  1. Open the site.
  2. Log into the site.
  3. Click the "Account Settings" link.
  4. Change the e-mail address via the settings form.
  5. Click "Save" button.

Expected behavior:

The pre-populated e-mail field should contain the new e-mail.

Current behavior:

The new e-mail address is not saved, the old one is visible after saving the form.
In your automated test script you should be able to easily re-create the steps above. The interesting part are the expectations. The just enough assertions to consider the bug fixed depends on the complexity of the error. In our case it's a pretty straight-forward conclusion: assert that the e-mail field after submitting the data holds the e-mail address we've entered before. Having test like these is pretty nice if you make them part of your regression suite. It helps you target error prone parts of your system and if such test case is present you can be sure you'll be notified if the bug resurrects.

But how to handle these before the bug is fixed?

Create a test suite for bugs. With TestNG you can easily manage test groups. I prefer having a group named Bugs and one called Regression. The latter contains only bugs that are fixed. The tests in the former are executed via a nightly run for example. Each run will report the number of tests failed only in this case it will mean: the number of bugs still alive! If you hook these up with a CI server you can get nice little trends showing the number of living bugs over time. It works for us! Leave your thoughts if you have tried this approach, I'm extremely curious!

How many bugs live in your system?

Just read: Elisabeth and Eric Freeman – Head First Design Patterns

Media_https3amazonaws_cqyna

Product Details

  • Paperback: 688 pages
  • Publisher: O'Reilly Media; 1 edition (October 25, 2004)
  • Language: English
  • ISBN-10: 0596007124
  • ISBN-13: 978-0596007126
  • Product Dimensions: 9.2 x 8 x 1.4 inches
  • Shipping Weight: 2.8 pounds
Not as bad as it may look by the cover! Elisabeth Freeman relies on the feminine way of association. There are a lot of pictures, arrows, speech bubbles, acts and life-examples describing the patterns. If you have a good imagination and can easily recall pieces of information by keywords like pizza and duck, then this book is for you. If you want a reference-book of design patterns that you can hit up while coding, look for something else. There is one thing you must read on page 526, the MVC song: MVC song

Editorial Reviews

Review

This is a gimmicky book that actually works for once. It is an intelligent and well thought-out discussion of Java design patterns, and if you dont know what a design pattern is then this is an excellent way to find out. It is also an interested discussion of object-oriented design. I found that the authors often anticipated my reaction to their initial explanations and asked the questions that I would have asked had it been a lecture. - Mike James, VSJ, April 2005

Product Description

You're not alone. At any given moment, somewhere in the world someone struggles with the same software design problems you have. You know you don't want to reinvent the wheel (or worse, a flat tire), so you look to Design Patterns--the lessons learned by those who've faced the same problems. With Design Patterns, you get to take advantage of the best practices and experience of others, so that you can spend your time on... something else. Something more challenging. Something more complex. Something more fun. You want to learn about the patterns that matter--why to use them, when to use them, how to use them (and when NOT to use them). But you don't just want to see how patterns look in a book, you want to know how they look "in the wild". In their native environment. In other words, in real world applications. You also want to learn how patterns are used in the Java API, and how to exploit Java's built-in pattern support in your own code. You want to learn the real OO design principles and why everything your boss told you about inheritance might be wrong (and what to do instead). You want to learn how those principles will help the next time you're up a creek without a design paddle pattern. Most importantly, you want to learn the "secret language" of Design Patterns so that you can hold your own with your co-worker (and impress cocktail party guests) when he casually mentions his stunningly clever use of Command, Facade, Proxy, and Factory in between sips of a martini. You'll easily counter with your deep understanding of why Singleton isn't as simple as it sounds, how the Factory is so often misunderstood, or on the real relationship between Decorator, Facade and Adapter. With Head First Design Patterns, you'll avoid the embarrassment of thinking Decorator is something from the "Trading Spaces" show. Best of all, in a way that won't put you to sleep! We think your time is too important (and too short) to spend it struggling with academic texts. If you've read a Head First book, you know what to expect - a visually-rich format designed for the way your brain works. Using the latest research in neurobiology, cognitive science, and learning theory, Head First Design Patterns will load patterns into your brain in a way that sticks. In a way that lets you put them to work immediately. In a way that makes you better at solving software design problems, and better at speaking the language of patterns with others on your team.

Just read: Chris Snyder & Michael Southwell – Pro PHP Security

Media_https3amazonaws_ggpkq

Product Details

  • Paperback: 528 pages
  • Publisher: Apress; 1st ed. 2005. Corr. 2nd printing edition (August 29, 2005)
  • Language: English
  • ISBN-10: 1590595084
  • ISBN-13: 978-1590595084
  • Product Dimensions: 9.2 x 7.4 x 1.2 inches
  • Shipping Weight: 2 pounds
I was expecting to have much heureka moments reading this book, but I was let down. Being good in encryption doesn't mean you're good at building secure websites. You shouldn't read this if you have experiences with xss, sql injection and apache with virtual hosts. If you have such knowledge, only read the first 20 or so pages. Pity for this book, I hope I'll find one covering the topic much more pro

Editorial Reviews

Product Description

Pro PHP Security is one of the first books devoted solely to PHP security. It will serve as your complete guide for taking defensive and proactive security measures within your PHP applications. (And the methods discussed are compatible with PHP versions 3, 4, and 5.)

The knowledge you'll gain from this comprehensive guide will help you prevent attackers from potentially disrupting site operation or destroying data. And you'll learn about various security measures, for example, creating and deploying "captchas," validating e-mail, fending off SQL injection attacks, and preventing cross-site scripting attempts.

About the Author

Michael Southwell is a retired English professor who has been developing websites for more than 10 years in the small business, nonprofit, and educational areas, with special interest in problems of accessibility. He has authored and co-authored 8 books and numerous articles about writing, writing and computers, and writing education.

Xml Serialization with java - SimpleXml

Media_https3amazonaws_bbpdi
For those of you out there who have problem implementing some complex xmls i have a good example for you: Xml : [cc lang="xml" lines="auto"]
Teszt1
Teszt2
Teszt2
Teszt3
[/cc] And this is your Class Hierarchy representing it: [cc lang="java" lines="auto" escaped="true"] @Root public class UIElement { @ElementList(name="Elements") public List divContainers; } @Root public class DivContainer { @ElementList(name="DivContainer", inline=true) public List divs; @Attribute public String name; } @Root(name="Div") public class Div { @Element(name="test") public String test; @Attribute(name="name", required=false) public String name; } [/cc] And the serialize code: [cc lang="java" lines="auto" escaped="true"] public void testXml() { Serializer serializer = new Persister(); File source = new File("c:\\tmp\\test.xml"); UIElement ui = null; try { ui = serializer.read(UIElement.class, source); } catch (Exception e) { e.printStackTrace(); } for (DivContainer divc : ui.divContainers) { for (Div div : divc.divs) { System.out.println("Value of test: " + div.test); } } } [/cc] You have to look out for two things... First note the @Root under Div tag. That is necessary there. Writing in the attribute name there is necessary too. Also the 'inline' tag. Without them it wont work. Gergely.

Show Your GIT Branch Name In Your Prompt

Media_https3amazonaws_hvyjm

Show Your GIT Branch Name In Your Prompt

Typing git branch over and over to see what branch you are on sucks. Sure, you could argue that you should always KNOW what branch you’re currently working on. And if you did, you would obviously not be a git user. Bouncing around branches can be pretty common, and I know I’ve messed some things up pretty bad not knowing what branch I was on. So set up your shell to always put the name of the current branch into your prompt. [cc lang="bash" escaped="yes" lines="27"] function parse_git_branch { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' } function proml { local BLUE="\[\033[0;34m\]" local RED="\[\033[0;31m\]" local LIGHT_RED="\[\033[1;31m\]" local GREEN="\[\033[0;32m\]" local LIGHT_GREEN="\[\033[1;32m\]" local WHITE="\[\033[1;37m\]" local LIGHT_GRAY="\[\033[0;37m\]" case $TERM in xterm*) TITLEBAR=&'\[\033]0;\u@\h:\w\007\]&' ;; *) TITLEBAR="" ;; esac PS1="${TITLEBAR}\ $BLUE[$RED\$(date +%H:%M)$BLUE]\ $BLUE[$RED\u@\h:\w$GREEN\$(parse_git_branch)$BLUE]\ $GREEN\$ " PS2=&'> &' PS4=&'+ &' } proml [/cc] Pastie Link Put this at the top of your .bash_profile and you’ll be pimping your branch all over. Thanks to @defunkt for this. via Show Your GIT Branch Name In Your Prompt.
I thank @fqqkd for this, He pointed me to the post. Though I didn't like the colors, so I've made blue [cc lang="bash" inline="yes"]BLUE="\[\033[0;36m\]"[/cc] and the propt: [cc lang="bash" escpaed="yes"] PS1="${TITLEBAR}\ $BLUE[$RED\$(date +%H:%M)$BLUE]\ $BLUE[$BLUE\u@\h:\w$GREEN\$(parse_git_branch)$BLUE]\ $BLUE\$ " [/cc]

Just read: Pro Git

Media_https3amazonaws_efbvp

Product Details

  • Paperback: 288 pages
  • Publisher: Apress; XXII, 265 p. edition (August 27, 2009)
  • Language: English
  • ISBN-10: 1430218339
  • ISBN-13: 978-1430218333
  • Product Dimensions: 9.1 x 7 x 0.9 inches
  • Shipping Weight: 14.9 ounces
Just read myself through Scott Chacon's Pro Git book. Had an unexpectedly fine time, while getting closer to the version control system that I'll be using in the future. Since finishing the book, I've started migrating all my running projects to git, and I must admit: I love it. So much easier, so convenient, so secure. I will write more about my adventures with Git later. For now I recommend everyone to read the book. It's free to do so online at: http://progit.org/book/. Though it is here, I suggest you put this relatively cheap book on your bookshelf, to be at hand when in need. (amazon)

Editorial Reviews

Product Description

Git is the version control system developed by Linus Torvalds for Linux kernel development. It took the open source world by storm since its inception in 2005, and is used by small development shops and giants like Google, Red Hat, and IBM, and of course many open source projects.
  • A book by Git experts to turn you into a Git expert
  • Introduces the world of distributed version control
  • Shows how to build a Git development workflow

What you’ll learn

  • Use Git as a programmer or a project leader.
  • Become a fluent Git user.
  • Use distributed features of Git to the full.
  • Acquire the ability to insert Git in the development workflow.
  • Migrate programming projects from other SCMs to Git.
  • Learn how to extend Git.

Who is this book for?

This book is for all open source developers: you are bound to encounter it somewhere in the course of your working life. Proprietary software developers will appreciate Git’s enormous scalability, since it is used for the Linux project, which comprises thousands of developers and testers.

About the Apress Pro Series

The Apress Pro series books are practical, professional tutorials to keep you on and moving up the professional ladder. You have gotten the job, now you need to hone your skills in these tough competitive times. The Apress Pro series expands your skills and expertise in exactly the areas you need. Master the content of a Pro book, and you will always be able to get the job done in a professional development project. Written by experts in their field, Pro series books from Apress give you the hard–won solutions to problems you will face in your professional programming career.

Dropbox - If you've lost your hdd space

Media_https3amazonaws_gzpcb
I came home the other day, and had my computer notifying me about less then 2GB free space left. I fiddled a bit round with my data, deleted cache, sources, downloaded archives, etc. All went fine, had about 7GB left. Closed the lid, went to sleep and work. I got home today, and the same message waited for me on the screen again. I did a deeper folder size analysis, and found the truth. DROPBOX (2Gb package) CACHE was 15GB! In my home folder was a
.dropbox/cache
directory, which had several YYYY-MM-DD formatted entries. I deleted all, but the last 2 dates, and freed 10Gb's. If anyone finds a good way to prevent this hog, please leave a comment.

Helmi Ble'be': Trac error - database disk image is malformed

Media_https3amazonaws_ocdzj
I've ran into an irritating error after migrating the data from one server to the other. One of my projects under Trac got corrupted. I've found the solution:
One of my trac page got the error message "database disk image is malformed" "underlying Trac DB is in serious trouble, may corrupted" - Ticket #6347 How I fix: [cc lang="bash" escaped="true"]sqlite3 trac.db .dump | sqlite3 trac2.db cp trac.db trac.broken.db cp trac2.db trac.db[/cc]
via Helmi Ble'be': Trac error - database disk image is malformed.

Code working for you

Media_https3amazonaws_ggjrj
I've had an interesting talk with one of my friends, who's not really into those magical "useless" crazy stuff we're doing just to get metrics about the "quality" of our code. He explained, that most of the programmers like to think of code as slaves. It needs to be tortured to do exactly what they want it to do. Sure, this is a working approach, but takes a huge amount of energy to regulate the codebase, and prevent it from rebelling. Imagine you're working on a project almost a year or so and everything seems to be going well until some minor changes break the consistence, and bugs start evolving from nowhere. It's like cancer. You fix one cell, two others seem to come. Most of the times the cure is either expensive, or impossible. Shotgun surgery can help, but you'll never want to touch your code again. Familiar? I'm sure that most of the coders in the (at least the www) world are struggling in a huge pile of  Technical Dept - not even knowing what it is.
TechnicalDebt You have a piece of functionality that you need to add to your system. You see two ways to do it, one is quick to do but is messy - you are sure that it will make further changes harder in the future. The other results in a cleaner design, but will take longer to put in place. Technical Debt is a wonderful metaphor developed by Ward Cunningham to help us think about this problem. In this metaphor, doing things the quick and dirty way sets us up with a technical debt, which is similar to a financial debt. Like a financial debt, the technical debt incurs interest payments, which come in the form of the extra effort that we have to do in future development because of the quick and dirty design choice. We can choose to continue paying the interest, or we can pay down the principal by refactoring the quick and dirty design into the better design. Although it costs to pay down the principal, we gain by reduced interest payments in the future. The metaphor also explains why it may be sensible to do the quick and dirty approach. Just as a business incurs some debt to take advantage of a market opportunity developers may incur technical debt to hit an important deadline. The all too common problem is that development organizations let their debt get out of control and spend most of their future development effort paying crippling interest payments. The tricky thing about technical debt, of course, is that unlike money it's impossible to measure effectively. The interest payments hurt a team's productivity, but since we CannotMeasureProductivity, we can't really see the true effect of our technical debt. One thing that is easily missed is that you only make money on your loan by delivering. Following the DesignStaminaHypothesis, you need to deliver before you reach the design payoff line to give you any chance of making a gain on your debt. Even below the line you have to trade-off the value you get from early delivery against the interest payments and principal pay-down that you'll incur. Technical Debt comes in various forms, some of which can be good and some bad - I use the TechnicalDebtQuadrant to describe them. (As far as I can tell, Ward first introduced this concept in an experience report for OOPSLA 1992. It has also been discussed on the wiki.) Martin Fowler @ http://martinfowler.com/bliki/TechnicalDebt.html
The same scenario could be applied to all levels of life. Company management, Governance, etc. People want other peoples working like slaves, without questions, without thoughts, and maximum effectiveness. You wouldn't go working for a company that will treat you like a slave, give you minimal money. But what is so magnetic about working for (let's say) Google?
Media_https3amazonaws_khvyo
Media_https3amazonaws_qaaog
Media_https3amazonaws_gfbpl
Media_https3amazonaws_eofjk
Media_https3amazonaws_ybbme
Media_https3amazonaws_nycht
Would you like to work here? Of course you do. There's no sane person in the world who wouldn't like to spend the day in such environment for such salary... But how does this apply to code quality?
Media_https3amazonaws_qbveo
Code is just like a simple employee in any company. You need to care for your workers, provide them everything you can to make them happy, just as mentally healthy. "But the code doesn't have needs!" - you say, but you're wrong. Of course it can't tell it's needs on it's own, but it has a language of metrics that can come handy. Measure coding standard violations, testability, writing unit-, integration-, end-to-end tests, collecting it's coverage data will get you a full report on the health of your code... trust me, it's worth it. The more healthy your software is, the easier will it be to apply changes to it. (= make the same amount of money, with less effort) Think about it.