Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 547 548 [549] 550 551 ... 796

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

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8220 on: October 18, 2015, 06:30:26 pm »

No, he means his teacher "looks unkindly" on repeated code sections, which is the opposite of "code reuse".

3man75 is thinking "but there was no other way!" when he does this, clearly. but that's always wrong. There's always a way, and usually not that difficult.
« Last Edit: October 18, 2015, 06:32:33 pm by Reelya »
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8221 on: October 18, 2015, 06:31:57 pm »

No, he means his teacher "looks unkindly" on repeated code sections.
Yeah, repeating the same check is kind of odd.
But in general, reuse between programs saves time and effort if you can do it.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8222 on: October 18, 2015, 06:33:10 pm »

There's always a way. My sample version shows one way.

if you want to get rid of the looping, you have to stop using the "while" loop in the code you showed.

I have to use infinite loops from what I remember though. I'm also sure that there IS a way I just don't know it. What I need to do is make it so that I can run checks even after a tie but that simply won't happen even when I make checks a lower part of the code. Still don't know why. I also know that one student did it in less code but I don't recall what he did at all.

@3man75: ...Reusing code is the bread and butter of programmers.  Seriously, your teacher either doesn't get it or doesn't get it.

Wait people re-use code for jobs and such? Wouldn't surprise me to be mislead since stories of my teachers incompetence sometimes is a topic of discussion (outside the classroom). Main problem for me is her vague instructions and her iron will to make it so that if something is wrong then she will only tell you if you ask/feels like saying that something your doing is wrong.

No, he means his teacher "looks unkindly" on repeated code sections, which is the opposite of "code reuse".

Ninja'd. So repeated code is bad but code reuse is good? I just googled that term and it's apparently not so hot. What's the difference?
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8223 on: October 18, 2015, 06:35:08 pm »

Code reuse is when you go "Oh, I did that for this earlier thing" and copy that section.
Repeating code is when you run the same check twice in the same program.
But yeah, I don't see why RPS needs to nest loops.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8224 on: October 18, 2015, 06:37:20 pm »

It only counts as "reuse" if you package it in a function. It's not called "reuse" if you cut and paste a chunk of code so that there are now two, identical chunks, it's refered to as "royally fucking yourself over if anything changes later".

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8225 on: October 18, 2015, 06:38:06 pm »

It only counts as "reuse" if you package it in a function. It's not called "reuse" if you cut and paste a chunk of code so that there are now two, identical chunks, it's refered to as "royally fucking yourself over if anything changes later".
Heh.  True that.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

nogoodnames

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8226 on: October 18, 2015, 06:41:46 pm »

Nothing immediately jumps out. Care showing the output for clarification?

Spoiler (click to show/hide)

I put an input validation twice in the code which I think counts as "reusing code" which is something my teacher looks unkindly too apparently. To me their was just no other way to shuffle or merge the code around without having crashes, breaks, or other errors.

What you could do is have basically the whole program in a single loop. If the input is invalid or if there is a tie then repeat the loop, otherwise finish the program. It would essentially act the same as you have it now, except it will generate a new computer guess for each invalid input and require a bit more processing time. Shouldn't matter for this.
Logged
Life is, in a word, volcanoes.
                        - Random human lord

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8227 on: October 18, 2015, 06:46:33 pm »

Nothing immediately jumps out. Care showing the output for clarification?

Spoiler (click to show/hide)

I put an input validation twice in the code which I think counts as "reusing code" which is something my teacher looks unkindly too apparently. To me their was just no other way to shuffle or merge the code around without having crashes, breaks, or other errors.

What you could do is have basically the whole program in a single loop. If the input is invalid or if there is a tie then repeat the loop, otherwise finish the program. It would essentially act the same as you have it now, except it will generate a new computer guess for each invalid input and require a bit more processing time. Shouldn't matter for this.
It actually should generate a new guess.  That's how real RPS works anyway.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8228 on: October 18, 2015, 06:46:51 pm »

I have to use infinite loops from what I remember though.
Put the loop outside the entire game. Then make it so that the game repeats as long as you don't enter a zero. add "0 to quit" to your instructions, too.

Ninja'd. So repeated code is bad but code reuse is good? I just googled that term and it's apparently not so hot. What's the difference?

Let me clarify, because the terms are vague. It's BAD to just cut and paste code all over the place so that you have the same code written more than once.

It's GOOD to take already-working code from an old program and use it again, or to package a commonly-used section of code into a function.

It's also GOOD to keep an eye out for a section of code which is repeated, but only one value used changes each time, then you can make that section of code into a function and pass the "value that's different each time" in as a function parameter. So, be on the look out for large sections of code which have a repeating structure, and turn those sections into functions.
« Last Edit: October 18, 2015, 06:48:47 pm by Reelya »
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8229 on: October 18, 2015, 06:47:45 pm »

Ninja'd. So repeated code is bad but code reuse is good? I just googled that term and it's apparently not so hot. What's the difference?

Let me clarify, because the terms are vague. It's BAD to just cut and paste code all over the place so that you have the same code written more than once.

It's GOOD to take already-working code from an old program and use it again, or to package a commonly-used section of code into a function.

It's also GOOD to keep an eye out for a section of code which is repeated, but only one value used changes each time, then you can make that section of code into a function and pass the "value that's different each time" in as a function parameter. So, be on the look out for large sections of code which have a repeating structure, and turn those into functions.
Yeah, this.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8230 on: October 18, 2015, 07:00:59 pm »

Spoiler (click to show/hide)

Like so? Not going to lie this program is making me smile in frustration and i'm going to be asking how to do this again next class.
Logged

nogoodnames

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8231 on: October 18, 2015, 07:20:06 pm »

Well, if you do it that way you need a do loop not a while loop, which is basically the same but runs through once and then checks the condition at the end instead of at the start. What you have now won't work the way you want to do. I was thinking of something a bit different, but I don't have the time to go too in depth right now.

Reelya's code from a few posts back should work, but it doesn't loop if there's a tie. You should take a look at it.
Logged
Life is, in a word, volcanoes.
                        - Random human lord

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8232 on: October 18, 2015, 07:35:17 pm »

you're over complicating things 3man75.

you don't need ALL the checks in the outer loop, that's retarded and makes no sense at all. Also, do-while loops are often more useful than while loops because you don't need to repeat yourself. the "do" loop does the thing first, then the check last, which is exactly what you want when getting input, then checking input, then getting the user to do the input again if it was wrong.

Here's the basic framework:

Spoiler (click to show/hide)
« Last Edit: October 18, 2015, 07:45:21 pm by Reelya »
Logged

Avis-Mergulus

  • Bay Watcher
  • This adorable animal can't work.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8233 on: October 19, 2015, 05:49:52 am »

So I keep fucking up with the bloody answer checking machine, it's straight-out unbelievable at this point.
The dealio this time was, there's a plaintext file which contains the dimensions of a matrix (M, N) and the number of queries to it (K) in the first line, the matrix itself in the next M lines, and the queries in the K lines after that. The queries are in x1, y1, x2, y2 format, and the program is supposed to calculate the sum of all elements of the matrix in the rectangle that has x1,y1 as its top left corner, and x2, y2 as its bottom right corner. Corners are included. The numbers in the matrix are positive or negative integers.
So I did this:
Spoiler (click to show/hide)

and it seems to work perfectly well for me with multiple examples, but when I submit it, the machine insists that I fucked up almost everything. Is there anything that seems obviously wrong with the code here?
Logged
“See this Payam!” cried the gods, “He deceives us! He cruelly abuses our lustful hearts!”

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8234 on: October 19, 2015, 05:59:52 am »

Avis-Mergulus:
What does it say you messed up with?
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.
Pages: 1 ... 547 548 [549] 550 551 ... 796