/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

benchmarksgame.alioth.debian.org/u64q/c.html
lights-of-holiness.eu/android
pythonprogramming.net/machine-learning-tutorials/
xyclade.github.io/MachineLearning/
github.com/jupyter/jupyter/wiki/A-gallery-of-interesting-Jupyter-Notebooks#statistics-machine-learning-and-data-science
github.com/jhund/filterrific/issues/147#issuecomment-341867147
medium.com/friendship-dot-js/i-peeked-into-my-node-modules-directory-and-you-wont-believe-what-happened-next-b89f63d21558
en.wikipedia.org/wiki/Streaming_SIMD_Extensions
stackoverflow.com/questions/11228855/header-files-for-x86-simd-intrinsics
twitter.com/AnonBabble

In for question:
beginnerfag here, i can "program", and by that i can make command line programs, basically calculators, fizzbuzz, manipulating strings and and all that shit

so
how do i learn to make real software now?

>What are you working on, Sup Forums?
Distributed userspace NVMe driver so you can have direct IO from your CUDA programs.

Java is a good language

learn gui programming

wxwidgets, libui, tcl/tk are probably the least painful

how do you know if you're too much of a brainlet for a programming career?

java:

public class HelloWorld {
public static void main(String []args) {
System.out.println("Hello World");
}
}

ruby:
puts 'hello world'


>Java is a verbose language
FTFY

Code complexity: what does it mean?

on this website: benchmarksgame.alioth.debian.org/u64q/c.html they do benchmarks of toy programs, and also they measure 'program complexity' by using gzip to compress the text of the source code.

But, when you compare C++ to C; C has the less complex code almost every time. Even though C++ is supposed to be a higher level language

is the issue here that C++ is simply more expressive, so the user is actually encoding more information about the problem into the source code?
or maybe the toy problems aren't using 'idiomatic cpp'; but I checked one of them and it was using a class with private and public methods. Didn't see any inheritance though.

maybe the gzip algorithm 'compresses away' code duplication so it raises the C score above its natural level; but they do mention that they use the 'lowest settings' on gzip

the java score is almost universally better than the sepples or c one btw

what do you think?

Code complexity isn't something that's quantifiable or measurable. Just gzipping and comparing the output is just measuring the amount of redundant characters, it doesn't mean shit at all.

what about static analysis tools like gnu complexity

That will help you remove redundant code and analyse stuff like code coverage. It's obviously a good thing, but m-muh code complexity is a meme typically spouted by Theo de Raadt and his followers and Plan9 autists.

OKAY FOOLS, you can stop making your web apps with your meme languages now!
Common Lisp has QT5 bindings and can deploy to all platforms that QT supports.
lights-of-holiness.eu/android

dumb frogposter

>C++ommon Lisp
>Not a meme language

dumb racket poster

>Racket is the only Lisp that isn't CL

chicken and gambit don't have native thread suppoort. I doubt you use bigloo. Clojure is not lisp.

if you have trouble making a program that shifts every element of an array right by one

Define "making real software".
I think what you might be looking for is higher level programming / software engineering, as in:
Think of a task, let's say you want to write a simple CLI program that can play raw waveform data from files on the disk, basically like mpv only very limited in the type of file it can handle. Think of what the system looks like to the user, how he interfaces with the program.
>keyboard shortcuts to give commands to program
>program reads file from disk
>user receives analog audio from speakers
Now divide those into smaller problems. For the keyboard shortcuts you might need to learn how to use ncurses or other UI toolkits. For the audio output you might have to look up documentation on various audio interfaces that you want to support, like ALSA, pulse etc. Essentially, define what part of the system communicates with what other part, and how it does that. Then think about interactions between the parts. E.g. the user invokes the program with a command line parameter that is the path to the file. The program normalizes the path (resolves symbolic links, turns relative paths into absolute paths, normalizes case if your filesystem doesn't care about it), checks if the file exists, initializes the audio interface... The user presses . Open the file, start buffering and playing (sending the data to the audio interface). If file ends, exit. If user presses again, stop playback but keep buffering. If user presses instead, stop playback, clear buffer and close file but do not exit. If user presses , advance in the buffer. Etc.

This is just one approach how to make a program but in essence it boils down to
>look at complex problem
>break it down into slightly smaller, less complex programs
>re-use existing interfaces, libraries etc. if possible because most meaningful programs are too complex to be developed by a single person from scratch
>look at existing source code

I'm unironically learning swing
end me pls

>Clojure is not lisp

Posting here because /sqt/ is too stupid.
If a Java superclass implements an interface, do any subclasses need to implement it to, or just use the superclass implementation?

dumb clojure poster

They'll implicitly implement it by extending the superclass.

Daily reminder that rust will not compile if word "nigger" is in the source code
The compiler will also try to post racist comments in your social media if your pc is to connected to such

Do you think I am ready?

#include
#include
#include
#include


void rshift(uint8_t* p)
{
__m128i in = _mm_load_si128((__m128i*) p);
__m128i shift = _mm_setr_epi8(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0);
__m128i out = _mm_shuffle_epi8(in, shift);
_mm_store_si128((__m128i*) p, out);
}


int main()
{
size_t i;
uint8_t array[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};

rshift(array);

for (i = 0; i < 16; ++i)
{
fprintf(stdout, "%u\n", array[i]);
}

return 0;
}

not portable

Portability is for MIT niggers

>Code complexity: what does it mean?
Code complexity is a measurement of the complexity of a language or program. (Not complicatedness.) It is an umbrella term, not meant to be used for comparison without specifying exactly what type of "complexity" you are comparing.

>not portable
>shitty naming, literally begging for name clash when linking

If all you can complain about is "m-muh portability" and "b-b-b-but naming" for a fizzbuzz-tier example, then there isn't a lot to actually complain about.

...

why did you use 16 elements

Where can I learn data science after datacamp jacked their prices up and removed student discounts?

Includes R, Python, etc

>he doesn't know

Because I use a 128 bit register.

how into bash and powershell? i want to know more about operationg systems so any books related too.

this is a good tutorial for python
pythonprogramming.net/machine-learning-tutorials/

What the fuck am I doing with my life
⍝ Sudoku row-column filler
(⊢∨0∘=∧(↑¨(1=≢¨)∧⊢)∘((⍳9)∘∼¨)∘(∪.∪⍨))

- What are you able to do ?

- /hack the NASA

-you're welcome

interesting things

I didn't ask for you to shift an array of 16 elements to the right though.
Confirmed for brainlet.
Delete your compiler and don't let the door hit you on the ass on your way out.

>failing to specify what you want
>gets upset

Tannenbaum?

xyclade.github.io/MachineLearning/
github.com/jupyter/jupyter/wiki/A-gallery-of-interesting-Jupyter-Notebooks#statistics-machine-learning-and-data-science

I specified what I wanted, you didn't fucking listen and just made some shitty program.

did you do that yourself or just copied form that video that gets posted here sometimes?

how to re-write this another way

if (!flag) {
hashmap.put("_max_", new JSONObject().put("var", data.getRange()));
} else {
hashmap.put("_max_", new JSONObject().put("var", "undefined"));
}

not him, but you're being a jackass

>you didn't listen
I don't care what you are rambling about by yourself, you're on the internet *WRITING*. I think you are insane.

hashmap.put("_max_", new JSONObject().put("var", flag ? "undefined" : data.getRange()));

That video is for Dyalog, and it's not even optimized; this one's for NARS2000.
The video is so old it doesn't even have trains!

>calling me a jackass after he wrote that abomination
I guess I'm in good company.

If it works it's not an abomination. Also, you really didn't specify shit other than the shifting array elements.

thanks

>abomination
It may be an abomination, but it is fast

#include
#include
#include
#include
#include


static uint64_t current_time()
{
struct timespec ts;

clock_gettime(CLOCK_REALTIME, &ts);

return ts.tv_sec * 1e6 + ts.tv_nsec / 1e3;
}


static uint64_t benchmark(void (*func)(uint8_t*), uint8_t* elems, size_t n)
{
uint64_t before, after;
size_t i;

before = current_time();
for (i = 0; i < n; ++i)
{
func(elems);
}
after = current_time();

return after - before;
}


static void rshift_fast(uint8_t* p)
{
__m128i in = _mm_load_si128((__m128i*) p);
__m128i shift = _mm_setr_epi8(15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
__m128i out = _mm_shuffle_epi8(in, shift);
_mm_store_si128((__m128i*) p, out);
}

static void rshift_slow(uint8_t* p)
{
size_t i;

uint8_t last = p[15];
for (i = 15; i > 0; --i)
{
p[i] = p[i - 1];
}
p[0] = last;
}


int main()
{
size_t n = 524288;
uint8_t array[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};

uint64_t slow = benchmark(rshift_slow, array, n);
uint64_t fast = benchmark(rshift_fast, array, n);

fprintf(stdout, "slow shift\t%8lluus\nfast shift\t%8lluus\n", slow, fast);

return 0;
}

I know nothing about apl expect that it has funky syntax
I watched those videos tho and it look very interesting, maybe some day I'll look into, for now I have way to many meme langs on my hand

Reminder to be kind once in a while to your fellow programmers.

github.com/jhund/filterrific/issues/147#issuecomment-341867147

#include

void main(void)
{
char a[9] = {'4', '2', '6', '7', '2', '5', '3', '7'};

for(int index = (sizeof(a) / sizeof(char)) - 1; index > 0; --index)
a[index] = a[index - 1];
a[0] = '0';
for(int index = 0; index < (sizeof(a) / sizeof(char)); ++index)
putchar(a[index]);
}

xD
our system thinks your post is spam, even though there are enough original content to justify this stupid post
mods are fags

it wouldn't work anywhere outside of CPUs supporting SSE2, like original intel chip i386, ARMs, etc.

>mods are fags
Indeed they are

Today I have discovered the best Haskell language feature.
{-# LANGUAGE Strict #-}

I was working on some software, and there was some memory leak I just couldn't explain.
I became really frustrated at this lazy piece of shit, and even looked for some strict functional languages, when I found this.
Just tell Haskell to not be a lazy ass, and everything works.

>{-# LANGUAGE Strict #-}
eww

in regards to all the different algorithm practice sites (codingbat, codefights, codewars, firecode, leetcode, hackerrank, etc) which one is the best for beginners?

feels like they all just give you questions without much help which is great if you already have a good foundation but horrible if you dont

IMO laziness by default was a huge mistake, especially since you can implement laziness explicitly with () -> a.

How much does this make you cringe?

>i386
If you're going to complain about portability to a processor that was made 32 years ago (and taken out of production over ten years ago), then I would claim that you're grasping for straws. I am fully aware that it isn't portable, that isn't the point. I just made a fast array shift function because user didn't specify data type or array length, okay?

There's no need for all this autism.

>needing to tell it to be strict
wew
>memory leaks
good lord

So...a linked list?

Linked lists are not arrays.

Lazyness is just not beneficial for any real world applications.
In anything big, it will just lead to space leaks.
It was a nice experiment, and has some nice usecases, but in the end it isn't worth it.

Yes this is Haskell.

>not writing a Strict monad

>tfw C++17

I'm not willing to read it if you don't structure that first function properly

I also don't get the argument that you lose equational reasoning with strictness. Besides, your reasoning is already fucked when you can prove anything with `error` or an infinite loop and still run into undefined behaviour if you don't remember to clutter your code with extra forcing. If Haskell was strict, you could be automatically guaranteed that you can't call a function without proof that you're using it correctly because the program would abort or hang before it gets a chance.

Is the lattice of N and GCD/LCM pseudocomplemented? Asking for a friend.

How do the built-in #defines work in C++?
So you can do like #define _USE_MATH_DEFINES to use pi and stuff. Are these built into the standard library or something?

pi is in i think

>ghc has gc
>somehow memory still leaks
the power of hasklel

Not that guy, but same.
So I typed it out for you.

#include
#include
#include

int cmp_int(const void *p, const void *q){
int x = *(const int *)p;
int y = *(const int *)q;

return (x < y)
? (x==y) ? 0 : -1 :
: (x==y) ? 0 : 1 ;
}

void sort(int *a, size_t n){
qsort(a, n, sizeof *a, &cmp_int);
}

int main(int argc, char *argv[]){
size_t n = argc - 1;
int a[n];
memset(a, 0, sizeof(int)*n);

for(int i = 0; i < n; i++)
a[i] = atoi(argv[i]);
printf("Printing unsorted array ... \n");

for(int i = 0; i < n; i++)
printf("%d ", a[i]);
printf("Sorting ... \n");

sort(a, n);
printf("Sorted!\n");

printf("Printing sorted array ... \n");
for(int i = 0; i < n; i++)
printf("%d ", a[i]);

printf("Done! Program closing ... \n");
return 0;
}

reminds me of this

medium.com/friendship-dot-js/i-peeked-into-my-node-modules-directory-and-you-wont-believe-what-happened-next-b89f63d21558

>Daily reminder that rust will not compile if word "nigger" is in the source code
Sauce

they are meant to be complementary to your algorithm studies, pick a book and solve exercises from it first. Like "dp chapter": read, ex from the book, ex from hackerrank

Working on a directX OBJ mesh loader for my CS degree, I can't get my texture to load properly and want to die, still have a week thought so should be fine

Don't listen to them user. I didn't even know what SSE was until now, so I've learned something new today thanks to you.

>it's fake
>not even april 1
fucking leftist fake news sites fucking spewing disinfo and not even saying it's a joke

But if you're building a list of objects that you plan on shifting to the right then why not just use a linked list instead of messing around with an arrays indices?

I'm not trying to be argumentative I'm just curious. I'm a pleb programmer and always like to know why people use certain practices.

A memory leak in Haskell is not a true memory leak. The memory is still reachable, often because a thunk pointing to it hasn't been forced, but the programmer assumes it isn't. Laziness by default makes this problem irritating to solve since you have to pepper your code with strictness boilerplate (unless you use the STRICT pragma).

If your data is already in an array for other reasons, obviously. Plus, unless you care about preserving order, you can implement insert and remove in constant time by swapping one element instead of shifting N elements.

>unless you care about preserving order, you can implement insert and remove in constant time by swapping one element instead of shifting N elements.
Not sure what you mean?

What GUI library should i use for a toy Matrix client in Python3 (for a school project)?

>Python3
>should i use
no

You ruined the complex beauty of my code

Inserting and removing elements from an array where the elements must remain in order are the most common reasons to shift array elements. If you don't care about order, the operations look like this:
insert(A, x, i) {
push(A, A[i]);
A[i] = x;
}

remove(A, i) {
x = A[i];
A[i] = A.pop();
return x;
}

in C++ you would just use std::copy_backward

I'm still not sure what it is.
If I ever get around to reading up on it, I may then know.
But not now: too late in the day.
en.wikipedia.org/wiki/Streaming_SIMD_Extensions
stackoverflow.com/questions/11228855/header-files-for-x86-simd-intrinsics

>push
>pop
Those are stack operations, stack is a higher abstraction than "arrays" (the latter generally being fixed in size, where resizing are costly operations).

Also, your remove function is broken if you try to remove the last element in the array, where you end up inserting it again in the same position.

std::priority_queue my_queue;

/*...*/

unique_ptr a (std::move(my_queue.top()));
my_queue.pop();


This... should work, right? It's telling me I'm trying to use unique_ptr(const unique_ptr&), and obviously that doesn't work - despite me trying to use std::move to make it an rvalue. Am I going crazy?

NEET virgin replies not needed

If someone's talking about shifting a part of an array, they already implicitly mean dynamic array. Push/pop are the canonical dynamic array operations. Yes, this means dynamic arrays are stacks.

>c++
for what reason?

internet points?