/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?


Functional thread: Previous thread:

Other urls found in this thread:

opengl-tutorial.org/)
glfw.org/
twitter.com/NSFWRedditGif

First for bunnies

When will people stop arguing over types

>That image
It's extremely obvious that a redditor wrote that.

Will 2017 finally be the year of a decent C++ alternative emerging?

>baiting for Rust this much

>image
I think we should make a banner out of that pasta.

>a decent C++ alternative
Literally any other language. Java, PHP, Javascript.

This is a good idea.

React router question:

Refreshing the app when it's on a nested route path (e.g. '/foo/bar') causes GET requests to be sent erroneously to /foo/some_static_resource, rather than to /some_static_resource.

I'm bundling my app with webpack, and I can partially fix this issue by changing the output file name from bundle.js to /bundle.js.

Unfortunately, this doesn't resolve GET request errors for other static stuff like images and fonts. I could possibly go through each CSS url and change these image/font urls to absolute versions of themselves, but that seems a bit hackish and defeats the purpose of some of my app structure. It may possibly break the url-loader I'm using with webpack.

tl;dr: How to fix page refresh errors on nested routes with React Router?

Too many languages are being designed that simply repeat the mistakes of the past. A new language should be an improvement, not a step backward. To that end, let's create a list of features that any new language must have. If it doesn't have everything on the list, it ought not to be made.

Here's a starting point:

>Static typing
>Sum and product types, with support for generic programming
>Higher-kinded types
>Higher-rank types
>Totality and purity annotations and checking
>No null
>Type inference
>Tail call optimization

>people here tell me haskell is a meme and I shouldn't use it
>they dont tell me why it's a meme or why it sucks, instead tell me to learn C

Kill yourself, you retarded frogposter.

how do I learn java? anybody have books or projects or both that they recommend? I work with C++ and learned Java in school, but my dream job requires Java...

Both C and Haskell suck.

Learn a real language like Java and stop wasting your time on meme languages.

>unbounded polymorphic recursion
>type indexed GADTs and constraint kinds
>quotient type constructors, type equality
>isomorphisms, first class cases, bicases

Go to an Indian university.

>ADTs magnify the memory consumption of any data structure and
Why though? Rust uses some clever tricks like NoneZero, so Optional has the same size as a regular Box by using address 0 as None, for example. And even it it can't reuse the values for a tag, it just adds a u8 tag field to a union if values, just like you would do in C.
>using them for "exception handling" completely nullifies branch prediction
Interesting argument, but again, the resulting code is more or less equivalent to constant error checking in a typical C code.

The other points, like lack of HKT, some form of inhertance and integer generics are legit drawbacks Rust devs should provide some solutions to.

>but my dream job requires Java...
what kind of a job requires java?

>some kind of inheritance
- n o -

existentials instead

Monoids in the category of endofunctors.
Zygohistomorphic prepromorphisms.
Mother. Fucking. Lenses.

what kind of dream is job

>should provide some solutions to
They should have done it years ago; it's probably too late now. Another useless language with countless man-hours of wasted effort behind it.

Maybe, just fucking maybe, programming language designers should listen to the PLT people instead of deciding "hurr it's all academic nonsense it's not relevant to real programmers" and later wondering why their language isn't working.

>Lenses
t r a s h

Well it already has trait objects, which is basically pointer to data + vtable.

mlb advanced media

>linking to splitters
kys you're selve

aw yeah, we styling now. just need to make some things optional and tweak some code.

does it have rank n polymorphic types?
polymorphic components?

What are things like microwaves usually programmed in?

But they're so elegant, look:
type IndexedLensLike i f s t a b = forall p. Indexable i p => p a (f b) -> s -> f t

asm or c

>elegant

>thatsthejoke.jpg

...

>>>/global/rules/15

did you just stole the design I stole from Pixiv?

yes, much thanks.
I had been meaning to add more text options anyway, and your pics inspired me to start on it.

to avoid having a bunch of random code style unrelated stuff in my commits, i saved the large code style refactor for the end when i was done implementing whatever i needed but it feels like it just hides any meaningful history that could have been seen at a glance, like pic related

it's probably fine but does anyone deal with it

the last commits i make to a project are always small miscellaneous tweaks. they don't really fit very nicely together, so taking a look at my project history could probably give someone the impression that my commit habits are scattered and structureless.

the only alternative is to gather them into one commit and tag it 'misc. tweaks', which is a pretty shitty commit message.

The following code keeps failing with "Error reading from datastream"
std::vector wav_data =
tv_audio_get_wav_data(audio);
SDL_RWops *rw =
SDL_RWFromMem(
wav_data.data(),
wav_data.size());
Mix_Chunk *chunk =
Mix_LoadWAV_RW(rw, 1);
if(chunk == nullptr){
std::cout

>this is valid C++ code

God damn, that is some awful code formatting.

how do you know when you're ready to work in a real job related to programming?

Here is tv_audio_get_wave_data
static std::vector tv_audio_get_wav_data(tv_frame_audio_t *frame){
std::vector retval;
tv_audio_wave(&retval, "RIFF");
tv_audio_wave(&retval, (uint32_t)frame->get_data().size());
tv_audio_wave(&retval, "WAVE");
tv_audio_wave(&retval, "fmt ");
tv_audio_wave(&retval, (uint32_t)16); // length of data section
tv_audio_wave(&retval, (uint16_t)1); // uncompressed PCM
tv_audio_wave(&retval, (uint16_t)1); // channel count
tv_audio_wave(&retval, (uint32_t)frame->get_sampling_freq());
tv_audio_wave(&retval, (uint32_t)frame->get_sampling_freq()*1*frame->get_bit_depth()/8);
tv_audio_wave(&retval, (uint16_t)(1*frame->get_bit_depth()/8)); // block aligh
tv_audio_wave(&retval, (uint16_t)frame->get_bit_depth());
tv_audio_wave(&retval, "data");
std::vector frame_data =
frame->get_data();
tv_audio_wave(&retval, (uint32_t)frame_data.size());
retval.insert(
retval.end(),
frame_data.begin(),
frame_data.end());
return retval;
}

"frame" here is just a snippet of raw audio samples with some info about it

C++ is the problem

I want to stick to the 80-col rule, and this code was nested pretty deep. I'll refactor it since it isn't nested as deep

std::vector wav_data = tv_audio_get_wav_data(audio);
SDL_RWops *rw = SDL_RWFromMem( wav_data.data(),wav_data.size());
Mix_Chunk *chunk = Mix_LoadWAV_RW(rw, 1);
if (chunk == nullptr) {
std::cout

>Static typing
Fairly standard for most compiled languages.

>Sum and product types, with support for generic programming
Translated into C++ terms -- tagged unions, structs, and templates.

>Higher-kinded types
>Higher-rank types
I know that one of these is equivalent to template template types, and do not know what the other is.

>Totality and purity annotations and checking
Purity should be optional, ideally.

>No null
This necessarily implies that raw pointers are impossible, and therefore while we will be using a compiled language, it will not be a systems language. Not suitable for replacing C, C++, Rust, or Ada (or D with the garbage collector turned off), it may be suitable for replacing Haskell.

>Type inference
>Tail call optimization
These should be implemented in pretty much every language.

tv_audio_wave just adds the data to the end of the std::vector

>80-col rule
Yeah, that rule only works if you're deliberately avoiding unnecessary nesting.
I prefer to use the soft-80, hard-100 rule:
Try to keep it under 80, but if it hurts readability to split the line there, you can go over. You must not go over 100 at all, though.

Is this place exclusively for programming, or do you guys mind if I make some reverse engineering and possibly encryption/decryption questions?

My way is easier to read IMHO

drop it like it's hot

whoops, meant
shoot

A higher rank type is something like

(forall a. a -> b) -> (x,y,z) -> (b,b,b)

The key point being the parametric nature of the parameter. You aren't just passing a "template instantiation", you're passing a parametrically polymorphic function.

>Totality and purity annotations and checking
>Purity should be optional, ideally.
That's what he means.

We assume that he's advocating the same handling of totality and purity in this sentence. Since he's referred to them as annotations, it implies the possibility of the absence of these features. Furthermore, if he were saying that purity should be mandatory, he would also be saying that totality should be mandatory. I do not think he is saying that all new languages should be Turing incomplete. Therefore, he is saying totality is optional via annotation, therefore he is saying purity is optional via annotation.

First class functions
Scheme-like macro system

is tv_audio_wave() appending a null byte to the vector when you pass a string literal to it? Like here:

tv_audio_wave(&retval, "RIFF");

That would fuck the format up.

no, here is the char* code
static void tv_audio_wave(std::vector *retval, const char *data){
retval->insert(retval->end(), data, data+strlen(data));
}


I will force it to do +4 and not +strlen, since there is no place where it isn't four long

What's your excuse for not being outside enjoying New Year's Eve?

I'm thinking it is an endian mismatch

Today is just an another arbitrary day chosen as reference for what you define as "new year".

So because you have no friends?

That pic also forgot to mention the fucking weebs fighting to see who gets to post their favorite anime picture in the OP

OP here. Sorry I didn't include an anime image.
Here you go

Yes - being able to write something like

total pure Nat factorial(Nat n) = ...


and have the compiler then refuse to compile if it detects that factorial is impure or non-total. You would be able to use them independently, e.g.

total void negate_some_global_somewhere() = ...

pure Nat i_cant_prove_this_terminates_but_it_has_no_side_effects() = ...


or use neither of them:

void do_whatever() = ...

Rather lost when it comes to using OpenGL with C++. Using this tutorial (opengl-tutorial.org/) to learn what I can, but I eventually want to make a snake game.

I think my biggest question is, given a window, how can I read keyboard inputs? Would I have to use cin? Because I want it to be like a regular video game, where the key press registers relatively quickly without needing to press ENTER

You would need another library for keyboard inputs

"Can you program?"
"Ehh... Maybe?"
"Alright you got the job!"

I wouldn't worry too much about this, user. Just try to work on personal projects to build a personal portfolio, and see how companies react to it.

cin is terrible for on the fly keyboard inputs
If you want to stick to a terminal, use non-canonical mode (a text editor for example).
Since you are making a game, I would opt for SDL_input

I've been working on this build of RetroPie for ages. I basically shoved a RPi 3 into a PSX and wired the controller ports directly to the Pi's board.

I noticed soon after it was complete that the controllers were throwing random inputs when the RPi was using lots of CPU. Tracked it down to the gamecon driver, and after rewriting half of the PSX related code and adjusting timings, no more random inputs.

Fuck yeah, feels good bruhs.

Fuck you

Thanks, kind anons!

wut

So you're taking a function that turns all of its arguments into something of type b, and a 3-tuple, and the result is a 3-tuple with all of its elements of type b. Presumably the function in the first argument is able to take elements of different data types?

Yes - that's what the forall is for.

Yeah, that's probably it.

Write the vector to a file and open it up in a hex editor. If you see "RIFF" backwards in the hex dump it's an endian problem.

OMG THE MEME I CREATED IS IN THE OP
I'M SO HAPPY, I WAS ALMOST GIVING UP
BEST NEW YEARS GIFT EVER

I'm not a redditor

ty bae

I will add it in my next meme. ty for your suggestion

>I'm not a redditor
>Posts a fucking frog
I beg to differ.

2017 is the Year of Rust; get over it!

No, that isn't it. Using RWFromFile and a test wave file worked, and they have everything in plaintext written like I have it in the calls. I'll look at the numbers in a hex editor to see what comes up

Some people are happy using crippled languages, get over it!

Yes, the point is that normally, even if your function was templated, its PARAMETERS (per instance) would be monomorphic. E.g. it would take a std::function;

But here, you can take TEMPLATED functions (and other parametric) as parameters.
So here it's like

template
std::tuple< X,Y,X,Y>
myFunction(template std::function, std::pair);

If you think of one SPECIFIC instance, e.g. X = Int, Y = String

std::tuple
myFunction(template std::function,
std::pair);

our parameter is still templated/polymorphic
because of this we know we could call that parameter on BOTH of the members of our pair, e.g.
it's not just been reduced to an (int -> (int,int)) or a (string -> (string, string)), it is LITERALLY an (forall a. (a -> (a, a)))

You can sort of do this in C++, but it's not actually type safe.

The creator the meme on the OP here.
AMA me anything

Pepe is a r9k meme

glfw.org/

Hey guys,

I spend a lot of time practicing practice algorithms problems for job searching, but oftentimes I legitimately don't understand the solutions and can't really see how to come up with it myself.

What do you do in those situations in order to "learn" the problem even when you really dont understand it?

Or rather, what do you do to understand solutions that are really unintuitive to you?

By not actually type safe, I mean it will follow the regular C++ convention

>instantiate template
>does it have this operator for int? yes?
>does it have it for string? no? fail

a sort of dynamic static typing (in the sense that errors are being deferred)
and you get these errors that occur when the template is instantiated, but don't occur inside the actual function that makes wrong assumptions

while in Haskell, there is no reason to assume that any arbitrary type can be called with an int and with a string.
so something like

template
auto func(T f) { return f(3); }

is valid C++, but not valid Haskell

>C++
>not actually type safe
Quelle surprise.

Ah, so where higher kinded types take a type constructor (templated type) and produce another type, a higher ranked type takes a function constructor (templated function) as an argument, producing another function?

Can you show me how to do monad transformers in C#?

Why haven't you killed yourself yet?

Surely this should be giving you some compiler warnings? You're passing in things like uint32_t for "data". What do you think strlen(uint32_t) is going to give you?

Turns out I never supplied it any bit depth info

Those are defined as separate functions. I would have used templates, but the documentation I was reading said something about different endians for different types of data

An useful way to learn how to solve problems is to thing of the basic building blocks of the problem, it's properties and how they relate.

I'm supposing you don't have a STEM background right? It's something you can learn by writing proofs.

Books that may help you are:
Calc I - Tom Apostol
A transition to advanced mathematics - Smith, Eggen(requires calculus)
Any introductory book in algebra(not linear algebra)
Some book about linear algebra
Some book about mathematical logic

Something like that

A higher ranked type can take polymorphic types as arguments.

So the main difference is that we can re-use that same function with different types, because we KNOW it has a polymorphic type.

Another thing Haskell allows is PolymorphicComponents, which means that you can store polymorphic types.

Ah, ok. Headers can be annoying to get right sometimes.

Thank you for your question. Your opinion is very valuable to me.

I have already considered suicide a lot, mainly due depression, which also brought me to Sup Forums.

I have been taking medication and I'm better now. Also since now I'm a famous memester killing myself would be foolish. No one can stop me now.

>implying that was the only problem
it still doesn't work, same error. It has to be some endian junk or something