/dpt/ - Daily Programming Thread

What emulator software are you writing up Jow Forums?

Previous

Attached: 1538945408235.jpg (3840x2160, 2.23M)

Other urls found in this thread:

medium.com/@chanakadkb/overhead-of-parallelism-d1d3c43abadd
merriam-webster.com/dictionary/most
twitter.com/NSFWRedditImage

Kpop fags get out, post anime girls

For me, it's the zig guy

Is there a sane, simple to use C++ socket library that also supports IPv6?

Attached: 1527831486059.jpg (480x360, 7K)

this

do you guys have some (possibly obvious) tips regarding performance that you can share?

Use multithreading whenever you can

don't use multithreading whenever you can

You should check out my book.

Multithreading is a bit of a meme. Dividing a problem into smaller pieces gives a large benefit, doing those smaller pieces parallel gives a relatively small one.

Attached: sedgewick-robert-image.jpg (300x300, 15K)

Work on abstract types whenever you can

In days of my youth working with Linq in C# I always used .ToList() or .ToArray() methods, which is stupid and impairs performance if you can work with IEnumerable

Don't optimise before you're certain your code works as it should, in all cases.

Also, run experiments on runtime multiple times. Begin with at least 10 times in a row. If you've got the time, do it 100 times or more.

Don't fall for the Java/C# meme

Attached: regexbenchmark.png (504x688, 80K)

>You should check out my book.
which one?

Wait what? Aren't you wasting your cpu cores for not using them?

what language for implementing high level logic fast would you recommend?

Are you wasting your muscles by not continually flexing and relaxing them?

Pick your favourite Lisp.

Any sort of number crunching that can be parallelized gets a massive performance boost (see: any parallel numerical analysis, e.g. CFD applications such as Ansys Fluent) up until inter-process communication and disk I/O throttle it. Many well parallelized programs scale linearly with the amount of FLOPS it has available into 1000s of cores.

what would the time complexity be of a loop where after each iteration the iterator increases by a factor of 1, 10, 100, etc?

but i don't like any

this is what retardation looks like

O(n), I think.

Pick your favourite functional language.

It's simply called "Algorithms" by me, Sedgewick and some other dude. It's available for free, and there's also a course website as well as a free course on coursera with video lectures.

Quick google gives this (lmao medium)
medium.com/@chanakadkb/overhead-of-parallelism-d1d3c43abadd

For sure, in some applications there are massive benefits to parallelism, but those are fewer and farther in between than I think people in general believe.

but the iterator isn't being increased by a constant

log_factor(N)

Every iteration it "skips" another part of the problem. Check out complexity analysis of binary search trees, it's the same thing. You get log2(N) performance since you always divide the problem in half each iteration.

thanks i actually just then thought it may be log_10(n) so i apprieciate the validation

np bro

IOstream(e.g Cin and Cout) can be faster than the standard scanf and printf if you disable io synchronization, but having that io synchronization is generally helpful and in all other cases scanf and printf will vastly outperform the IOstream.
It is therefore a good general idea to just use scanf and printf instead of Cin and Cout.

Attached: 1495649258667.jpg (640x484, 111K)

>run experiments on runtime multiple times. Begin with at least 10 times in a row

this
when benchmarking remember to call GC right before calling benchmarked method
if you're benchmarking two methods try chaning their order and see if results are consistent
when measuring time always make at least 100 iterations of each method

>sane socket library
Does not exist, whatever the language.

Zeromq?

Should I even bother writing a CMakeList.txt for a project with 2 files?

Today I did the Hackerrank problem Mini-Max Sum which asks you to find the maximum and minimum sums possible using 4 out of 5 input numbers.
Here is my code:
// Complete the miniMaxSum function below.
void miniMaxSum(int arr_count, int* arr) {
long int minsum, maxsum;
int min, max, sumnummin, sumnummax;
sumnummin = sumnummax = 0;
max = min = arr[0];
maxsum = minsum = 0;

//Go through input array to find max and min numbers
for(int i = 0; i < arr_count; i++){
//New max value
if(arr[i] > max){
max = arr[i];
}
//New min value
if(arr[i] < min){
min = arr[i];
}
}

//Go through array to find max and min totals
for(int i = 0; i < arr_count; i++){
//Add max number to maxsum
if(arr[i] == max & sumnummax!=4){
maxsum = maxsum + arr[i];
sumnummax++;
}
//Add min number to minsum
if(arr[i] == min & sumnummin!=4){
minsum = minsum + arr[i];
sumnummin++;
}
if(arr[i] != min & arr[i] != max){
maxsum = maxsum + arr[i];
minsum = minsum + arr[i];
sumnummin++;
sumnummax++;
}
}
printf("%ld %ld", minsum, maxsum);
}

Attached: Yuki-Using-Computer-GIF-yuki-nagato-38663943-311-360.gif (311x360, 136K)

yes, embrace object oriented programming asap.

nigga I've never used that shit for projects bigger than 5 C files

ignore this massive memer

Employed Haskell programmer reporting in

Attached: 1474325315193.jpg (636x616, 44K)

Newfag here
Best way to learn python for someone next to no experience in programming ? Reason for python is due to uni course

How about reporting out?

hackerrank

why is c so hard?

Help me understand circular references. This is invalid
// class A header
#include "B.h"
class A ...
B* b_ref;

// class B header
#include "A.h"
class B ...
A* a_ref


But this isn't.

// class A header
#include "B.h"
class A ...
B* b_ref;

// class B header
class B ...
class A* a_ref

// class B source
#include "A.h"


First, what's wrong with circular references? In many cases I know two classes to know about each other. And keeping a direct reference to the other (through weak pointers, not through raw pointers like I did in the example just for brevity) is very useful. Besides, if circular references are bad, why does the language give you a tool to include them through forward declarations?

it's not though, it's so simple

javalet here
How do I instantiate objects of different classes to an arraylist?
for instance, I have a super class called animals, with two subclasses: cats and dogs
I want to add 1 animal, 2 cats, and 2 dogs to my list.

Use base class pointers.

In 1st one, looks like both files will infinitely include the other file, which obviously wouldn't work

the 2nd one, B source includes A header, which in turn includes B header. There's no circular reference, no infinite inclusion of 2 files

Circular references are fine. They only cause issues with reference counting.

So the only problem is with headers including each other? Then forward declarations are fine to use like that? I've heard a few times that I should avoid forward declarations

>Then forward declarations are fine to use like that?
From your 2nd example, it looks like that. Expanded B.c would look like the following and contain forward declarations:
// class B source
class B ...
class A* a_ref

class A ...
B* b_ref;

I don't understand what your problem is
ArrayList a = new ArrayList();
a.add(new Animal());
a.add(new Dog());

Cool, that's a much saner approach than casting when I needed to access A from B

I just realized I sounded condescending, I was just trying to say that I wasn't sure if that snippet of code was what you were asking for

>Holds P1 stick
>Presses P2 buttons
What did she mean by this?

Only the cutest kpop idols are hardcore enough to control 2 players at once

she inputs cheat code.
I cant tell what game is on screen but Bubble Bubble for example does that.

So none of them?

Hello, programming help desk? I've started to misuse extension methods, please send help

Whatever you're doing you should probably consider hashsets

JavaScript rocks!

Attached: 1539753243576.png (1000x494, 369K)

Haskell will help you

Attached: enemy of the state.png (478x618, 84K)

Javascript paper! I win!

I feel like I should've added some kind of timestamp to the printout

Attached: shaders.png (979x505, 48K)

Is carrying a weight with one hand easier than with two?

Javascript scissors.. aw shit

That solution is pretty over-complicated.
void miniMaxSum(int array_size, int* array)
{
int min = INT_MAX;
int max = INT_MIN;
int sum = 0;
for (int i = 0; i < array_size; i++)
{
if (array[i] < min)
min = array[i];
if (array[i] > max)
max = array[i];
sum += array[i]
}

int minsum = sum - max;
int maxsum = sum - min;
print(whatever the fuck);
}

kek

Attached: Screenshot from 2018-10-17 15-33-18.png (488x43, 6K)

Avoid floating point operations and use lookup tables wherever possible.

Isn't this whole problem based on sorting an array of numbers and then getting the n objects from each end of it and sum them?
def minimax(argarr, count):
finalarr = sorted(argarr)
print("Min is {:d}, Max is {:d}".format(sum(finalarr[:count]), sum(finalarr[count:])))
I assume the inputs are caught before sent to it, so count is strictly < argarr.len

Multithreaded code is much harder to get right and even then Amdahl's Law applies. A 3-legged race is a better metaphor.

fpbp

Writing an OS is a good use of your time

>calls it best post
>doesn't post anime girl
you had one job, user

Attached: youshouldbeabletosolvethis.png (1000x1024, 709K)

Quit your job
Make videogames

Attached: 1526195828936.jpg (400x400, 50K)

Why would you make video games when you could buy them

Attached: todd.jpg (550x550, 36K)

Most self-employed video game programmers fail.
Most employed video game programmers work horrible hours at mediocre pay.

ummm sweatie ever hear of a little game called, I don't know, maybe "Minecraft"? ;)

Locality is big given the way cache works. Compact homogeneous data structures will be much faster than indirect heterogeneous ones. This favors arrays over linked lists in defiance of big-O up to surprisingly high scale, this favors structs of arrays over arrays of structs, and this favors languages that give you control over layout and specifically over boxing/unboxing over more purist OO or FP languages where everything is boxed and every data structure is a rat's nest of pointers.

OTOH computers are fast now, so write that compiler in Haskell rather than C++ unless you really know you need sanic speed.

merriam-webster.com/dictionary/most

>he uses OOPs in 2018

you know what "most" mean, don't you?

eeeerm my dear ever heard of funny little guy called Jeff Bezos, also known as RICHEST FUCKING MAN ON PLANET? why don't you just make online bookstores?

>he uses a functional language in CURRENT YEAR

cave story, stardew valley, touhou, rim-world, ...
I could go on but if you're not good enough then you're not good enough ;)

Attached: anecdotal.jpg (1106x962, 333K)

Now compare it to buying lottery tickets.

>rim-world
you REALLY REALLY REALLY don't want to go there senpai

BUY MY BOOK AND SOUNDTRACK YOU MOTHERFUCKER.

multi-paradigm languages rock. I want a tool, not a church.

Multi-paradigm code is a mess

>keeping a handful of spaghetti in with your tools
why tho

How would you request a random entry from an API call in python?

J/k

Why would you allow overriding registrations with SimpleInjector?

Lisps eternally btfo

Just some file uploading tool, to make things faster

Attached: 2018-10-17-170709_723x542_scrot.png (723x542, 69K)

pic related

Attached: common_lisp.gif (477x185, 1018K)

Needs help here, this is a small bit of my code covering a void function that is not woking, this is how I tested it.

It should display a + character, but nothing appears.


void check_cell(char cell, bool cell_status);

bool cell_status[rows][columns];
char cell[rows][columns];

int main()
{
cout

>get back to a project after 2 months
>not a singe comment throughout

Why did € turn into 竄 on different machine?