News for hackers. Stuff that matters.
Re:Java Verbal Expressions by jjice on Wednesday November 25, 2020 @11:08AM (#25210684)
While neat, I think that if you're a developer, you'd be better off learning basic regular expressions instead so you can use them in whatever language you'd like. Depending on this would probably just make moving to a new code base that doesn't use this a lot more confusing.

A normal regex with a comment above it explaining what it does (for complex cases) always worked well for me.

Re:Java Verbal Expressions by TonyTrapp on Wednesday November 25, 2020 @11:13AM (#25210748)
Even as a developer you may have to assemble a regular expression at runtime, at which point a library that can do it for you may be much more handy than having to assemble the string yourself.

And even if you know regex by heart - assembling it with function calls can still be better / safer just like you shouldn't insert SQL parameters by hand into your SQL query strings.

Re:Java Verbal Expressions by nsxwolf on Wednesday November 25, 2020 @11:30AM (#25210958)
I can't learn them. I've tried for over 20 years and every time I use them the knowledge is deleted from my brain immediately. A library like this would be very helpful if it worked.

One problem is that I'm more likely to need regex almost anywhere but Java code.

Re:Java Verbal Expressions by rhacker on Wednesday November 25, 2020 @12:57PM (#25212055)
At the bottom there's a list of other languages that support the same API
Re:Java Verbal Expressions by patal on Wednesday November 25, 2020 @03:48PM (#25214144)
That does not work so well if you're working in a team. A fairly complex regular expression is always hard to read.

We see this as early as in code review and as late as when you find a production bug because expectations of the surrounding code have changed.

For those reasons, we usually break regexes into parts anyway, and name and comment the single parts. Using the library's example, we might have:

  protocol = "^(?:http)(?:s)?"
  protocol_separator = "(?:\:\/\/)"
  url = "(?:www\.)?(?:[^\ ]*)$"
  
  regex = protocol + protocol_separator + url
Which turns out to be in the direction of these Java Verbal Expressions. I find the Verbal Expressions idea really enlightening.
Re:Java Verbal Expressions by spatx on Wednesday November 25, 2020 @11:37AM (#25211056)
I think there is value in both cases. I've seen many developers that have struggled with regex even with all those hundreds of tools to learn and to build/test regex. This could be useful to them to start with, and they can learn regex according to their time/needs. I see solutions like this as a choice, and the fact that people are using these shows that there is value in having that choice, even if is not obvious to us at first glance.