Hot answers tagged

10

Given that arrayCopy has exactly one line, it's not clear that there's much value in having it extracted as a method. toArray() is documented to return a safe array, so there is no need to copy it. getCopyOfList returns a fixed-length list without documenting that fact. Clients may be surprised that optional List methods such as add() and remove() are not ...


2

I'm probably not polished enough with Java to propose new code, so here are some abstract thoughts anyone else can use: Fewer bigger writes will generally be more efficient. Disk access is heavily optimized at the OS level, and those optimizations will work best if the number of things you're doing (from the disk's perspective) is smaller. It seems likely ...


2

Declare variables close to where they're used. hour and min are declared and then ignored for half the body of the method. They can be assigned at declaration time, rather than being set to 0 first. And consider making them final, as they should not be reassigned. sep can also be assigned later. It is unclear to me why hour and min are doubles and not ...


1

Seeing you hyperlinked Princeton Algorithms, 4th Ed. resources, I assume you know how to view their take of Prim's. I do not understand your concern about terseness. There is one striking difference between the code you present for review and that of edu.princeton.cs.algs4.Edge and EdgeWeightedGraph it uses: Theirs is documented using the standard mechanism -...


1

There's a lot of code here, so here's a few things to get started with... Comments Consider JavaDoc for function description comments that the clients of your library might want to know, such as // if width is 0 then the frame is maximized horizontally. There's a good chance that their IDE will pick them up and give them hints when they're calling your ...


1

Eric Stein and Azahe have covered many points already. I won't repeat those here, although some of their points may be reflected in my code. Decomposition This code is made up of one large function. The function does a lot of things, any of which we might want to pull out and used separately. For example, both the hour and minute hand angles are computed ...


1

Comments - there is too many of them, usually in places where you could extract code to the well-named method (or just remove comments), try to make the comments unnecessary by improving the code structure - leaving only the ones that explain something not obvious (not needed here) e.g. consider value of: //turning strings to doubles hour = Double....


1

Steps to solve this problem: Get slice of array related to season Sort slice (we could use custom for loop to get min and max but sorting is quite similar in performance and takes one line instead of few) Get first and last value from sorted slice Calculate amplitude and save this result in Array or List Example implementation (C#): using System; using ...


1

Don't create Rube Goldberg machines. There is an easier way to accomplish what you want: public static <T> List<T> getCopyOfList(List<T> list) { return new ArrayList<T>(list); }


1

This code does not do what you want it to do, there is no check for the minimum distance. I'm not going to review code that does not exist. However, I will review the rest of the code. Naming conventions Variable names should be descriptive. int[] a does not pass that requirement. numbers, values or even just arr would've been better. Note that x and y are ...


Only top voted, non community-wiki answers of a minimum length are eligible