Live data from Hacker News

JEP 430: String Templates (Preview) Proposed to Target Java 21

openjdk.org

231–240 of 246 posts

Re: JEP 430: String Templates (Preview) Proposed to Target Java 21

#231
post #65

Earlier quoted context omitted.

Do you have a link for the 1997 document? The history is surprisingly difficult to explore for being pretty recent.

Here's a public 1997 document where much of that is said: https://www.win.tue.nl/~evink/education/avp/pdf/feel-of-java...

Thanks!

Re: JEP 430: String Templates (Preview) Proposed to Target Java 21

#232
post #75

Earlier quoted context omitted.

Pity that the Streams functions don't support checked exceptions.

It's the only sane way. Checked exceptions were a fundamental mistake which basically makes it impossible to actually use (non-RuntimeException derived) exceptions reliably for their intended purpose. As soon as you introduce any higher-order programming (e.g. functions that take other functions as parameters) you start to have to wrap e.g. IOException... but that means that calling code can no longer catch that wrap…

It's not impossible, it would just require type inferencing/unification on the checked exceptions as part of the function signature.

Re: JEP 430: String Templates (Preview) Proposed to Target Java 21

#233

Earlier quoted context omitted.

It's the only sane way. Checked exceptions were a fundamental mistake which basically makes it impossible to actually use (non-RuntimeException derived) exceptions reliably for their intended purpose. As soon as you introduce any higher-order programming (e.g. functions that take other functions as parameters) you start to have to wrap e.g. IOException... but that means that calling code can no longer catch that wrap…

It's not impossible, it would just require type inferencing/unification on the checked exceptions as part of the function signature.

It runs counter to variance rules for method signatures; see pron's sibling comment and my reply to that. I'm not exactly sure what he's alluding to in terms of an actual solution, but he is an insider, so there may be hope for Java programmers :).

Anyway, the key point is that any implementation of a method will (almost by definition) need to be able to throw more types of errors than the writer of the original interface anticipated. That is the fundamental problem and unless you get rid of overriding there's no solution for that. The only solution is to force everything into a single super-type... but that just leads to "throws Exception" and we've been there before.

(I mean, there's approximations to solutions as in OCaml's polymorphic variants, row types, intersection types, etc. .. but those only work when variance isn't involved... or do away with most of the touted benefits of the "checked" part of checked exceptions, so...)

Re: JEP 430: String Templates (Preview) Proposed to Target Java 21

#234
post #127

Earlier quoted context omitted.

It is not really innovating, if it has been battle-tested by other languages, is it? While modern Java sometimes makes me think about reviving and modernizing an old project of mine, if Java is simply always behind by design of its evolution process, that makes it less likely, that I want to spend time with it.

Your mileage may vary, but I went from liking simple languages like Java, to very expressive, complex ones (Scala, Haskell, Rust) back to Java. I mean, I like all those languages (and many more), but the thing is, most programs really don’t need all that many language features — an okayish type system, OOP for encapsulating private vs public state, and preferring immutable public APIs have served me well in almost ev…

I really like Java. Also Go, C, LISP. I find most of the languages I like are very pragmatic. I'm much more interested in getting stuff done than being clever. I used to quite like C++ but it seems like a minefield of features and gotchas these days. I'm very much a fan of the principle of least astonishment. I feel like Java manages that well and not being a kitchen sink language aids in that.

Re: JEP 430: String Templates (Preview) Proposed to Target Java 21

#235
post #127

Earlier quoted context omitted.

Your mileage may vary, but I went from liking simple languages like Java, to very expressive, complex ones (Scala, Haskell, Rust) back to Java. I mean, I like all those languages (and many more), but the thing is, most programs really don’t need all that many language features — an okayish type system, OOP for encapsulating private vs public state, and preferring immutable public APIs have served me well in almost ev…

Smalltalk should be a no-brainer then. Arguably one of the simplest languages with merely 6 keywords and immense power. The ecosystem is of course a question. I think I can understand the journey from Java -> other -> Java, because as you learn more about programming, you become more capable of solving problems properly in a simpler language. But there might be a point, when you get fed up again with writing the same…

I've tried to get into Smalltalk many times but I find I always get turned off by the required, clunky, development environments

Re: JEP 430: String Templates (Preview) Proposed to Target Java 21

#236
post #98

Earlier quoted context omitted.

Right, and that's why Java introduced checked exceptions in 1.0. A feature which wasn't proven back then and remains unproven now. Another example being overengineered streams. Parallel streams look really cool as a demo, but have been proven dangerous in their default configuration (they can exhaust the default thread pool).

I, for one, like checked exceptions.

Me too. Error handling is a problem that programming languages still struggle with (witness Golang). But IMO Java does it really well.

Re: JEP 430: String Templates (Preview) Proposed to Target Java 21

#237
post #135

Earlier quoted context omitted.

> STR."My name is \{name}"; What is the method call ? Agree with grandparent this looks too inconsistent for Java STR.format(“”) would be more Java with import as Alias

StringTemplate t = RAW.”My name is \{name}”; STR.process(t)

That’s special magic if I recall my Java syntax correctly

System.out.print.”hello” isn’t a thing

Re: JEP 430: String Templates (Preview) Proposed to Target Java 21

#238
post #135

Earlier quoted context omitted.

StringTemplate t = RAW.”My name is \{name}”; STR.process(t)

That’s special magic if I recall my Java syntax correctly System.out.print.”hello” isn’t a thing

Yes, it is a very tiny new syntax so that templates can be distinguished from string literals (so string templates can never stand without a template processor, hence the RAW)

Re: JEP 430: String Templates (Preview) Proposed to Target Java 21

#239
post #217
post #194

Earlier quoted context omitted.

It doesn't eventually add the same stuff (even in this case, the feature is quite different from C#'s) as it will never add most of the stuff C# has because we want to keep Java as minimal as possible. But if your point is that Java usually only adds features that other languages already have, that is absolutely true and we'd like to keep it that way. We believe most programmers generally prefer languages with fewer…

I don't think that's working out so well for you, because developers disagree https://survey.stackoverflow.co/2022/#section-most-loved-dre...

Could a diet people would say "works well" be determined by looking at the dishes people say they love most? Topping the list would be foods that are too unhealthy or too expensive, foods that most would agree wouldn’t "work well" as a sustainable diet.

When you've followed such polls for many, many years, you see that programmers report they "love" languages that they pick more than those that are picked for them, that they tend to use for hobby more than work, that they tend to use in newer/greenfield projects, that they tend to use in smaller projects, and that they tend to use alone or in a small team. But the languages that end up working out well -- for the kinds of projects where Java is used -- are those that gain wide adoption in industry, that scale to large codebases and large teams, and yield programs that are maintained for many years. The languages that have managed to achieve that best are Java and C, and, to a lesser degree, C++.

If you've lived through the BASIC and later VisualBasic craze of the eighties and nineties, the SmallTalk craze of roughly the same era, the Haskell craze in academia in the mid to late nineties, the PHP craze of the early oughts, and the Ruby craze of the mid oughts, you see that the most "loved" languages are rarely the ones that end up working well.

Aside from a short ~5 year period (its first five years), Java was never a particularly "loved" language. Hell, James Gosling designed it to be a boring, conservative, "blue collar" language for work, and this work-in-teams-on-large-import-projects has been the main focus of Java's evolution. It's hard to argue that this hasn't worked out really well for Java. Even if Java isn't your cup of tea, you should appreciate the need for a language you can safely bet on to build a very important codebase that should be maintained for twenty years or more.

Having said that, I believe we should work on making Java more suitable for smaller, more fun projects without giving up its scalability. That's a difficult challenge, and, as far as I know, no language has ever achieved it, but perhaps Python is a reasonable source of inspiration.

Re: JEP 430: String Templates (Preview) Proposed to Target Java 21

#240
post #230

Earlier quoted context omitted.

we should probably also not blow this "problem" out of proportion. If you actively maintain your things, you can probably handle swapping a few strings out that are garantueed to give buildtime errors. If you dont maintain your application and run on antiquated runtimes? well good news, it keeps totally unchanged... edit: okay, i guess if you do some funky stuff like reflection or having stuff in various config files…

It's more involved than just "swapping a few strings". You also need to make sure that all the libraries you depend on are on the same side of the divide, that is, you have to "swap a few strings" and update all your dependencies at the same time (and these updates could bring unrelated breaking changes with them). And some of these dependency changes might be unexpected; you might not expect a general-purpose loggin…

I guess Jakarta thought that leaving the JCP and changing the name was necessary, but that's something only they can explain.
Post reply on HN