/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous Thread:

Other urls found in this thread:

dictionary.com/browse/swapping
pastebin.com/bLDELate
youtube.com/watch?v=Yii1u2Lz-II
github.com/sindresorhus/awesome
mozilla.org/en-US/MPL/2.0/
twitter.com/AnonBabble

why aren't you using mathematica?

Rust!

>Traits based Generics
Never ever

>suicide tier

hey if i post a program i'm working on and the (unintended) output i'm getting would you guys mind looking it over and seeing if you notice how i fucked it up? or is that kinda thing frowned upon here, sorry for new i'm not from this board

>thinking Sup Forums is his personal indian IT team

Let's see your program

yeah just post that shit nigga. if the code is long use ideone.com or pastebin

just put it in tags

thanks! it's super simple, it's supposed to reverse an int array, but when i input an array with
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
it outputs
{10, 9, 8, 7, 6, 6, 7, 8, 9, 10}

does it have to do with the = operator taking the greater value? i'm new to the language but that seems kinda ridiculous

Literally just try "executing" this code in your head on an array with 4 numbers and you will figure it out. The sheer laziness of kids these days...

Why don't you just go trough your algorithm one by one. It's fucking obvious, from the first glance, that you should stop swapping numbers half way in

>int b[] = a;
you're overwriting the input array. make a new array.

Disregard what these retards are saying. int b[] = a means those arrays are both pointing to the same place. So you're not actually instantiating a new array.

>you should stop swapping numbers half way in
He wasn't swapping them. He was just copying numbers from one end to the next, overwriting the array in the process.

change int b[] = a; to int b[a.length];

>rewriting
So swapping.
dictionary.com/browse/swapping

>assigning a to b is swapping a with b
You're a fucking retard.

Idris!

I have a winform application in C# with a function that loops on a background worker which adjusts a progress bar with a delegated update function. Everything works fine if I let the bar finish filling, but if I close the application while the bar is filling I get a null reference exception, even though I set the appstate in the closing event of the form. Do I need to delegate the retrieval of the appstate too?
public void doRun(){
while(state==(int)AppState.RUNNING && !finished){
...//calculate some stuff
this.Invoke(delegatedFormUpdate, params);
...//set finished if done[spoiler][/spoiler]
}
}

>Idris
Absolutely awful. Only brainlets like dependent type systems unironically.

dictionary.com/browse/swapping

void rajeesh_swap(int* a, int* b) {
*a = *b;
}

int a = 5;
int b = 3;
rajeesh_swap(&a, &b);

Kill yourself.

oh shit you're so right i'm so dumb i can't believe i forgot i was working with pointers
i really appreciate it
yeah definitely. i thought i was making a new array and copying the values but i was a fool.
nah stopping half way is what you'd think looking at the output but it isn't a problem with the loop, it's the fact that i was altering the same array as a and b point to the same thing

thanks so much guys i had been smashing my brain against the keyboard for like 45 minutes

Thanks for proving me right with your virgin code.

Let me guess, Python?

>anyone who doesn't program in my meme language likes python

I'm learning javascript(first programming language) and can't solve the simplest shit. Am i brainlet?

What can you even """"solve"""" with JS?

>What can you even """"solve"""" with JS?
You can write a program to analyze your professional needs and tell you if you should use Idris:
function shouldUseIdris(_) {
return false;
}

console.log(shouldUseIdris(needsInputArea.getText()) ? "No" : "No");

Can anyone explain to me why I'm getting false positives on this function?

//check for 3/4 of a kind in a 5-card hand
int num_of_a_kind = 1;
int the_face = -1; //face of the matching cards (if there are any)
for (int i = 0; i < 5 && num_of_a_kind < 4; i++) {
for (int j = i + 1; j < 5; j++) {
if (the_face == -1 && hand_faces[i] == hand_faces[j]) { //first match
num_of_a_kind++;
the_face = hand_faces[i];
}
else if (hand_faces[j] == the_face) {
if (++num_of_a_kind == 3)
printf("There is a 3 of a kind in the hand!\n");
else if (num_of_a_kind == 4)
printf("There is a 4 of a kind in the hand!\n");
break;
}
}
}

wait a minute, that outputs No no matter what!

try learning an actual programming language, not a client side browser scripting language.

You are silly.

The first card out of three increments the counter by 2. Second increments by one. So you get 4 when it's only 3.

Also two pairs would count as 4 of a kind.

absurd suggestion

>not working on a nearly 3000 line Batch script under XP
Useless

take the pill, grandpa

4. What are the final values in x , p_int , and p_p_int in the following code:
int x = 0;
int *p_int = & x;
int **p_p_int = & p_int;
*p_int = 12;
**p_p_int = 25;
p_int = 12;
*p_p_int = 3;
p_p_int = 27;
A. x = 0, p_p_int = 27, p_int = 12
B. x = 25, p_p_int = 27, p_int = 12
C. x = 25, p_p_int = 27, p_int = 3
D. x = 3, p_p_int = 27, p_int = 12


Answer:
[spoiler]C. x = 25, p_p_int = 27, p_int = 3
[/spoiler]

Am I being trolled?

>implying it's wrong

Depends on what it does, dad.

>literal implying implications

Name another Batch script that can identify what operating system it's being run on, I dare you.

I'ts for web development.

>web development
nice oxymoron

Does doing embedded systems / OS / Network programming fall under software engineering? How do I find jobs in these fields?

>gentoo
Nice meme

screenfetch lol

>uses wincuck xD
>calls other OSes memes

nobody writes plain javascript for front end development anymore

Actually, I'm using Prnt Scrn and MS-Paint, saving to a PNG.

>uses Linux
>unable to eat greens

>Actually, I'm using Prnt Scrn and MS-Paint, saving to a PNG.
Do you go to special classes?

No. I just didn't want to wait for Paint.NET to open.
It's not like I'm dropping any quality, my display is only 1280x800.

...

It's crazy how people thought javascript wasn't bloated enough so they make all these faggot frameworks to make it even more bloated

...

Thought so

Glad to hear we've cleared things up.

Got any ideas on how I can rewrite the save descriptor generator so that I can properly remove saves from the list without modifying other files?

Yeah, I'm sure your nurse knows about it

>day 2 of learning modern opengl
>373 lines of boilerplate written
>still can't draw a triangle on the screen

why does gl have to be so hard?

Is Machine Learning actually the future? As in, will it become one of those skills were if it's missing from your CV you can forget about getting hired anytime soon?

If by that you mean my physician, yes, I do have arthritis.

Because GL was made by people who think all that matters is an open license.

In theory, yes. In practice, not for several years yet.

Should a game entity object store its own location data?

Were those 373 lines written by you or were they automatically generated?

>several years
You mead decades.

>decades
You mean centuries.

It depends on the situation. In most cases, I'd say yes, but if you're looking at something like a map or any other objects that need this position information, I would suggest creating a master object that monitors it's location or that the object reports location changes to.

I try to be optimistic. I'd like to see it happen in my lifetime, but that's probably wishful thinking on my part.

>If by that you mean my physician, yes
Is that what you were told?

Why did they decide to make every function void and take a pointer to a pointer to data instead of simply returning that data?
It's not very C-like, and I can't use the assignment operator for easy error handling.

me, i'm dealing with the GLSL part now

If it didn't store it's own location, how would you get an object's location? A separate class that holds all the objects locations? Then when you would need an object's location that's a lookup call to the other class?
So the Map class would hold an array/vector of all mappable objects with their locations, and anything that gets added/altered must report the changes to this class?

It's what I'm telling you.

Because it's all for the "open source" dream.

Yes, or the class could monitor them on it's own. I doubt it would be doing much else, so it's not like you'd have to schedule it to do so - Just have it periodically request the position of each object individually and build a map of their locations.

Is there not a builtin heap/priority queue implementation in the Haskell standard library?

That seems pretty important.

>open source
free software > "open source" software

>haskell
>expecting important things to be done
heh

Hence the existence of several other (albeit less popular) methods of drawing graphics.

Situation:
>1x1 square
>2D bitmap
>need to see if there's a collision and if so calculate penetration
My solution (the main function): pastebin.com/bLDELate
What do you think?

open source software > free software
Fuck GPL. BSD rules.

It looks like you can just use Data.Set. The only downside is inserting and deleting are both log(n), however that's not too uncommon anyway.

youtube.com/watch?v=Yii1u2Lz-II

I'll put it the other way.
individual's freedom > society's freedom.

All the libraries I use (GLFW, soundio, nuklear, linmath, tinycthread, glibc (LGLP is fine), GLESv2) are under permissive open-source libraries. Also, everything I do is under BSD-2 too.

Anything else would be communism.

Oh and by the way you can legally circumvent GPL by providing it as a cloud service, lol

>individuals > society
I see you live in eastern Europe.

>open source
Is it fun to write dozens of lines just to print some text?

Attention all:

github.com/sindresorhus/awesome

This is your new primary resource for finding shit for , , , or whatever.

mozilla.org/en-US/MPL/2.0/

>I see you live in eastern Europe.
You guessed it.

>Is it fun to write dozens of lines just to print some text?
I'm actually doing a game engine.

Temporarily though. I will have no problem coming to your country for higher wages, and running away when shit goes down.

That's why I use AGPL.

Why do people teach legacy pointers instead of smart pointers?

Because when you do "foo"+"bar" you will have to learn legacy pointers anyway

That doesn't need pointers at all

Why do people teach smart pointers instead of pointers and capabilities?

smart pointers are pointers

That's an error. You can't add them. Why? Because they're legacy pointers. BOOM, now you need to know what are legacy pointers.

user, string concatenation requires no pointer handling

What language are you talking about? I'm talking about C++.

this isn't printing the last couple letters of my first input until after the sleep, any idea why?
#include

int main(){
int BUFFLEN = 4; // Easier to view the effect on smaller input than BUFSIZ
char* BUF[BUFFLEN];
int n = 0; // number of bytes read
while (1){
if ((n = fread(BUF, sizeof(char), BUFFLEN, stdin)) > 0){
fwrite(BUF, sizeof(char), n, stdout);
fflush(stdout);
}
else sleep(1);
}
}


echo First round of output!
sleep 3
echo Second round!


prints up until the u of the word output. idk why

>C++
Are you, though?
#include
#include

int main() {
std::string x{"Foo"}, y{"Bar"};
std::string z = x + y;
std::cout

stop using while (1), and sleep.