![]() Queries can be placed in /src/main/resources and loaded as templates (and cached) by the QueryUtils. String query = QueryUtils.loadQuery("age-query.sql",Īrrays.asList("param1Name", "param2Name"), String query = QueryUtils.loadQuery("age-query.sql", timestamp, diff, other) This is certainly readable when you browse the code: The example that Vlad gave illustrates that – do you want to have a 20-line SQL query in your Java code? I’d say no – you’d better extract that to a separate file, and using some form of templating, populate the right values. I know it sounds counter-intuitive, but bear with me. The second, and bigger problem, is code readability. In this context – for 2-line strings do you use a text block or not? Should you do multi-line formatting for simple strings or not? Should you configure checkstyle rules to reject one or the other option and in what circumstances? The less important one is consistency – if you can do one thing in multiple, equally valid ways, that introduces inconsistency in the code and pointless arguments of “the right way to do things”. ![]() ![]() I’ve used it in Scala several years ago, and other languages also have it, so it seems like a no-brainer to introduce it in Java.īut, syntactic sugar (please don’t argue whether that’s precisely syntactic sugar or not) can be problematic and lead to “syntactic diabetes”. This write-up is partly inspired by a recent post by Vlad Mihalcea on LinkedIn about the recently introduced text blocks in Java.
0 Comments
Leave a Reply. |