|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On November 18 2013 23:32 Manit0u wrote: For Java I would use NetBeans. Worked much better for me than Eclipse ever did.
Any reasoning behind choosing NetBeans over Eclipse?
|
|
|
It is pretty much irrelevant whether you use ++i, i++ or i+=1, as a single statement(as in this case), all do exactly the same.
|
On November 19 2013 04:09 darkness wrote:Show nested quote +On November 18 2013 23:32 Manit0u wrote: For Java I would use NetBeans. Worked much better for me than Eclipse ever did. Any reasoning behind choosing NetBeans over Eclipse?
Most companies use Eclipse, I haven't been to one that uses Netbeans. Netbeans is much more intuitive IMO but I would lean how to use Eclipse if you plan on doing Java for a living.
|
On November 19 2013 05:25 Yoshi- wrote: It is pretty much irrelevant whether you use ++i, i++ or i+=1, as a single statement(as in this case), all do exactly the same.
++i and i += 1 will get translated into the same thing assembly-wise - saying i++ is the same is wrong though, it creates a temporary to hold the return value (pre-incremented i) and thus is slower ^^ it's pretty nitpicky but it's an easy habit to get into to type ++i instead of i++ unless you REALLY need the pre-increment value of i, and it can have some impact on performance of something big if it's in a deeply nested main loop.
|
On November 19 2013 05:30 Cyx. wrote:Show nested quote +On November 19 2013 05:25 Yoshi- wrote: It is pretty much irrelevant whether you use ++i, i++ or i+=1, as a single statement(as in this case), all do exactly the same. ++i and i += 1 will get translated into the same thing assembly-wise - saying i++ is the same is wrong though, it creates a temporary to hold the return value (pre-incremented i) and thus is slower ^^ it's pretty nitpicky but it's an easy habit to get into to type ++i instead of i++ unless you REALLY need the pre-increment value of i, and it can have some impact on performance of something big if it's in a deeply nested main loop. Most of the time that is pretty much irrelevant, and most compilers will most likely realize whether the temporary is actually needed or not.
E: yea just tested it, both create the same assembly code.
|
On November 19 2013 05:30 Cyx. wrote:Show nested quote +On November 19 2013 05:25 Yoshi- wrote: It is pretty much irrelevant whether you use ++i, i++ or i+=1, as a single statement(as in this case), all do exactly the same. ++i and i += 1 will get translated into the same thing assembly-wise - saying i++ is the same is wrong though, it creates a temporary to hold the return value (pre-incremented i) and thus is slower ^^ it's pretty nitpicky but it's an easy habit to get into to type ++i instead of i++ unless you REALLY need the pre-increment value of i, and it can have some impact on performance of something big if it's in a deeply nested main loop.
Premature optimization much? Also unless you actually *use* the value (which the compiler can statically determine) it won't make any difference 
EDIT: What Yoshi- said :D
|
On November 18 2013 23:32 Manit0u wrote:For Java I would use NetBeans. Worked much better for me than Eclipse ever did. Edit: Also, Show nested quote +On November 13 2013 06:57 EscPlan9 wrote:Really should just initialize the loop variable inside the loops. Cleans up the code a bunch: #include <stdio.h>
int main() { int array[10][10]; int count;
for ( int i = 0; i<10; ++i ) { for (int j = 0; j<10; ++j ) { array[i][j] = count; count++; } }
for (int i = 0; i<10; ++i ) { for (int j = 0; j<10; ++j ) { printf( "%d", array[i][j] ); printf( " " ); } printf("\n");
} }
I don't think you should be using "++i" statements for incrementation in a for loop. I'm of the opinion that they did a great job in Python with eliminating the ++ and -- operators (both pre- and post-) and leaving just += and -=. So much more consistent.
There's a reason Python didn't include increment operators, but its not because of consistency. Its because it messes with mutability, and you can't self assign. In a dynamic language that supports all kinds of overrides this is important.
While in the case of a loop it doesn't matter, understanding the difference between prefix/postfix incremental operators and augmented assignment is kind of important, as they all do different things. You may have a hard time fixing bugs otherwise.
EDIT: Sorry I projected that a bit strongly, consistency [POLS] is a decent side effect of it though I do miss it from time to time.
To explain further, if they said it was for consistency then it has less to do with using it than it does with the actual implementation. Python can't modify an immutable object, so you can override += but you can't override ++ because ++ changes the state of the actual referenced object itself and you can't self assign an immutable object. So it would be the only operator you couldn't override and would behave differently to all other methods, which would be inconsistent.
@EscPlan9 As for cleaning up the code. Use functional decomposition, that's how you make clean code, tinkering with control flow only helps a little bit.
|
It will pretty much never make a difference, but ++i is strictly superior to i++ unless you explicitly need the behavior of i++. It is as fast or faster and easier to understand as you always know that you get i+1 for all calculations and not i for one and i+1 for another. Therefore it's a good habit to use ++i over i++ if you want either of the two. You might want to use other options though.
|
On November 19 2013 07:04 spinesheath wrote: It will pretty much never make a difference, but ++i is strictly superior to i++ unless you explicitly need the behavior of i++. It is as fast or faster and easier to understand as you always know that you get i+1 for all calculations and not i for one and i+1 for another. Therefore it's a good habit to use ++i over i++ if you want either of the two. You might want to use other options though.
I agree, though IMHO there should never be any code where the difference between ++i or i++ would cause a problem in your program. (got nothing against what you said, just wanna make a point about the effectiveness of the increment operator)
This would mean that you have two variables that need to be in sync with each other for whatever reason, which seems silly to me.
For example, I don't think there should ever be a time where this is necessary.
i = 1 a = ++i
<use a and i for different things, but the number needs to match>
In a complex business application there would never be a time where you would even want to use the increment operator as using iterators would always be a much cleaner way of doing things.
|
On November 19 2013 07:04 spinesheath wrote: It will pretty much never make a difference, but ++i is strictly superior to i++ unless you explicitly need the behavior of i++. It is as fast or faster and easier to understand as you always know that you get i+1 for all calculations and not i for one and i+1 for another. Therefore it's a good habit to use ++i over i++ if you want either of the two. You might want to use other options though.
This is pretty much my point too =) it's not premature optimization in the usual sense because it incurs absolutely no penalty to you when you write it or to people who read it later, in either time or clarity. It's just a good habit to get into. Like I said, pretty nitpicky... but once you've thought about it, why would you ever write the one that has the potential to be slower if there's literally no other difference between the two? Obviously it's not going to make or break anything, but if you don't care about the actual semantic difference, there's just no reason to write i++.
|
On November 19 2013 05:25 sluggaslamoo wrote:Show nested quote +On November 19 2013 04:09 darkness wrote:On November 18 2013 23:32 Manit0u wrote: For Java I would use NetBeans. Worked much better for me than Eclipse ever did. Any reasoning behind choosing NetBeans over Eclipse? Most companies use Eclipse, I haven't been to one that uses Netbeans. Netbeans is much more intuitive IMO but I would lean how to use Eclipse if you plan on doing Java for a living.
Pretty much this, it was more intuitive and seemed to run smoother and faster overall. It was quite some time ago and I was pretty noob at it so NetBeans' code assist and other features were of great help. Anyway, I remember that doing Java in NetBeans was fun while Eclipse made me feel a bit lost.
|
Is it generally bad to catch unchecked exceptions? I know it's a problem with the program's logic
|
There are some places where it's reasonable to catch all exceptions. For example if you have a complicated rpc server, your main entry point may want to catch Exception. That should be immediately followed by loudly logging said exception, probably incrementing bits for monitoring, and definitely returning a failure for your rpc.
|
On November 19 2013 10:27 darkness wrote: Is it generally bad to catch unchecked exceptions? I know it's a problem with the program's logic
Depends what you want to do with it, generally there should never be a need.
You also want to handle exceptions (in general) in a way that doesn't cause you to have code bloat, and methods spanning a mile long just to handle them.
That is if you're like me and prefer the new jersey style of coding.
http://en.wikipedia.org/wiki/Worse_is_better
You will find most inhouse software has no exception handling at all, and libraries will do it in a way that doesn't affect code complexity. If you can do validations or exception handling declaratively then that is a good time to do it, but if you have to put it in the main body of code, I would err on the side of not doing it unless it is super important.
|
If you can recover from any kind of exception and can't accept a program crash (like pretty much any kind of server - one request may fail due to an unlikely combination of circumstances, but the next request should work again), it is a good idea to catch everything.
It's also a good idea to always log all exceptions before you end the program.
Catching all exceptions anywhere else other than the root of the program is likely a bad idea.
|
Hey guys. For a small project I'm doing in Java I want to create and assign to a 2D Array(I just started learning about them so I feel like playing with it and making a small text adventure game, the array is an array of the rooms). The size is 21x3(ignoring the 0 row) and I want to have the 3 columns be assigned so that i=#of row and then the #of column is done like so:
(when i =a number between and including 2 and 10) column1 is i-1 column 2 is i+1 and column 3 is i+10 so for the number 2 the result would be [1][3][12].
(when i = a number greater than 11) column1 is i-1 column 2 is i+1 and column 3 is i-10 so for the 12th row the result would be [11][13][2].
(when i = 1) column 1 is 10 column 2 is 2 and column 3 is 11. [10][2][11]
(when i = 11) column 1 is 20 column 2 is 12 and column 3 is 1.
Any chance you guys know how I would assign to the array without doing each number individually and probably making a small mistake? Could I use a few different for loops to assign? I tried using for loops for it already but apparently while it was sintactically correct it terminated when I tried assigning.
|
First, I would say to just make your array the size you need, and access elements from 0, rather than having an extra element in each "column", and an extra "row". This might save you some grief if you start accessing things you shouldn't, and the way you're doing it seems weird. If you need to display the number, just add 1 to it.
You should be able to initialize everything with a loop for the first two cases, and then just doing it by hand for the two exceptions.
I can already spot one bug in your assignment however. Consider room 21. For room 21, according to your assingment, the array at that index should be [20][22][11]. However, room 22 does not exist.
|
(I just started learning about them so I feel like playing with it and making a small text adventure game, the array is an array of the rooms) As I said here, this is for a set of 20 rooms to be navigated in. It gets really complicated to navigate more than one or two players/creatures through a ton of numbers that are listed but don't really make much sense. The reason I have 3 columns is because there are 3 routes to other rooms for each room on the map.
I'll make sure I take 21 out of a loop and make it have its own separate assignment statement, thank you for pointing that out.
|
I'm somewhat confused on what you're trying to do exactly, could you share the code you have? Doesn't matter if it's incomplete or doesn't work.
|
|
|
|
|
|