5 ms·
Java annotations are terrible to reason about. Once you get a hang of them, then it's somewhat easier. That being said, Spring takes these annotations to the ne
by deepGem 5y ago
Java annotations are terrible to reason about. Once you get a hang of them, then it's somewhat easier. That being said, Spring takes these annotations to the next level of complexity. Spring boot just makes this more difficult to reason about with added annotations. Anyone who states that Spring annotations are just 'abstractions' and that's how software is built is welcome for a healthy argument.
There are much better web development alternatives such as Javalin.
Compare this
import io.javalin.Javalin;
public class HelloWorld {
public static void main(String[] args) {
Javalin app = Javalin.create().start(7070);
app.get("/", ctx -> ctx.result("Hello World"));
}
}
to
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return String.format("Hello %s!", name);
}
}
However, Spring cloud, has all the necessary distributed features built in. While I haven't used these, not having to write code for these is a god send.
Load balancer - Check
Service mesh - Check
Circuit breaker - Check
Heck, they have even included all Netflix OSS components. So this alone is worth the pain of living with annotations.
https://spring.io/projects/spring-cloud https://spring.io/projects/spring-cloud
- kaba0 5y agoI doubt that a hello world could meaningfully compare the two. What about a complex web app with many more http endpoints? Some of them having parameters that should be queried from, validated and converted from the URL? It is still the same amount of lines in Spring. Declerative does win in my opinion in this case.
- deepGem 5y agoThe pain point raised was about annotations. So just providing an example framework that doesn't use annotations or any other code magic.
- tubs 5y agoYour javalin example returns a static string and doesn't read parameters so how is it a meaningful comparison?