vincentnl Posted December 10, 2003 Posted December 10, 2003 Hi, I am wondering, whether I should compact my code more in general. Will the first block run faster than the second? or will the compiler create speedequivalent code? codeblock 1 int i = 3 int j = 6 point d = new point(i,j) SomeMethod(d) Or should I sacrifice some readability and compact this to codeblock2 SomeMethod( new Point(3,6) Quote
Moderators Robby Posted December 10, 2003 Moderators Posted December 10, 2003 I would go with method 2, why declare variables if you don't need to. Quote Visit...Bassic Software
vincentnl Posted December 11, 2003 Author Posted December 11, 2003 Readability, although it does not really show from the chosen examples. Compilers must be smart enough to see that these local variables are only used once ! Quote
Moderators Robby Posted December 11, 2003 Moderators Posted December 11, 2003 Oh yeah of course, these local vars are destroyed soon after they go out of scope. I don't care much for readability... we use overloaded methods that have 5 or so args then readability is already lost. Quote Visit...Bassic Software
Administrators PlausiblyDamp Posted December 11, 2003 Administrators Posted December 11, 2003 I personally find the second way more readable anyway in one line I can see that a method is being called with a point of x = 3 and y = 6. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.