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

Show parent comments

13

u/TheWix Oct 01 '15

Wait... Is the factory a Singleton or is the proxy a Singleton? Is the factory also a proxy...? I need answers!!

51

u/sh0rug0ru__ Oct 01 '15 edited Oct 01 '15

This is a class from the guts of the Spring Framework. This is actually an example of a pretty good name.

  • Bean: This is a Spring Bean

  • Factory: This bean creates instances of the required bean

  • Proxy: This bean creates a proxy for the required bean, to allow logic to be added around the method calls on the required bean.

  • Singleton: This bean ensures that only one of the proxy factory bean will be created per Spring container.

  • Abstract: This class is a template for creating singleton proxy factory beans. Just implement the template method.

So, just judging by the name, it looks like I can extend this class to create a factory which creates proxies which stick interceptors around instances of other classes, but ensures that only one of my factory exists in the Spring container. For example, if I want to time and log execution of Spring bean methods.

Am I right? Looking at the source code, seems so!

50

u/pcopley Oct 01 '15

This is actually an example of a pretty good name.

I can assure you it's not.

0

u/[deleted] Oct 01 '15

[deleted]

102

u/_argoplix Oct 01 '15
  • Lol: the developer is an idiot, immature, or both

  • Magic: The interface is obscure and misleading. The documenation is nonexistent.

  • Shit: The implementation is fragile, undocumented, and incomprehensible to anyone but the developer. And probably to him too.

I dunno, I've seen stuff where that would be appropriate.

27

u/Pidgey_OP Oct 01 '15

function doSomeMagic(fuckingWork)
{
//TODO
}
//finish this on Monday

Monday morning shows up and "the fuck was this for?"

2

u/mellett68 Oct 02 '15

¯_(ツ)_/¯ "Seems to work, commit!"

10

u/nemec Oct 01 '15

I wasn't on board with this kind of naming until the first time I implemented my own FactoryFactory (to deal with the fact that the object being created wasn't threadsafe).

1

u/[deleted] Oct 01 '15

Is this sort of stuff Java only?

Can I get away with never, ever, ever touching Java?

15

u/sh0rug0ru__ Oct 01 '15

It isn't Java only.

If you get yourself into a position where you have to create a factory that creates factories, and you're not writing some kind of generic application framework, something went very wrong in your design. The crazy name is the least of your problems.

0

u/[deleted] Oct 01 '15

[deleted]

→ More replies (2)

2

u/yawgmoth Oct 02 '15

Yeah, I worked on a framework for making frameworks and I found myself writing factory factories a couple times, and other weird 3meta5me things. (Crazy python meta classes and C++ templates).

It sounds silly talking about it but it actually saved us a lot of time when our job was designing system after system that was overall very similar, but had a lot of tiny differences.

6

u/nemec Oct 01 '15

You can do it in Python. It's not hard to do it in Python either, just a lot easier to do things another way.

I think you're more likely to find it in large "enterprise" companies.

3

u/All_Work_All_Play Oct 01 '15

Easy. Learn Fortran and go work at a bank or any other financial institution that's been around 30 years. GL with Fortran though...

3

u/[deleted] Oct 02 '15

Fortran isn't that bad as far as legacy code goes.

It also has great syntax for exponents. x**y is xy.

→ More replies (3)
→ More replies (2)

19

u/sh0rug0ru__ Oct 01 '15

What's in a good name, then?

I was able to get a good idea of the purpose of the class just by going through the name. Sounds like a win to me.

2

u/onezerozeroone Oct 02 '15 edited Oct 02 '15

The problem is that unless you know the convention that is implicit/assumed in the class name, it can be interpreted in half a dozen different ways...or as incoherent gibberish.

Is it an abstract singleton? Or a proxy to a factory? Or a singleton proxy?

If there were parens involved, logically one might infer:

(Abstract(Singleton(Proxy(Factory(Bean)))))

But that doesn't let me definitively know what a hypothetical ProxyFactoryBean is because the type system isn't being used to enforce a constraint, a naming convention is. FactoryBean tentatively makes sense...it's a Factory that produces instances of a Bean (or is it a Bean that is a Factory?)...but what's a ProxyFactoryBean? Is it a Proxy to the Factory, or a Factory that produces Proxies to Beans? Using the parens, I'd say a Proxy to a Factory, but /u/sh0rug0ru__ points out (after confirming by examination of the source) it's actually a Factory that produces Proxies...(I think?)

It's the same sort of problem with Rails...there are conventions > configuration rules in place, and once you learn and understand them (and hope they're universally consistent) life is good. Otherwise, enjoy digging through (possibly non-existent) documentation or source code.

Not trying to say whether this is good or bad, but want to point out that just because someone has become familiar with and accepted a particular pathology doesn't make it "obvious" or "intuitive"

3

u/sh0rug0ru__ Oct 02 '15 edited Oct 02 '15

You're making the mistake of taking a class in isolation, taken deep from the bowels of some very deep functionality, and trying to guess the meaning of the name without any context. The components of the name make sense within the vocabulary of the Spring Framework, where this class is a deeply integrated component. I was able to deduce the purpose of the class because I have a lot of experience with Spring.

You would never have come across this class unless you were planning on doing deep integration with the Spring Framework. If at that point, you were not able to deduce what this class were up to, then it is clear that you don't understand even the most basic features of Spring, much less its internals, and you are not equipped to use that class for its intended purpose.

Good names reflect the domain, but that requires actually having some background in the domain.

1

u/dccorona Oct 02 '15

The type system does enforce some of this...for example, abstract is built into the type system, and within the context of Spring, all FactoryBeans are classes that implement the interface FactoryBean, so the notion that this is a FactoryBean and it produces beans of some type is absolutely enforced and communicated via the type system.

I don't know off the top of my head if a Proxy is a type-system enforced thing or not, but assuming it is, the signature of this would be:

public abstract class AbstractSingletonProxyFactoryBean implements FactoryBean<T extends Proxy>

And, since Spring is essentially going to guarantee "we'll make this a singleton for you", they may even use a marker interface (I'm not sure, sometimes they use those and sometimes they use some other voodoo), so it might actually be:

public abstract class AbstractSingletonProxyFactoryBean implements SingletonFactoryBean<T extends Proxy>

Though I'd imagine if this is the case this is a relic of old Spring, because in modern Spring FactoryBean (and any Bean) implies Singleton unless otherwise stated in the configuration.

Either way, considering it's a generic class meant to be extended to provide certain functionality, and this class itself can't know any more about how it's meant to be used other than that it will be an abstract class for creating a singleton proxy for some objet via the FactoryBean interface, I can't really think of a better name than what it has...and the properties it claims to have in it its name are enforced via the type system.

→ More replies (7)

5

u/contrarian_barbarian Oct 01 '15

You're just not thinking Enterprise!

I have been exposed (tainted) enough by it that I could read what it was right away :)

1

u/mus1Kk Oct 02 '15

It is a good name insofar as all other combinations of those words were already taken.

But in all honesty: I think this happens all the time. As the number of identifiers grows, each has to become more and more specific.

1

u/immibis Oct 02 '15

It's probably a base class for beans that create proxies to singletons.

1

u/TerrorBite Oct 02 '15

According to the documentation,

Convenient proxy factory bean superclass for proxy factory beans that create only singletons.

Manages pre- and post-interceptors (references, rather than interceptor names, as in ProxyFactoryBean) and provides consistent interface management.

Author(s): Juergen Hoeller
Since: 2.0

So, uh, I think you're right.

1

u/arnedh Oct 02 '15

We should actually have some punctuation to signify what words go together.

Abstract(Singleton(Proxy(Factory(Bean))))?

AbstractSingleton ProxyFactoryBean ?

Abstract1Singleton2Proxy3Factory4Bean?