The Thread for Programming

here's a good place for FRIENDLY, ENJOYABLE, and otherwise very GENERAL discussion!
User avatar
sonicspin
wishes
Banned
Posts: 310
Joined: 8 years ago
First name: t
Pronouns: whatever

Re: The Thread for Programming

Post by sonicspin »

Rénà wrote:its a double major in photography and programming

photographic programming
it's the future
soon OCR devkits will appear, and people will write code, not type it
the future, man

NINJAEDIT: then just use fstream c:
first line input second line output
2ND NINJAEDIT: damn it renanjaed
3RD NINJAEDIT:
nope.png
nope.png (5.08 KiB) Viewed 3241 times
d̀͢͏̷͢ȩ̢͡͞͠-̸̢͟҉g̶̡͟͞҉e͞͏͞͞͠n͢҉e̸̛͠͞r͟á̡͠͡ţ̛́͜i̧̛o̵̢ń̴͠͝͝
dA
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 »

Played around with the sizeof operator for a bit and I get it now.
I know WhattayaBrian explained it earlier but I wasn't getting it quite as much at the time. When finding the length of arrays, the first sizeof gives you the sum of all the bytes of the data types in the arrays. So an array with 10 int values is int * 10, or 8 bytes * 10 which is 80 bytes.
The second sizeof is just the size of an individual data type being stored in that array. So when you put [0] in there, it doesn't even have to be zero. You're just asking for the size of the data type in slot 0, which is an int (like the rest of the things in the array) which is 8 bytes, and that's why you can also just do sizeof(int), since both will give you 8 bytes.
Then 80/8 = 10.

Oh man, figuring things out!
Image
Image
Image
Image
Image
Image
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

You're working with a compiler where ints are 8 bytes?
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
sonicspin
wishes
Banned
Posts: 310
Joined: 8 years ago
First name: t
Pronouns: whatever

Re: The Thread for Programming

Post by sonicspin »

WhattayaBrian wrote:You're working with a compiler where ints are 8 bytes?
Turbo c++
or emacs
d̀͢͏̷͢ȩ̢͡͞͠-̸̢͟҉g̶̡͟͞҉e͞͏͞͞͠n͢҉e̸̛͠͞r͟á̡͠͡ţ̛́͜i̧̛o̵̢ń̴͠͝͝
dA
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

Well, it'll be a bit more complicated overall, but I recommend grabbing an express version of Visual Studio for use. It's free, and pretty much the industry standard for everything but Mac development.

It'll also help get you used to multi-file development if you are not already.
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 »

WhattayaBrian wrote:You're working with a compiler where ints are 8 bytes?
Oops! Sorry, I was writing that explanation after just having been playing around with a double array. No, my ints are 4 bytes.

And on the topic of IDEs, I've been using Visual Studio Express on my PC though I just noticed I can get a free copy of Professional from my university's website. I'm downloading that now but it's kind of annoying you get an .iso instead of an installer but whatever. I have a big ol' stack of DVD-R's by my desk for this reason.
For my Macbook I use Xcode which is free and actually really nice as well.
Image
Image
Image
Image
Image
Image
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

Oh, don't burn the iso. Just mount it. I think I've used DaemonTools in the past? If someone has other suggestions, by all means, but don't feel like you need to burn it.

Also I hate Xcode. :P
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 »

Well if I burn it can I reuse it in the future?
I'm not sure how these university things work, but if I can reuse it I think I'll want to burn it.
edit: actually I think they send you an activation code in your email so it's probably only good for as long as the activation code is I'd guess. Unless that's reusable too? Or it might expire. I don't know. I'll figure it out.

And why the hate for Xcode? :c
Image
Image
Image
Image
Image
Image
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

You can reuse it as an iso too.

Honestly I don't really have a good reason for hating Xcode other than it's weird and different. The interface makes no sense to me.

But it does compile fast, that's for sure.
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 »

Yeah, Xcode took me a bit to get used to (not to say there's any IDE I really know my way around).
It kinda threw me off that it didn't have a tab-system for files like every other IDE in existence has. Regardless, though it is different, like you mentioned it compiles fast and is also really polished. Like, it seems that they had spare time after making it as functional as it is, so they added animations and whatnot just for the heck of it. (If you start an open parenthesis, when you close it, the open one from earlier kinda pops out for a second so you know which set of brackets you just closed. I know most IDEs will indicate this for you as well but it's kinda funny they actually made a bubbly animation for it in an IDE.)
I don't know; I don't mind using it!

Also apparently if you're an iOS developer it has a super amazing iOS emulator built in that puts Android's to shame (though that probably isn't hard, cause Google's Android emulator is pretty clunky and takes forever to launch).
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 with my assignment I mentioned earlier, it converts tons into other units. As it stands, the units it converts to give pretty big numbers. Ounces being one of them, it pretty much always spits out scientific notation for them and I want to know if that's a bad thing.

Like, I could add

Code: Select all

#include <iomanip>
//at the beginning,
//and then
cout << fixed << setprecision(2)
//before spitting out the conversions
This would make it so not only would it not give scientific notation, but it would only give numbers to a certain amount of decimals places (we're expected to use doubles for everything).

I've already submitted my code, but it hasn't been graded yet, so it's not too late to resubmit. Do you think I should add something like that?

I've never had anything graded in this class yet, so I'm not sure what's expected of me. I think whatever he expects of me, I can do, I just don't know what it is. I don't want to do too much and then get a crap mark because I made the program too complex, and I don't want to do too little and lose marks for obvious reasons.

wat do
Image
Image
Image
Image
Image
Image
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

As a general rule, just follow the professor's specifications, and anything else is up to you ("implementation defined"). If they said they wanted a specific format for the output of the floating point numbers, then follow that.

That said, this assignment is probably more about rudimentary arithmetic in programming than text formatting, so I think you're fine.
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
sonicspin
wishes
Banned
Posts: 310
Joined: 8 years ago
First name: t
Pronouns: whatever

Re: The Thread for Programming

Post by sonicspin »

we got a class on recursive functions (math functions), so now I understand how fibonacci works, so I coded it in C++ in the shortest way possible...It gets slow around 36-37, i5 processor

Code: Select all

#include <iostream>
unsigned long long fibo(unsigned long long input){
	if (input == 0LL){
		return 0;
	}
	else if (input == 1LL){
		return 1;
	}
	else{
		return fibo(input - 1LL) + fibo(input - 2LL);
	}
};
int main(){
	std::cout << "fibonacci number enter" << std::endl;
	unsigned long long inputty;
	while (true){
		std::cin >> inputty;
		if (inputty == 0LL){
			goto end;
		}
		std::cout << std::endl;
		std::cout << fibo(inputty);
		std::cout << std::endl;
	}
	end:
	;
}
d̀͢͏̷͢ȩ̢͡͞͠-̸̢͟҉g̶̡͟͞҉e͞͏͞͞͠n͢҉e̸̛͠͞r͟á̡͠͡ţ̛́͜i̧̛o̵̢ń̴͠͝͝
dA
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

It's preferable to simply use "break;" where you have "goto end;"

The suffix for unsigned long long is "ULL", not "LL".

Functions do not need a semicolon at the end of their scope-finishing brace.

Since you're new to recursion, you may not quite understand why it starts to get slow around 36. May I suggest adding a simple:

Code: Select all

std::cout << "Input: " << input << std::endl;
...to the beginning of your fibo function? It will make it very clear just how many calls you're doing.

...

Except that won't work. Go ahead and try it, and you'll realize that you'll never finish. Printing that many values would take a very, very long time.

Instead, make a global unsigned called "calls", initialize it to 0, and "++calls;" at the beginning of your function. Then, once it's done, print out its value.

You've now seen first-hand why people invented memoization.
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 »

and then implement it with a loop and find out exactly how expensive recursion is when you don't need it
User avatar
sonicspin
wishes
Banned
Posts: 310
Joined: 8 years ago
First name: t
Pronouns: whatever

Re: The Thread for Programming

Post by sonicspin »

WhattayaBrian wrote:It's preferable to simply use "break;" where you have "goto end;"

The suffix for unsigned long long is "ULL", not "LL".

Functions do not need a semicolon at the end of their scope-finishing brace.

Since you're new to recursion, you may not quite understand why it starts to get slow around 36. May I suggest adding a simple:

Code: Select all

std::cout << "Input: " << input << std::endl;
...to the beginning of your fibo function? It will make it very clear just how many calls you're doing.

...

Except that won't work. Go ahead and try it, and you'll realize that you'll never finish. Printing that many values would take a very, very long time.

Instead, make a global unsigned called "calls", initialize it to 0, and "++calls;" at the beginning of your function. Then, once it's done, print out its value.

You've now seen first-hand why people invented memoization.
at 35 the calls are more than the triple than the number
d̀͢͏̷͢ȩ̢͡͞͠-̸̢͟҉g̶̡͟͞҉e͞͏͞͞͠n͢҉e̸̛͠͞r͟á̡͠͡ţ̛́͜i̧̛o̵̢ń̴͠͝͝
dA
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 the .iso for Visual Studio Professional ended up being like 6+GB so it was too big to be burned to a disc.
But Windows 8 lets you mount .iso's just by right clicking them, which I didn't know until now. So yeah, that's pretty cool!
Image
Image
Image
Image
Image
Image
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

Pop quiz! This requires some beginner level class and polymorphism knowledge.

Code: Select all

int gNum = 1;

class Foo
{
private:
	int mNum;
public:
	int func1()
	{
		return gNum;
	}

	virtual int func2()
	{
		return gNum;
	}

	int func3()
	{
		mNum = 1;
		return mNum;
	}

	virtual int func4()
	{
		mNum = 1;
		return mNum;
	}

	int func5()
	{
		int lNum = 1;
		return lNum;
	}

	virtual int func6()
	{
		int lNum = 1;
		return lNum;
	}
};

int main()
{
	Foo * test = nullptr;
	
	// #1
	//test->func1();
	
	// #2
	//test->func2();
	
	// #3
	//test->func3();
	
	// #4
	//test->func4();
	 
	// #5
	//test->func5();

	// #6
	//test->func6();
	
	return 0;
}
Which of the preceding lines, if uncommented, will crash, and why? The answer is not "all of them".

Try to figure it out without running the code yourself. Really think about what's going on here.
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 »

Ha, I only recently learned polymorphism in Java, and I don't know anything about virtual functions in C++. I think they have something to do with class inheritance though, so the problem might have something to do with that?
I'll look into that stuff and then try to find the answer. I'm still pretty new to C++ so I'll try to figure it out soon!

Thanks for the quiz thing though, that's kinda fun and forces me to learn things I might not have known, or put into practice things I do know.
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 »

I feel like the material in this course is being covered in a really strange order.
Last class was on file IO and now we're doing booleans and if statements.
Image
Image
Image
Image
Image
Image
User avatar
docopoper
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla non pharetra enim, nec maximus odio.
Posts: 78
Joined: 11 years ago
First name: Shane Farrell
Pronouns: they/he
Location: Ireland

Re: The Thread for Programming

Post by docopoper »

0_o
The first thing I would do with infinite power would be to make myself a cave where I could look at my shadow forever.

Image <- Go team Yeah Doctor Shemp.!
Image <- That's everyone being nice to me. ^^

I made a game called Utter Confusion! Play it! :D
It's a lot of fun and has been incredibly popular at every indie game dev party I've brought it to.
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 don't know.
I was glad when we were doing file IO cause that's actually something I didn't know how to do and I learned it but now we're doing really basic stuff again.
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 »

Yeah.
Although actually I did learn something today. Not something super important, but I found out that "else if" isn't really a keyword on its own.
You're basically just stringing together a bunch of if else statements, but in the else of the previous statement you're adding another if. Technically you could indent them infinitely to the right but that would be stupid so we just look at it as "if", "else if", "else".

Not really important but I never caught that until today.
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 for one of the optional exercises which I never touched until just now, there was a cool little ball physics demo made with SDL (I attached it, I don't think anyone would care since the project is publicly available to download on their site) and you can basically tinker around with the code and add things and whatnot.

(since it's not explained, a and d move the ball left and right, move the cursor to change direction/force, click to throw, escape to quit)

I managed to add an ability to move the ball up and down with w and s:

Code: Select all

switch(key)
	{
	case SDLK_d: //move ball right
		pos_x_init += 0.01;
		break;
	case SDLK_a: //move ball left
		pos_x_init -= 0.01;
		break;
	case SDLK_w: //move ball up
		pos_y_init += 0.01;
		break;
	case SDLK_s: //move ball down
		pos_y_init -= 0.01;
		break;
	}
And since that lets you go under the table, I made the bottom of the table bouncy as well by adding an else if statement to the HandleBall() function (specifically into the table top collision if statement):

Code: Select all

else if ((pos_y + radius > 1.0) && (last_pos_y + radius <= 1.0)) //If top of ball is above table top and ball was below table last time checked
	{
		//And if the ball is not past either edge of the table
		if (pos_x < 1.5 && pos_x > -1.5)
		{
			//Then reverse the ball's velocity and steal some kinetic energy
			vel_y = -vel_y * 0.9;		//Energy lost to "Elastic Collision"

			//and set its top on the table
			pos_y = 1.0 - radius;

			//Energy is also lost to "Rolling Friction"
			if (vel_x > 0)
				vel_x = vel_x - 0.01 * mass * dt;
			else if (vel_x < 0)
				vel_x = vel_x + 0.01 * mass * dt;
		}
	}
Attachments
Bounce.zip
(288.66 KiB) Downloaded 29 times
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 question about the thing ball physics thing I posted earlier.
When people write something like that, would they use a 3D modeling program for something like that, or is that still in the territory of things easy enough to model with just code? I mean, the only somewhat complex thing there is the tiles on the table, and I was looking through the code of how those are generated, and I'm not sure if stuff like that is just something you get used to or if you just have a program where you can model out a simple shape and then it generates code for it.

I honestly don't know much about how this stuff works so if I said something that makes no sense, sorry.
Image
Image
Image
Image
Image
Image
Post Reply