background preloader

Code quality

Facebook Twitter

What Makes Code Readable: Not What You Think. You often hear about how important it is to write “readable code.”

What Makes Code Readable: Not What You Think

Developers have pretty strong opinions about what makes code more readable. The more senior the developer, the stronger the opinion. But, have you ever stopped to think about what really makes code readable? The standard answer You would probably agree that the following things, regardless of programming language, contribute to the readability of code: Good variable, method and class names Variables, classes and methods that have a single purpose Consistent indentation and formatting style Reduction of the nesting level in code There are many more standard answers and pretty widely held beliefs about what makes code readable, and I am not disagreeing with any of these. (By the way, an excellent resource for this kind of information about “good code” is Robert Martin’s excellent book, Clean Code, or Steve McConnell’s book that all developers should read, Code Complete.

The vocabulary and experience of the reader 01..model small. Reading Code. We Recommend These Resources.

Reading Code

Defensive Programming vs. Batshit Crazy Paranoid Programming. We Recommend These Resources Hey, let’s be careful out there.

Defensive Programming vs. Batshit Crazy Paranoid Programming

--Sergeant Esterhaus, daily briefing to the force of Hill Street Blues When developers run into an unexpected bug and can’t fix it, they’ll “add some defensive code” to make the code safer and to make it easier to find the problem. Sometimes just doing this will make the problem go away. They’ll tighten up data validation – making sure to check input and output fields and return values. Expect the Unexpected The whole point of defensive programming is guarding against errors you don’t expect. The few basic rules of defensive programming are explained in a short chapter in Steve McConnell’s classic book on programming, Code Complete:Protect your code from invalid data coming from “outside”, wherever you decide “outside” is.

Autogenerated Comments Rant. We Recommend These Resources Let me clear up potential confusion right at the start.

Autogenerated Comments Rant

My rant is not auto-generated. Auto-generation of comments is its object. What I have to say about this abomination can be summed up in six words: why, why, why, why, and why? Oh, and a seventh: I am talking about those handy little JavaDoc comments that well-known IDEs thoughtfully generate for you along with JavaBean-style property accessors, new classes, and indeed anytime a "wizard" (wash my mouth out with soap and water) gets its hands on your project. Package bet3.gov.it.abc; // import statements /** La constante serialVersionUID. */ private static final long serialVersionUID = -6370799192505622281L; /** Le/la email. */ private String email; /** Le/la fax. */ private String fax; /** Le/la id. */ private long id; /** * Permet d'obtenir la valeur de "email". * * @return la valeur de "email" */ public String getEmail() { return email; } The purpose of a comment is to help understand the code.

CheckThread.org. Quality Assurance With Sonar. It's incredible how unknown a tool like Sonar is yet.

Quality Assurance With Sonar

I guess Gradle suffers the same destiny. After all, they're both similar in their intent, improve the quality of your software. It seems lots of people know about unit testing (not so many about code coverage), less know about tools like Checkstyle or FindBugs (static analysis of code) and just a minority are aware of other esoteric metrics like cyclomatic complexity.

And even the few that use all of them do not extract all the value that a dashboard provides. That's what Sonar handles, it will take your project and stress it showing the results in a visually appealing site. But seeing is believing so I'll try to convince you showing the whole process and what kind of enhancements you'll be getting. The first task is downloading the project and installing it. Next step is to build our project and include the Sonar phase. Mvn clean compile sonar:sonar Pretty easy, wasn't it? Here's the bread and butter! Sonar. Checkstyle - Checkstyle 5.0. FindBugs%u2122 - Find Bugs in Java Programs. New Patent Around Race Condition Fixing. Today, Replay Solutions announced its success in obtaining a US patent around their software's ability to reproduce and fix race conditions.

New Patent Around Race Condition Fixing

Race conditions are a big problem for developers working on multi-threaded applications. Voke Inc. analyst firm founder Theresa Lanowitz says that the software gaming industry and embedded systems vendors have addressed race conditions, but now enterprise developers have a growing need to address them as well. Race conditions are a very common defect type in multi-threaded Java apps, and one of the toughest classes of software problems to reproduce and fix. With the growth in demand for virtualization and cloud computing software, as well as the rise of multi-core processors, multi-threaded applications are critical to the future of computing.

In the worst cases, a race condition bug can wreak havoc on a system like it did in 2003, when this kind of bug caused the largest power outage in North America.