• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please refactor these 6 java lines

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Any ideas on how to improve this code's readability ?
 
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any safe refactor depends on having good tests to verify that you do not change the behaviour of the code.

Perhaps you can post the entire method and include any tests you have written for it? I can derive that your method returns boolean due to the "return false" on line 10 but that's about it.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dieter Quickfend wrote:



You missed what it said on line 12 of the original post.
 
Dieter Quickfend
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joanne Neal wrote:
You missed what it said on line 12 of the original post.


I would assume that it would be no great feat to use longValue(randomString) in the rest of the method.
 
Saloon Keeper
Posts: 15525
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After saving it to a local variable of course ;)
 
Myke Enriq
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your replies. I feel these exercises may prove useful both for me and others. Here is another piece of code:



This is from a function that has multiple similar blocks of code like this one, one after another. Basically an object has many fields, and I need to set each of those values from an array of String.

Could I write this easier to read/more elegant ?
 
Tim Cooke
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Myke, It's best if we keep it down to one discussion point per thread so feel free to start a new thread with your new question. Otherwise this will become an endless bucket for random refactor efforts.
 
Myke Enriq
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shouldn't we have a topic only for refactoring ?

This could be useful as it will improve a lot of people's coding style.
 
Tim Cooke
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Far too generic. We'll end up with a huge single topic with multiple refactoring discussions in it. How would that be useful? How would you search it? How would we talk about it? "Oh that particular refactoring was discussed in the 'Refactoring' topic on page 74". It's just not manageable at all. It's akin to saying "Shouldn't we put all our code in main? It's all just code after all right?"

I agree that discussing refactoring is a valuable thing to do but we should do it one problem at a time, one topic at a time.
 
Myke Enriq
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Cooke wrote:Far too generic. We'll end up with a huge single topic with multiple refactoring discussions in it. How would that be useful? How would you search it? How would we talk about it? "Oh that particular refactoring was discussed in the 'Refactoring' topic on page 74". It's just not manageable at all. It's akin to saying "Shouldn't we put all our code in main? It's all just code after all right?"

I agree that discussing refactoring is a valuable thing to do but we should do it one problem at a time, one topic at a time.



I like the way you think, and indeed this has the potential to turn into an epic thread. Would it not be better though if all refactoring discussions happen in a single thread just like you described ? I mean, a novice programmer could just browse through conveniently because it is all in one place.
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't speak for anybody else, but once a thread reaches a certain size I wouldn't start reading it because I'd assume it would be too much effort to get up to speed with the discussion. You're also going to get confusion when discussions of different problems start interleaving.

What I'd suggest is using one thread per discussion. And if there were enough of these threads, or if we decided we wanted to encourage more of them, then a new forum could be created specially for them. That would meet the requirement for someone to find them all in one place.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic