/dpt/ - Daily Programming Thread

Old thread: What are you working on, Sup Forums?

Other urls found in this thread:

youtube.com/watch?v=jD8Tu1tqvZo
blog.ielliott.io/why-LINQ-is-broken/
twitter.com/NSFWRedditVideo

What api style do you prefer when writing GUI code? Immediate mode/retained mode? OOP/procedural? Setup heavy and automated or iteratively constructed?

I'm gonna have to write something others interface with soon.

Guys I am looking for this design principle I found some time back. It talked about some clever way to manipulate data/class design/ late binding and some whatnot. I am little bit blurry in here but I remember it said "This principle is used extensively in class design of QT framework and KDE framework. What is it ?? fuck

>OOP/procedural?
Functional/Generic

Anyone have a cheat sheet or resource that covers every permutation of *, & in variable declarations for c++?

Coming from Python and having trouble in how I should be reading the variables in my head and which symbol means what.

Got any example api I could look at?

...

First for OLD

what does it need to do

It's very general. Any gui stuff really. As simple as drawing static rectangles and as complex as having your own opengl context.

Why is Linux saying I have 16 cores while I have 8? Does Linux tread cores as threads?

I hope the trannies learned their lesson.

Why not you porting linux kernel to python?

Rewriting the linux kernel in JS

I'm going to make a point of posting more frogs since apparently it triggers the tranny poster so much.

dumb frogposter

Why did you put some gay-ass little doodle on that image?

/dpt/, how do I approach this design pattern?
I have a 2D grid data structure.
I need to do something like wildcard pattern matching and substitution on it, but in 2D.
The problem is, not only can I not figure out an algorithm for it, I can't even begin to fathom what it would actually mean.
How would you even do NON-pattern-matching substitution in 2D? It's not like 1D, you can't just replace a region of a 2D grid with an unequally sized region, can you? From a conceptual perspective, wouldn't that warp the geometry of the grid?
And when you GET to pattern matching, how would you even talk about wildcards? What does a 2D wildcard look like? What does it even MEAN? Sure, an arbitrary number of elements that don't have to match anything, but arbitrary which way? Left-right? Up-down? Both? What about the elements around it in the format grid? Same problem as the unequally sized region issue.
I just don't know where to even start with this.

do you seriously not recognize the anime gopher

just use comonads bro

Of course I do. I was really just trying to subtly insult it.
God damn, it's such a fucking stupid logo.

not as stupid as the language

bloat?

What exactly are you trying to do?
What's the data? What are you matching on it? What is it being replaced with?

How can I use 'in' in python3 to parse any three consecutive digits from a text? Pls help

Example I/O?

Basically, I'm using urlib.request to parse a certain statistic from a webpage. Now, given that the page only has a single three-digit number, I'm using
from urllib.request import urlopen
with urlopen('website.com/niggers') as response:
for line in response:
line = line.decode('utf-8')
if [HERE GOES THE THREEDIGIT PARAMETER] in line:
print(line)

Note that I can't into Beautifulsoup due to unspecified issues.

First for golang

the usual crap

>Capture-less lambdas have deleted copy-assignment operator
The fucking fuck?

Maybe something like:
if(any(char.isdigit() for char in line:

I don't exactly know the format but that may be close

in haskell this is just

any isDigit line

Decay to a function pointer with unary+.

Thing is, it has to be the Python analogue of
if any three consecutive chars are digits
I'm not THAT retarded, user.

Why the fuck would I want to decay to a function pointer you stupid fucking nigger retard?
Do you hate efficiency? Do you want me to double to size of my struct for no good reason?

Well you could use a regex that would contain [0-9]{3}

>if [HERE GOES THE THREEDIGIT PARAMETER] in line:

so why exactly isn't this working?

is the three digit parameter a string?


line = 'abc123'
if '2' in line:
print(line)

I've got no idea what else you want.
>Capture-less lambdas have deleted copy-assignment operator
Doesn't make sense otherwise. A captureless lambda is a struct with no member variables and one nonvirtual member function. What do you expect the assignment operator to do?

f (x:y:z:ws) | all isDigit [x,y,z] = True
| otherwise = f (y:z:ws)
f _ = False

Any functional fags here?
Is there any function that returns combinations of multiple arrays? zip is 1-1 only. what I want is: [1, 2, 3].combination([-2, -8]) == [[1, -2], [1, -8], [2, -2], [2, -8], [3, -2] [3, -8]]

The length of T[][] is unknown at compile time.

Chicken Scheme's (amb) library can do this.

(amb-collect
(let ((x (amb 1 2 3))
(y (amb -2 -8)))
(list x y))))


((1 -2) (1 -8) (2 -2) (2 -8) (3 -2) (3 -8))

>amb
What does it even stand for?

It's like the symbol the singer Prince used.

ambiguous

it comes from the nondeterministic chapter of SICP

it's not especially performant for combinatorial reasons, but if you're just returning all the permutations of two sets it's fine

combinations = [ [x,y] | x [[x,y]]) [-2, -8]) [1,2,3])

What language is that?

Haskell

I live in Texas and is working on a drone based object detection platform to track illegal border crossing.

I wanted multiple arrays, the length is unknown at compile time. So that int[2] was just a test case
auto x = [[12, 23, 34], [0, 1], [-12, -88, -5, -74]];
combine(x) should return [[12, 0, -12], [12, 0, -88], [12, 0, -5], [12, 0, -74], [12, 1, -12], [12, 1, -88], [12, 1, -5], [12, 1, -74], [23, 0, -12], [23, 0, -88], [23, 0, -5], [23, 0, -74], [23, 1, -12], [23, 1, -88], [23, 1, -5], [23, 1, -74], [34, 0, -12], [34, 0, -88], [34, 0, -5], [34, 0, -74], [34, 1, -12], [34, 1, -88], [34, 1, -5], [34, 1, -74]].

>that image
>literally me

Resetting my router 5 times a day. I'm running out of mac addresses here.

Anons, I need some C++ help.

I'm using a function from a library (nftw from ftw.h, to be specific) that calls multiple times some function that I pass to it. That function I pass needs access to variables, but I don't really want to use global variables.

What's the neatest way of wrapping it?
The way I understand it, I can't make it call a non-static method of an object, so there's no point in wrapping it in a class. So do I have to put it all in a namespace and use global variables anyway?
I might be misunderstanding this C-like way of handling things.

I-I-It's so beautiful

I appreciate that it requires so much less typing. But it lacks expressiveness.

>it lacks expressiveness
Is this a troll? Functional programming is the MOST expressive. Try it for a bit. After some time, you will realise that other paradigms are just trying to do the same thing in an extremely longwinded and retarded way.

'Expressive' means that it's easy to write code that's easy to understand, both for the compiler and for a human reader.

Two factors that make for expressiveness:

intuitively readable constructs
lack of boilerplate code

Compare this expressive Groovy, with the less expressive Java eqivalent:

3.times {
println 'Hip hip hooray'
}

vs

for(int i=0; iyou will realise that other paradigms are just trying to do the same thing in an extremely longwinded and retarded way.
I already know. However languages that features a good balance of FP paradigm and performance such as Dlang, Rust are the best way to go. Laziness is not a panacea.

Your example literally shows that a functional style is superior to an imperative style. We don't use stupid loops like that in FP, rather use Map, Reduce etc.

>However languages that features a good balance of FP paradigm and performance such as Dlang, Rust are the best way to go.
>haskell
>poor performance
???

>Two factors that make for expressiveness:
>intuitively readable constructs
>lack of boilerplate code
Ok, but FP excels at both of these for non-brainlets. Haskell has pretty much the minimum "boilerplate" possible.

There's a MapReduce.
Is there a ReduceMap paradigm that could be similarly useful?
Something that takes a list of functions, rolls their functionality to one, then maps them to a(nother) list of inputs to produce a resulting list.
Or maybe it first creates a closure by reducing a normal input list(so that the final closure has some shared property of all the inputs), and then applies that closure to the original list.
Is something like this in use? Or maybe that's what MapReduce ends up doing if it's done recursively anyway? I wish I wasn't dumb so I could think good, somebody save me.

>>haskell
>>poor performance
>???

Can someone please explain what functional programming is actually used for?

Not even memeing.

Fizzbuzz

It's LINQ for advanced programmers + some other stuff

Remember times when somebody had a nice idea in theory but it actually turned out to be shit in practice? That's what functional programming is.

youtube.com/watch?v=jD8Tu1tqvZo

combos = sequence

main = print (combos [[12, 23, 34], [0, 1], [-12, -88, -5, -74]])[[12,0,-12],[12,0,-88],[12,0,-5],[12,0,-74],[12,1,-12],[12,1,-88],[12,1,-5],[12,1,-74],[23,0,-12],[23,0,-88],[23,0,-5],[23,0,-74],[23,1,-12],[23,1,-88],[23,1,-5],[23,1,-74],[34,0,-12],[34,0,-88],[34,0,-5],[34,0,-74],[34,1,-12],[34,1,-88],[34,1,-5],[34,1,-74]]

blog.ielliott.io/why-LINQ-is-broken/

That's a C# problem.

Psuedo-mathematicians wank over it, mostly. Occasionally useful if you need mass concurrency.

I'm going to implement an imageboard in .NET Core on Azure.

What features do you think are necessary?

General programming with very clear places where IO fit and you have virtually no performance requirements.

Realistically it's for math people who don't actually write anything that anyone would use.

Where do these variables need to be accessed from? Because if it's completely local to the function, you can use static variables.
#include

void somefunction()
{
static int counter;
std::cout

Lambda objects in both g++ and clang++ have their move-assignment operators not defined and not defaulted, which causes move operations to fall back to the copy-assignment operator which is defined as deleted. I.e. it's impossible to move-assign a lambda object.
This basically makes unique_ptr's with custom deleter lambdas completely fucking useless, as they can't be moved, which makes the unique_ptr unmovable. Very useless indeed.

Apparently this is the committees fault for having ambiguous wording in the standard.
How the fuck is this not fixed yet? This is a huge problem.

Example using g++:
#include

int main() {
auto del = [](int *p) {
delete p;
};

std::unique_ptr p1(new int(3), del);
std::unique_ptr p2(new int(2), del);

p2 = std::move(p1); // Doesn't compile! decltype(del) is MoveConstructible but NOT MoveAssignable!
}

$ g++ main.cxx
In file included from /usr/include/c++/7.1.1/memory:80:0,
from main.cxx:1:
/usr/include/c++/7.1.1/bits/unique_ptr.h: In instantiation of ‘std::unique_ptr& std::unique_ptr::operator=(std::unique_ptr&&) [with _Tp = int; _Dp = main()::]’:
main.cxx:11:19: required from here
/usr/include/c++/7.1.1/bits/unique_ptr.h:284:16: error: use of deleted function ‘main()::& main()::::operator=(const main()::&)’
get_deleter() = std::forward(__u.get_deleter());
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cxx:4:14: note: a lambda closure type has a deleted copy assignment operator
auto del = [](int *p) {
^

>posting images + text
>viewing images + text

C++ is a fucking joke. Why are you even using that garbage?

What should I be using?

It's a rebellion against the last 20 years of having OOP forced down our throats.

Certain languages were always functional, Haskell, Clojure, Ocaml, etc. And everyone who ever attended a class anywhere were told they were shit and should die already because OOP is the best thing in the world ever.

And it turns out OOP is no longer cool, so we're getting horrible memes where people take languages like JavaScript and use a map() function and declare they are programming functionally.

I really like it, but honestly, certain languages work certain ways, obsessing over patterns beyond just doing what your chosen language is good at is where the real meme is at.

Use whatever the hell you feel like. It's completely fine to use a general-purpose, high-performance language with a massive user base and a great amount of third-party libraries and extensions. The declarative/functional languages so praised on Sup Forums are just that - a Sup Forums meme, the hipsterism of programming. Don't take memes at face value.
While C++ has its issues, such as an ugly, inconsistent syntax (no native for-each loop in AD 2017, please), the lack of a proper dependency/package management system, or lack of modern features such as OS-independent Unicode UTF-8 strings, it is certainly usable and not the monster Sup Forums makes it out to be if you don't abuse it and decend into the more advanced features. D-lang looks like a nice replacement for C++, though. You might be interested in it.

Why do POOfags and the like always make it an "OOP vs FP" argument?
They have very little to do with each other.

>no native for-each loop in AD 2017
>hur dur what is range-based for

>no native for-each loop in AD 2017, please
std::vector vec{2, 4, 5, 1};
for (int i : vec)
std::cout

>At least it's easy to link with C and C++.
No it's not. C is easy to link with. Every language worth a shit can link with C.
C++ is a fucking nightmare to link with.

>why the fuck is this not fixed yet
Iirc you didn't have any way of overloading new to use specific alignment without doing global variable hacky stuff until C++14

The committee is lazy and C++ is a bad language.
Use C instead. It's not worth dealing with incomplete languages.

Damn. Got me.

Can you still do this?
foreach (index, element; array)
writefln("%s - %s", index, element);

That's somewhat my point. Use what works well with your language rather than trying to force classes into C or immutability into PHP.

Unless you're using Dlang, which understands name mangling and other C++ fuckery.

tfw too dumb to understand shellsort :^|

You're just calling insertion sort a bunch of times. Instead of sorting the entire array, you sort sub-arrays; for example, every 5th element or something.
Every iteration of shell sort, you reduce the size of the gap between sub-array elements. This tends to push larger elements to the end of the array, smaller ones to the start, and the array gets "more" sorted. At the very end, the gap is 1, and you end up performing a normal insertion sort on the array.
It works pretty well because of some of the properties of insertion sort:
- It works well with small arrays
- It works well with almost sorted lists
What size the gap should be and how it gets smaller is up for debate. Wikipedia had some examples of sequences that have proven to do well experimentally.

I'm trying to make an image scraper in Python but I've been failing miserably so far.

where are you failing and why?

tfw still no non-retarded-faggot summer project
why even live?

Kill yourself, you fucking retarded frogposter.

write a virus that deletes all animu from this world

...

just like surf github and start CONTRIBUTING like a madman

>implying I'd touch any project that uses the CoC made by this fucking disgusting tranny

>Caring more about CoCs than programming
Not gonna make it.

If someone goes out of their way to make the CoC more prominent than the actual project, than its a red flag.

>Rust won't let you unborrow values.
I find a new flaw every single day I use this language. It's unbelievable.

No, "she" doesn't. Try doing that pose.

Every attempt to fix C++ only results in a worse language.
C++ is clearly the best language ever designed, because all attempts to improve it fail.