• Hey Guest. Check out your NeoGAF Wrapped 2025 results here!

GAF Devs Thread - a thread about programmer's rants

Status
Not open for further replies.
BLSwagger10 said:
Now, my window shows up with all 6 buttons and the text but clicking any of the buttons doesn't do squat.

Because you haven't set their action commands?

BLSwagger10 said:
Code:
if(actionCommand.equals("R"))

Code:
if("R".equals(actionCommand))

is better. Using a constant instead of embedded strings is probably even better.

Edit: For the radio buttons, you're picking up the event fine - your problem is in what you're doing after that.
 
BLSwagger10 said:
Alright guys, I'm doing a Lab for my CompSci class and this is my first time using GUI's and things aren't going my way so far. Basically, I have 3 buttons at the top that will change the center background to the corresponding color and 3 radio buttons on the bottom that will change the text to that corresponding color. Now, my window shows up with all 6 buttons and the text but clicking any of the buttons doesn't do squat. i've looked through it a bunch of times but can't figure out what exactly it is that I'm doing wrong. Here is my code, and no there arent any comments right now. I only tend to add them in when I'm cleaning it up before handing it in. Sorry for the super long post

The actionCommand method returns the actual string of the action that set it off...in other words do

Code:
if(actionCommand.equals("Red"))
instead of just "R". And the same for the other 2.

Now, the JRadioButtons are done correctly, though you're changing the foreground color. You might want to stick to changing the background for the panel like above.
 
dabig2 said:
The actionCommand method returns the actual string of the action that set it off...in other words do

Code:
if(actionCommand.equals("Red"))
instead of just "R". And the same for the other 2.

No. Set an explicit action command against the buttons. Otherwise you're going to end up screwed if you ever want to look into i18n.

And again, when you're making a .equals() comparison between a constant value and a variable, always put the constant first. The reason should be obvious. :P
 
I have a question for the pro devs on here. What is the value of a CS Masters in the industry? I am hatching a plan to go back to school and get a CS Masters. I have an EE undergrad but I have become so specialized that in order to change jobs I would probably have to move, so I think a CS masters would make me much more well rounded. Also, are RA/TA positions common like they are in Engineering? I.e. do most full time grad students get paid like in engineering or is it pretty rare?

Third question, what are some good solid areas of specialization in CS?
 
Figured some of you would get a kick out of this, sorting Algorithms shown using Folk Dance

http://www.i-programmer.info/news/150-training-a-education/2255-sorting-algorithms-as-dances.html

Edit: Also, I have a question. How do you all make test cases for code? I am nearly done with an assignment, but I want to make sure nothing is broken and can't think of a really good way to make a meaningful test that isn't writing anther program to randomly generate test cases, which could easily end up longer then the small program I am writing.

If it helps, this is the kind of input we will be dealing with.

XX:XX [AM/PM] [E/L] NAME PRIORITY

XX:XX represents the time (hours, minutes, seconds). Hours will be represented with one digit,
if possible. Minutes will always be represented with two digits.

[AM/PM] – the appropriate two uppercase letters will be provided to specify the time.

[E/L] – E represents wanting to enter the club while L represents the time at which one leaves the club.

NAME is the name of the person entering or leaving. It is guaranteed to be unique, all uppercase letters and no longer than 29 letters long. Since the club is empty at the beginning and end of each simulation, you will see each name in a case twice: once for entering and once for leaving.

PRIORITY is a positive integer from 1 to 100 that represents how important that person is. The lower the number, the more important that person is. If two people have the same priority to get in, then the person who came into line earlier gets to go. This number will NOT be included if the line in the file is specifying the person leaving. (Since you only need to know about the person’s priority once.)
 
Hari Seldon said:
I have a question for the pro devs on here. What is the value of a CS Masters in the industry? I am hatching a plan to go back to school and get a CS Masters. I have an EE undergrad but I have become so specialized that in order to change jobs I would probably have to move, so I think a CS masters would make me much more well rounded. Also, are RA/TA positions common like they are in Engineering? I.e. do most full time grad students get paid like in engineering or is it pretty rare?

Third question, what are some good solid areas of specialization in CS?
Depends on the industry, but I think Masters are starting to be valued more. In the game industry, it used to always be 2 years experience >> 2 years in school, but now it's shifting since games are becoming more complicated and algorithms need to keep up.
 
dabig2 said:
Now, the JRadioButtons are done correctly, though you're changing the foreground color. You might want to stick to changing the background for the panel like above.

The problem with the radio buttons is that they have to only change the text color while the top buttons have to change the panels color. I also am only using the first letter as it wants us to set the action command to the first letter. It says to do the same for the radio buttons, but I don't know how it would work for them like that. I did it the way I've seen it done for the radio buttons.
 
I know this is the wrong thread, but I can't find the other one. Just a quick question:

Type 'This is a test...' at the Python prompt and hit enter. Record what happens.

Now create a python script named test1.py with the following contents (be sure to save it before you try to run it):

How do I run the script? I'm using the command line(Python 2.7, windows 7) because whenever I click IDLE(Python GUI) nothing pops up.

Edit: Nvm, resolved.
 
iapetus said:
And again, when you're making a .equals() comparison between a constant value and a variable, always put the constant first. The reason should be obvious. :P
Should it be? Would you mind explaining to me why

(5 == i)

is preferable over

(i == 5)

? Thanks. I was discussing this with a friend, and all that I can come up with is that you know that primitive types will have operator== defined, though not necessarily for the type you pass in, so it doesn't seem, as you put it, obvious.
 
I think it's for nulls (also, he said .equals() meaning Java).

If you call a method of a null variable it will throw an error(?), if you call a constant with a null parameter nothing will happen.
 
Kalnos said:
I think it's for nulls (also, he said .equals() meaning Java).

If you call a method of a null variable it will throw an error, if you call a constant with a null parameter nothing will happen.
I don't have any real Java experience, but I imagine the equals member function is similar to the operator== member function in C++, or the == function in C. I've seen conditionals that read (constant == variable) before, but I assumed it was just due to style, and could not see any substance to the decision.

I agreed with my friend on the note that in an assertion that you should state what you know first, and therefore the constant should lead, but in a regular conditional that doesn't really apply.

edit: If what you say is correct, Kalnos, that would be reasonable, then. It'd also highlight how little I know about Java :)

edit2: Does that mean Java variables are typeless, a la Perl?
 
poweld said:
Should it be? Would you mind explaining to me why

(5 == i)

is preferable over

(i == 5)

? Thanks. I was discussing this with a friend, and all that I can come up with is that you know that primitive types will have operator== defined, though not necessarily for the type you pass in, so it doesn't seem, as you put it, obvious.

In C++, if you accidentally type = instead of ==, the second one will evaluate to a valid assignment statement, even though you didn't mean it... Doing the first will generate a compile time error as it's not valid to assign to the literal.

It's one of those accidental typos that can be a bitch to track down.

No clue about Java though ;)
 
fenners said:
In C++, if you accidentally type = instead of ==, the second one will evaluate to a valid assignment statement, even though you didn't mean it... Doing the first will generate a compile time error as it's not valid to assign to the literal.

It's one of those accidental typos that can be a bitch to track down.

No clue about Java though ;)
Ooh, I LIKE that reason. That's compelling enough for me to accept. Doesn't really affect me, however, since I hvae impeccable typing skills.
 
fenners said:
In C++, if you accidentally type = instead of ==, the second one will evaluate to a valid assignment statement, even though you didn't mean it... Doing the first will generate a compile time error as it's not valid to assign to the literal.

It's one of those accidental typos that can be a bitch to track down.

No clue about Java though ;)
Pretty sure java throws a compile time error if you do an assignment in a if/while statement.
 
poweld said:

I actually consider this to be poor style. It reads unnaturally ("if five is equal to i"), and only a very inexperienced C or C++ programmer will lose time tracking such a bug down. Is it really worth writing code that reads so awkwardly just to avoid introducing a bug that comes up rarely (I haven't done this in years) and takes seconds to recognize? Since a piece of code is read many more times than it is written, this does not seem like a very good trade-off.
 
poweld said:
I don't have any real Java experience, but I imagine the equals member function is similar to the operator== member function in C++, or the == function in C. I've seen conditionals that read (constant == variable) before, but I assumed it was just due to style, and could not see any substance to the decision.

I agreed with my friend on the note that in an assertion that you should state what you know first, and therefore the constant should lead, but in a regular conditional that doesn't really apply.

edit: If what you say is correct, Kalnos, that would be reasonable, then. It'd also highlight how little I know about Java :)

edit2: Does that mean Java variables are typeless, a la Perl?

Java variables aren't typeless. It's a strongly typed language.


.equals() needs to be used because == does a reference comparison on objects.

Code:
String r = readLine();

if (r == "foo")
{
   // won't hit here ever
}

"foo".equals(r) is also a good way to avoid typing a redundant null check
 
BLSwagger10 said:
The problem with the radio buttons is that they have to only change the text color while the top buttons have to change the panels color. I also am only using the first letter as it wants us to set the action command to the first letter. It says to do the same for the radio buttons, but I don't know how it would work for them like that. I did it the way I've seen it done for the radio buttons.

Then what you need to do is:

1. Actually set the action command for the buttons.
2. Also actually set the action command for the radio buttons.
3. Check the action command, not the source for the radio buttons. It's trivial - pretty much exactly the same as the code for the buttons.
4. Fix your code so that you're setting the foreground colour on the right object.

Wormdundee said:
It doesn't. It might throw a warning, I don't know.

It normally does give a compile time error, actually, because typically the assigned value won't be a boolean. You're in slightly more trouble if it *is* a boolean you're dealing with, but you'd need a very specific set of conditions for that to be an issue (comparing two boolean variables).
 
prodystopian said:
Why don't you use Visual Studio for Unity?

Edit: I primarily use VS2010 for C# with Unity.
Monodevelop boots faster. I don't have to worry about VS2010 crashing on me when I'm doing something in pure C++ (well, not much anyway, crashes still happen). However Unity can be very bitchy when it comes to doing work in the Unity GUI and the IDE simultaneously. If it crashes or if I accidentally close it, I'd like for it to boot faster when I open it again. Thus, Monodevelop.

Unrelated:
Two weeks to program a lever connected to a hinge on one end, with a spring attached to the other end. Ideally it'll oscillate when set into motion. I need to use full rigid body physics.

Not so bad in and of itself but ontop of everything else I have it's murder. The kicker is that homework group partner is dropping the class after the midterm kicked his ass (I didn't do stellar either).
 
Halycon said:
Monodevelop boots faster. I don't have to worry about VS2010 crashing on me when I'm doing something in pure C++ (well, not much anyway, crashes still happen). However Unity can be very bitchy when it comes to doing work in the Unity GUI and the IDE simultaneously. If it crashes or if I accidentally close it, I'd like for it to boot faster when I open it again. Thus, Monodevelop.

Interesting. I gave up on Monodevelop because it crashed on me a lot. I have heard they have made it significantly more stable in the new version (I haven't used it in almost a year). Also, I haven't had many crashes with VS2010, luckily. I haven't done much work in C++ on VS2010, though, either.
 
y7Hm9.jpg
 
Currently making (or trying to make!) a simple grid-based tower defence game at the moment in C++. Each enemy takes up the height and width of one cell of the map, as does a section of the path which they'll follow.

I have a very simple movement system set up, in that I give the object, in this case the enemy, a vector and it'll add this to it's position continuously.

It's getting the enemies to actually follow the path which I'm having a bit of trouble with. Each cell has a value which can either correspond to Empty, Tower or Path.

This is the code I'm currently using to try and get the monsters to follow the path:

Code:
if (cells[monsterColumn][monsterRow + 1] == APath) //if the cell in front of the enemy is path, go forward
		{
		       monsters[0].move(forward);
		}
		
		else if (cells[monsterColumn + 1][monsterRow] == APath) //else if the cell to the right of the enemy is path, go right
		{
			monsters[0].move(right);
		}

		else if (cells[monsterColumn - 1][monsterRow] == APath) //else if the cell to the left of the enemy is path, go left
		{
			monsters[0].move(left);
		}

My path goes forwards, then right, then forwards, then left, then forwards. Currently the code "works" partly, as the enemy will go forward and right when the path does the same. Where it gets stuck is when the path goes left - the enemy will get "stuck" and not move left, I assume this is because it's also hitting the "right" condition as soon as it moves.

Is there a way around this, to get it to discard the "go right" condition if go left should be used? I tried using a bool, but either I implemented it wrong (likely), or it just wasn't having the desired effect, as it didn't change the outcome.
 
PaulLFC said:
My path goes forwards, then right, then forwards, then left, then forwards. Currently the code "works" partly, as the enemy will go forward and right when the path does the same. Where it gets stuck is when the path goes left - the enemy will get "stuck" and not move left, I assume this is because it's also hitting the "right" condition as soon as it moves.

Is there a way around this, to get it to discard the "go right" condition if go left should be used? I tried using a bool, but either I implemented it wrong (likely), or it just wasn't having the desired effect, as it didn't change the outcome.

Hard to tell from the code/data without seeing more. When the monster won't turn left, is there also a valid block to its right or forwards? Those will always take priority over turning left because of the "if x else y" structure.

It's not column 0 or row 0 you're in BTW? Because right now, you've no guards when you subtract/add + 1 to the array entries.
 
Do you have something that ensures the monster is always moving in a direction that counts as progress down the path? Cause otherwise it would just get into an infinite loop of moving left and then immediately moving right.

Edit: You could try something like storing the monster's previous space and then adding a condition that won't let it move to that space.
 
fenners said:
Hard to tell from the code/data without seeing more. When the monster won't turn left, is there also a valid block to its right or forwards? Those will always take priority over turning left because of the "if x else y" structure.

I think that's what the problem may be, the right block would still be valid, as when it's moved left a bit, the cell to its right would also be a Path cell, so it'd try to go right at the same time as left.

I think I need to tell it to not check the "go right" condition if it should go left, I'm not sure how to achieve that though. Setting a bool didn't seem to work, but that may have something to do with the continuous nature of the game loop, I'm not sure.

fenners said:
It's not column 0 or row 0 you're in BTW? Because right now, you've no guards when you subtract/add + 1 to the array entries.

That's a good point, the point where it gets stuck isn't column or row 0, but it'd definitely benefit me later on in the game when more levels are created to have the guarding in place, so I'll sort that out. Thanks :)

ultron87 said:
Do you have something that ensures the monster is always moving in a direction that counts as progress down the path? Cause otherwise it would just get into an infinite loop of moving left and then immediately moving right.

Edit: You could try something like storing the monster's previous space and then adding a condition that won't let it move to that space.

Good idea! At the moment my map is stored in a simple 2D array, 'cells', which is 20 by 20. So if I replicate this array in the enemy class, and have an enum which can set the cell value to "steppedOn" or "notSteppedOn", I could then say "if ((world.cell directly above) is path, AND (monster.cell directly above) is notSteppedOn)" move to it, and set the cell to steppedOn."

Does this sound plausible? Will get to work on it now :)
 
PaulLFC said:

That's not enough to tell but just a word of advice, if you are using a OO language, do OO programming. That'll help you debug your code faster, for example instead of:

Code:
if (cells[monsterColumn][monsterRow + 1] == APath)
  monsters[0].move(forward);

Do something like:

Code:
if (monster.can_move(forward))
  monsters.move(forward);
 
Personally I would probably just introduce a "direction" member variable to the Monster class, and then just call

Monsters[0].moveForwards()

Which checks for a valid path square in the next square determined by "direction" and moves there if it finds one, or if it doesn't, finds a new path square (via the method you have there), sets direction to that, and moves there. That way it can never go backwards.
 
Proprietary banking language that is outdated, loosely based off C, and when viewed graphically looks like visual studio for windows 3.11 ...


good job security though!
 
iapetus said:
Then what you need to do is:

1. Actually set the action command for the buttons.
2. Also actually set the action command for the radio buttons.
3. Check the action command, not the source for the radio buttons. It's trivial - pretty much exactly the same as the code for the buttons.
4. Fix your code so that you're setting the foreground colour on the right object.
Ok I decided that I could make a char variable that takes the first character in whatever button they pick to do the decision making. Now the problem is I forgot how to compare chars. It's not == defintely and when I use .equals it says that char cannot be dereferenced which I guess is due to .equals being used with strings. Is there another way to compare the chars?

Code:
char letter = actionCommand.charAt(0);
if(letter.equals("R"))

EDIT- Disregard all of this, I'm just retarded. letter == 'R' is how I'm supposed to do it. Can't blame myself for forgetting all this char business as it's been awhile but still, very stupid mistake.
 
Good idea! At the moment my map is stored in a simple 2D array, 'cells', which is 20 by 20. So if I replicate this array in the enemy class, and have an enum which can set the cell value to "steppedOn" or "notSteppedOn", I could then say "if ((world.cell directly above) is path, AND (monster.cell directly above) is notSteppedOn)" move to it, and set the cell to steppedOn."

Does this sound plausible? Will get to work on it now :)

I'd recommend not copying the array. Keep it simple. louis89 has good ideas. You could always keep a list of cells you've visited in the monster and check to see if the cell you're thinking about is in that list instead of just keeping a copy of the whole array.
 
Thanks for all the help everyone :)

It's past midnight here so I'm gonna call it a day/night for now, will work on it tomorrow though and give louis89's suggestion a try.
 
"The updates to the files are 99% cosmetic. I am not sure how or even if that would affect the checksums."

......................
 
Zoe said:
"The updates to the files are 99% cosmetic. I am not sure how or even if that would affect the checksums."

......................

seriously?

I'm working in something with a terrible architecture, but even then I would never expect such ignorance, it's mostly just laziness, which is annoying on its own, but to have coworkers that don't even grasp basic concepts like a freaking checksum must really be a nightmare.
 
Zoe said:
"The updates to the files are 99% cosmetic. I am not sure how or even if that would affect the checksums."

......................
WHERE IS MY :LOL ICON GOD DAMNIT

Incredible. I'm assuming it was a dev that wrote this?
 
poweld said:
WHERE IS MY :LOL ICON GOD DAMNIT

Incredible. I'm assuming it was a dev that wrote this?

Yep. The files submitted to me were from a build older than a patch pushed out a couple of days ago. They're binaries, so I have to depend on checksums rather than line by line compares to prove they're different.
 
I managed to come by two books the other day, VBS and perl (meant to be used in 1-2 week courses), so I went over them during some breaks and finished both. I was doing it more to pass time than to learn anything, but are those two useful for anything? Because I just had the basics and syntax, so I wanna know if I should go deeper.
 
perl is known for regular expressions and it's fantastic for parsing files. But that's really about it. VBS? I haven't seen it used seriously.
 
Alright so I need to make a toString method does the following: returns a String containing data in descending order and the mean. So far I have this:

Code:
public String toString()
	{	
		String str;
		String ing; 
		String str1;
		str ="The sorted values are: ";
		for (int i = 0; i < data.length; i++)
		{
			ing = System.out.print(data[i] + ", ");
		}
		str1 = str + ing + "\n" +
				" and the mean is: "+ mean;
		return str1;
	}
Its a complete mess but I threw it together as I couldnt think of another way to do it. The error I get is for the line inside the for loop. It says that there are incompatible data types there. I just need to find out why it's giving me that error. Then I just have to get it to print everything is descending order.
 
Status
Not open for further replies.
Top Bottom