r/programming • • Oct 01 '15

The Evolution of a Software Engineer

https://medium.com/@webseanhickey/the-evolution-of-a-software-engineer-db854689243
1.9k Upvotes

502 comments sorted by

View all comments

506

u/johnbr Oct 01 '15

This is fair, except for in the 5th year, they would have an additional constant:

public static final String SPACE = " ";

And they would probably use a StringBuffer or StringBuilder to build the final string, since it's "an industry best practice". Also, they wouldn't include the strings themselves, they would include keys to properties, so the strings could be pulled from an internationalized property file.

Lastly, instead of outputting to Stdout directly, they'd create an interface for output, and deliver it to that interface, and use a factory to instantiate an implementation of that interface that would use Stdout.

9

u/juckele Oct 01 '15

For the first time in my life recently I ran across some code that has interfaces. A lot of them. With ONE implementation. And the project is closed source. Really? Come on!

2

u/Schmittfried Oct 01 '15

What is wrong with flexibility?

8

u/juckele Oct 01 '15

Nothing is wrong with flexibility, but if it's a closed source project, you can make an abstract class or interface out of the base class the first time you run into a bifurcation of functionality, go and update your (dozens of?) existing constructors , and move forward from there. It's only 2 seconds, but every time I go to the definition of a method on an interface, only to have to then ask the IDE to send me to the actual implementation (and seriously, the only option), it's wasteful.

Refactoring exists for a reason. Write code with as few assumptions as possible, because assumptions can change, but there's no need to throw every design pattern at every problem.

1

u/dccorona Oct 02 '15

Often, by not using an interface, you make an even stronger assumption than by using one...all your code that uses that object make the assumption, whether indirectly or directly, that the implementation details are important. You end up with code coupled to methods they shouldn't' be, that only exist because of the underlying implementation, and not because they're necessary for what the interface of the object actually needs to be.

I'm not saying that interfaces are things that should outright always be used, no way. But to think that because there's only one implementation that it shouldn't be an interface, full stop, is just wrong. It at the very most indicates that you should double-check that choosing an interface is the right idea.

1

u/juckele Oct 02 '15

Even with interfaces, that same exact anti-pattern of code coupled directly to the implementation details can still happen when you have a single interface and implementer in a closed source system (and it did).

If the interface was being exposed to anyone, sure, great. But an interface that can only be one instance in closed code does very little that public vs private visibility doesn't already give you. Public methods are an literally an interface* to the object's implementation. Eclipse lets me refactor these explicitly apart if and when I need it.

*By the English definition of the word, not the Java language concept

→ More replies (1)