Michael Sims
Dave Tolls wrote:If you want to remove by index, then the API has a remove method which states: "Removes the element at the specified position from the specified array."
Michael Sims
Michael D Sims wrote:
Dave Tolls wrote:If you want to remove by index, then the API has a remove method which states: "Removes the element at the specified position from the specified array."
You see, thats EXACTLY how I read that to mean as well ... but it DOESN'T mean that ... look at all of the return classes that the ArrayUtil can send back ... NONE of them are String[], and as far as the "position" to be removed, it appears to me that it is only a position that it locates based on criteria that you provide which has everything to do with the data in the array, and not the array index itself.
Michael D Sims wrote:
here is the new code (it's about a fifth as large as the first attempt:
...
It's been a fun project ... still much to do, but it's awoken the closet programmer in me.
Junilu Lacar wrote:
Not trying to rain on your parade but if you look at the structure of your new code and read this article: http://blog.codinghorror.com/flattening-arrow-code/, you'll realize that there's still some things that your newly-awakened closet programmer can do to shake off the cobwebs
Michael Sims
Junilu Lacar wrote:
Not trying to rain on your parade but if you look at the structure of your new code and read this article: http://blog.codinghorror.com/flattening-arrow-code/, you'll realize that there's still some things that your newly-awakened closet programmer can do to shake off the cobwebs
Michael Sims
Junilu Lacar wrote:Ok, since we're doing a code review now...
1. You're not following Java naming conventions. Method names, variables, fields should start with lowercase and camel case for the rest of the name. MakeSingleLines should be makeSingleLines, Counter should be counter, CrunchLines should be crunchLines, etc.
2. Comments like the ones you wrote, while I applaud the effort, are likely to be ignored. Plus, they tend not to get updated along with the code so they become obsolete fairly quickly. When I see comments that explain what the code is doing, I strive to refactor
to make the code more expressive and make those comments redundant. As I was saying in another thread, I reserve writing comments for those times when I feel I need to explain why the design is the way it is.
3. Style-wise, your indentation and brace placement are non-standard, too. I use the more common style, which is default in Eclipse and I believe what has been in the official Java Coding Style Guide since forever. If I'm not mistaken, JavaRanch Cattle Drive recommended style is to put braces on a separate line aligned with the statement. Examples:
It's a matter of taste but it's better to follow one of the latter two so more people are comfortable reading the code. People are funny when it comes to style and indentation and brace placement.
If you're up for it, we can do some refactoring as I would do it with developers on my team. And I don't mean just addressing the style and, as you say, "aesthetics" of the code either. I'd go for clarity first, then flexibility and maintainability next. Performance always comes last, if I feel that I need to address it. If this is something that will be used often and there's a chance that you may need to modify the code as you encounter more date formats that you have to handle, then it may be worth structuring the code so you can do that with minimal effort and change.
Michael Sims
Michael Sims
In a 12 August 1997 Usenet post, Netscape engineer Jamie Zawinski wrote:Some people, when confronted by a problem, think "I know, I'll use regular expressions." Now they have two problems.
Junilu Lacar wrote:Ah, great way to start the weekend... do a code review!
![]()
It's always good to start these with a little bit of humor, so here's something to think and perhaps chuckle about:
In a 12 August 1997 Usenet post, Netscape engineer Jamie Zawinski wrote:Some people, when confronted by a problem, think "I know, I'll use regular expressions." Now they have two problems.
Junilu Lacar wrote:Objects and classes represent things and therefore should generally have names that are nouns or noun phrases. Names like ProcessData, ReadWholeFile, and TestThings are verb phrases. Verbs and verb phrases are appropriate for method names, not object and class names.
Junilu Lacar wrote:Also, words like "process", "data", and "things" are very general. Combined, as in "ProcessData", they don't really say anything more specific than "DoSomethingWithSomeStuff". I always ask my team to change names like that. Put a little more effort into clearly expressing what that "process" actually does to that "data" or explain exactly what those "things" are. And don't give that name to an object or class. That's a method name.
Junilu Lacar wrote:Would you name your dog "Stay"? Can you imagine how hard it would be to train that dog?
Junilu Lacar wrote:
The name useTextFile is perfect; it reveals exactly how you intend to use it.
However, you declared it as public. Do you really want this available to everyone?
Junilu Lacar wrote:There's a lot more (don't get discouraged, you're making progress) but I'll leave it with this one for now:
Junilu Lacar wrote:
First of all, I don't know if you intended to make this a constructor or a class method.
Junilu Lacar wrote:Second, again with the long comments. While I applaud your effort ...
Michael Sims
Michael D Sims wrote:A Stephen Wright reference?
I could have Main instantiate ProcessData
So following that example … it only seemed right to declare the “main” procedure for the stated class in like manner …
those comments don’t actually exist in my code … I write them for the benefit of this forum … should I not do that anymore?
PLEASE! you are so far from my discouragement level that you should actually picture me like a three year old that your in the process of handing a new ice cream cone to … hand clapping and everything … :-)
Steven Wright wrote:A lot of people are afraid of heights. Not me, I'm afraid of widths.
Junilu Lacar wrote:Well, here I am again, two days after the Bucks served up a nice cold dish of revenge to Sparty for last year's loss in the B1G championship game. Completely forgot about coming back after the game.
Junilu Lacar wrote:
Michael D Sims wrote:A Stephen Wright reference?
No, it was actually in reference to something that Michael Sims wrote![]()
Google gave me a bunch of Steven Wright quotes but I've never heard of either Steven or Stephen before your mention. Funny guy though, that Steven. Thanks for the introduction.
Junilu Lacar wrote:
I could have Main instantiate ProcessData
Yes, that's exactly one of the strategies suggested in our "Main Is A Pain" article. But, just to deal the fatal blow to this dead horse named ProcessData one more time, make sure to take care of that name, Ok?
Junilu Lacar wrote:
So following that example … it only seemed right to declare the “main” procedure for the stated class in like manner …
I can see how you might think that and that's actually kind of logical if you didn't know otherwise. However, some things defy conventional logic which is why main can be a confusing pain. All public static void main methods have a "special" standing with the JVM since they are the ones that the runtime system will look for, literally by name, at startup. No other method has this (dubious) honor. It's like a curse to the poor fella. He's the JVM's #1 goto guy but once they know better, all the programmers want as little to do with main as possible and try to stay the heck away from him. Despite his favored position with the JVM, main is essentially just a Redshirt.
Junilu Lacar wrote:
those comments don’t actually exist in my code … I write them for the benefit of this forum … should I not do that anymore?
Yeah, let's leave those out of the code tags since they're only serving to trigger my OCD tendencies towards comments. If you really feel the need to, just put your clarification notes in the main post text, like this.
Junilu Lacar wrote:
PLEASE! you are so far from my discouragement level that you should actually picture me like a three year old that your in the process of handing a new ice cream cone to … hand clapping and everything … :-)
Well, I guess you're too young to be afraid of widths then. Put your big boy pants on and get ready for a lot more ice cream, buddy!![]()
In case you missed it, that there was a reference to your friend:
Steven Wright wrote:A lot of people are afraid of heights. Not me, I'm afraid of widths.
Michael Sims
Junilu Lacar wrote:Maybe you should try to make a few changes based on the feedback so far before we go on, assuming you still want to go on.
Michael Sims
Junilu Lacar wrote:There's really nothing technically bad about it besides the issue that Carey pointed out about reading the entire file into memory.
Michael Sims
Junilu Lacar wrote:Anyway, to continue the code review...
I want to skip ahead to this code:
I don't know if I can explain very well what I find "a little off" about this code. <snip> I just don't see that there's enough encapsulated information and behavior in it to justify a whole 'nother class.
Michael Sims
Consider Paul's rocket mass heater. |