/dpt/ - Daily Programming Thread

Lain edition. What are you working on, Jow Forums?

Previous thread:

Attached: 1537519025070.jpg (1440x1080, 447K)

Other urls found in this thread:

godbolt.org/z/KLdxyQ
rosettacode.org/wiki/Category:C++
twitter.com/SFWRedditVideos

can't spell In GoD we tRust w/o top-tier languages

Based and akaripilled

Attached: 1529555902163.gif (287x344, 72K)

Lisp is the most powerful programming language.

Can't spell Haskell is the best programming language without Haskell

LISP IS LOVE AND LIFE

Go, D, and Rust aren't programming languages.

I was really hanging out just to see if Jow Forums would let a /dpt/ fall off the end before creating a new one

is R functional?

Attached: programming anime waifus.png (1920x1080, 1.03M)

I know some rudimentary C++, Java and Python from some courses I took. Where can I look for some beginner-friendly open source projects to start learning more? Preferably those without a CoC and all that.

are you still traumatized from your interview?

R is cutest

This will never happen as long as autism exists.

I don't get this pseudo code. Won't the recursion just enter the first merge sort on line 3 until p >= r and then just exit, never even touching line 4 and 5?

Attached: Capture.jpg (298x143, 15K)

>tfw no C mommy

Attached: 1530171690128.gif (286x119, 449K)

q is passed in as r on line 3.

No.

When any function returns, it returns to the point of its invocation. That includes recursive functions.

So whichever line 3 is the first to complete immediately from p>=r, whichever function called that can then go to its line 4.

Why is the generator faster?

import time

items = ['knife',
'compass',
'first aid',
'tent',
'food & water',
'camping supplies']

def time_it(func):
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
finish = time.time()
print(func.__name__, 'took {}'.format(float(finish - start)))
return result
return wrapper


@time_it
def items_generator():
for item in items:
yield item

@time_it
def items_list():
return [item for item in items]

items_generator()
items_list()

fast bin2ascii
#include
#include
#include
#include
#include
#include
// compile with -O2 -mbmi2 -mmovbe
int main()
{
const std::size_t PageSize = sysconf(_SC_PAGESIZE);

void* ReadBuffer = mmap(
nullptr,
PageSize,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS,
-1,
0
);
void* WriteBuffer = mmap(
nullptr,
PageSize * 9,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS,
-1,
0
);
std::memset(WriteBuffer,'\n',PageSize*9);
std::uint8_t CurByte;
while( !feof(stdin) )
{
const std::size_t ByteCount = std::fread(ReadBuffer, 1, PageSize, stdin);
for( std::size_t i = 0; i < ByteCount; ++i )
{
*reinterpret_cast(
reinterpret_cast(WriteBuffer) + i * 9
) = __builtin_bswap64(
_pdep_u64(
reinterpret_cast(ReadBuffer)[i],
0x0101010101010101
) | 0x3030303030303030
);
}
std::fwrite(WriteBuffer, 1, ByteCount * 9, stdout);
}

munmap(ReadBuffer, PageSize);
munmap(WriteBuffer, PageSize * 9);
return EXIT_SUCCESS;
}

It doesn't do anything, it just returns a generator object

the disassembler of python byte code is the same for both functions

....

import dis

print (dis.dis(items_generator))
print (dis.dis(items_list))

you're looking at the disassembly of wrapper

What are some good, easy ways to get better at programming?

Attached: functional.jpg (1280x1817, 363K)

"ld returned 1 exit status", this error I'm getting what does it mean? I'm using gcc and I've been told ld means it's a linker error but I don't have any clue what's wrong.

Stop falling for fag propaganda and write some programs.

Read the damn error message before that.

main1.o:main1.cc:(.text$_ZN5dlistIiE12front_insertEi[__ZN5dlistIiE12front_insertEi]+0x40): undefined reference to `dnode::dnode(int, int*, int*)'

yeah, idk wtf it want's from me...

It should give you a more detailed error message.

What is `dnode::dnode(int, int*, int*)'?

Tells you right there. In the function dlist::front_insert(int) there's a reference to a function dnode::dnode(int, int*, int*) which cannot be resolved by the linker.

read uncle bob trilogy

Take something you don't know how to do yet and do it, using whatever info sources you need. Repeat until comfy.

Attached: vomit.jpg (650x650, 90K)

Programming what? You didn't finish your sentence.

switch to functional

front_insert has access to the declaration but not the implementation of the dnode constructor. causes may vary.

okay, so I just started to learn about templates, so I'm really confused as to what the issue could be.
Here's front_insert() being used in the main
dlist lis1, lis2;
int tmp;

cout tmp;
lis1.front_insert(tmp);
lis1.show();
and here's the implementation

template
void dlist::front_insert(T item){

dnode *tmp;

if(!head){//perhaps change this to if (! == NULL) ect..

tmp = new dnode(item);
head = tmp;
tail = tmp;
head->set_previous(NULL); head->set_next(tail);
tail->set_previous(head); tail->set_next(NULL);

node_count++;

}

the rest I'll fill in later, I'm just trying to get the most basic first part to work.

Basic question. Are your templates in a header or a source file?

What does it do?

Converts binary to ascii.

As in it converts a single byte "0x01" into the eight ascii characters "00000001"

it's being included from dlist.h, I wrote #include "dlist.template" at the very bottom.

Sorry my code looks so hideous, I didn't mean for it to turn out this way, I realize I must appear to be a gigantic faggot.

You should have #include "dlist.h" at the top.

I was wondering why it looked so ugly until I saw the ::

Building a C application that has the only purpose of being a wrapper for an embedded Mozilla browser, to create a netflix web-app. This whole mess is because Netflix will only work on Mozilla, while Mozilla makes it practically impossible to directly execute javascript.
What are your thoughts?

Is it malicous or not?

good luck. you'll need it.

who's your therapist?

Is your implementation of dnode in the same file as the declaration or not?

In Haskell this is just
import Data.Word
import Data.Bits

binToAscii :: Word8 -> String
binToAscii n = flip map [7,6..0] $ digit . (.&. 1) . shiftR n
where digit 0 = '0'
digit 1 = '1'
digit _ = error "Non binary digit"

reconfigure mozilla

Unrivaled C, C++, and Python.

My Java professor used generics to tell a class what type it should use for a private instance variables. Is this retarded?

Basically:
Class {
private TypeOfId id;
}

Sure as hell, especially when I realize that I can't code in C. This makes it even more fun, yay.

The bare fact that I'm trying to do such an insanity tells you I don't have one, and also that I probably really absolutely need one.

If there only was a way.

Except that is slow as fuck

undefeated C++ wins again

no it's not,

I already tried that, it doesn't do anything.

No it isn't.

linux torvaldus

nice bait

post your code

programming programs

I'm not sure why you'd do that, but it's valid Java.

BTW, generic type parameters are usually single uppercase letters. T, U, V, E, K, V are good examples.

What about P, R and L?

It is. R is much more of an interesting language than people give it credit for. People shit on it for not being a proper language, but it's design was quite deliberate for interactive/exploratory statistics.

no, it's not retarded, although I certainly have never had cause to do that

what do you mean? I already posted pretty much all of it

Quit your job
Make videogames

Attached: 1538544225936.jpg (1280x1280, 1009K)

you tell 'em, buddy

I enjoy R a lot and in recent years it's become my go-to for high level scripting
probably because it's functional

buy my games then

Objectively wrong

godbolt.org/z/KLdxyQ

>Haskell
>453 rows
>C++
>20 rows
HAHAHAHAHAHHAHAHAHAHAHHAHAHAHAHAHAHAHA

Is there anywhere online where I can find generic forms of various algorithms? I'm taking a data structures class and we have to write every single fucking thing from scratch and I'm getting sick of it, can't use STL either. I'm looking for C++

>20 rows for C++, and thats for TWO implementations of the function.
The simplest of the two is only 7 instructions.
5 of which is the actual entire algorithm

C++ is undefeated

*leaks memory*

what is row 100 in the haskell assembly about?
> .asciz "/tmp/compiler-explorer-compiler118103-58-ocrbvu.yy6yc/example.hs"

Its generating a new string for the caller to cleanup. if you want, you can supply it your own char* to write to. If thats the case then the C++ implementation is even faster.

What do you mean, generic forms? Surely that information is available in your course material.

thats just the backend path of where the compiler explorer writes your source code to before compiling

why is that part of the compiled assembly?

are you being sarcastic? If you really want I'll post the node and the class pieces...

just changes the bswap to a movbe, which does both a write and an endian swap in one instruction

Attached: chrome_2018-11-03_15-21-05.png (1525x606, 67K)

probably to give some diagnostic info for a stack trace in the case of a crash

Things like binary trees and their various operations, linked lists, pop and push functions. Stuff like that

dude post as much as you can if you want help

And for the most part it's not available

like dis?
rosettacode.org/wiki/Category:C++

#include "dlist.h"
#include

using namespace std;

template
class dnode{

public:
dnode(T data_field = T(), T *previous_pointer = NULL, T *next_pointer = NULL);
T data() {return data_field;}
dnode *previous() {return previous_pointer;}
dnode *next() {return next_pointer;}
void set_data(T d) {data_field = d;}
void set_previous(dnode *prv){previous_pointer = prv;}
void set_next(dnode *nxt) {next_pointer = nxt;}

private:
T data_field;

dnode *next_pointer;
dnode *previous_pointer;
};
///////////////////////////////////////////////////////////////////////////

#ifndef DLIST_H
#define DLIST_H

#include
#include "dnode.h"

using namespace std;

template
class dlist{

public:
dlist(){
head = tail = NULL;
node_count = 0;
}

void front_insert(T item);
void rear_insert(T item);
void rear_remove();
void rear_insert();

void show();

private:
int node_count;
dnode *head;
dnode *tail;
};

#include "dlist.template"

#endif

Why are you including dlist.h in dnode.h dudezer?

yeah idk, I guess that's pretty pointless but I've been just trying random combinations of things.

>collected a neat data set
>some people requested it
>no way to share it

Attached: 1539505586292.jpg (693x1024, 233K)

What's in dnode.template?

>just

ok never that's dlist.template

so if this is everything the issue is that you haven't defined the constructor for dnode

there are a couple sites
I can't remember where I bookmarked them

I thought that's what this was doing...
>dnode(T data_field = T(), T *previous_pointer = NULL, T *next_pointer = NULL);

binToAscii n = concat . flip map [7,6..0] $ show . (.&. 1) . shiftR n
>This kills the brainlet

I know of academictorrents, but then I need to be able to upload torrents, and for that I need to be able to open ports. But my ISP doesn't allow that, so no dice.
I'm thinking I'll upload it to MEGA and then post it on here and then maybe someone else makes a torrent of it.

What's the best way to protect assets? is making a custom file format the only way?

that's a declaration with three optional arguments, not a definition