Latest Features

                        What Do You Need To Keep Your Code DRY

                        DRY is an acronym for Don’t Repeat Yourself. It’s a critical programming concept and skill to learn. So What Do You Need To Keep Your Code DRY?

                        Here’s how it works in real life. Plus a DRY joke at the end.

                        Imagine you’re a programmer. Someone has asked you to write code to generate a random number between 1 and 1000. The random number is to be used by another bit of code. You sit down and write simple clean code to generate a random number:

                        1 nbr = create_rnd_nbr(1,1000)
                        2 print nbr

                        where create_rnd_nbr is a built in function included in the programming language which expects a start number (1) and end number (1000) to be passed into it. You assign the result of create_rnd_nbr(1,1000) to the variable named nbr then print the variable as a number to your computer screen.

                        A month passes, you’re busy, and they ask you to write another bit of code to generate a random number between 1 and 500 to be used by another part of the application. You could adapt the code you have to work in both cases, for numbers between 1 and 1000 and 1 and 500. But you’re busy. So you copy paste your oode and change the limit from 1000 to 500:

                        1 nbr = create_rnd_nbr(1,1000)
                        2 print nbr
                        3
                        4 new_nbr = create_rnd_nbr(1,500)
                        5 print new_nbr

                        Now you have two blocks of code that generate random numbers.

                        Imagine this happens a third and fourth time. You have four different blocks of code to generate random numbers. Time passes, you leave the company, and a few years later the company hires a new programmer. Someone has noticed the application generates weird random numbers. They think its the random number code you wrote.

                        Source: Tim Slavin