And yet nothing binds us together as a profession. We share no ethics. We share no discipline. We share no standards. We are viewed, by our employers, as laborers. We are tools for others to command and use. We have no profession.I like uncle Bob very much. He's the only one I know that has been warning and continues to warn us about the way we treat our own industry.
Don'ts and don'ts
I'm a java developer. Personally, I don't have the feeling that we share no standards. My world is full of them. Rules, principles, standards and things a developer cannot, should not do. They're not explicit, but implicit. Still, those rules exist. Here's a list of some of them:- fat controllers are bad
- mutable data is evil
- premature optimization is the root of all evil
- goto considered harmful
- static is bad
- duplicate code is evil
- if statements are evil
- null references are the billion dollar mistake
- getters and setters are evil
- extends is evil
- dependency injection is evil
- frameworks are evil
- ...and the list goes on...
The heretic
Here's another one. It must have been about the first rule I learned when starting programming in java. A little while ago I was pairing with a colleague and created a class that was used as a data container, a dto. I created the class and made all fields public. It looked something like this:public class Employee {
public final EmployeeId id;
public final String firstName;
public final String lastName;
public final Email email;
public Employee(EmployeeId id, String firstName, String lastName, Email email){
....There you have it. I broke one of the oldest rules in java development: Never create public fields! Always keep your fields private and create public getters.
}
}
My colleague looked at me with a strange look. He didn't have the energy to start a discussion with me and didn't say anything, but I could tell he was thinking I was doing a very, very bad thing.
Nevertheless, there is no reason why I would add all those extra intellij-generated lines of useless getter code. The class is not part of any api nor will it ever be. There's no information hiding necessary. It's just a data structure that contains certain data in a strongly typed way. By leaving out the getters, the class remains concise, clean and maintainable.
But, public fields are evil! Evil, I say!
The point is... people forgot the reason why that rule exists. They only remember the rule. The fact that it's evil. Truth is (=my opinion), in a lot of our code, there's no reason to hide information. Especially when it's immutable (which is another one of my rules).
Saying something is evil or considered harmful is a great way to create a meme, but it's detrimental in the long term when you forget the reason why.
Greetings,
Jan
No comments:
Post a Comment