Skip to main content
13 events
when toggle format what by license comment
Jan 3, 2012 at 10:25 vote accept cypronmaya
Jan 3, 2012 at 14:37
Jan 3, 2012 at 9:55 comment added Mike Nakis As to the approach you followed, no, I have nothing to say about that, it seems just fine to me.
Jan 3, 2012 at 9:55 comment added Mike Nakis In any case, my advise to you would be to stop worrying about performance so much. The rule in the industry is to code things in the simplest, most readable and most maintainable way possible, then establish performance requirements, then measure the software against these requirements, and if and only if the software fails to meet these requirements, go optimize that 1% of the code which will make the software meet the requirements. And usually, these optimizations turn out to be algorithmic, not hacky.
Jan 3, 2012 at 9:53 comment added cypronmaya Sorry about set method, ya it does exactly what u've said,i've forgot to see the name set,it looked like add to me :P to say like that. Regarding initialization , i completely agree
Jan 3, 2012 at 9:52 comment added Mike Nakis Regarding pnt_x and pnt_y, studies have shown that when humans try to hand-optimize code at that level, the results are in most cases worse than if they had left the compiler do it for them, and in the majority of the remaining cases they are no better than what the compiler would have done by itself, anyway. Declaring your own variables instead of letting the compiler use what is known as "inference variables" is a typical example of such a well meant, but ill advised optimization.
Jan 3, 2012 at 9:46 comment added Mike Nakis arrayList.set( k, new_pnt ) will do exactly what I intended it to do; don't theorize about it when you can just look it up: docs.oracle.com/javase/6/docs/api/java/util/…, E)
Jan 3, 2012 at 9:44 comment added Mike Nakis Regarding the initialization to null, the warning, and why you should do it the way I suggested, read this: codereview.stackexchange.com/a/6329/8381 starting from "One more note:"
Jan 3, 2012 at 9:35 comment added cypronmaya Can u comment on the approach i've followed? any unnecessary methods, unnecessary loops,is it too obvious or lengthy or lame one?. Can u suggest a good approach to solve this?
Jan 3, 2012 at 9:33 comment added cypronmaya Regarding ->Get rid of the pnt_x and pnt_y variables and simply use pnt.x and pnt.y instead.-> If i didn't use pnt_x,pnt_y, every time is use pnt.x,pnt.y in if conditional's it has to calculate or get wht is pnt.x and pnt.y from object, so for that, i've assigned them to pnt_x,pnt_y, so that they don't have to be calculated again and again..
Jan 3, 2012 at 9:28 comment added Mike Nakis Regarding ensureCapacity, you are right. Regarding the for loop, the compiler will optimize it for you anyway, so you don't have to worry about it. Even if the compiler was not going to optimize it, readability is usually far more important than minuscule optimizations. The couple of seconds I wasted looking at it represent a much longer time period than the sum of all the nanoseconds that would ever be saved by this little optimization on all the runs of your application by all the users who will ever see it in all the years that it is going to be in use.
Jan 3, 2012 at 9:26 comment added cypronmaya Regarding names,un-necessary variables,declarations thanks. BTW i've initialized it to null as compiler thrown me a warning. About replacing this "arrayList.remove(k); arrayList.add(k, new_pnt);" ----> Here first i'm removing the element at pos-k and then inserting newly modified element at the same position. As u suggested arrayList.set(k, new_pnt); , what it does is , it doesn't replace the existing element, it only checks if an element exists, if so their index will be increased and new_element is inserted at tht position.
Jan 3, 2012 at 9:20 comment added cypronmaya Speaking of -> for (int i = num_of_queries; --i >=0;) is lot better, it removes useless checks and optimized. -> ensureCapacity it's better only if i'm having lots of records, atleast more than 10(initial capacity).As i'm having very few records, i don't it doesn't really matter ....:P
Jan 3, 2012 at 9:05 history answered Mike Nakis CC BY-SA 3.0