The Thread for Programming

here's a good place for FRIENDLY, ENJOYABLE, and otherwise very GENERAL discussion!
Frozelar
Retired Screamer
Posts: 5
Joined: 11 years ago
Location: The Place You Wish You Were

Re: The Thread for Programming

Post by Frozelar »

Hey, thank you, Rena and WhattayaBrian! Y'all are the best.
The benefits of minimizing dependencies actually made perfect sense. Thanks!
And the precompiled headers is new to me, but the explanations made perfect sense. Thanks again!

I think the problem did actually have to do with having global variables in Include.h. I ended up just putting everything in one header file. I might try to divide it up again in the future and take advantage of precompiled headers though.
Ashan wrote:
WhattayaBrian wrote:

Code: Select all

if ( DoStop >= ( GGFxEngine->GameHasRendered > 1 ? 1 : 2 ) )
Wait...
That's like... They made an if statement a condition for an if statement?
Yeah, pretty much. So the result of

Code: Select all

GGFxEngine->GameHasRendered > 1 ? 1 : 2
is then plopped into

Code: Select all

DoStop >= (the result of the first conditional)
So, say GameHasRendered is greater than 1. That conditional would be true, so it would substitute in 1 where it was originally written (if it were false, it would substitute in 2). Then, it would compare DoStop >= 1 (or >= 2 if the first one were false).
That's how I look at it, but it's probably not the best way to explain it.
(I feel really weird trying to explain things as if I know anything more than you, haha.)
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Yeah, I get what it does.

Also, I did the laziest thing today and I feel very dirty about it.

Code: Select all

    if(atomName == "Be")
        return 3;
    else if(atomName == "C")
        return 4;
    else if(atomName == "Si")
        ...
        ...
    else if(atomName == "I")
        return 7;
    else if(atomName == "Xe")
        return 8;
    else 
        return 999; //return an extreme outlier (easy to tell if a mistake is made on respective line)
I was literally laughing as I wrote it but I don't care, I'm leaving it.
Image
Image
Image
Image
Image
Image
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

You may want to check out std::map, which lets you type any type to any other. Like:

Code: Select all

std::map<std::string, unsigned> PeriodicMap;
// init values
PeriodicMap["Be"] = 3;
PeriodicMap["C"] = 4;
// etc
And then later, when you want to get the values back, you can just do:

Code: Select all

return PeriodicMap[atomName];
You'll need to do a bit more for proper air checking though.
If you read this post and thought "Wow, what a swell guy, I sure would like to hear his voice and also watch videogames?" then do I have a link for you.

Current Game: Distorted Travesty 3
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

The assignment specifically said to use a bunch of if statements.

Also did you just say air checking?
Image
Image
Image
Image
Image
Image
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

It brings me an inordinate amount of joy to do so.

#justprogrammerthings
If you read this post and thought "Wow, what a swell guy, I sure would like to hear his voice and also watch videogames?" then do I have a link for you.

Current Game: Distorted Travesty 3
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Image
Image
Image
Image
Image
Image
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

So I got a 98 on my CS exam.

It's funny, I actually immediately noticed 2 things I did wrong in the code itself as I read it again (I mentioned before, I never set the character back to something other than \n so it would only get the third character on the second line) and the other thing is I made a for loop like this:

Code: Select all

for(int i = 0; i < 2; i++)
{
    //code and stuff
    i++
}
but they didn't notice that either.

The thing I lost marks on though is pretty hilarious. They always want us to add the "program purpose" in our header docs which usually say something useless like "test functions", but I don't know. They want us to do it.
For some reason I did this:
http://i.imgur.com/3EPXATy.jpg
That was literally all I lost marks for. Okay!
Image
Image
Image
Image
Image
Image
User avatar
ano0maly
Discord User
Posts: 2835
Joined: 11 years ago

Re: The Thread for Programming

Post by ano0maly »

Well that's because they want the students to think in terms of conceptual problem-solving instead of narrowly looking at just codes.
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

Why is there code/grading up on a whiteboard?
If you read this post and thought "Wow, what a swell guy, I sure would like to hear his voice and also watch videogames?" then do I have a link for you.

Current Game: Distorted Travesty 3
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

Yeah but, even then...shouldn't it be on paper? Do they have each student come up and write code on the whiteboard in sequence?

I can't wrap my head around this.
If you read this post and thought "Wow, what a swell guy, I sure would like to hear his voice and also watch videogames?" then do I have a link for you.

Current Game: Distorted Travesty 3
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

Oh. So it is.

Herp.
If you read this post and thought "Wow, what a swell guy, I sure would like to hear his voice and also watch videogames?" then do I have a link for you.

Current Game: Distorted Travesty 3
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Haha, yeah the picture is super close up so the pencil strokes look thick.

Also update:
today my prof's slide said "error checking" but whenever he says it it sounds 100% like he's saying "air checking" so I don't know, it's possible that he's never said air checking before in his powerpoint but I translated it in my head because of how he pronounces it.
Image
Image
Image
Image
Image
Image
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Nobody really mentioned that a side effect of learning programming is you think about it all the time when using computers now.
With all of my playing of BoI:R lately, I've spent a lot of time thinking about the logistics of the random generation and how the game works, so I decided to try and make a little simulator of the homeless beggar guys from the game.

In case you haven't played the game, you can encounter random beggars in levels and you can give them money, one penny at a time. Whenever you donate, there's a chance he'll drop consumable, a trinket, an item, etc. (I actually don't know off the top of my head all he can drop but whatever.)
If he drops an item, he'll disappear so you can't donate to him any more.

I made a little simulator of this in C++. More than anything else, I kind of wanted to try out organizing a project a bit more properly than I'm used to doing (i.e. not writing all the code in the main function) so I gave that a shot. It's far from perfect, I didn't really know what odds I wanted to do for drops so I just did what I did, and I only made it so he can drop one of 5 things per item category but it would be easy to add more.

http://pastebin.com/vs3tbURR

I kind of had to experiment around with things as I went and it's very possible I did things in ways you didn't normally do them. For example, the Isaac object was originally in the bumGuy class rather than the main, but that seemed bad and didn't make sense so I ended up just passing in the Isaac object by reference. I don't know if there's a better way to do this, if you should use friend or something, I'm pretty sure in Java you use extends but I just kind of did what I knew to do so yeah. There's a thing!
Image
Image
Image
Image
Image
Image
Frozelar
Retired Screamer
Posts: 5
Joined: 11 years ago
Location: The Place You Wish You Were

Re: The Thread for Programming

Post by Frozelar »

I would think it would be easier to have, like, pretty much everything in a programming class be written on the computer, but then again I don't know anything about it
User avatar
pholtos
Loves adorable things.
Posts: 1590
Joined: 13 years ago
Location: One of the States in the Center of the U.S.

Re: The Thread for Programming

Post by pholtos »

Interesting thing from my past. I could pass programming class exams no problem. Actually coding? I was terrible. So yeah, there's that.
Host and Organizer of the Rando Pokemon Tournaments. Completed: I, II, III, IV, V
Dealer of the Pokermon Discord Tourneys.

ImageImageImageImage
ImageImageImageImage
ImageImageImageImage

I do LPs, check them out if you'd like.

Currently playing:
Image

The 500 char limit is evil. :P
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Yeah, I'm hoping that they're only doing paper exams for now since it's such a huge class. Hopefully once the classes get narrowed down to just people majoring in CS we can do typed exams cause programming on paper is the worst.

There were several points where I almost didn't end lines with a semicolon because when I'm typing that's just second nature for me to hit when I end a line, but it's not on paper. Everything feels wrong writing on paper.
Image
Image
Image
Image
Image
Image
User avatar
pholtos
Loves adorable things.
Posts: 1590
Joined: 13 years ago
Location: One of the States in the Center of the U.S.

Re: The Thread for Programming

Post by pholtos »

Ashan wrote:Yeah, I'm hoping that they're only doing paper exams for now since it's such a huge class. Hopefully once the classes get narrowed down to just people majoring in CS we can do typed exams cause programming on paper is the worst.
Sorry but this wasn't the case for me.
College in terms of a CS major are half learning how to take tests and half learning how to code.

It really doesn't matter what major you are in, you'll have to take tests.
Host and Organizer of the Rando Pokemon Tournaments. Completed: I, II, III, IV, V
Dealer of the Pokermon Discord Tourneys.

ImageImageImageImage
ImageImageImageImage
ImageImageImageImage

I do LPs, check them out if you'd like.

Currently playing:
Image

The 500 char limit is evil. :P
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Well yeah, but the tests themselves aren't my concern. I just hate handwriting programs.
Image
Image
Image
Image
Image
Image
Frozelar
Retired Screamer
Posts: 5
Joined: 11 years ago
Location: The Place You Wish You Were

Re: The Thread for Programming

Post by Frozelar »

Yeah, I can imagine after programming on the computer for such a long time, handwriting it would just feel really weird.
I might try it some time just to see.
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Speaking of that, remember this:
Ashan wrote:Hell, I forgot to air check (by the way, not sure if it's actually called that cause I Googled it and nothing came up, but we were told checking if i/o files exist and giving an error if they don't is called air checking) and realized it after I wrote everything else out so I had to draw a big bubble and write the code in there and draw a big line pointing between 2 other lines of code to show "this code codes here".
Here's what that looked like.
http://i.imgur.com/egaS9DE.jpg

All caps AIR CHECK. I'm so ashamed.
Image
Image
Image
Image
Image
Image
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Considering it's a class of like 2-3 hundred people so there were that many tests to mark, chances are it was marked by a random TA that was really confused.
Image
Image
Image
Image
Image
Image
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

Ashan wrote:BINDING OF ISAAC STUFF
Code critique:
addToInventory(), heldTrinket(), and addToConsumables() should all take const refs instead of value arguments.

getPennies(), printInventory(), printTrinket(), and printConsumables() should all be const member functions.

heldTricket() is a bad function name. It sounds like an accessor for getting your currently held trinket, rather than a function that changes it.

Be careful about using C arrays. For one, it's very rare that it's acceptable to have your size be a magic number. Should generally have something like "const unsigned MAX_CONSUMABLES = 50;". The second thing is that you're not bounds checking in addToConsumables(). The aforementioned variable would help with that.

However, really, just use a vector instead.

Your exit logic is a bit convoluted. It's not terrible, but it's somewhat strange how you're setting flags vs doing things directly. For example, "itemFlag = true;" could just be replaced with "break;" and the program wouldn't change. It could be cleaned up a bit to make it easier to understand.

In consumables(), items(), and trinkets(), you're using a switch case for a bunch of sequential numbers. In situations like this, you can pretty easily convert it into using an array:

Code: Select all

std::string trinkets()
{
	static const unsigned NUM_TRINKETS = 5;
	static const char * trinkets[MAX_TRINKETS] = { "Ace of Spades", "Counterfeit Penny", "Fish Head", "Liberty Cap", "A Missing Page" };
	int x = rand()%5;

	if(x >= 0 && x < NUM_TRINKETS)
	{
		return trinkets[x];
	}
	else
	{
		return "error";
	}
}
I didn't compile this, so I hope it works! A strategy like this makes it a lot easier to add new items in the future.
I did a few paper programming tests at Digipen. They're pretty silly, but at the same time I can understand the desire to test students when they don't have access to google. It's true that programming is less about knowing things and more about knowing how to figure things out, but there are certain things you should know off the top of your head if you want to be considered a programmer professionally.

And, if nothing else, every single on-site programming interview involves writing code on a whiteboard, so at the very least they can claim they are preparing you for that.
If you read this post and thought "Wow, what a swell guy, I sure would like to hear his voice and also watch videogames?" then do I have a link for you.

Current Game: Distorted Travesty 3
devil†zukin

Re: The Thread for Programming

Post by devil†zukin »

User avatar
Alice
Posts: 2367
Joined: 11 years ago
Pronouns: Girl person
Location: Wonderland

Re: The Thread for Programming

Post by Alice »

RenaBeach wrote:this is a neat list, specifically i tried out codecademy and it was pretty cool:

http://www.codecademy.com/
Codeacademy is really neat. I like how their tutorials start at a fairly low tier and on top of that they give you an active preview of what you're doing which helps a lot when you're learning stuff like CSS.
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

I assume argCount is a debug variable?

To date I've only used variadic templates once professionally, so I'm still not quite comfortable with them. You'd definitely have to specify Ret in the template specifier, but does that mean you have to do so for Args as well? If so, that's pretty unfortunate, since it should be able to deduce them from the parameters themselves.
If you read this post and thought "Wow, what a swell guy, I sure would like to hear his voice and also watch videogames?" then do I have a link for you.

Current Game: Distorted Travesty 3
Post Reply