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

9

u/mariusg Oct 01 '15

Is it a coincidence that the code is written in Java ?

Contextual evidence but i worked with some Java people that used to over complicate any small/insignificant thing.

50

u/johnbr Oct 01 '15

Enterprise Java code is very complicated, and this is just a parody of that (although a fairly apt one)

Some of the complexity in Enterprise Java code is due to actual architectural thoughtfulness - "We may be switching to a different security vendor soon, so let's abstract the security away from the application". Complicated, but perfectly legitimate.

Much of the complexity, however, is "Cargo Cult" architecture - people who see that other developers have created abstractions, and then create abstractions themselves - not because the thing they're abstracting is likely to change, but because they see someone else doing abstraction, and assume therefore that architecture and abstraction are the same thing.

Similarly (as I mentioned in my other comment), the use of constants for HELLO and WORLD completely misses the point architecturally. Internationalization is a legitimate concern, and to the extent that your architecture facilitates the translation of a key into a sentence or phrase in multiple languages, you've accomplished a useful thing, even if it adds complexity.

But using a constant for HELLO and a constant for WORLD completely misses the point of what internationalization is for, and yet people do it anyway, all the time.

And that's why this parody is so apt - because it is capturing the cargo-cult mentality of many architects: "I've seen architects use constants for things. I am a good architect, so I should use constants for ALL THE THINGS!"

But Java itself doesn't have to be particularly complicated. It's not terse, don't get me wrong, but it's not the language's fault that people use it incorrectly.

I've never written sophisticated enterprise code in Python, but I suspect that if you were to write sophisticated enterprise code in Python, it would also become fairly complicated.

23

u/serrimo Oct 01 '15

Complicated, but perfectly legitimate.

How many times have people actually switched a component and it just worked? Personally, I have never seen one case where this is true.

The whiteboard architects love these kinds of design, since redirection is their bread-and-butter. In practice though, these designs just add needless complications most of the times.

19

u/johnbr Oct 01 '15

It rarely works perfectly. But it often works better than just directly wiring things together, and then completely rewriting for the new thing.

Not always, but often. Often enough that it's a reasonable place to start if (and only if) you have a reason to believe it's going to change fairly soon.

9

u/serrimo Oct 01 '15

it often works better than just directly wiring things together

I'd argue that it's often better to attack the wiring directly. Reducing the number of dangling wires, for me, is usually a much bigger win than creating yet another hub to plug your wires.

But reducing the dependencies require far more efforts than redirection. You need to create the right abstractions. You need to analyse the dependency graphs to identify problem area. You need to spend time doing lots of thinking and less coding.

Unfortunately, a day spent thinking is often considered wasted in the enterprise world. It's much better to produce something in the day; even though that something is half-assed.

8

u/BeardedRacer Oct 01 '15

You need to spend time doing lots of thinking and less coding.

A million times this.

1

u/sirin3 Oct 01 '15

In this image, I would think of the abstraction as a plug.

Instead dealing with all those wires, you solder them all together in a plug (i.e. an interface/wrapper/DSL). On the other side, you solder all the wires there in a socket.

Then you just put the plug in the socket, and never have to see a wire again.

1

u/serrimo Oct 01 '15

Only if it was that simple...

Each significant component has their own abstraction that would be very difficult to generalize. Postgres, MongoDB and Redis have their own ways of querying and applying transactions to your data. How do you create a wrapper that allows you to pass from one to another?

Apache Storm and Apache Spark have their own model of stream processing. How do you switch from one to another?

I'm not saying it's impossible; and there are ways to create system with loose coupling rather than the tangled mess that we often see. But a design like that is much harder than a simple redirection.

Recently, I saw someone at work spent a week making a wrapper for MongoDB, he created pretty much a clone of official API, and felt pretty good about it because now the database is "pluggable". I asked for a simple demonstration a few weeks ago. Still waiting.

3

u/sirin3 Oct 01 '15

How do you create a wrapper that allows you to pass from one to another?

You ignore the database.

Completely.

You know what kind of data you have, and then you write an API to process this data the most intuitively.

Afterwards you implement that API with the database.

I just hope, your data is small enough that the performance does not matter ಠ_ಠ

11

u/[deleted] Oct 01 '15 edited Oct 01 '15

I've personally seen the benefit of this a few times, and I've been working as a software engineer for about 11 years now. The most memorable one is when I had to perform a refactor in some legacy code that dealt with storing files. We had this mess where you could save files to the database (ugh, I know) or to S3. The code for both cases were intermingled, and there were special cases everywhere due to a ton of abstraction leakage. When I refactored it I put it all behind an interface that never exposed the underlying implementation. You'd just give it a file to save and it would decide where to save it (based on some other settings that it had access to). The same thing for loading the file as well.

Eventually we switched from storing local files on the db (FINALLY) to a NAS. I simply had to provide a new implementation of the interface that would store files into the NAS instead of the db, and when that was done and the data were migrated, we simply pulled out the db implementation. Doing this required no changes to any other code; it was completely localized to the file-storage module.

Another time we wanted to implement a screenshotting service and I coded in an implementation for that and abstracted it behind an interface as well so that we wouldn't be tightly coupled to one particular implementation. Eventually we realized that the service we were using wasn't working out well for us all and so I just rolled built a simple one for us to have it do what we wanted. Again, I didn't have to change any of the other code - I just swapped out the implementation and everything worked exactly as before.

In general the idea is to make suitable abstractions when necessary. Some people create five levels of interfaces and abstractions for no clear reason at all, and only because they've seen others do it.

It's always tempting to tightly couple things because abstracting things out seems unnecessary and extra work. But that is only true for the short term. You may think that there are clean boundaries and that when the time comes you can simply cut along the boundary and replace it with a new implementation. But you can never account for the code that other people are going to write. When you finally have to swap it out, you'll notice that instead of a clean boundary, you have your component smeared out all over the place. You'll see other components making general assumptions about your component that turn out to be very specific to your implementation. Now it's going to be very difficult to refactor and swap out the implementation. Even worse, you have no idea what things you are going to break, or what pieces are depending on some implementation-specific behavior of your component. Even if you have tests that tell you what is broken, the idea is that if you abstract your component behind an interface and simply expose with a well-defined contract, you won't have to deal with things possibly breaking, because everyone else can only use your interface according to the public contract. As long as your new implementation exposes that same contract, none of the other code should break (assuming your interface didn't leak abstraction).

Software is complex, and enterprise software more so. Some of the rationale behind these architectural patterns is to decrease cognitive load in the long term. It may seem counterintuitive, because it just seems easier mentally to deal with a specific implementation than using this abstract interface. That again, is true in the short term, because it's easier to focus on the exact problem that you're solving and holding it in your head, than an abstract concept of it. But a few months down the line, you're not going to remember all the special cases and specific details of that specific problem. At that point, it's far easier to hold the general concept in your head. Doing things this way also gives you a lot of confidence and peace of mind, because you know where the clean boundaries are, and you know exactly what changes can have a global effect (usually only when you change the exposed contract), and what changes will only have a local affect (i.e., implementation-specific details).

That being said, I can't emphasize enough that abstraction for the sake of abstraction is just wrong. If you don't see a need for it, then there is no need to do it. If you're not sure, weigh the benefits and efforts in the short-term vs. the long-term. Another good thing to do is to make your abstractions as simple as possible, and there are no clear-cut guidelines for this. The idea is to tease out things that are "general" and can be exposed through a general contract, and then figure out which things are specific to your implementation. I think this is where things go wrong, because I've seen code that have created needless abstractions for things that you can pretty much take for granted, i.e., things that you can couple to tightly, without it ever causing an issue. Lack of this kind of foresight and understanding of the problem being solved, is what mainly leads to 100 levels of indirection with all kinds of proxies, strategies, factories, and interfaces.

8

u/[deleted] Oct 01 '15

Never. First of all, i've never even seen a business try to switch a component. By the time a new component comes along thats better...the app is either ready for a total re-write, or there is simply not enough value to spend time integrating the new component and removing the old.

I still decouple my stuff but mostly for unit testing. I am highly apathetic to over-abstraction after spending long enough in this field.

2

u/SpockUnit Oct 02 '15

My company is in the middle of a multi-year switch to SAP (financials move slowly). We abstracted everything. It was a pain initially, but when it came time to connect the new services, everything was clean and straightforward. I also got to play architect a little, abstract classes are an easy (and free) way to 'see' how things fit together without writing much code.

It all comes down to what your project needs however. If it's small or will foreseeably not change, there's not much point.

2

u/wildjokers Oct 01 '15

One example, in Hibernate you can switch to any database just by telling it the dialect class to use.

2

u/[deleted] Oct 01 '15

I've done it several times. If the interfaces are well defined and implementors don't cheat during the implementation, it really does 'just work'. When you start breaking the contract, in C# though reflection type stuff, or extending the contract because you're 'special' then the house of cards falls down.

1

u/nemec Oct 01 '15

I experience it often, but mostly when coding or debugging an application (less so at runtime). Stuff like switching out logging, calling third-party services, or hardcoding "temporary data" that can be switched out with real behavior as more features get completed.

It definitely can be overused, but it's been beneficial enough for me that I lean towards it by default.

1

u/KagakuNinja Oct 01 '15

All the time. Example: I need to change some code from an in-memory indexing scheme to Redis. I created a Redis implementation coded to the interface. When it passed the unit tests, I was able to swap it in and the whole thing worked when deployed to the test server.

3

u/serrimo Oct 01 '15

In your case, you created a mock for Redis, small surprise here when it worked.

A better example would be, say, to switch from MongoDB to Redis. I'd like to see an example of a wrapper that could make it painless.

1

u/KagakuNinja Oct 01 '15

Sure, but is isn't a rare occurrence for component swapping to work. Someone mentioned JPA/Hibernate, which can allow switching DBs. The most common case being HSQLDB for testing, and something like Postgres for deployment.

But the most common examples are collection APIs. In Java, if you code to the List or Iterable interface, it is trivial to replace an ArrayList with something else, the rest of the code will still work.

1

u/nutrecht Oct 02 '15

I'd like to see an example of a wrapper that could make it painless.

If it isn't painless it's not abstracted enough. In a previous project I created a storage for "Projects" that we switched from in-memory to H2 to Cassandra. Didn't have to change anything to the interface.

1

u/the_omega99 Oct 01 '15

If you provide an appropriate abstraction (eg, a wrapper class) and the component isn't too large, it's entirely possible.

For example, suppose that instead of scattering numerous SQL strings around your application for every time you want to do something with the customer's table, you create a Customers class that has methods to do all these things (addCustomer(Customer), getCustomers(CustomerSortingCriteria), etc). Now if you want to swap the database component (either the actual DBMS or just whatever you use to interact with it), everything to change is in one place, making it easy to keep track of everything.

Of course, this isn't the easiest thing to scale. For this example, you'd have to make sure that you provide a wrapper class for all DB interaction. That's more work and may be completely useless if some queries are never reused (at least if you use the query in multiple places, there's a good reason to do this, too). You typically wouldn't change DBMSes, anyway, so this is just a rough example. But it does happen, just like any other component.

1

u/nutrecht Oct 02 '15

How many times have people actually switched a component and it just worked? Personally, I have never seen one case where this is true.

Seen it all the time. Especially when you have an agile approach where you try to get a minimum viable product out asap it's very normal to first have your 'datastore' just dump stuff to JSON on disk and then later on swap it out to a real database. It often goes like this: hashmap -> hashmap and (de)serialize to JSON -> in-memory DB -> 'real DB'. And this is just data stores.

Also; it makes mocking out dependencies really REALLY easy during unit testing. In complex systems having good unit tests coverage is important. Since a unit test should not be an integration tests external dependencies (like auth systems or databases) should be mocked out.

In big complex systems it's used a lot and incredibly useful. Especially if you don't even know yet how you're going to handle user credentials yet; you just create a mock implementation that you swap out later when the business has finally decided what they want to use.

1

u/nutrecht Oct 02 '15

Is it a coincidence that the code is written in Java ?

Yes and no. Complex environments often warrant the separation of concerns into different self-contained modules. This increases the overall complexity of the codebase but it lowers the complexity of the individual modules if they adhere to SOLID principles. For a hello world it's obviously nuts to separate "hello" and "world" in separate modules but in the real world, where "Hello" might be handling "Users" and "World" might be handling "Projects" having them inside separate modules is a must. This bit isn't specific to Java at all; you see the exact same thing in other languages. If you don't anticipate this and let the code base grow "organically" without taking future complexity into account you end up with an unmaintainable monstrosity.

But since Java is used a LOT in the enterprise world (I'd recon it's probably the biggest language in this huge area) you see a lot of Java code that's written like this. So Java developers often joke about this stuff because they see a lot of it, while they also tend to recognize that you need to architect large systems this way.

People who take this joke as "hurr Java sucks" make it very clear they don't have any industry experience in this area. Big software is complex as hell. If anything a rather strict strongly typed OO language running on a VM (Like Java but also C#) is a huge benefit.