Saving fish by writing code! Applications developer in fisheries, specializing in webapps and moving 'enterprise-y' legacy systems to modern agile systems - Email or tweet me if you want to talk!
Maybe I've spent too much time in the Java world with Spring and Hibernate, but I don't mind generated code. The main thing is to always be able to regenerate it, imho. Never modify it, and don't ask it to do anything it isn't designed for
I don't trust generated code either in most cases. It's too easy for scaffolds to fall out of date or require a lot of work to make the generated code do the additional stuff you need.
However, Java's annotation processing API is really nice for compile time code generation, so you know it is always up to date and works exactly as it should. Code generation that gets destroyed and recreated continually can be quite invaluable.
In my opinion, code generation can work but it shouldn't be static generation, only done once. It should be part of your build process.
Is this dynamic code generation responsible for slower server start ups in spring boot? I'm learning spring boot right now and love it so far except for the slower server start ups.
I'm not too familiar with Spring Boot, but code-gen would make the compilation step take longer, not the server startup. Java code generation libraries (such as Dagger and Butterknife which are common on Android) actually dramatically increase application startup times, because all the hard work has been done at compile-time.
Taking Dagger as an example (dependency injection), the generated code doesn't require Reflection as a runtime-library would. It looks for @Inject annotations in your code, finds the @Modules which provide those dependencies, and writes new Java source files to create the object for you. Super fast, no reflection required. Spring Boot does runtime injection, and so uses Reflection to find the @Inject/@Autowired annotations, and then uses Reflection to call the constructor or set the fields as necessary, which is known to be slow. This is in addition to the many other things Spring is doing on server startup (classloading, resolving routes, connecting to databases, etc.).
A spring boot app with 1000s of beans and component scanning still starts in 1-2 seconds. Most of the startup time is consumed when using Hibernate and flyway eg.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I prefer to write code. I don't trust generated code.
Maybe I've spent too much time in the Java world with Spring and Hibernate, but I don't mind generated code. The main thing is to always be able to regenerate it, imho. Never modify it, and don't ask it to do anything it isn't designed for
I don't trust generated code either in most cases. It's too easy for scaffolds to fall out of date or require a lot of work to make the generated code do the additional stuff you need.
However, Java's annotation processing API is really nice for compile time code generation, so you know it is always up to date and works exactly as it should. Code generation that gets destroyed and recreated continually can be quite invaluable.
In my opinion, code generation can work but it shouldn't be static generation, only done once. It should be part of your build process.
Is this dynamic code generation responsible for slower server start ups in spring boot? I'm learning spring boot right now and love it so far except for the slower server start ups.
Probably. Everything that has to be calculated for each new visitor inevitably leads to additional latency.
I'm not too familiar with Spring Boot, but code-gen would make the compilation step take longer, not the server startup. Java code generation libraries (such as Dagger and Butterknife which are common on Android) actually dramatically increase application startup times, because all the hard work has been done at compile-time.
Taking Dagger as an example (dependency injection), the generated code doesn't require Reflection as a runtime-library would. It looks for
@Inject
annotations in your code, finds the@Module
s which provide those dependencies, and writes new Java source files to create the object for you. Super fast, no reflection required. Spring Boot does runtime injection, and so uses Reflection to find the@Inject/@Autowired
annotations, and then uses Reflection to call the constructor or set the fields as necessary, which is known to be slow. This is in addition to the many other things Spring is doing on server startup (classloading, resolving routes, connecting to databases, etc.).A spring boot app with 1000s of beans and component scanning still starts in 1-2 seconds. Most of the startup time is consumed when using Hibernate and flyway eg.