Message from @Tero

Discord ID: 620831451272970240


2019-08-28 16:23:29 UTC  

I know 20 year old electronics graduates that won't install an altium product if it pops up windows utc

2019-08-28 16:24:00 UTC  

lol

2019-08-28 21:14:46 UTC  

https://cdn.discordapp.com/attachments/423219052849397773/616380177923964948/39hico4n67j31.png

2019-09-02 03:39:21 UTC  

how do i avoid getting scope fucked in c++

2019-09-02 03:39:32 UTC  

if i have an if statement

2019-09-02 03:39:39 UTC  

to store a smaller or larger int

2019-09-02 03:40:27 UTC  

but then i want to use those variables globally

2019-09-02 04:00:59 UTC  

maybe extern keyword could help?

2019-09-02 04:01:09 UTC  

not sure, I've only done arduino C++, but that's how I usually do it

2019-09-02 05:00:23 UTC  

BJ's PPP has some prank questions, like it gives questions that require knowledge of scope and list sorting before it teaches you it

2019-09-02 14:32:23 UTC  

avoid global variables for most purposes

2019-09-02 15:47:50 UTC  

globals are fine as long as properly named and it has few setters (ideally, it's just set in one place, once)

2019-09-02 15:49:38 UTC  

having used threads a bit it's abundantly possible to make the kinds of errors people supposedly cause with globals by referencing an object or variable with multiple threads

2019-09-02 16:08:09 UTC  

`Although threads seem to be a small step from sequential computation, in fact, they represent a huge step. They discard the most essential and appealing properties of sequential computation: understandability, predictability, and determinism.`

2019-09-02 16:53:33 UTC  

(this is probably where functional fans come in and tell everyone about how having any shared state is bad)

2019-09-02 17:01:34 UTC  

https://cdn.discordapp.com/attachments/423219052849397773/618128396731416603/unknown.png

2019-09-10 03:54:10 UTC  

for some reason this program returns x as 25 million times its number

2019-09-10 03:54:12 UTC  

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
inline void keep_window_open(){ char ch; cin>>ch; }

//for some reason, the square function returns 25 million
int square(int x)
{
x +=x;
cout << x;
}

int main()
{
int i = 0;

cout << "Enter a value.\n\n";
cin >> i;
cout << square(i);
}

2019-09-10 04:02:20 UTC  

seeing all these double >> around are you sure you're not bitshifting something?

2019-09-10 04:02:32 UTC  

i don't actually know C++ though

2019-09-10 04:06:32 UTC  

@Tero that's how you print in c++

2019-09-10 04:06:37 UTC  

And take input

2019-09-10 04:06:48 UTC  

In C++ the '>>' and '<<' indicator data flows with iostream

2019-09-10 04:06:48 UTC  

ok

2019-09-10 04:07:06 UTC  

why's it returning wrong results if not bitshifting then

2019-09-10 04:07:08 UTC  

Why use '+=' here @What Would Jack Conte Do? ?

2019-09-10 04:07:20 UTC  

I don't get the point of the cout in the function

2019-09-10 04:08:09 UTC  

Hmm, that could be something, nesting Couts in the return sequence

2019-09-10 04:08:23 UTC  

Why not ```return x;```?

2019-09-10 04:11:43 UTC  

He's already imported the cmath library, so why didn't he use the pow() function?

2019-09-10 04:12:15 UTC  

both good questions

2019-09-10 04:14:10 UTC  

so apparently the int-returning function square with no return statement results in undefined behaviour

2019-09-10 04:14:30 UTC  

sure do love C/C++

2019-09-10 04:17:08 UTC  

Okay so definitely swap the function to
```int square(int x)
{
x *=x;
return x;
}```

2019-09-10 04:17:41 UTC  
2019-09-10 04:18:13 UTC  

Oh yeah that's super useful

2019-09-10 04:18:17 UTC  

Saves me the trouble of having to unpack Visual Studio's doodads

2019-09-10 04:18:37 UTC  

Saves me the trouble of SSHing

2019-09-10 05:13:18 UTC  

well its an excercise to replicate multiplication without multiplying, like what was done in ancient times

2019-09-10 05:13:20 UTC  

kinda stupid tbh