/dpt/ - Daily Programming Thread

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

Attached: 230ced60c25c77279c5c02989fd48f5f--fresh.jpg (567x850, 39K)

Other urls found in this thread:

reddit.com/r/dailyprogrammer/comments/bazy5j/20190408_challenge_377_easy_axisaligned_crate/eyrvtsj?utm_source=share&utm_medium=web2x
twitter.com/NSFWRedditGif

a very interesting project

this is now the doll thread

Attached: CXSaVdEUwAEo5K6.jpg (693x1039, 119K)

if i learn haskell will i get a big tiddied gf

production malware scanner in a meme toy lang that /dpt/ LARPers should stop talking about so the adults can discuss Python and Java.

no, you get me and you have no say in the matter

how big are your tiddies

probably not even a real gf

Attached: buried-optic-cable-gf.jpg (1539x743, 266K)

bigger than what you deserve, worm

I like C!

Is there any cool discord channels to discuss code?

no

So I had a question a few weeks ago about how to use epoll. In the networking program I'm currently working on, I originally had a separate thread to deal with each client's socket, and the main thread to deal with the server's socket. But since epoll can work with multiple file descriptors, I was thinking I could let it poll all the sockets, and so have one thread to deal with all the clients and another thread to deal with server stuff.

However, now I've run into the issue of how exactly I should deal with the epoll instance itself. Should it just be in global memory so both theads can access it? Should it be shared memory? Should there be one epoll instance for clients and another epoll instance for the server?

How do I even know what to optimize? For example, how do programming languages implementations get optimized? There must be a 80/20 pareto principle going on here, with simple general techniques giving me huge performance speedups. Only thing I can think of is taking advantage of pointer alignment in order to store some state in the always 0 bits, letting me store numbers in the pointer type itself by making it an odd value which is illegal as a pointer.

Is there anywhere I can read about general optimization techniques like this?

Does everyone just use GCC to turn NASM object files into executables?

>Should it just be in global memory
user, epoll() rearranges the array you give it. So the only way for a separate thread to manage that array is O(N) checking each member to see if it's what you're looking for, when epoll can rearrange the array underneath you.

>discord
Fuck off.

So you're saying have 2 then?

you don't have to, calling ld directly comes out to the same but it's easier to do it through gcc.

Started learning my first language, C#. I thought programming was fun but it's more for unathletic gaymers and basedbeans.

have two whats? all I'm saying is that only one thread should manage epoll's array, and that thread should only care about responding to epoll events.
you can have separate threads close fds, and then let the epoll thread kick the dead fd out of its array.

I use this to link glibc to my nasm obj. It keeps gcc from goobering up the file.
nasm -o build/asmslam.o -f elf src/main.asm
ld --dynamic-linker /lib/ld-linux.so.2 -m elf_i386 -o build/asmslam -L/usr/lib32 -lc build/asmslam.o

Attached: 1565724649892.jpg (869x1077, 139K)

Learn about complexity and caching. If performance is really that important for what you're doing learn Assembly too.

what are you assembling my dude

Where I can buy one of these small dolls?

go find the doll thread on /jp/

Attached: 1565392611161.jpg (1000x1498, 224K)

FUCKING C IN MY DAMN C++. I swear I run into an issue every single week where C-backwards compat gets in the way of making clean C++ code.

This time its string constants, known in C as const char*. Lets say I have a class that I want to be constructible from any Iterator pair, Iterable, or Aggregate where the type of the sequence element is constructible into a destination (storage) type. See below.

#include
#include

template
class vector_t {
public:
template ::value
>::type
>
constexpr vector_t(const Iter b, const Iter e);

template ::value
>::type
>>
constexpr vector_t(const Iterable& i);

template ::value
>::type
>>
constexpr vector_t(const Element (&a)[N]);
};


There is an issue with this though. Lets say you wanted to construct the vector from a string constant vector_t("abcdef"). Obviously, you want the output object to contain ['a', 'b', 'c', 'd', 'e', 'f'], but if you write that third constructor the "correct" way, you'll actually get another element: '\0'. You could special case const char*, but of course, that will also match char arr[] = {1, 2, 3, 4};. There is no way around this problem that I can see.

but user, this is now the new doll thread...

Attached: 1558361113015.png (728x729, 863K)

>clean C++ code
lol

what's it like coding because you like it, and not because you're too scared to do what you actually like but suck at?

Attached: 57948422_p0.png (707x1000, 1022K)

Jesus christ, C++ is such a clusterfuck. How do you faggots possibly defend it?

STOMP STOMP CLAP
STOMP STOMP CLAP

>calling ld directly comes out to the same
gcc adds a _start so your entry point has to become main, along with adding other functions that you wouldn't get otherwise. Although it is a lot easier to just use gcc

nasm -o build/${PROG_NAME}.o -f elf src/main.asm
gcc -m32 -o build/${PROG_NAME} build/${PROG_NAME}.o


Trying to make a x86 fuzzer based of a video an user linked. It uses pagefault/sigsegv and trap signals to detect valid opcodes. Trying to see if I can find valid opcodes that are undocumented. I posted the source I had in last thread when all I had was a SIGSEGV handler.

Attached: scrot.png (3840x1080, 450K)

doing pythonchallenge. fuck it took me all day to figure out a hint.

not very intuitive but i finally figured it out by trying the last possible thing i could think of.

Thank you.

there's options to turn that off, -nostartfiles I think

It's nice when you can just use it as C with classes

True, you can also define an entry point with -e iirc

>Should it just be in global memory so both theads can access it?
epoll updates the memory on system call return. two threads touching this memory sounds like a horrible idea since you need to lock around epoll to avoid memory race on return - rendering the whole point of 2 threads moot.

windows programmers should really just stick with thread per socket, especially if the thread operates only on its own local data (no synchronization). threads are much cheaper nowadays, provided you don't descend into deep stacks.

epoll works best with separate worker process per cpu, with no threading involved at all.

No, that's fucking stupid. Both C programmers and sepples scum will hate you for that.

>decltype(*std::declval())
use std::iterator_traits

use rust bro

Currently writing my own linker, so I don't have to rely on another one.

No, you'll just waste several months of your worthless life just like any other Haskellfags.

Attached: smug_ran.jpg (709x1063, 656K)

how can i waste my life if it's worthless

I want a qt azone gf but i'm poor

Attached: 1564140339404.jpg (240x240, 28K)

Playing with Rust
mod lib {
use permutohedron::LexicalPermutation;

fn get_blocks_count(crate_dims: &[u32], block_dims: &[u32]) -> u128 {
#[cfg(debug_assertions)]
println!("{:?} {:?} in blocks_count", crate_dims, block_dims);
let mut result = 1u128;
for (crate_dim, block_dim) in crate_dims.iter().zip(block_dims) {
result *= *crate_dim as u128 / *block_dim as u128;
#[cfg(debug_assertions)]
println!("So far the result is {}", &result);
}
result
}

pub fn fitn(crate_dims: &[u32], block_dims: &[u32]) -> Result

Every time with rust it looks unintelligable

Attached: 1565019294258.jpg (665x574, 25K)

>xer programming language's syntax doesn't highlight properly on 4channel

Attached: fc542486b829523c2a377e093f5856649ed8b9e2.png (1247x768, 681K)

Context:
reddit.com/r/dailyprogrammer/comments/bazy5j/20190408_challenge_377_easy_axisaligned_crate/eyrvtsj?utm_source=share&utm_medium=web2x

Attached: 1549201508463.jpg (300x168, 9K)

I only do that when I’m using printf, otherwise ld has yet to let me down.

I aint clicking that shit, nigga. Thanks though for the problem.

Attached: 1565338454386.gif (500x281, 1.48M)

happens to Ada as well.
I blame shitty scripting languages. ' should never have been used for strings.

it's still using the same from almost 10 years ago, the one dev mod here doesn't care

Couldn’t you write a constructor to handle strings? Constructor delegation shouldn’t bloat out the code too much, and all you’d be doing is chomping the constructors argument. That’s my naive answer.

can i turn my raspberry pi into a TOR node?

>chomping the constructors argument
so, assuming it's always got a useless \0, and skipping it?
so users who try to use an explicit array of chars that only happens to end in \0 will have their deliberate \0 removed?

yes but that's not programming related

That still matches a char array. And is the third constructor will still match a string constant first.

What really needs to be done is to make all string constants a string_view-like object with an implicit const char* cast. But I'm sure 50% of the standards committee would whoop like howler monkeys at the notion.

ssize_t readlink(const char *pathname, char *buf, size_t bufsiz);
>On success, these calls return the number of bytes placed in buf. (If the returned value equals bufsiz, then truncation may have occurred.) On error, -1 is returned and errno is set to indicate the error.
pop quiz, hotshots: given a symlink that points to "urmom", what number will readlink successfully return and how many bytes will it write into the buffer?

whats the super tiny worm doll?
what was its original purpose suposed to be? it look too small to give to a kid

>dolls are for children
uh young man you need to be 18 or older to visit this site.

I would check for a \0 on the end and get rid of it. It’s a standard that a c-string is null-terminated, so no sane programmer should wish to keep null chars on the end of a string (or anywhere in a string where they want the following chars to be preserved). You can then document that behavior of your constructor and cite the standard present in C; I wouldn’t waste another afternoon on such an edge-case scenario.

go back and reread what I said you fucking weeb.
The doll is tiny.
The doll has a stuffed worm the size of its hand.
the stuffed worm is super small compared to the doll.
the stuffed worm would be a choking hazard but has a retail tag on it apearing to say hasbro.

yikes, nevermind. I was reading undefined memory and thought that readlink wrote a NUL byte when it had room.
The Linux manpage says that readlink doesn't do this, but I didn't notice until I checked the OpenBSD manpage.
>the stuffed worm would be a choking hazard
>you're wrong to mock me with "dolls are for children"
ok kiddo how about you go outside and throw some ball around. You can be introduced of the wonderful world of dolls for adults when you're an adult yourself, OK?

also, considering the flowers and window for scale, that's probably a child-sized doll. A kid would have to work really hard to choke on the worm.

>A kid would have to work really hard to choke on the worm.
calm down Jeffrey

>oking hazard
>>you're wrong to mock me with "dolls are for children"
>ok kiddo how about you go outside and throw some ball around. You can be introduced of the wonderful world of dolls for adults when you're an adult yourself, OK?
look at the size of the screw in the background, the size of the window mecanisms.
The doll is less than a foot tall.

that window sill is already more than a foot off the ground. screws come in different sizes.

>doll faggotry
I speak to trannies and SJWs online too but no other places make me feel like my T level is reducing just by being present like /dpt/. I can't imagine how many litres of onions you have to drink to ooze that amount of estrogen in your body.

I'm leaving at as it was. The user will have to make sure they know the difference between a char* and a string. They can use string_literals. I'll also add a user-defined literal for the concrete vector types I plan to introduce and recommend users to use the UDL for literals and not constructors. There is no such thing as a char array literal that isn't a string.

to be fair you're programming the more of your brain you use the less testosterone. programmers usually aren't the most brutish men.

I get called mires from girls everytime I take of my shirt.

Attached: 1566865823233.jpg (2677x1450, 563K)

Common Lisp is so cool can't believe people don't like it cause of parentheses.

and the lack of performance

I don't like languages that require editor assistance just to indent sanely.

What are compiler optimizations.

What about it?

what's so hard about a tabs and spaces.
I used vim before emacs, and I was fine with it.
emacs just makes lisp development better.
Also, you do know IDE's exist right, and they all indent properly, and you probably use IDEs, so pls no hipocrisy.

Also, reminder Lisp doesn't require correct indentation like Python and Haskell.

They allow for more efficient and performant code.

And?

>straw man
>works for me
>you're just wrong
>you probably need editor assistance just to indent other languages too
>indentation doesn't even matter lol
there should be limits to how cultish and defensive you can be about a single complaint.

Ah the sweet smell of syscalls.
>_main = s _ :
= s "Hello world!"
@sc(4, 1, s, 12)

Therefore your claim about non-performance is null.

What languages do you use?

cope

Attached: Screenshot from 2019-08-31 08-54-12.png (1334x708, 162K)

>meanwhile, finding symlinks in half the time
sudo sync; sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches' ; time ./my_shit /home >/dev/null
8857 ms

sudo sync; sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'; time find /home -lname / -printf "%p -> %l\n" >/dev/null
17815 ms

What would make Haskell more useful?

Attached: Screen Shot 2019-07-04 at 4.03.32 PM.png (743x463, 326K)

a stricter upbringing.
Simon Peyton Jones should've had a job that required him to wear a belt.

mutability

>Don't optimize code
>Surprise it doesn't perform as well as compiled languages.

Where did your compiler optimization go?

That must be some shittily written Fortran.

Attached: Screen Shot 2019-07-04 at 4.03.54 PM.png (651x468, 314K)

>-lname /
what about -type l? not saying a generic search program will be faster but you're doing pattern matching on all filenames.

fortran is only fast for number crunching

Compiler can't optimize Lisp because it has not types.

But you are wrong.
In which cases do you need special indentation rules?
Only in languages like Python and Haskell do you require such.
Do you know how s-expr works?
I can just write this and it'll still work.
(defun foo (x) (+ x 1))

Doesn't matter if I insert ten million tabs or spaces or newlines in between each item, it will work regardless.

no*

Silence, you don't know what you're talking about.