Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7013445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:23:18+00:00 2026-05-27T22:23:18+00:00

In my answer to my own question here I posted some code and @Dave

  • 0

In my answer to my own question here I posted some code and @Dave Newton was kind enough to provide me with a gist and show me the error in my not-so-Groovy ways. <-- Groovy pun

I took his advice and revamped my code to be Groovier. Since then the link I am making (which Dave represents with the replaceWith variable) has changed. Now the closure representation of what I want to do would look like this:

int i = 1
errorList = errorLinksFile.readLines().grep { it.contains "href" }.collect { line ->
    def replaceWith = "<a href=\"${rooturl}${build.url}parsed_console/log_content.html#ERROR${i++}\">"
    line.replaceAll(pattern, replaceWith).minus("</font>")
}

And the for loop representation of what I want to do would look like this:

def errorList = []
def i = 1
for(line in errorLinksFile.getText().split("\n")){
    if(!line.contains("href")){
        continue
    }
    errorList.add(line.replaceAll(pattern, "<a href=\"${rooturl}${build.url}parsed_console/log_content.html#ERROR${i++}\">").minus("</font>"))
}

The closure version is definitely more concise, but I’m worried if I always go the “Groovier” route the code might be harder for other programmers to understand than a simple for loop. So when is Groovier better and when should I opt for code that is likely to be understood by all programmers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:23:19+00:00Added an answer on May 27, 2026 at 10:23 pm

    I believe that a development team should strive to be the best and coding to the least knowledgeable/experienced developer does not support this. It is important that more than one person on the team knows how to read the code that is developed though. So if you’re the only one that can read it, teach someone else. If you’re worried about someone new to the team being able to read it I feel that they would be equally hard to read since there would be lack of domain knowledge. What I would do though is break it up a little bit:

    def originalMethod() {
        //Do whatever happens before the given code
        errorList = getModifiedErrorsFromFile(errorLinksFile)
    }
    
    def getModifiedErrorsFromFile(errorLinksFile) {
        int i = 1
        getHrefsFromFile(errorLinksFile).collect { line ->
            def replaceWith = getReplacementTextForLine(i)
            i++
            line.replaceAll(pattern, replaceWith).minus("</font>")
        }
    }
    
    def getHrefsFromFile(errorLinksFile) {
        errorLinksFile.readLines().grep { it.contains "href" }
    }
    
    def getReplacementTextForLine(i) {
        "<a href=\"${rooturl}${build.url}parsed_console/log_content.html#ERROR${i}\">"
    }
    

    This way if the next person doesn’t immediately understand what is going on they should be able to infer what is going on based on the method names. If that doesn’t work adding tests would help the next person understand what is going on.

    My 2 cents. Good topic though!!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going to answer my own question here because I spent a few hours
I Can't answer my own question yet, so here is the answer I'm an
PLEASE NOTE: I've answered my own question with a link to an answer to
EDIT: This question is solved, but I can't accept my own answer just yet.
As in my own answer to my own question , I have the situation
In an answer to his own controversial question , Mash has illustrated that you
There is a jQuery quiz posted on the W3Schools site here... http://www.w3schools.com/quiztest/quiztest.asp?qtest=jQuery Question #16
ANSWER: If you ever see these lines and are mistified like I was, here's
An answer to a Stack Overflow question stated that a particular framework violated a
In answer to this question Joel Coehoorn said Finally, only after the site's gone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.