3 years ago
csgeek
in English · 2,161 Views
likes 2clips 3comments 0
7 Ways to Write Beautiful Code
I found a great blog post over at equivalence.co.uk where Gregg O’Malley shared some tips for beautiful code. These are not the only ways to write beautiful code, but they are good to note! >> 1. Return from if statements as quickly as possible. [Slide 1] When you have a bazillion if statements nested, it can look pretty bad. Simplify your life and return if statements asap. >> 2. Don’t use an if statement when all you simply want to do is return the Boolean from the condition of the if. [Slide 2] This one is really handy! >> 3. Take advantage of white space [Slide 3] So much yes. When looking at other people's code, this is the first thing I notice. Also, their brackets. White space makes your code easier to read and looks less cluttered! >> 4. Don’t have useless comments!! [Slide 4] Comments should enhance understanding, not state the obvious >> 5. Don’t leave code that has been commented out in the source file, delete it! I'm guilty of this...especially when debugging. >> 6. Don’t have overly long lines. [Slide 5] Try to keep your lines at a good width so that it is readable. If you're using a good IDE, usually when you hit enter, it will tab the code for you. >> 7. Don’t have too many lines within a function/method. When you have a function be 50 lines or more or it requires you to scroll. it makes it much harder to understand what is going on. Try to break up the code if possible I think these are all great tips. I personally would add keeping function and variable names neat and relevant to what it is being used for. I notice a lot of beginners come up with any random variable or function name and then they forget what they used it for. Any programmers out there have more tips to share? [Source: http://equivalence.co.uk/archives/101]
csgeek clipped in 1 collections
0 comments