/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1547829160546.jpg (1000x1125, 746K)

Other urls found in this thread:

vocaroo.com/i/s0DBKcPYMJTK
twitter.com/AnonBabble

Use const

Attached: 1560258429996.webm (1280x720, 1.93M)

This isn't really fair, what if he needed to modify the array?

To me it's an emphasis thing. I put the * next to the type when it seems more logically like it's part of the type, like maybe when I have some overloads that all take a variable x of different types, and one just happens to take a pointer type, it should be int* x, not int *x. I put it next to the variable name when I want to emphasize the "pointerness" of the variable, like if I'm going to do pointer arithmetic or something. It's the difference between the phrases "an object of type X pointer" and "a pointer to an object of type X", they both mean the same thing but they have different implications.

Don't use const then.

Putting it on the left is entirely a sepplescuck thing, because of the asine and retarded shit you were just going on about.
In C, it 100% logically makes more sense to put it on the variable, and that is where it was originally intended to go. Even the standard itself puts it with the variable.

Attached: 1559946247032.jpg (815x1071, 836K)

best drug for programming?
>inb4 muh exercise and sleep
fuck off

Attached: 19129348239.jpg (1280x720, 136K)

a cup of tea

We're talking about C++ you dingus, C doesn't have templates or any kind of high level operations on types so yeah, if I was limiting myself to writing C I probably wouldn't put it to the left ever.

Read the reply chain. The original code this was brought up on was C.

Say i'm using c++ and I have some pointer.
And I'm too lazy to dereference it every time I want to modify its contents.

Is it possible to "convert" the pointer to a regular variable? Like, assigning the contents of the pointer to a variable without copying?

coke/speed

template
T& ref(T* ptr) { return *ptr; }

someone please explain what i'm doing wrong?
I typedef'd a Queue struct which has a head and tail index (int). I then create a test function defined like so:
void test (Queue q) {
q.head++;
}

and a main function like so:
void main ( ) {
Queue que;
que.head++; // (1)
test(que); // (2)
}

For some reason i am unaware of, incrementing the elements of `que` in main (1) works, but passing it to a funciton and incrementing it there (2) does not actually increment its elements, leaving them unaffected. Why is this, and how do i modify the elements of the Queue in main via a function outside of main?


>inb4 "muh c"
please don't bully

ey rick, lemeaskusumthing *scratches head*, consts.

You're passing a copy, pass a pointer instead.

test is getting a copy of the Queue and incrementing the copy not the original.

>pass a reference instead
ftfy

Queue isn't a pointer, so a copy is passed in. head is an element of q, so it can only be modified locally. If head were a pointer to a value, accessing a copied pointer would work, but it'd be real sketchy since you'd be modifying a value through a pointer from a copied element. Sketchy because pointers should only exist in one place at a time, otherwise you risk dangling pointers and failed updates and stuff.

then again i don't know why you'd do ref(ptr) every time. you can do
auto& var = *ptr;
// alter var to alter *ptr

No, you should only ever pass const references, and since you're going to modify the object, you do not want a reference.

will bad things happen if I free the original pointer after that?

You free the original memory. Any further access is undefined.

Stupid question but programming related.
In C#, how can I create and write a document in $HOME/Documents in a cross-platform way?

Attached: oh lawd he coming.jpg (1280x720, 303K)

did the user who wanted to make a bot for some MMO using a microcontroller and then deciding to use python and people told him how dumb he was ever finish the bot?

undefined behaviour

whats wrong with micropython

if(os.startsWith("Windows 9"))
else

A) use a library
B) ifdef WINDOWS #define HOME %USER% endif ifdef LINUX #define HOME "~/"
something like that, presumably.

nothing, the problem was he wanted a bot, which is a program that automates clicks for tedious video games
a microcontroller has no use for botting, unless it controlled a robot hand that actually used the mouse

Absolutely wrong, when you need to modify an object and you will never pass null, a mutable reference is much better than a pointer.

Why would the bot need to run on a microcontroller?
Also, I don't think performance really matters for shit like MMO bots, so Python would probably work fine.

Attached: 1557772985307.jpg (850x1188, 243K)

>reading compression
I'm talking about that one guy from a /dpt/ from about 5 days ago, he made some decnet progress

No it went the way of 99% of /dpt/ poster's projects: come up with an idea-guy tier idea, post about it here, argue about what language to use for thirty posts, then abandon it completely.

user, that's C#

Attached: 1556594859326.jpg (564x811, 55K)

does my life count as a /dpt/ poster's project

what the fuck are rvalue references who comes up with this shit

this guy

Just dump that garbage language already.

cniles and their high level ivory tower abstractions

Found the brainlet.

That is a C++ thing. C has no such concept.

has anyone checked if bjarne is developing alzheimers or dementia, or are sepples cucks simply used to having pure insane garbage shoveled down their throats every few years

>C standard
>What is sometimes called ‘‘rvalue’’ is in this International Standard described as the ‘‘value of an expression’’

How do you recommend that i modify the elements in Queue q?

"rvalue references" is something much more specific, and only related to C++.

In C, rvalue vs lvalue is pretty simple, and largely unimportant when normally writing code.
An lvalue can appear on the left side of an = and & works on it. Basically, it has storage associated with it.
An rvalue cannot, and does not have storage associated with it.

The only exception is non-modifiable lvalues, which include array labels and const variables, which are not valid to put on the left of =.

std::bump();

cringe

vocaroo.com/i/s0DBKcPYMJTK

std::teleport();
std::set_position(enemy.back());
std::unleash_katana();

but what you posted was literally cringe
like there was no other appropriate response

kek

assert !personnel && enemy == "kiddo";

Imagine actually struggling to understand rvalue references LMAO

>you don't understand the difference between a declaration and an expression

No that's you.

int x; //the expression x evaluates to an int
int *x; //the expression *x evaluates to an int

//proof
int x, *y, **z; //the expressions x, *y, and **z all evaluate to an int

so in cpp, if I want to have optional initialized parameters in a function, but want to preserve the order of the parameters being passed, how do I achieve that?

do I have to pass a dummy to pad the parameters to the right, if I have nothing to pass to the first parameter?

If you're using C, you have to pass in a pointer. If you're using sepples cancer, you can choose a pointer, but that's not sepplesy enough, so use a reference or whatever.

Holy shit, the declarations in C makes sense now.

Use overloads instead of default arguments in that case:

void f(A a, B b);
void f(A a) { f(a, B()); }
void f(B b) { f(A(), b); }
void f() { f(A(), B()); }

>no results in archive
>nothing on google
user...

how do i overcome math anxiety so i can become a better programmer?

Attached: 18134857189.jpg (1074x1074, 179K)

Programming doesn't have a lot of math. It took until Borderlands 2 before the graphics developer had to learn tangents for field-of-view calculations, and that's baby-tier math.

>all that shitflinging about ambiguous variable declaration and operator syntax
Feels good to be a Pascal chad.
program superiorSyntax;
TYPE
PInteger = ^Integer;

VAR
number: Integer;
iptr: PInteger;

BEGIN
number := 100;
WriteLn('Number is: ', number);

iptr := @number;
WriteLn('iptr points to a value: ', iptr^);

iptr^ := 200;
WriteLn('Number is: ', number);
WriteLn('iptr points to a value: ', iptr^);
END.


Come home, white man.

Go uses similar syntax.

Erm, what happened to all those job opportunities programmers supposedly have? I was promised lots of opportunities and money after I graduate. I can't find a single job opening in PA.

Attached: 18fad8ac186db6488890a7e6dedcdd12e039756ae9a8b225240cdaf98d44a3d1.jpg (612x716, 313K)

Oh there's plenty of openings. You just had to have a free pass for 5-10 years worth of experience to get them

Attached: fuck everybody.png (1370x994, 83K)

I smelled early that the industry was rotting, and started focusing much more on my drawing hobby.
Now I make a decent living drawing foot fetish porn + autismbucks, and program for fun.

I love my Art Chad lifestyle, STEM cucks btfo.

It was all a lie.
When companies say they want more people, they are specifically talking about senior-level programmers, but they also have ridiculous expectations about what they can get. Hardly anybody wants to take on less-experienced programmers and actually spend the effort giving them some experience.

The problem is 10 times worse if you went into webshit.

and live in the middle of a major city (and still be willing to commute)

How do I into job out of college though? My dad's going to get really irritated if I end up turning into a neet.

>send thousands of resumes till one sticks
>apply for every job in sight

Do some open-source shit in your downtime.
It counts as real experience, and makes you a much more desirable hire.

I got my first job after only applying to like 5 places, and 2 of those 5 got back to me.
For my second job, I only applied to a single place and got it.

Do you mean like non-trivial projects on github or contributing to Linux tier open source?

Non-trivial github projects are fine. It does look better if you're not the only developer.

Not him but for some reason I never thought to do open source stuff for experience, pretty brainlet but thanks

Oh thank you so much. I already have five years of experience I can put on my resume. What a relief. Unfortunately, I think I still might have to move out of state. All the openings I found are in Jersey or NC.

Cute chino

^ and @ are so much more aesthetic than * and &

Anyone who thinks ^ and @ is more aesthetic than * and & have fucking shit taste and should never design a programming language ever.

at least the @ symbol makes sense

Was JavaScript (dare I say it) right? Are the only types you really need number, string, map/object, and list?

They really are.
>TRIGGERED

@71384281
It's ugly

you only need true and false

>Are the only types you really need number, string, map/object, and list?
no

You only need tables.
Lua master race

I've applied to more than 100 places with only a handful of interviews and no offers, and that's with a BS in EE and a year experience in embedded programming. The market fucking sucks if you're not "in".

try a market that isnt embedded programming

Figured out my GCC "bug" from the other day — turns out Clang executed argument statements in order, GCC didn't guarantee that. Don't know off the top of my head what the standard says, but this solution works for both compilers & is probably safer anyways.

Attached: Screen Shot 2019-06-11 at 9.48.43 PM.png (940x644, 104K)

Order of argument evaluation is undefined in the standard, never depend on it.

are there places where you believe you could add to their bottom line?

>Order of evaluation of … function arguments in a function-call expression … is unspecified.
Well that answers that

>standard doesn't say about order of argument evaluation in C++
no shit people have been shitposting about this in /dpt/ for like a year

Yeah it typically doesn't even cross my mind because I usually put thought into interfaces, but I prefer keeping my unit tests terse so I'm more willing to use hacky code.

kinda scary

I did. Programming, PLC, hardware dev, analog research, even industrial machine operators. I got turned down from a logistic/inventory position for being too qualified (explicit reason). Only from one interview did I get feedback, and it was "you didn't wear a dress shirt". I was wearing a dress shirt.

Yes. The one job I had for a year I simplified their work cycle (it was very manual and error-prone before hand), implemented a back-up system and restored the lead developers computer after a hard drive failure, and wrote new features, besides isolating a bug that affected only the highest performance tier of our software. They stopped paying salary so I had to fucking walk out. I'm sure other people thought I just quit so I've since updated my resume to include unpaid salary as the reason I stopped working.

Why are you using std::make_tuple? Are you stuck with pre-C++17 or something?

HEY JOSEPH

You don't end up looking like this without seeing hell on earth that you created manifesting itself.

Attached: 1520364854884.jpg (482x565, 28K)

That's a hold over from C.