Unless you consider looping forever a bug, it looks kosher to meRecently bought this:
http://www.amazon.com/gp/product/098478280X/?tag=neogaf0e-20
And it's actually pretty good from what I can glean from first flip through.
Also came across this when I opened to a random page:
Find the bug in these lines of code
Code:unsigned int i; for i = 100; i >= 0; --i) printf("%d\n", i);
and I was quite surprised at myself for how fast I was able to spot the issue. Made me feel a little more confident in what I know as I start to go into interviews for jobs and such, even if it is a small bug.
It's an unsigned int, and we enter the block while i is >= 0. This means that when i == 0, we decrement it, and since it is unsigned, we underflow the structure and wind up with the largest number an unsigned int represents (on 32 bit systems, 2^32 - 1). For this reason, the loop will continue indefinitely.Is it the missing parentheses?
Is it the missing parentheses?
Unless you consider looping forever a bug, it looks kosher to me![]()
Would it really loop infinitely? The variable is still being decremented right? Man I might be looking really dumb right now.
This isn't necessarily programming related, but I'm not sure if I should make a new thread. I'm finally transferring from a community college to a University this upcoming fall. The only problem is that I have no idea what I should specialize in. I could go for a general software engineering path or specialize in robotics,security, etc.. I'm thinking about doing there AI track since the college has a highly rated AI department, but I'm not sure if that is the best choice career wise. Anyone have any experience in something like this? Because I could use some advice.
It's an unsigned int, and we enter the block while i is >= 0. This means that when i == 0, we decrement it, and since it is unsigned, we underflow the structure and wind up with the largest number an unsigned int represents (on 32 bit systems, 2^32 - 1). For this reason, the loop will continue indefinitely.
It would. The loop evaluates at i = 0 and then decrements before exiting, so it'll be a negative number and blow up cause it's unsigned and never terminate cause it'll never reach the required conditions.
Well shit. I have never actually had to declare whether a number was signed or unsigned in my (school) programs :S
Well shit. I have never actually had to declare whether a number was signed or unsigned in my (school) programs :S
int main( int argc, char **argv ) {
unsigned int i = 10;
for ( int j = 0; j < 20; j++ ) {
i--;
printf( "%d\n", i );
}
return 0;
}
$ g++ -o test test.cpp && ./test
9
8
7
6
5
4
3
2
1
0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
It's interesting to note that because %d (which indicates a signed integer) was used in the print formatting we would see what we would "expect" on stdout, meaning we would count from 100 to 0, and then continue to -1 and so on. This is because even though the variable is designated as unsigned, the bits are still arranged in such a way that the two's complement will get us negative numbers even though in actuality we've underflowed an unsigned integer.
I haven't had to much either. Your compiler would've caught it if you had tried to do it anyway. But only as a warning. [as least with gcc as I tried it]
![]()
Visual Studio lets it go (no warnings either). I have Visual Studio configured for General Development instead of C++ though, not sure if that would make a difference or not.
So...I have my Java final project and it's been getting really busy for me here deployed...would anyone be interested in doing my final project? Of course I will pay ;]
Pms please!
Yup. The sign bit is the most significant bit, so once you decrement below 1000 0000, you will re-enter positive numbers.Yep. Been a while since I had to manually calculate two's complement, but it just flips the sign bit and continues decrementing the value, no?
ie
0000 0101 -> 5
0000 0100 -> 4
0000 0011 -> 3
0000 0010 -> 2
0000 0001 -> 1
0000 0000 -> 0
1111 1111 -> -1
1111 1110 -> -2
1111 1101 -> -3
1111 1100 -> -4
1111 1011 -> -5
At least that's how I remember it.
Hey guys, does anyone know of a good Java development environment that would run on old computers running Windows XP?
Did you try Eclipse?
Hey guys, does anyone know of a good Java development environment that would run on old computers running Windows XP?
Hey guys, does anyone know of a good Java development environment that would run on old computers running Windows XP?
I don't have access to the computers yet, I'm just gathering recommendations at the moment. I might be teaching a workshop type thing for 12-14 year olds this summer on making simple Minecraft mods, and the computers at the place are old machines running XP. We're not sure if we can even run Minecraft on them yet![]()
Eclipse and Netbeans are both resource hogs, I haven't used Netbeans as much, but Eclipse is pretty bad in that respect. I'd just fall back on some nice text editor (notepad++ for instance) and cmd.exe. It's not as convenient, but I assume they have no programming experience, so a full-blown IDE would probably confuse them more than anything, unless you abolutely need one for building the mod or something.
Yeah, Sublime Text 2 is fantastic and it's what I use currently as well (when I'm not doing anything in Visual Studio) but I was concerned about the licensing, so I didn't recommend it. (it costs ~50$ iirc)
Hey guys, does anyone know of a good Java development environment that would run on old computers running Windows XP?
Eclipse and Netbeans are both resource hogs, I haven't used Netbeans as much, but Eclipse is pretty bad in that respect.
You might want to take a look at blueJ for an intro to java workshop.
Speaking of java...Why do many people seem to hate it?
print "Hello World"
Speaking of java ... Why do many people seem to hate it?
Speaking of java, I know I will eventually be required to learn it for college so I've been doing some stuff in it to prepare myself. I can pretty much only do basic stuff at this point, as I've only been programming for a year, sporadically, but I like it so far. Why do many people seem to hate it?
note that this isn't my first language, I did python before this
Speaking of java, I know I will eventually be required to learn it for college so I've been doing some stuff in it to prepare myself. I can pretty much only do basic stuff at this point, as I've only been programming for a year, sporadically, but I like it so far. Why do many people seem to hate it?
note that this isn't my first language, I did python before this
imo top of the list is:
1. the press confuses java web apps with regular applications, and then everybody runs around screaming about hijacking.
2. oracle patches exploits, people assume because java wants to update a lot "it must be a virus".
... and the legitimate issues a lot further down ...
97. speed, especially of graphics stuff.
98. It's sometimes overly verbose
99. Doesn't support tail-call optimization.
imo top of the list is:
1. the press confuses java web apps with regular applications, and then everybody runs around screaming about hijacking.
2. oracle patches exploits, people assume because java wants to update a lot "it must be a virus".
... and the legitimate issues a lot further down ...
97. speed, especially of graphics stuff.
98. It's sometimes overly verbose
99. Doesn't support tail-call optimization.
1. Oracle is a terrible company. Shift everything down one.
Speaking of java, I know I will eventually be required to learn it for college so I've been doing some stuff in it to prepare myself. I can pretty much only do basic stuff at this point, as I've only been programming for a year, sporadically, but I like it so far. Why do many people seem to hate it?
note that this isn't my first language, I did python before this
imo top of the list is:
1. Oracle are a terrible company.
1. Oracle is a terrible company. Shift everything down one.
I being owned by Oracle is the only real complaint I have.
List<Integer> list = new LinkedList<Integer>();
// fill list with tons of numbers
for (Integer i : list) {
// do maths
// UH OH you got fucked by unboxing
}
no emacs love?![]()
There are lots more but those are the main complaints I could come up with on the spot. You'll notice the common theme with all of these issues is that they all make Java easier to understand for bad programmers. This is why people hate Java, it's designed to be an easy language for bad programmers to make shitty software with en masse.
Reasons why Java sucks without even getting into whether its brand of OO is a good thing or not or attacking design decisions of the language:
9. Interfaces are not a full featured replacement for multiple inheritance.
10. Static methods aren't even methods, they're global functions, you can't override them in a subclass. Good OO there java.
Multiple Inheritance is a terrible thing. It's incredibly unnecessary to. If you need multiple inheritance, I would question your design because you're probably violating the single responsibility principle.
I agree with most of what you say, but this summation is just a bad one. The reason Java is the way it is is because it is focused around enterprise development which is slow moving, often consists of massive teams and massive projects, and relies heavily on backwards compatibility and legacy support.
That also happens to be the exact reason why it's pretty much the best language for that sort of setting. The portability also helps. There's a reason why it has the most tools out there for that sort of development.
Screw multiple-inheritance. I almost never use inheritance of any kind anyway. Imo you can use composition more effectively most of the time to solve the same problems.
Multiple Inheritance is a terrible thing. It's incredibly unnecessary to. If you need multiple inheritance, I would question your design because you're probably violating the single responsibility principle.
public class PriorityQ<T>
{
PriorityQ(){}
void Sort()
{
int varPos = m_queue.size() - 1;
int swap = 1;
while(swap == 1 && varPos > 0)
{
if([b]m_queue.get(varPos) < m_queue.get(varPos - 1)[/b])
{
}
else
swap = 0;
}
}
private ArrayList<T> m_queue;
}
I agree with most of what you say, but this summation is just a bad one. The reason Java is the way it is is because it is focused around enterprise development which is slow moving, often consists of massive teams and massive projects, and relies heavily on backwards compatibility and legacy support.
That also happens to be the exact reason why it's pretty much the best language for that sort of setting. The portability also helps. There's a reason why it has the most tools out there for that sort of development.