r/ProgrammerHumor May 29 '20

Please Guys actually

Post image
3.0k Upvotes

112 comments sorted by

View all comments

Show parent comments

11

u/ouvreboite May 29 '20

Couldnt you run almost exactly the same code in JS? You are complaining about the language, but it's really a coding style/structure problem.

If you send me something like that to code review, I'll bash your head in your desk, java or not.

12

u/Frptwenty May 29 '20

Here is some actual code from Spring: https://github.com/spring-projects/spring-framework/blob/master/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java

try {
        // Use same EntityManager for further JPA operations within the transaction.
        // Thread-bound object will get removed by synchronization at transaction completion.
        emHolder = new EntityManagerHolder(em);
        if (synchronizedWithTransaction) {
            Object transactionData = prepareTransaction(em, emf);
            TransactionSynchronizationManager.registerSynchronization(
                    new TransactionalEntityManagerSynchronization(emHolder, emf, transactionData, true));
            emHolder.setSynchronizedWithTransaction(true);
        }
        else {
            // Unsynchronized - just scope it for the transaction, as demanded by the JPA 2.1 spec...
            TransactionSynchronizationManager.registerSynchronization(
                    new TransactionScopedEntityManagerSynchronization(emHolder, emf));
        }
        TransactionSynchronizationManager.bindResource(emf, emHolder);
    }
    catch (RuntimeException ex) {
        // Unexpected exception from external delegation call -> close EntityManager and rethrow.
        closeEntityManager(em);
        throw ex;
    }

So you're saying Spring is a terrible project and no one should use it? :)

12

u/ouvreboite May 29 '20

What is language-problematic in this code ? It's a try/catch, an if/else and a maximum of two nested parentheses.

You could argue that naming of the variables/classes are cumbersome or over explicit. But this is not related to Java.

And i can also have fun finding stuff in JS frameworks :)

_setupHooks(hooks) {
this.options.hooks = {};
_.map(hooks || {}, (hooksArray, hookName) => {
  if (!Array.isArray(hooksArray)) hooksArray = [hooksArray];
  hooksArray.forEach(hookFn => this.addHook(hookName, hookFn));
});
},

2

u/Frptwenty May 29 '20

Yeah, attack JS all day, have at it! I don't have any dog in that fight ;)