/dpt/ - Daily Programming Thread

What have you been working on, /dpt/?

Last thread:

Attached: [email protected] (1060x1260, 73K)

Other urls found in this thread:

pastebin.com/6xnrdAuN
pastebin.com/HHqeWQ7H
twitter.com/AnonBabble

for me, it's zig

Attached: move zig.png (4824x1527, 119K)

please stop bullying haskell >w

Attached: 1465344167062.jpg (441x415, 19K)

this

Attached: 1536322676030.png (490x366, 231K)

I'm making a FOSS replacement for Emby, since it's gone closed source and has apparently had closed source components for awhile (in complete violation of GPL). I'm building my replacement from the ground up and I would like the database backend to be configurable by the user (ie. user should be able to configure it to use mariadb, sqlite, postgesql, etc..). What frameworks exist to help facilitate this? I don't care about language. I will be selecting the language(s) based on what has the best libraries available.

Also, what is a good name? I am really terrible at picking names. If nobody stops me I'll probably call it something like DodongoViewer.

JavaScript rocks!

Attached: js_rocks.png (1433x779, 473K)

they should change glsl syntax so its a little more conducive to chaining functions
reading floor(pow(sin(fract(dick)), 5)) or whatever gives me a fuckin headache

What's the name of the Python3 library which added all sort of weird new syntax?

From what I remember, it made metaprogramming a lot easier, made lambda functions Ruby-like, and added a couple new operators.

Does anyone know?

Attached: rms.jpg (236x177, 10K)

Use intermediate variables or use a preprocessor that makes chaining better

If they changed it, it wouldn't read like C
Changing anything to be different from C is a non-starter

If your functional programming is so superior, how come 99% of all decent software is written either in procedural or at worst in OO?

Functional programming is good at what it's good at, which is writing fluent and optimized algorithms, joining, splitting, mapping, re-joining, etc in an optimized way that is also easy to read (if you know how).

The problem is that real world code scenarios are generally stateful, interface-based, and message-driven so even though functional principals are going to help you write the meat of your algorithm code very well, you're going to want the more-OOP-like scaffolding to link all the components to the real-world events that trigger them.

Modern programming languages are learning to take advantage of both paradigms, and the limitations of something purely one way or the other are really showing their age.

As per usual, Lisp is decades ahead of "modern" programming languages.

Because functional programming is new and fresh.

No offense to Lisp, but they really should have learned the benefit of more than one scoping-like character. Although I do find the solution of color-coding the parens cute.

flamewars

itertools? functools?

Uh... hmm. Not sure how to respond to that one.

the syntax of the language is the parsing tree itself

If I want to port my simple bitmap image program from Windows to Linux, where do I begin? How do I draw pixels in Linux?

Why?

>Dancer succubus,
>like a fake penis.
This one doesn't even make sense.

Google " BMP tutorial".
My noob solution is using python and pygame, which I find more intuitive to use than other image manipulation libraries.

I get that (to some degree, anyway; I "learned" Lisp, but I never used it too deeply, so it was it was pretty shallow learning), but you have to give the programmer better tools for formatting their code. If you're not readability-driven, you ain't modern. In the real world, senior coders work along side junior coders and your clever algorithm is going to have to be read and reviewed by someone at some time.

Just like JavaScript

Attached: 1538196114202.jpg (639x724, 45K)

At least it doesn't have syntactically significant whitespace.

I been sleeping with every twink on my department while making them wear pink kneesocks and glasses. Productivity is up 5%.

flan, no!

yes,yes,
except that gives lisps a great power and code, data it's all the same, makes for metaprogramming - for example - very easy.

Thanks, but nope.
I think it implemented a few proposeds PEPs and hacks into a single package.

Whocares? You can use any AST you want. As long as you can adequately express it as a data structure in your language you can do metaprogramming just fine.

Lists being the only data structure Lisp is well equipped to describe is a limitation, not a feature.

The absolute state of nu/g/

some of these are horrifying but then it's mixed in with some first-month-of-programming kid's "holy fuck floats have rounding errors" in there too

Hy

GTK+ any good? Any better alternatives?

WxWidgets

What makes it better than GTK+?

tkinter

It makes perfect sense for max with no arguments to return -inf and min with no arguments to return inf. This is basic lattice theory.

Can I have a short explanation?

Are they variadic functions? If so, the return value makes some degree of sense.

Well I guess you're right, people just pick lisps because they like to make it harder for themselves
gee you're one dense motherfucker

They are.

But still don't understand why the return values make sense.

Explain functional programming to me

avoid writing dysfunctional code

People don't pick Lisps, though. They're irrelevant.

Attached: 1523276338310.jpg (392x495, 45K)

Functions take arguments and return values, and are not allowed to modify state or have side effects.

Am I a Pythonista? This is in my .pythonstartup file.
I usually have a couple interpreters open at once and I was typing pp(dir()) a lot to see what I had in each one. I want ls to have the function code in its docstring and I don't want to repeat the code in the function body.

from pprint import pprint as pp

def ls():
'''pp(sorted(globals().keys()))'''
exec(ls.__doc__)

From a constructive mathematics point of view (which is important for actually being able to compute things), an N-ary (variadic) operation is typically derived from a more primitive binary operation which follows some rules. Minimally, generalizing a binary operation to an operation that processes a list of arguments requires the operation to be associative and have left and right units (be a monoid). Associativity means that max(a, b, c) = max(max(a, b), c) = max(a, max(b, c)) and left and right units mean that a = max(a) = max(max(), a) = max(a, max()). If max() = inf, then inf = max(a) which is obviously not what we want. max() can only be -inf in this case.

As an aside, max is also commutative (max(a, b) = max(b, a)) and idempotent (a = max(a, a)), which means it conceptually operates on a set of arguments, not a list. This is exactly how it works in lattices, where every finite set has a supremum (least upper bound, or informally, maximum element). The situation is reversed with min.

Yes.

Maybe that's not short enough, but that's the formal reason. A shorter and maybe more intuitive explanation is that if you have a set of numbers, and you remove one of the numbers, the maximum of the initial set always >= the maximum of the new set. Now let's say the your set only has one number, in which case the old maximum is the number itself, and it should be >= the maximum of the empty set. In order for this to always hold, the maximum of the empty set must be -inf.

You are too generous user, you are explaining this to people who can't spend a few minutes to look up type coercion rules which are 100% reasonable.
Shit like what that image has wouldn't even get anywhere near code review because people who write code like that wouldn't even be hired anywhere.
Well maybe they can kode with klossy or something, that shouldn't exceed their capabilities.

Very cool explanation. Thank you.

But why couldn't Max(NaN, a) be defined as a?

N520 T17 D1
N530 M6
N540 F50 S1000 M3
N550 ;G90 G00 Z50
N560 ;G90 G00 X81 Y62,83
N570 ;G90 G00 Z0
N580 G90 G81 X81 Y70.83 Z0 I-20;A
N590 G90 G81 X86.657 Y68.487 Z0 I-20;B
N600 G90 G81 X89 Y62.83 Z0 I-20;C
N700 G90 G81 X86.657 Y57.173 Z0 I-20;D
N710 G90 G81 X81 Y54.83 Z0 I-20;E
N720 G90 G81 X75.343 Y57.173 Z0 I-20;F
N730 G90 G81 X73 Y62.83 Z0 I-20;G
N740 G90 G81 X75.343 Y68.487 Z0 I-20;H
N750 G80
N760 G90 G00 Z50

No, but every GUI toolkit is shit.

JS's coercions are only reasonable once you accept the premise that it's the language's job to fix the programmer's braindead code.

The general rule with floating point operations is that if one of the arguments is NaN, the result is NaN. You want NaNs to carry through operations because you want your bugs to be found.

Makes sense.

That has always been the case, as long as programming languages have existed.

ignore everyone else
functional programming means you can use functions, they are treated as first class
they are data, can be returned, given as input, etc
pure functional programming means functions really are functions (in the sense of mathematics) because for every input there is an associated output
stay away from pure functional programming, as it just constrains you

>optimized
Yeah, no.

Not really, most languages give you an error when you use the wrong data type. This forces the programmer to fix their mistake.

Even C can treat functions as first class objects, using function pointers.

yeah but it's painful to use it
just use a proper language for it

Sure, but all programming languages are abstractions over lower level languages, assembly, and ultimately machine code. The entire reason to have a programming language is to fix the programmers braindead machine code.

JS isn't the first and it won't be the last dynamically typed language so that statement does not apply here.
Besides, every single resource, learning course and the community itself encourages the use of strict equality operators and typeof use, so if you started learning today and got involved with the community then you'd quickly learn that and how to write typesafe JS code.
If that's not enough for you there is always TS for those who can't go an inch without their types.

Thoughts on how I can improve this to handle .webms?

Can PIL handle Webms?


pastebin.com/6xnrdAuN

Attached: 1513803213544.gif (500x280, 1.17M)

typeof NaN === "number" is still retarded.

Fuck. I think i'm going to have to reinstall Python.

Holy shit! Call the standards committee! user says NaN is not a valid IEEE 754 floating point value!

If a programming language prevents the programmer from writing braindead code in the first place, that's a good thing. What JS does is to happily accept shit code and try to make it work anyways.
Dynamic/static typing is irrelevant. There are plenty of dynamically typed programming languages that are happy to crash your program when you use an incorrect data type. Try passing a number to one of the string-* functions in Scheme, for example.
And sure, if you're forced to use a shit language then you can come up with all kinds of conventions to make it better. That's not an excuse for the languages poor design.

i'd be fine with typeof NaN === "IEE 754 floating point value"

I don't understand it
what's so revolutionary about it when you can do all of this just using pointers to functions

I mean what does Haskell do that it is considered so special and revolutionary

Literally every language and every FPU that implements IEEE 754 will tell you that NaN is in fact a valid number, despite the name. Retard.

It provides syntax and a standard library to make it easier to program functionally, while also hampers your ability to program non-functionally.

Just wrote an implementation of the date programing C: pastebin.com/HHqeWQ7H

I told myself last night I was going to try to do four hours of coding every day to regain my edge over the Macbook-using söyboys and koders who infest Starbucks.

I'm almost at my 2 years at my current place. Time to start leetcoding

I guess being called retard is a small price to pay for learning new things.

They should just call it "float" or "double" then. "number" is a bad substitute no matter how you spin it, since a significant percentage of floating point bit patterns (all of which are valid) are not numbers.

No it won't. Valid floating point value doesn't imply a number.

>Lists being the only data structure Lisp is well equipped to describe
[citation needed]

Lisp is the most powerful programming language.

what does the code do anyway?

Attached: 1536226741096.jpg (564x564, 99K)

So for some reason I can access a queue freely in the first portion, but not after executing function access(...), which basically means I'm opening a file to write/read from it and then closing it. What the fuck? I'm pretty sure it has nothing to do with the queue. If you have any idea why this could be happening, just tell me.
void send_reply(server_args *server) {
request *req = fcfs(server);
printf("queue size = %d\n", queue_size(server->requests_queue)); // NO PROBLEMS
int id_sector = req->id_sector;
int op = req->op;
char *cont = req->cont;
buffer *buf = req->buf;

reply *reply;

void *p = malloc(512);
char *aux = (char*) p;

if (op == WRITE) {
strcpy(aux, cont);
resp->result_up = access(id_sector, op, 0, aux, strlen(aux));
}

else {
reply->result_op = access(id_sector, op, 0, aux, 0);
reply->cont = aux;
printf("%s\n", reply->cont);
}

printf("queue size = %d\n", queue_size(server->requests_queue)); // ERROR HERE!
// do some stuff...
}

aaa.c: In function 'main':
aaa.c:57:37: error: 'struct tm' has no member named '__TM_ZONE'
case 'Z' : printf( "%s", curtime->__TM_ZONE ); break;

Forgot to say, but the error is a seg fault.

use a debugger

>error is a seg fault.
fire up gdb and debug the problem

Fire up a debugger.
Also access is the name of a POSIX function from unistd.h.
You should name it something else.

Haskell is unique in that it's purely functional (functions are side-effect free) and lazy (arguments to a function are not evaluated until required). Most of the cleverness of Haskell follows from it being lazy and having global type inference.
You can define a function in terms of itself, for example.
foldr _ [] y = y
foldr f (x:xs) y = f x (foldr f xs y)

factorial in Hasklel
fac n = snd (until ((>n) . fst) (\(i,m) -> (i+1, i*m)) (1,1))

malloc already returns a void pointer, why call that way?

Hello /dpt/, I need to do a large computation that's going to be bottlenecked by set operations, specifically the set sum A + B defined as (A + B) = {a + b | a in A, b in B}. Does anyone know a fast library for calculating this sum?

Oh, the elements of the sets are integers. Probably 16 bit in practice but 32 bit would be nice.

you're gonna need to be a lot more specific

there are set data structures designed specifically for ints, e.g. IntSet in Haskell

Why are the results invariably terrible when normies try to design programming languages? Look at Java. Look at Python.

>normies
The pot calling the kettle black.

let's see your language, autist

*tips fedora*