Live data from Hacker News

Refactoring: How do I even start?

socalledprogrammer.com

1–10 of 41 posts

Re: Refactoring: How do I even start?

#3

    if( masterList[z].list2 != NULL && masterList[z].list2.length() > 0 )
    {
        for( Integer y = 0; y 
The if-statement is a good summary of what is wrong with Java. The author doesn't even notice that the second argument of && is redundant and keeps it in the "refactored" version as well...

Re: Refactoring: How do I even start?

#4
I can only recommend Feathers' Working Effectively With Legacy Code, which far expands on OP's themes, notably OP is missing tests - how can you improve on existing code when you don't even know that it works like it says it works?

In some cases it shows its age (especially when it comes to rolling your own mock testing, most languages have automated frameworks for that now), but it's still a great overview of the techniques you can employ.

Re: Refactoring: How do I even start?

#5
post #2

> is the name of the blog; the title of submitted post is "Refactoring: How do I even start?". Could mods change this please?

That's a good point. I clicked on it thinking it was one of those depressing rants about programming. Misleading and disappointed OP!

Re: Refactoring: How do I even start?

#6
post #3

if( masterList[z].list2 != NULL && masterList[z].list2.length() > 0 ) { for( Integer y = 0; y The if-statement is a good summary of what is wrong with Java. The author doesn't even notice that the second argument of && is redundant and keeps it in the "refactored" version as well...

> The author doesn't even notice that the second argument of && is redundant and keeps it in the "refactored" version as well..

That's false. A list object may be initialized but be empty (making it's length zero). Or it may not be initialized (making it null).

Both conditions may happen independently of one another. He checks for the null first so that checking the length does not throw a NPE.

> The if-statement is a good summary of what is wrong with Java.

Frankly, I see nothing wrong here.

Re: Refactoring: How do I even start?

#8
post #6
post #3

if( masterList[z].list2 != NULL && masterList[z].list2.length() > 0 ) { for( Integer y = 0; y The if-statement is a good summary of what is wrong with Java. The author doesn't even notice that the second argument of && is redundant and keeps it in the "refactored" version as well...

> The author doesn't even notice that the second argument of && is redundant and keeps it in the "refactored" version as well.. That's false. A list object may be initialized but be empty (making it's length zero). Or it may not be initialized (making it null). Both conditions may happen independently of one another. He checks for the null first so that checking the length does not throw a NPE. > The if-statement is…

No, you don't need the the second argument since the for loop just won't execute at all if the list length is zero.

Re: Refactoring: How do I even start?

#9
post #3

if( masterList[z].list2 != NULL && masterList[z].list2.length() > 0 ) { for( Integer y = 0; y The if-statement is a good summary of what is wrong with Java. The author doesn't even notice that the second argument of && is redundant and keeps it in the "refactored" version as well...

> The author doesn't even notice that the second argument of && is redundant

Doesn't it check if a list isn't null and then if the list has at least one item in it? Or are you simply saying the for loop takes care of the situation where there are 0 items in the list?

Re: Refactoring: How do I even start?

#10
post #6
post #3

if( masterList[z].list2 != NULL && masterList[z].list2.length() > 0 ) { for( Integer y = 0; y The if-statement is a good summary of what is wrong with Java. The author doesn't even notice that the second argument of && is redundant and keeps it in the "refactored" version as well...

> The author doesn't even notice that the second argument of && is redundant and keeps it in the "refactored" version as well.. That's false. A list object may be initialized but be empty (making it's length zero). Or it may not be initialized (making it null). Both conditions may happen independently of one another. He checks for the null first so that checking the length does not throw a NPE. > The if-statement is…

He then proceeds to iterate over the list using zero based indexing. The loop would not execute once if the list had length zero, making this check just plain wrong.

I know an even lower level language (C++, C) that doesn't have the problem of things which make no sense to be NULL (list elements). The problem is that Java did away completely with value types and made everything pointer only. That has been recognized by later languages (C#) and fixed.

The whole code consists of problems: the first is the language, the second is the programmer, the third is the missing for-each construct.

Post reply on HN