Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 34 35 [36] 37 38 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 887893 times)

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #525 on: January 13, 2012, 10:35:00 pm »

Depending on how c# handles out of bound array values, this might work:

Code: [Select]
while(output[xCurrent, yCurrent] and output[xCurrent, yCurrent].GetStyleType() == 001) {
output[xCurrent, yCurrent] = new MapTile(002);
yCurrent--;
}

In ruby, an out of bound array returns a null value, which also counts as a false when testing conditionals.  Not sure if c# does the same with its arrays though.

I don't know for sure, but Google is telling me C# throws an exception at array out of bounds conditions...I suppose you could catch the exception, but preventing it from happening is easier...
Logged

Willfor

  • Bay Watcher
  • The great magmaman adventurer. I do it for hugs.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #526 on: January 13, 2012, 10:36:42 pm »

C# not only throws an exception, it slows down. The ideal is to not go out of bounds at all.
Logged
In the wells of livestock vans with shells and garden sands /
Iron mixed with oxygen as per the laws of chemistry and chance /
A shape was roughly human, it was only roughly human /
Apparition eyes / Apparition eyes / Knock, apparition, knock / Eyes, apparition eyes /

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #527 on: January 13, 2012, 10:37:14 pm »

Stargrasper, I did check array bounds. In the first one, I check that yCurrent >= 1, so that there's no errors from yCurrent-1. In the second, I have yCurrent >= 0 in the while conditions.

Why wouldn't you use a for loop with multiple conditions? There's nothing wrong with it, especially when you consider that the following code examples are equivalent:

Code: (for) [Select]
for(init; cond; update) { code; }

Code: (while) [Select]
init;
while(cond) { code; update; }

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #528 on: January 13, 2012, 10:37:20 pm »

I don't know for sure, but Google is telling me C# throws an exception at array out of bounds conditions...I suppose you could catch the exception, but preventing it from happening is easier...

Yeah, if it throws an exception than that is too much work.  :)
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #529 on: January 13, 2012, 10:38:24 pm »

And I was taught not to use do loops.  Why exactly did you have that as a do loop initially, anyway?  A while loop is a check that stops the player from doing anything illegal to begin with and a do loop means the content will happen at least once, so you need to make sure it's a legal move first.

I'm not sure I understand your concerns about Do-While loops (I'm using Mego's #2 example right now, because it feels the most familiar).  Obviously those four lines were not the whole code - because of the way it's nested in an if-else ladder, it will never reach that loop if it's operative condition isn't already true.  I also set it up that way because I forgot there exists a While loop as opposed to Do-While loops.

As for ANDs and ORs, I just plain got confused, and thought OR meant it would kick out if any condition turned False.  Which is obviously dumb.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #530 on: January 13, 2012, 10:40:42 pm »

And I was taught not to use do loops.  Why exactly did you have that as a do loop initially, anyway?  A while loop is a check that stops the player from doing anything illegal to begin with and a do loop means the content will happen at least once, so you need to make sure it's a legal move first.

I'm not sure I understand your concerns about Do-While loops (I'm using Mego's #2 example right now, because it feels the most familiar).  Obviously those four lines were not the whole code - because of the way it's nested in an if-else ladder, it will never reach that loop if it's operative condition isn't already true.  I also set it up that way because I forgot there exists a While loop as opposed to Do-While loops.

As for ANDs and ORs, I just plain got confused, and thought OR meant it would kick out if any condition turned False.  Which is obviously dumb.

I think you need some programming supplements. Try coffee.

MaximumZero

  • Bay Watcher
  • Stare into the abyss.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #531 on: January 13, 2012, 10:43:34 pm »

Coffee is not strong enough. I drank 4 Monsters and a Mountain Dew for my final and freaking aced it in C++. I did none of the above in VB. Coincidence? I think not.
Logged
  
Holy crap, why did I not start watching One Punch Man earlier? This is the best thing.
probably figured an autobiography wouldn't be interesting

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #532 on: January 13, 2012, 10:48:04 pm »

You do realize that the vitamin B dose on those energy drinks is high enough that you are not supposed to drink more than 2 in one day, for the sake of your liver?
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

MaximumZero

  • Bay Watcher
  • Stare into the abyss.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #533 on: January 13, 2012, 10:48:31 pm »

My liver has seen much, much worse. It's cool.
Logged
  
Holy crap, why did I not start watching One Punch Man earlier? This is the best thing.
probably figured an autobiography wouldn't be interesting

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #534 on: January 13, 2012, 10:48:36 pm »

No, you aced C++ because Bjarne Stroustrup was guiding you. Alan Cooper was giving you the finger.

MaximumZero

  • Bay Watcher
  • Stare into the abyss.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #535 on: January 13, 2012, 10:51:46 pm »

MaximumZero has been possessed!
MaximumZero keeps muttering "Final Project"...
Logged
  
Holy crap, why did I not start watching One Punch Man earlier? This is the best thing.
probably figured an autobiography wouldn't be interesting

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #536 on: January 13, 2012, 10:53:33 pm »

Stargrasper, I did check array bounds. In the first one, I check that yCurrent >= 1, so that there's no errors from yCurrent-1. In the second, I have yCurrent >= 0 in the while conditions.

Why wouldn't you use a for loop with multiple conditions? There's nothing wrong with it, especially when you consider that the following code examples are equivalent:

Code: (for) [Select]
for(init; cond; update) { code; }

Code: (while) [Select]
init;
while(cond) { code; update; }

Alright.  I'm an idiot that didn't pay close enough attention to your code.  Moving along.

Like I said, the reason I don't use for loops with multiple conditions is that it's entirely a stylistic thing.  I don't know why I was taught not to do that.  We were taught that it was possible but told not to do it.  Yes I'm entirely aware of the equivalency.  When I start off by saying it's a stylistic thing, please assume I know what I'm talking about and am doing it my way for a particular reason.

And I was taught not to use do loops.  Why exactly did you have that as a do loop initially, anyway?  A while loop is a check that stops the player from doing anything illegal to begin with and a do loop means the content will happen at least once, so you need to make sure it's a legal move first.

I'm not sure I understand your concerns about Do-While loops (I'm using Mego's #2 example right now, because it feels the most familiar).  Obviously those four lines were not the whole code - because of the way it's nested in an if-else ladder, it will never reach that loop if it's operative condition isn't already true.  I also set it up that way because I forgot there exists a While loop as opposed to Do-While loops.

As for ANDs and ORs, I just plain got confused, and thought OR meant it would kick out if any condition turned False.  Which is obviously dumb.

Okay.  So long as it's impossible to get to that code when with an illegal move.  No offense, but all of my code tutoring has told me that when given a code excerpt unless you know enough about a person's skill to say otherwise, always assume the worst.

I don't use do loops often just because I was taught not to use them.  I was taught that if there is a block of code that you need to execute at least once and potentially an indeterminate number of times, use a boolean to control the loop and ensure that it executes at least once.  I was taught that there is no other circumstance where you would want to use a do loop instead of a while or for loop.  In your case, that's not necessary; just putting the conditions in the while will work.  I'm not saying your way is wrong.  I'm saying it's contradictory to how I would handle things and was thus curious as to why you were electing to do it that way.

Everyone, I have stylistic things I do that I do specifically because I was taught them when I was taught to program or developed them as habits later on and as I'm teaching others, have found that people usually learn better coding practices in the end by doing these.  I'd be happy to discuss them, though.
Logged

MaximumZero

  • Bay Watcher
  • Stare into the abyss.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #537 on: January 13, 2012, 10:54:57 pm »

So, our teacher threatening to auto-flunk us for using GOTO statements is stylistic? Is this a good or bad thing?
Logged
  
Holy crap, why did I not start watching One Punch Man earlier? This is the best thing.
probably figured an autobiography wouldn't be interesting

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #538 on: January 13, 2012, 11:00:35 pm »

So, our teacher threatening to auto-flunk us for using GOTO statements is stylistic? Is this a good or bad thing?

1. It's not stylistic, it's to keep you from wrecking a computer's memory.
2. It's a good thing.

GOTO Statement Considered Harmful.

@Stargrasper: Yes, I know you said stylistically, but I was curious as to whether or not there was any reason given by your prof.

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #539 on: January 13, 2012, 11:03:05 pm »

I don't use do loops often just because I was taught not to use them.  I was taught that if there is a block of code that you need to execute at least once and potentially an indeterminate number of times, use a boolean to control the loop and ensure that it executes at least once.  I was taught that there is no other circumstance where you would want to use a do loop instead of a while or for loop.  In your case, that's not necessary; just putting the conditions in the while will work.  I'm not saying your way is wrong.  I'm saying it's contradictory to how I would handle things and was thus curious as to why you were electing to do it that way.

Everyone, I have stylistic things I do that I do specifically because I was taught them when I was taught to program or developed them as habits later on and as I'm teaching others, have found that people usually learn better coding practices in the end by doing these.  I'd be happy to discuss them, though.

Sounds to me like you had a stubborn teacher.  Why would Do-While loops exist if there was never a good reason to use them?  Don't worry though, you have inspired me to be diligent about examining loops.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.
Pages: 1 ... 34 35 [36] 37 38 ... 796