Hey what's up Dawg? (Generic Chat Thread)

General discussion.
User avatar
Saladin
Spider Mastermind
Posts: 8402
Joined: Mon Aug 11, 2003 22:39
Consoles: PS4 PS3 Wii Wii-U PC
Location: DANCE MASTAH!
Contact:

Re: Hey what's up Dawg? (Generic Chat Thread)

Post by Saladin » Thu Dec 07, 2017 02:22

Oh yeah, I see the issue here. So, you have to remember that return only returns the value *to the function that called it*. Not all the way up the call stack.

Think of it like a dinner plate handoff down a line of people. One person passes it to the next, then to the next, one at a time, until the front person sets it on the table. The person at the end can't just pass it to the person at the front.

So, in your original code, you call the recursive stuff, but it never matters, because it only returns that value *to that function*, which you don't set to anything, so it just throws it away! It doesn't pass it along, it passes *its own value*.

For example, if someone were to call your function, they might say...

int myvar = find(a, b);

Right?

But what if they didn't set it to anything? They just put.

find(a, b);

What would be the result? Sure, the function runs, but nothing recorded its value. So what's the point?

The *same thing* happens in your first code.

You call find(index, gcs); , but you don't *set* it to anything, which means that when you do index = 2 * index + 1; and then find(index, gcs); ... you might as well have not even written "find(index, gcs);" because nothing recorded it! You could have written anything, like index = index, and it would have the same effect.

It *does* do the recursion, which I'm sure you saw as you stepped through it, but when it returned the value lower down, the upper functions didn't grab the value, so they just continued on.

So it steps through and everyone returns their own node's value *to no one*.

The one thing I don't understand is what foundIndex is. Is it a global variable? It should be a super weird value if that's the case, and not 0.

But if it were locally defined, and it *started* at zero, then it makes perfect sense your function always returns 0.

A simple run-through:

Start function

Is left child null? No, so let's go left.

....does a shitload of recursion, all irrelevant because no value is recorded....

Ok, done going left, what's next? Well, we're done with this if statement, what's after that?

Oh, return foundIndex, which, in this context, is zero! Wheeeee

Hopefully that made sense. Let me know if you need it explained more clearly.

The key here is that return foundIndex at the end *combined* with the fact that you call find(index, gcs);

If it makes it easier to understand, you could also have said. int foundthething = find(index, gcs); And thennn return foundthething;

return find(index, gcs); is just a shorter, snippier way of writing the same thing.
Quack wrote:ok but so now what do I do besides masturbate

User avatar
kob
CyberDemon
Posts: 12804
Joined: Sun Nov 14, 2004 14:40
Consoles: PS3 - PC
Location: get slam'd
Contact:

Re: Hey what's up Dawg? (Generic Chat Thread)

Post by kob » Thu Dec 07, 2017 03:51

that makes a lot of sense thank you. i guess my expectation was that once the recursive call was done x amount of times, the return at the end of the function would then return it all the way back up, but i can see now why that doesn't work. it'll probably take more attempts at recursion for it to truly stick in my head. like it makes sense now but when you start programming what you learned goes out the window sometimes until you do it enough.

and yeah foundIndex is a local variable, although i realize now that i'm not initializing it to 0 anymore. it used to be until we started messing with the function and then i just forgot to add it back. glad you caught it haha.

User avatar
Saladin
Spider Mastermind
Posts: 8402
Joined: Mon Aug 11, 2003 22:39
Consoles: PS4 PS3 Wii Wii-U PC
Location: DANCE MASTAH!
Contact:

Re: Hey what's up Dawg? (Generic Chat Thread)

Post by Saladin » Thu Dec 07, 2017 04:25

There's just a lot of tiny details that can really screw you over. I cannot tell you how many times I've fucked something up, and a really crazy bug happens, and the core reason was an incredibly minor thing like that. As you program more and more, that'll happen less.

But yeah, that's why it helps to have that low level understanding. It makes it easier to catch why something went wrong. If you go too high level, you'll keep looking for logic errors when the problem is typically simpler than that.
Quack wrote:ok but so now what do I do besides masturbate

User avatar
kob
CyberDemon
Posts: 12804
Joined: Sun Nov 14, 2004 14:40
Consoles: PS3 - PC
Location: get slam'd
Contact:

Re: Hey what's up Dawg? (Generic Chat Thread)

Post by kob » Wed Jan 31, 2018 19:09

hey saladin could you help me understand dynamic binding more? i've been to the lecture, done the lab work and talked to my professor, but i don't really get the usefulness of it.

for example in our assignment the user is supposed to select 3 different translation options (texting, formal, and one we decide - i chose spanish). so e.g. a user wants to text someone "be right back" and then the program should spit out "brb", or if they chose formal it'll spit out "Be right back." etc. we're supposed to use a doubly linked list of base class pointers that point to the type of translation they want. so i'm guessing we'd have an abstract base class called Language or whatever and then derived classes called Texting, Formal and Spanish.

alright so i get the basic idea. you have a class hierarchy and in the base class you declare a function virtual which lets you use a base class pointer to access derived class functions through that pointer. but why is this useful? to my understanding the pointer needs to know what it's pointing to to call the right function e.g.

Language *ptr = new Texting

so now if i call ptr->fn() it'll call Texting's version of fn(). why not just create a Texting object and then say object->fn()? if i have to declare what class the pointer points to what's the advantage?

User avatar
Saladin
Spider Mastermind
Posts: 8402
Joined: Mon Aug 11, 2003 22:39
Consoles: PS4 PS3 Wii Wii-U PC
Location: DANCE MASTAH!
Contact:

Re: Hey what's up Dawg? (Generic Chat Thread)

Post by Saladin » Wed Jan 31, 2018 22:53

You're at the juncture in CS where you're being taught advanced things for advanced things sake.

I would say this *specific* thing doesn't matter. In fact, you may never even use C++ again in your entire career.

But, programming frequently does get weird and abstract like this under certain circumstances. Occasionally, you'll be interfacing with systems that need to be extremely flexible and generic because you'll have limited or no control over the source material or how people call your code.

I know that's not super encouraging, I'm basically telling you there's not necessarily a good reason to do what you're doing.

But you will occasionally run into problems in which you'll have to think like this, so I recommend soldiering through it, and not sweating the details.
Quack wrote:ok but so now what do I do besides masturbate

User avatar
kob
CyberDemon
Posts: 12804
Joined: Sun Nov 14, 2004 14:40
Consoles: PS3 - PC
Location: get slam'd
Contact:

Re: Hey what's up Dawg? (Generic Chat Thread)

Post by kob » Thu Feb 01, 2018 01:07

that makes sense. my professor really hammered home how useful and powerful it is, but i can't wrap my mind around how it's useful. i guess it reduces code bulk somehow? maybe so you only have to write a function once and you can just pass in the ptr and then use downcasting to find out what type it points to and go from there?

i dunno, maybe i have to fiddle around with it to grasp it.

User avatar
Saladin
Spider Mastermind
Posts: 8402
Joined: Mon Aug 11, 2003 22:39
Consoles: PS4 PS3 Wii Wii-U PC
Location: DANCE MASTAH!
Contact:

Re: Hey what's up Dawg? (Generic Chat Thread)

Post by Saladin » Thu Feb 01, 2018 02:34

The idea is supposed to be that you massively reduce the amount of grunt work you have to do in large solutions because everything is made up on the fly, the computer is doing the work for you.

This is amazing in theory, but what tends to happen in practice is that it has too limited of an application, so it has to be extended anyway. Or it's so complicated that no one understands and uses it correctly, so it's underutilized. Etc etc.

CS professors appreciate elegant and useful code. But most commercial code is strung together garbage that was built on a strict budget and didn't have the luxury of a limited goal, focused planning, and lots of dev time.

There's a divide between computer science and software engineering. The former is pure math, theory and excellence. The latter is just trying to get shit done quickly and effectively. Those two things are at odds a lot more than you'd think.
Quack wrote:ok but so now what do I do besides masturbate

User avatar
Mr. Smith
Spider Mastermind
Posts: 9459
Joined: Mon Dec 24, 2007 06:44
Consoles: 360, PC, Apple Faggot Machine
Location: In your sister

Re: Hey what's up Dawg? (Generic Chat Thread)

Post by Mr. Smith » Thu Feb 01, 2018 04:51

Work is getting more stressful. Drawing labs still fucking sucks and makes me nauseous. lol
OBrocks wrote:i need to know if ill actually be getting a penis pump in the mail so i can prepare an explanation for my parents
Saladin wrote:I do not want to play two truths and a lie with Smith.
Quack wrote:PF BATTLE ROYALE 2015: EVERYONE DRAWS SALADIN LICKING HIS OWN BUTTHOLE

User avatar
Saladin
Spider Mastermind
Posts: 8402
Joined: Mon Aug 11, 2003 22:39
Consoles: PS4 PS3 Wii Wii-U PC
Location: DANCE MASTAH!
Contact:

Re: Hey what's up Dawg? (Generic Chat Thread)

Post by Saladin » Thu Feb 01, 2018 08:18

Drawing labs? Is that like processing blood samples and such?
Quack wrote:ok but so now what do I do besides masturbate

User avatar
Mr. Smith
Spider Mastermind
Posts: 9459
Joined: Mon Dec 24, 2007 06:44
Consoles: 360, PC, Apple Faggot Machine
Location: In your sister

Re: Hey what's up Dawg? (Generic Chat Thread)

Post by Mr. Smith » Thu Feb 08, 2018 04:10

Saladin wrote:
Thu Feb 01, 2018 08:18
Drawing labs? Is that like processing blood samples and such?
Yes, I fucking hate needles.
OBrocks wrote:i need to know if ill actually be getting a penis pump in the mail so i can prepare an explanation for my parents
Saladin wrote:I do not want to play two truths and a lie with Smith.
Quack wrote:PF BATTLE ROYALE 2015: EVERYONE DRAWS SALADIN LICKING HIS OWN BUTTHOLE

User avatar
Saladin
Spider Mastermind
Posts: 8402
Joined: Mon Aug 11, 2003 22:39
Consoles: PS4 PS3 Wii Wii-U PC
Location: DANCE MASTAH!
Contact:

Re: Hey what's up Dawg? (Generic Chat Thread)

Post by Saladin » Fri Feb 09, 2018 17:48

Damn, it still makes you squeamish even to be on the other side of it huh?
Quack wrote:ok but so now what do I do besides masturbate

User avatar
Mr. Smith
Spider Mastermind
Posts: 9459
Joined: Mon Dec 24, 2007 06:44
Consoles: 360, PC, Apple Faggot Machine
Location: In your sister

Re: Hey what's up Dawg? (Generic Chat Thread)

Post by Mr. Smith » Sun Feb 18, 2018 18:47

Saladin wrote:
Fri Feb 09, 2018 17:48
Damn, it still makes you squeamish even to be on the other side of it huh?
It does. Old people have the worst veins, lol.
OBrocks wrote:i need to know if ill actually be getting a penis pump in the mail so i can prepare an explanation for my parents
Saladin wrote:I do not want to play two truths and a lie with Smith.
Quack wrote:PF BATTLE ROYALE 2015: EVERYONE DRAWS SALADIN LICKING HIS OWN BUTTHOLE

User avatar
Saladin
Spider Mastermind
Posts: 8402
Joined: Mon Aug 11, 2003 22:39
Consoles: PS4 PS3 Wii Wii-U PC
Location: DANCE MASTAH!
Contact:

Re: Hey what's up Dawg? (Generic Chat Thread)

Post by Saladin » Mon Feb 19, 2018 01:19

Yeah, I don't think I'd have the stomach to be anywhere in the medical profession. Even the simple stuff seems like it wears you down.
Quack wrote:ok but so now what do I do besides masturbate

User avatar
kob
CyberDemon
Posts: 12804
Joined: Sun Nov 14, 2004 14:40
Consoles: PS3 - PC
Location: get slam'd
Contact:

Re: Hey what's up Dawg? (Generic Chat Thread)

Post by kob » Tue Feb 20, 2018 03:56

same

amazing pay and (sometimes) hours though. my sister is a nurse and works 3 12s. would kill for those hours

User avatar
Saladin
Spider Mastermind
Posts: 8402
Joined: Mon Aug 11, 2003 22:39
Consoles: PS4 PS3 Wii Wii-U PC
Location: DANCE MASTAH!
Contact:

Re: Hey what's up Dawg? (Generic Chat Thread)

Post by Saladin » Tue Feb 20, 2018 20:43

Pfft. I dunno about that. Maybe 3 12's at my software job, sure.

But a 12 hour shift on your feet? Caring for sick or injured people? All of whom are stressed out or scared? Some of whom might be combative or trying to scam the place for opiates?

That sounds fucking rough. Although I suppose you at least do get a long weekend to recuperate.
Quack wrote:ok but so now what do I do besides masturbate

Post Reply

Who is online

Users browsing this forum: Baidu [Spider] and 16 guests