/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?
Previous thread:

Attached: 1537819329025.jpg (1280x720, 806K)

Other urls found in this thread:

youtube.com/watch?v=HddFGPTAmtU
open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0844r0.html
winestockwebdesign.com/Essays/Lisp_Curse.html
johngustafson.net/pdfs/BeatingFloatingPoint.pdf
en.wikipedia.org/wiki/Boo_(programming_language)
twitter.com/NSFWRedditVideo

first for Nim

second for C

youtube.com/watch?v=HddFGPTAmtU

cppcon2018!!!!
concepts are a god send desu

Attached: Nico 354 (NT).png (1920x1080, 2.88M)

vector v{begin(c), end(c)};

a vector of iterators to a range

vector v( begin(c), end(c));

range constructor, vector of range c's value type

initialization in c++ still freaking sucks
funny when its supposed to be one of its core defining features lol

Attached: Maki 223 (OY).jpg (564x793, 83K)

Fifth for Haskell

In Rust, this just
let v: Vec = c.into_iter().collect();
Note: The T in Vec is inferred.

Attached: 1509286299607.jpg (1920x1080, 310K)

>
Rust is cute. Cute!

-> concepts

Attached: .jpg (1920x1080, 177K)

we already have type functions, they're called templates

is it possible to make a program that just has your waifu randomly saying she loves you at points of the day?

Attached: monika.jpg (367x371, 55K)

whoops i put the 0 in the wrong places, i mean 2200, 2230, 2260

Attached: 1505287152812.jpg (1566x1449, 746K)

lol no

what's a type function?

a function on types

open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0844r0.html

also forgot to mention modules
modules and concepts are already gimped, modules gimped by corporate interests

Templates receive types as arguments and return types as values. Templates can receive other templates as arguments, which means that they can behave as higher order functions too.
Type functions in C++ are implemented as templates. is just another redundant proposal in a language that is full of them.

even though this is a good feature the complexity of C++ is just getting ridiculous at this point

>missing template arguments
also do you understand the difference between calling a constructor and uniform initialization?

All of you disgusting attention whoring anime pedo faggots, tell me this
Why can't you just fucking neck yourselves? It is so easy

Template arguments for class templates can be inferred in C++17.

>thread scraper is running nicely
>now i need to figure out how to clean up each post's formatting

type functions are much more expressive and simple than pretending that SFINAE and template metaprogramming is an acceptable way to do it

even simple type functions written as actual functions turn into dozens of sfinae statements but we already had this same exact argument like last week

You don't need sfinae to do type functions with templates. You only need to use sfinae if you want ghetto reflection.

Guys, I invented a way to do dependent type text in Haskell

Here is a string which by definition must equal "fourchan"

Attached: DANK MEME 2018-09-25 at 21.39.32.png (778x188, 9K)

well then ignore me i'm a faggot

Dear fatsos: If you don’t have the willpower to stop eating carbs, you won’t have the willpower to do truly succeed in programming. #truth.

im fat and im a brilliant programmer

c++ can do statically checked dependent types

auto sort (Range) -> SortedRange

I'm trying rudeposter

GUYS I HAVE QUESTION ON SQL
I have db: airport with 2 tables: tourists and flights. One of column in Tourists is listOfBookedFlights, and one of column in Flights is listOfTouristsBooked, and both are depend on each other. How would you make it?

im fat as shit and unemployed so i guess it must be true

Got a question regarding pointers in C
Now let say I write a program in main like this where I declare a structure m of type ka:
struct ka m;

Then later in main I pass the address of m as an argument in method load()
load(&m);

and method load() look like this
void load(struct ka *m){

unsigned int a

m->var = a;
}


What does passing the address of the ka variable do here? Does it simply just turn it into a pointer in the load method?

Also what's the advantage of using a pointer here? Can't I just use m.var=a and not pass the address as an argument?

& is the address of operator in this context
pointers point to an address
If you didn't pass it with a pointer it would not mutate the original variables member
It would instead mutate the member of a copy of the variable that would then be immediately discarded
in affect doing absolutely nothing in that function

ah so if it was not a pointer, it would just treat m as a completely different variable?

Eg say m.var is set to 2 in main, then if the address was not passed as a pointer, m.var in load would be uninitialized before assigned a?

An address is a pointer. They're the same thing.

Say you have code like this.
void foo()
{
int x = 0;
modify(&x);
printf("%d", x);
}

void modify(int *ptr);
{
*x = 1;
}
modify() will follow ptr to the variable x within foo(). It will then set the variable x to 1. When modify returns, foo's x will still be modified - and so the number 1 will be printed.

Pointers can be used to share values, for example to make a change that is expected elsewhere or to reuse data without copying it. Other languages like Java do it implicitly.

It would make a copy of what you passed
So m.var in load would have the same value but changing it wouldn't change the one in main. This can be useful of course
note that this can have some frustrating behavior if the struct has members that are pointers

It's not like in Java where you can pass an object to a method with no problem? You absolutely need to pass the address of the struct variable for it to be properly read in the function?

okay so it directly modifies the struct variable then if you pass address. If I just used m, it wouldn't do anything to m in main unless I set m=load(m); right?

$ ls -R /usr/share/vim | wc -l
2047
$ du -hs /usr/share/vim
33M /usr/share/vim
$ du -h /usr/bin/vim
3.0M /usr/bin/vim

>vim is minimal

Attached: maxresdefault.jpg (1280x720, 77K)

>& is the address of operator in this context
& evaluates to a pointer, not to an address.

I though java had pass by references?
Yes
An address is a pointer and I'm pretty sure its called the address of operator

Java does it automatically for you, because in Java all class types are automatically references.
Here's some Java and how it might look in C instead.
class Rectangle
{
int width;
int height;
}

static void demo()
{
Rectangle rec = new Rectangle();
makeWider(rec);
}

static void makeWider(Rectangle rec)
{
rec.width += 10;
}

struct rectangle
{
int width;
int height;
}

void demo()
{
struct rectangle *rec = malloc(sizeof(struct rectangle));
make_wider(rec);

// Remember that C does not have a garbage collector
free(rec);
}

void make_wider(struct rectangle *rec)
{
rec->width += 10;
}
Rectangle is equivalent to struct rectangle* and new is equivalent to malloc.

>I though java had pass by references?
Sorry, I brainlet'd myself

What's the princess king boo of programming languages?

Attached: 1537902301593.png (874x931, 637K)

julia

>cute
>useless
>pure
it's Haskell

How fast can I pick up c# when I already know c/c++ well ? How hard is using c# on linux?

>An address is a pointer and I'm pretty sure its called the address of operator
that would not surprise me at all, c was designed by plt illiterates.

Do you know Java? It's a lot more like Java than either of those.

>pure

Attached: 1537905983776.jpg (1194x657, 118K)

do not lewd boo

Attached: 1482426035780.jpg (444x470, 40K)

Is anybody else doing something like this?

isNumber() { read -t 0.1 arg; arg=${arg:-$1}; [[ $arg =~ ^[0-9]+$ ]] && speak $arg; }


To the function above you can pass both positional parameters and stdin:

isNumber 44
# stdout: 44

printf 55 isNumber
# stdout: 55


I know it looks terrible but I am so fascinated by functional programming in javascript that I started creating some bash functions which you can compose. Like this:

add10() { read num; num=$(( $num + 10 )); printf "%s" "$num" ;}

printf 20 isNumber | add10
# stdot: 30


What do you think? Garbage?

If I have an array of doubles of size 360, and I want to create the averages of every sequential element and place the averages between the corresponding elements in a new array, how large should the new array be?

Say I want to do this:

[1, 2, 3, 4, 5, 6] -> [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6]

I see that with 6 elements I only need (6-1) more. Is that true for n elements with (n-1) required to add the averages?

winestockwebdesign.com/Essays/Lisp_Curse.html

>Lisp is so powerful that problems which are technical issues in other programming languages are social issues in Lisp.

Attached: rustle2.webm (1280x720, 1.81M)

based

this semon demon gets my dick hard every time.

>Lisp is a painfully eloquent exemplar of this lesson. Lisp is so powerful, that it encourages individual independence to the point of bloody-mindedness.
nice

its too late

Attached: 1537907125257.jpg (449x1000, 418K)

Bretty cool article, but it seems too complimentary to Lisp. Seems like a similar phenomenon goes on in JavaScript, for example. Its not just because Lisp programmers are so good.

I am a complete newb at programming so please forgive this retardation, but in my python program I have 72 pictures of busses that I am using for somethin, but I don't know how I should properly import them efficiently. At the moment I have this going on for 72 lines and I know it's retarded, but I've been googling it for a couple of days and I still can't find a better way.

bus_template_1 = cv2.imread('bus1.png',0)
bus_template_2 = cv2.imread('bus2.png',0)
bus_template_3 = cv2.imread('bus3.png',0)
bus_template_4 = cv2.imread('bus4.png',0)
bus_template_5 = cv2.imread('bus5.png',0)
bus_template_6 = cv2.imread('bus6.png',0)
bus_template_7 = cv2.imread('bus7.png',0)
...


how would you go about importing this many pictures in python?

Attached: 1498043618331.jpg (960x516, 50K)

dumb frogposter learn to use loops and arrays

Attached: 392578978235.png (412x282, 196K)

bus_list = []
for i in range(1,73):
bus_list.append(cv2.imread("bus%d.png"%i,0))

>Hey I wanted to touch base to let you know that we are interested in making an offer to you, I have a number of things to finalise internally before we can get to that stage.
>still waiting to hear from them after five days

Attached: 1530486038219.jpg (938x1182, 230K)

I drank the DDD/CQRS/ES kool-aid and now I cant write software anymore, what do?
Should I go back to anemic models?

i wrote something in pypy (significantly faster than python)
but the problem is i have this bottleneck function that multiplies huge matrices
i want to extend my program with C, anyone know how to extend pypy with C
(if i ran the thing in python AND wrote tha matrix multiplication in C, it will still be slower than just pypy)

do i have to start over in C now?

If you care about performance this much you should have been writing in C/++ to begin with
>significantly faster than python
Everytime

pure maths you should be doing in C, that's how numpy, scipy, ffi, etc are made

Learn how to do so, or if you just started, just write it in C

So contact them

thank you very much, here is the funniest picture on my hard drive

Attached: 345253612346.jpg (1280x720, 73K)

What if they think I'm a desperate loser and decide not to hire me. This is like girls all over again

They said they were going to contact you and didn't. So you contact them.

Show that you care. You can do it bro

I have some trouble with my school assignment project guys.
I want to store some memory addresses and instructions of a simulator like this:

940 3
941 2
300 1940
301 5941
302 2941
303 7000

The first 3 digits are addresses and the last 4 digits are instructions. I want to make so that my C program will read each of those separately

>*breathes in*
Ok, I can do this

Attached: 1502569430181.jpg (528x640, 31K)

well pypy IS about 10 times faster than python in my case
i can't into C++
i could rewrite in C, but GOD it's so much faster to write it in python
it's a machine learning algorithm i implemented without libraries(no numpy and the like), but it will take about 2 to 3 hours for it to train using pypy
in C that's probably 10 minutes

i'm just going to run it overnight and feel like a shitter, whatever

dumb frogposter

*goes faster than you*
nothin persenel rabbi

Attached: 1280px-The_C_Programming_Language_cover.svg.png (1280x1653, 180K)

johngustafson.net/pdfs/BeatingFloatingPoint.pdf

Are you not using a library like TensorFlow or sk.learn? They're all C++ wrappers

Just check in. Its nothing. They will probably say they are still figuring stuff out, which is totally normal because stuff can be difficult to figure out. Thats fine if thats what they say. Just check in.

looking at the doom3 source code, specifically the matrix vector product:
ID_INLINE idVec3 idMat4::operator*( const idVec3 &vec ) const {
float s = mat[ 3 ].x * vec.x + mat[ 3 ].y * vec.y + mat[ 3 ].z * vec.z + mat[ 3 ].w;
if ( s == 0.0f ) {
return idVec3( 0.0f, 0.0f, 0.0f );
}
if ( s == 1.0f ) {
return idVec3(
mat[ 0 ].x * vec.x + mat[ 0 ].y * vec.y + mat[ 0 ].z * vec.z + mat[ 0 ].w,
mat[ 1 ].x * vec.x + mat[ 1 ].y * vec.y + mat[ 1 ].z * vec.z + mat[ 1 ].w,
mat[ 2 ].x * vec.x + mat[ 2 ].y * vec.y + mat[ 2 ].z * vec.z + mat[ 2 ].w );
}
else {
float invS = 1.0f / s;
return idVec3(
(mat[ 0 ].x * vec.x + mat[ 0 ].y * vec.y + mat[ 0 ].z * vec.z + mat[ 0 ].w) * invS,
(mat[ 1 ].x * vec.x + mat[ 1 ].y * vec.y + mat[ 1 ].z * vec.z + mat[ 1 ].w) * invS,
(mat[ 2 ].x * vec.x + mat[ 2 ].y * vec.y + mat[ 2 ].z * vec.z + mat[ 2 ].w) * invS );
}
}
i'm totally lost here. what is s? and why can they just add the 4th row of the matrix to the result? i thought you can only multiply a 4x4 matrix with a 4d vector.

no
just implementing it from the bottom, for the exercise

Praise Stallman for such an efficient compiler which generates actually fast code and useful error messages.

Is there any news about when they are going to implement this in hardware, if at all?

it's math, baby! believe it!

i'm an idiot, didn't know the matrix is row major

>why can they just add the 4th row of the matrix to the result? i thought you can only multiply a 4x4 matrix with a 4d vector.
you can just treat a vec3 as a vec4 and assume the fourth value is 0 (or 1, I forget)

Some people are working on it in FPGAs. I imagine if it turns out to be as good for machine learning as it's said to be then there will be a bigger push to get it on silicon.

>assume the fourth value is 0 (or 1, I forget)
If w = 0 then the vector is interpreted as being purely a magnitude and direction. If w != 0 then the vector is interpreted as a position (x/w, y/w, z/w), where w = 1 is obviously the "normalized" encoding.

Please tell me what this code does. I cannot understand
while ( EOF != scanf("%x%x\n", &adr, &instr) )
ptr->memory[adr] = instr;

Wouldn't adr and instr have to be decleared first?

This actually works, by the way. A translation matrix will not affect vectors with w = 0, so they really are positionless.

It's related to this
Does this simply scan the file for first segment which is adr and second segment which is instr?

are there any books that teach about stuff like this? Or is it just basic vector calculations?

w can be seen as the "degree" that translation will apply. So w = 1 means that (x, y, z) translated by (t, u, v) will end up with (x+t, y+u, z+v) which is exactly what does.

en.wikipedia.org/wiki/Boo_(programming_language)

you learn about it in math class
it's called linear algebra

meant that
Fuck I need to master that much more.

you dont need to know about them to use them
I copy pasted most matrix functions off the web, it was faster than learning it all from the ground up

pls respond

all I really need is to find out how to open this memory file and have the program read those lines properly