/dpt/ - Daily Programming Thread

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

Attached: dpt_flat.png (1000x1071, 102K)

Other urls found in this thread:

youtube.com/watch?v=AEOodTzjXxA
bartoszmilewski.com/2014/10/28/category-theory-for-programmers-the-preface/
pastebin.com/T9izr61c
home.deib.polimi.it/gini/robot/docs/spong.pdf
github.com/SDL-mirror/SDL
github.com/libSDL2pp/libSDL2pp
github.com/Rust-SDL2/rust-sdl2
github.com/DerelictOrg/DerelictSDL2
github.com/nim-lang/sdl2
twitter.com/SFWRedditGifs

Common Lisp (CLOS) is the best OOP language.

Espernato-user, isn't word "vorto"?
i.e. wouldn't it be vortserĉilo ?

Does /dpt/ listen to music while they program?
If so, what kind?

nigga rap, of course

Working my way through K&R today. Lots of C# and Python experience but I want to work at the lower level now. Feels pretty familiar as I'm already used to working with pointers for C# interop.

Does /dpt/ recommend doing more book" learning" after K&R (I've seen lists of assignments posted here before, and other books) or should I just start writing a C plugin for a program with an API that I'm familiar with?

What is this format and how to convert into readable?

X4444444444444

youtube.com/watch?v=AEOodTzjXxA

dj夜色DJ candy现场 艺涛粵语嗨爆全场 跨年特辑 神曲夜色 高清

spurdo text

K&R is all you should need, but I've heard some people recommend Modern C by Jens Gustedt

What would happen if someone were to put this in your company's code base?

# define true (rand() > 10)

Attached: devilish.gif (425x481, 1.51M)

breddy gud, though you have poor taste in border padding

>company's code base is in C
lmao no

It would be a comment and people would wonder why you did that

pls help =(

Beej's guide to network programming (not a book, just a short guide) is good if you need to do stuff directly with sockets.

Also you should probably know the basics of concurrency, threading, locking primitives, etc., but I'm not sure what the best guide for that stuff is.

What is this format and how to convert into readable?

T346546564654321

this is what you're asking bro.

no one knows

is array/vector of pointers the correct way to have heterogeneous containers and modifiable structs at runtime?

>true
>not using 1 and 0

I was wrong about both linear and non-commutative linear logic when it comes to verifying linked data structures. It turns out it's much simpler than either of those (well, it might be, depending on how you look at it. Personally, I think it is). The key is the class of data types introduced in "Categories of Containers", where each data type is defined by a shape and a labeling function from positions in the shape to elements. If the shape is defined as the intial algebra of some functor F, then the positions inhabit a type indexed by shapes and defined by the initial algebra of (1 + F') where F' is the derivative of F. How does this relate to linked data structures? Well, you can use the shape of a container as the shape of the heap that it inhabits, where each position corresponds to the address of a piece of heap-allocated memory.

For example, a list's shape is a natural number (it's length) and its positions are those natural numbers strictly less than its length. Each position corresponds to the unique address of a node. The head pointer corresponds to position 0. The tail pointer corresponds to position (length - 1). The node at position i has a next (resp. previous) pointer corresponding to (i + 1) (resp. (i - 1)). You could also implement binary heaps by adding pointers corresponding to ((i - 1) / 2), (2i + 1), and (2i + 2) for the parent, left child, and right child respectively. You can do this for other algebraic data types, too, but the shapes will be more complex than natural numbers. For instance, the initial algebra of the functor (F X = 1 + X * X) defines the shapes of binary trees, and the type of positions is a suitable indexing of the initial algebra of (G X = 1 + F' X = 1 + X + X).

bruh

At first, I thought this would all break down when it came to adding or removing elements. Wouldn't some of the positions change even though the addresses don't? However, it turns out that the conceptual fixing-up already occurs when using containers. For instance, to concatenate two lists, you add their lengths to get the new shape, and combine the labeling functions f and g into (h i = if i < n then f i else g (i - n)) where n is the length of the first list (the domain of f). Even though the position i of each element of the second list turns into (i + n) in the resulting list, it's mapped back to (i + n - n = i) in the labeling function, witnessing that the address of the corresponding node doesn't change.

Now I just have to turn this into a program logic. Easy, right?

What math do I have to study to understand this?

Say I have a function that writes to a file. Is the proper way to write non-character types (ints, structs, etc) just to treat the type as a character array?

ie:
void write_fd(char* fd_pos, struct fs_fd* fd_buf)
{
char* fd_ptr = (char*)fd_buf;
for(unsigned int i = 0; i < FD_SIZE; ++i)
{
fd_pos[i] = fd_ptr[i];
}
}

(for all intents and purposes, fd_pos is a buffer here to be written to the file)

in C
int mul(int x, int c)
{
switch (c)
{
case 2:
return x*2;
case 3:
return x*3;
case 4:
return x*4;
default:
return x;
}
assert(0); //not reached
}

In Python:
def mul(x, c):
switch = {0: lambda x: x, 2: lambda x: x*2, 3: lambda x: x*3, 4: lambda x: x*4} #can't even break this up without using escape sequences
if c in switch:
return switch[c](x)
else:
return switch[0](x)

Why do people claim this is a readable language again?

>ints
Raped by endianness.
>structs
Raped by struct padding.

>Is the proper way to write non-character types (ints, structs, etc) just to treat the type as a character array?
Yes and no.
You can just treat any type as an array of bytes and just write it anywhere. However, if you want to have a robust and portable file, you need to take things like endianess and structure padding into account.
Basically, you want to come up with or use and existing serialization format.

>assert(0); //not reached
Not necessary. The compiler is smart enough to know it's not possible to be reached and won't complain.

bartoszmilewski.com/2014/10/28/category-theory-for-programmers-the-preface/

int mul(int x, int c) {
return (c >= 2 && c

Yes.
There's also mmap.
The first one is the reader's problem.
But yeah, be careful around structs.

Thanks guys I really appreciate it.

Oh, I assumed you were complaining about C, and then I scrolled the Python code over. I guess all I can say is that a trash program is going to look like trash no matter what language you write it in.

Alright. So if I was writing the other side (the reader), and I knew what type to expect (and where to expect it), and read it exactly as I wrote it, it wouldn't be an issue?

I'm making a simple filesystem and am working out how to store file descriptor data and other non-byte type data

Yeah I know, just for my personal sanity, it looks odd if it just "in theory" flows off.
It was a quick example to show a switch statement that did some kind of calculation.
Okay, here:
int mul(int x, int c)
{
switch (c)
{
case 2:
return (x+382991)*1239;
case 3:
return (x*1723)+271;
case 4:
return (x^2913);
default:
return x-19;
}
assert(0); //not reached
}

My point still stands: Python is a crippled language designed by basedboys in California to create the epitome of a "safe space".

Looks interesting, thanks!

Lisp is the most powerful programming language.

Lisp is just Scratch for university students, and it has been since 1988.

What's wrong with this code?

import os
import shutil

for file in os.listdir("/home/gentoo"):
if file.endswith(".png"):
shutil.move(file, "/home/gentoo/Pictures")


inb4 python

python

what if /home/gentoo doesn't exist

if str(file)[::-1].split('.')[0][::-1] == 'png'

Can you explain how this works?

/home/gentoo does exists

if str(file).split(".")[-1] == "png"

Reverse string
[::-1]


Split string, select element 0
.split('.')[0]


Tip: use ipython

Attached: ipython_.png (376x255, 14K)

if file.lower().rsplit(".") == "png"
or
import pathlib

You killed it

corrected:
if file.rsplit(".", limit=1)[0].lower == "png"

whats up with this then (python regex)

('n">(.*) ($|

I escaped the ( before $ with \. but it doesnt match text.

You need to escape $

Escape both the ( and $. They're special characters in regex.
Also, use a raw string literal, so you don't need to do any double-escaping shit.
Finally, | has a very interesting precedence. You should wrap the thing you want to OR in ( ).
re.compile(r'n">(.*) (\(\$|

employed nigga here

I'd like a burger and fries. Make it snappy, I don't have all day.

I want to do something like this

#include
void createBuffer(std::array& buf) {
...
}

int main() {
std::array buffer;
createBuffer(buffer);
}

where PAGELIMIT is a constant and Page is a struct. The code in createBuffer is repeated several times because I need to clear the buffer several times. When I try to compile the code I get


error: cannot convert ‘std::array’ to ‘int’ in initialization
createBuffer(buffer);


What gives?

Um fast food is bad for you sweetie

>|

How hard would it be to modify dragon's dogma to let me create up to 3 pawns rather than just one?

Attached: 89.jpg (275x357, 31K)

hope you know how to use ida

Sorry, yeah the issue was I forgot to add a semicolon at the line above my createBuffer() call which was giving me that error.

My university never really taught proper dynamic allocation or move semantics. I need to load and store ~32,000 lines from a file in the array was trying to avoid the issue where there is too much being allocated on the stack by dynamically allocating my Page struct. Not sure if that's the right way to do it.

>and should just be having your createBuffer() method returning an array via move semantics;

You mean like this?
std::array createBuffer() {
...
}


int main() {
std::array buffer = std::move(createBuffer());
}

Anyone familiar with pygame? Right now im making a separate class for every object. Is there a way I can lump them together and call a different image for similar objects? Any source code I can look at?

I deleted it because I remembered std::array's move semantics are kinda retarded (basically it 'moves' each element of the array, which basically is copying) so you really want to just return it by value and let return value optimization take care of constructing it efficiently, i.e. auto buffer = createBuffer()

However, from the rest, it sounds like you really just want a vector, since vector stores its contents on the heap and does support move semantics properly.

I'm in a dilemma. Do you come up with algorithms and solutions first and then write the program or vice versa? Why?

Attached: 19640650354164.png (205x187, 30K)

If you are locking into that data format then yes, it wouldn't be an issue. If you wanted flexibility you could use a self describing format like JSON, but for finalized formats reading a sequence of bytes in a specific order is probably the fastest way to do so.

Using a vector would be the easiest way, but the issue is the professor is keeping us on a restriction that we can't load all the data in memory. So right now I'm limiting myself to loading in 50 lines of text per page, and I can only keep a fixed number of pages in memory at a time. std::array just seemed to make the most sense in my mind.

figure something out to about 80% and then start programming

what happens when you fold a list of functions in haskell? do they get composed?

Attached: wat.png (1105x227, 8K)

Thanks I understand completely now :)

Attached: 89641-LoaB1ccWsIIp.png (225x337, 94K)

is this c? just use fwrite. cast your data to a void pointer and pass sizeof(fs_fd) as the size parameter
the standard library will automatically handle all the endian shit for you

There's definitely something to that. I still think even here, it will be easier to just make a vector to hold those 50 lines at a time over having an array of pointers, since the vector will handle the memory management automatically that way.

How do you guys style single-line if's?
if( (count + buf_pos) > BLOCK_SIZE ) {
get_fd_info( oft[file_index].of_fd, &fd_buf );
}

vs
if( (count + buf_pos) > BLOCK_SIZE )
{
get_fd_info( oft[file_index].of_fd, &fd_buf );
}

vs
if( (count + buf_pos) > BLOCK_SIZE )
get_fd_info( oft[file_index].of_fd, &fd_buf );

Is there any free service I can attach to a git repo to automatically run some jmh tests (scala btw). I have to rerun my benchmarks but don't want to sacrifice my only computer for a few hours while they run.

my results for this guys challenge
Im new to golang so let me know how I could impove
pastebin.com/T9izr61c

Depends how you fold them.

You should use an applicative functor

Looks pretty good for you being a beginner

lst [4]

It doesn't make sense because you didn't use the compose function on the fold.
Prelude> let lst = [(\x -> x), (\x ->4)]
Prelude> let fx = foldr (.) (\x->x) lst
Prelude> fx 4
4

Fold takes 4 arguments, that's only 2.

I mean 3.

Why is golang such a good language?

Attached: golang-gopher.png (1500x1000, 52K)

>the standard library will automatically handle all the endian shit for you
No it won't.

cant spell good without go

plan9

Can't spell god-awful without go

Can't spell fucking retard without u

can't spell BTFO without

Knowing Japdevs they probably hardcoded your main pawn separately from your other two. Even if you had the source, I bet it would be painful.

Endianess is not an issue if you read and write on a per byte basis.

It is if you actually want to interpret those bytes as anything other than a byte-stream.

No, why would it?
lo = filebuf[i]
hi = filebuf[i+1]
u16 w = lo | (hi

89th for wasting time using Haskell!

I need to start learning java so I can transfer.
What's the best book in 2018 ?

red and blue pilled

Do you know any reference books for industrial robots?
I'm reading Robot Dynamics and Control home.deib.polimi.it/gini/robot/docs/spong.pdf because it's the first one I found and it's written clearly so far.
I'm more interested in the modelisation of the kinematic and dynamics of the robot than the control so far.

Out of curiosity, in which language were these classy 8bit music keygens back in the days programmed? found these GUI always super cool

I have no real programming experience yet, except some light JS. I am diving now into Python and already made some scripts which are working fine. If I would like to continue making some (potentially cross-platform) desktop apps, which language would I have to look into? Preferable a language which is not dead in 2 years.

I know this might be a rather broad question, but maybe you can give me some hints anyways.

i like to divide my program into blocks that i can work on separately, effectively giving it a base structure
then i work on each block separately, researching algorithms and possible implementations

C
github.com/SDL-mirror/SDL

C++
github.com/libSDL2pp/libSDL2pp

Rust
github.com/Rust-SDL2/rust-sdl2

D
github.com/DerelictOrg/DerelictSDL2

Nim
github.com/nim-lang/sdl2

The list goes on

usually they want to show off so Ive seen many made is ASM

what kind of blocks