/dpt/ - Daily Programming Thread

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

Attached: 1558502852411.png (704x841, 191K)

Other urls found in this thread:

falstad.com/circuit/e-index.html
godbolt.org/z/mgOS89
isocpp.org/wiki/faq/serialization#serialize-with-cycles
cs.helsinki.fi/u/wikla/OTS/Sisalto/examples/html/ch18.html#sec6
youtu.be/-a3SIjNKHHg?t=34
twitter.com/SFWRedditGifs

eating ice cream about to do some XLib programming.

Trying to make an esolang that looks as KODE as possible and is purely functional.

>XLib
Please user, no.
Even if you're doing X11 programming in 2019 for some fucking reason, at least use xcb.

Attached: 1545439289095.jpg (681x635, 116K)

Packet* p = new Packet(seqnum, acknum, data)

Attached: unknown.png (1783x1004, 1.64M)

nice semicolon, colon

That’s so cute. She looks like an Aryan met (from Megaman)

Attached: 1547875971957.jpg (1052x1342, 402K)

How do I export a program from code blocks?

bytesSent = sendto(sockfd, p->getData().data, p->getSize() + HEADER_SIZE, struct sockaddr*)&serv_addr, &clilen);
poll(polldata, 1, RTO);
// process incoming ACKS from server

>needlessly performing heap allocation

She's from Shoujo shuumatsu ryokou, the main theme is bomb.

Anyways, I'm picking up Kim's C book in hopes to learn this language finally.

>7am
>coffee
>light raining
>18°C
Perfect.

Packet p;
p.setSetAttrs(seqNum, ackNum, data);
poll(polldata, 1, RTO);
// detect loss by 3 duplicate ACKs
// retransmit lost packet

You forgot your socks, tranny

You seem upset, what's on your mind?

while(fileDiff > 0){
for i in cwnd:
file.seekg(fileByesSent);
file.read(buffer, MAX_PACKET_SIZE)
sendDataToServer();
if (receivedExpectedAck())
fileBytesSent += file.gcount();

}

I've been trying to wrap my head around creating a circuit simulator library, something simple and easy to code like the following pseudocode:
Clock clock = new Clock();
Wire R = new Wire(0), S = new Wire(1); //reset = 0, set = 1

NorGate nor1 = new NorGate(), nor2 = new NorGate();
nor1.setInputs(new AndGate(R, clock), nor2);
nor2.setInputs(new AndGate(S, clock), nor1);

//run the simulation
while(clock.tick()) {
Wire result = nor1.getOutput();
print(result.toString());
}


But I can't for the life of me figure out how I'd make it run properly.

If I did this normally, getOutput() will call upon nor2, but then nor2 calls nor1 ... and thus infinite recursion.

Pic attached is what I'm trying to illustrate. On a clock cycle, All As must be completed before the signal can be passed down to Bs, then to Cs. If you do the first AND then go to the NOR out of order, you'll get the wrong result.

I've been trying to think this through for the last few days and I have only 1 idea and that is propagating the signal forwards when an input changes rather than when you request an output. For example, when the clock ticks, I'd propagate the change forward to the AndGates, which process, then propagate forward to the Nors, then to the output wire. But once C is processed, it will send its signal back to B, which will cause B to process again.

The issue I have remaining is how do I not have this update the NorGates twice?

Attached: 1559969763637.png (600x326, 33K)

Prolog goes hand in hand with these types of problems. Not kidding, code this is in prolog

Anyone know the C++ implementation of std::vector.push_back?

I'm pitting it against realloc() in some profiling and realloc() is winning my margins every single time. I thought push_back was just a wrapper for realloc/alloca?

Not technically correct. It's actually using an std::allocator
template class vector;


iirc, Allocators are actually less performant than basic allocation tools in C. You can try comparing std::allocator to realloc and see if your margins stay the same/similar (vector does have a little bit of overhead of course)

I'm not entirely sure how prolog would help with an implementation. I'm asking for how to do it in a traditional language not a logic based one.

>allocators are less performant than basic allocation tools in C
What. I thought they'd be zero overhead. Why wouldn't they be? They're 'stateless' allocators just like malloc.
Should just be a call to alloc and free.

You're misinformed. If they were stateless, why would you need to free/deallocate the memory? How could they allocate if they didn't keep track of which memory was available?

They're stateless in that they don't keep track of what a pointer is used for (is it type T or type K? who cares). They only care about keeping track of memory available to dole out and freeing them when returned.

The reason why they have overhead is it's a *software* implementation of a heap, rather than a kernel implementation. For example, looking over some source code, it implements its own heap management system. In Windows/Linux heap management is provided by the kernel and is significantly faster.

I have an idea. Don't mutate the state of the world, instead use the state of the world at t to construct a new world state at t+1.

Another way to implement the same algorithm would be to continue mutating state, but each gate could store two states, for both t and t+1.

Attached: ssr_resting.jpg (1885x1141, 394K)

>I've been trying to wrap my head around creating a circuit simulator library
Why are you starting with logic gates? Do you understand what circuit simulators are usually used for? Have you looked into how they work?

Check out falstad's sim, maybe read the source code
falstad.com/circuit/e-index.html

Then pick up a book on circuit analysis and look into Runge-Kutta.

The reason for the performance difference is not due to the allocator in this case. It's because the std::vector doesn't always have to reallocate its buffer if it has enough capacity for the new element. From what you said I assume you're reallocing for every element.

The purpose of allocators is to improve cache performance by guaranteeing that the values are allocated in some contiguous pool instead of being scattered around the heap.
Allocators are much more efficient than your malloc and free when used correctly.

I thought of something like that, but I just didn't like the idea of cloning an entire circuit every time. The idea of having two states per wire is a neat idea though and I'll keep that in the back of my head.

But now I have another question. When do I define time t+1? In this case it's easy, it'd be every clock tick. But what if I changed that to another wire, call it K. I then manually cycle through K on and off like a clock. I'd have to keep track of every wire to see when it gets updated to decide when to begin this new t+1. Would make the implementation cleaner as clocks could just be treated as wires, and every clock tick just updates the wire.

>Why are you starting with logic gates?
Because I'm not doing a full 1 to 1 analogy with real circuit simulators
>Do you understand what circuit simulators are usually used for?
Yes. For precise voltage, resistance, amperage, and heat simulation. What if I just wanted a simple logisim like simulator rather than an overly complex masters in engineering simulator?
>Then pick up a book on circuit analysis and look into Runge-Kutta.
No, because that's not what I'm trying to do.

It depends on the compiler and their implementation of vector. Here you can see what g++ is doing godbolt.org/z/mgOS89
push_back will call realloc when there is not enough space available (.L20)
which will call memmove, memcpy and new depending on what's needed
Also notice that access to memory with [] has no overhead

push_back will when resizing allocate new space and do std::move_if_noexcept

This reminds me of a problem I came across that involved saving the state of a series of references between objects. The issue was that you couldn't follow the references recursively because the connections formed a graph with cycles and joins. I read about it here:
isocpp.org/wiki/faq/serialization#serialize-with-cycles

Conceptually, instead of calling the function directly, note that it should be called first, and put it in a table. For each subsequent function call, check the table first. If it is in the table, don't follow it recursively. If it isn't, add it. This table would need to be rebuilt every tick.

I also think you should not view it as getting output from each gate. I think you should have the gates and wires, and write an interaction manager that knows the connections between gates and manages the table of functions to be called every tick.

>I assume you're reallocing for every element

Yeah, but std::vector just can't win whatever way I put it.
Syntactically it's neater than C++'s stupid casting requirement on mallocs, but you're right, vector should be a bit quicker because it does preallocate more the extent.

>malloc
>stateless

No.

C is the most powerful programming language.

C right now seems like the only non-braindead language.
Just make C 2.0 but use C#'s assembly system and we'd be gold.

It would be neat to have constexpr in C

It would be even better with a strongly typed system.

tryna understand how text search works by building an in-memory inverted index, and now I'm confused by how search engines combine relevance with quality

also, working with unicode instead of bytes is way more complicated than I thought

Reminds me of the circuit simulator example in "Programming in Scala".

How did they do it there?

It was used as an example of creating a mutable data structure. The code for it is here: cs.helsinki.fi/u/wikla/OTS/Sisalto/examples/html/ch18.html#sec6

>at C++ exam
>the teacher is extremely strict
>write my program perfectly, so I'd meet his standards and be praised
>signal I'm finished
>his assistant comes to look at it indtead
>So what does your program do?
>say a few words, he stops me
>Alright, alright, does it compile?
>It does, okay here's an A, goodbye

Attached: 1531339253371.gif (400x300, 259K)

At my Objective Oriented Design exam the hardest question (which the professor asked if he really didn't want you to get the highest mark) was "So what's the advantage of OOP over procedural programming?"
Literally every textbook answer, even the ones he himself talked about, was shot down.
>Code reuse
>"We built good libraries without OOP"
>Encapsulation
>"C allows for that, and in languages without it we could just agree on the interface of a module"
>Allows for standardized design patterns
>"You really think there weren't any before?"
And so on.

>Encapsulation
>"C allows for that
It doesn't even have namespaces

the correct answer was there is no advantage because OOP is POOP!

non sequitur?

Do headphones help you get into the zone?

Attached: anime_girl_with_headphones-wallpaper-1280x800.jpg (1280x800, 251K)

No, music is very distracting to me, especially music with lyrics

I can't concentrate without any music. As a bonus: coworkers are less likely to disturb you while wearing headphones.

yea
i don't listen to anything, but the headphones themselves help

// undefined code C
i = ++i + i++;

results in i = (i + 1) * 2;

Depends on the compiler

why do all zoomers wear headphones
I've only ever used speakers

Because of how they grew up with smart phones

i know this isn't a "friendly" thread but pls no bully
i want to get into either C or, if possible, Rust, but only specifically for audio purposes. making synthesizers, effects, simple mixing tools, stuff like that, and integrate it into microcontrollers to build hardware audio gear and stuff, which means I'd need to know how to read datasheets and shit too. where should I start? any good resources you could recommend? thanks

Because they either live with their parents, or share a tiny apartment with 25 mexicans

What's your experience in software development? What's your experience in audio engineering?

>get to the office
>sit in my cubicle
>turn on computer
>turn up the knob on the speakers to the max
>youtu.be/-a3SIjNKHHg?t=34
*Sip* yeah, damn zoomers don't know how to really listen to music.

Whats the difference in C++ in changing a variable by changing whats in its memory address and changing it through reference? Isn't it the same shit?

Attached: 131342535.jpg (1106x1012, 70K)

It's straight up undefined behaviour. The code is invalid.

Because perhaps some people are trying to be considerate of those around them.
But if I have the opportunity to use speakers (e.g. at home), I will usually use them.
Your shitty "zoomer" maymays would probably use airpods or some shit. You don't even see people with "proper" headphones very often.

Depends on the music.

Propagate data the other way around, so don't use getOutput, but a setInput function

Fuck off, you stupid frogposter. Why the hell do you stupid redditor fucks keep spamming the same fucking image over and over again?
It's been fucking years, and you're still posting the same god damn shit. It was never even funny or endearing at all to begin with.

The one thing uncle bob goes on about is that OOP makes for easy polymorphism.

Wow. You seem upset, everything okay?

Attached: 1545634875441.png (1180x590, 88K)

>Seething over a drawn frog

please have sex

There are even easier ways to get polymorphism.

OpenGL question. If I set attributes for a vertex array object do I have to specify them every time I bind a different buffer to it?
Or maybe I should use multiple vao's? I have no idea how they work internally but it seem unnecessary to store same attributes for x object.

A reference is guaranteed to be initialized, otherwise it's the same.
Oh, and if something "owns" a resource, it shouldn't do it via reference. Use smart or raw pointers.

dumb frogposter

Owning via raw pointers is a bad idea tbqh

Attached: 1558664521722.gif (800x450, 2.59M)

>If I set attributes for a vertex array object do I have to specify them every time I bind a different buffer to it?
No. The main point of VAOs is so you don't actually have to.
If you use some ancient version of OpenGL without them (or just decide not to use them), then you are respecifying them every time.

Well yeah, but when I get something from an external library that has to be freed with a special function I sometimes can't be arsed to write a custom deleter or a wrapper.

>Because perhaps some people are trying to be considerate of those around them.
you don't even have your own room?

I have a template that takes care of this.

Apparently React "devs" get paid more than actual devs. True?

depends who you work for dumbass

Apparently React devs get paid more than C++ "devs". True?

For the user who wanted more AI generated pepe's. I only have a 1050 ti so I can't train fresh models very fast heres a decent one I pulled just now

Attached: 800_539.png (128x128, 31K)

CREATE MATERIALIZED VIEW TEMP AS SELECT * FROM students WHERE year > 2005

I do a lot of prototyping my own synths and stuff in Pure Data, so I like to think I know something about dsp, logic, math stuff. I'm not entirely noob-status but I don't know the first thing about doing this kind of thing in the world of low-level shit and finding the best, most crucial resources for this rather specific application of low level programming is like navigating a maze, there isnt really a "noobs guide to building digitally programmed synthesizers and effects" that I know of

This looks like a real frog, not a cartoon frog

Yes but its only trained on pepe's so I consider it a rare pepe, don't you?

No what even is that thing

Apparently Forth devs get paid more than C "devs". True?

why not gtk+

same thing as this just a more realistic version

Attached: a.png (256x256, 72K)

Are you trying to hack four channel?

I have a piece of C code that scans text of a file and searches for a specific charecter. For example, something like this.
size_t counter;
for (counter = 0;counter < text_size; text[counter] != '\n');

After the loop is finished, counter will contain an offset in text that contains the first new line.
This works well with ASCII, but what if I'm scanning a text of a file in UTF-8? What do I need to change?

Attached: 1559068358125.jpg (3420x2280, 1.4M)

Or how about demon frog

Attached: 2300_229.png (128x128, 26K)

Attached: sal.png (786x1014, 70K)

I guess Forth is so high they didn't even include it in the chart

These are absolutely horrible.

Attached: 1550993873727.jpg (793x786, 54K)

>text[counter] != '\n'
The last section of a for loop isn't a condition. That code literally does nothing.
You would expect it to be for (size_t i = 0; i < text_size && text[i] != '\n'; ++i) instead.
>what if I'm scanning a text of a file in UTF-8?
You would actually need to decode UTF-8. The C standard library sort of has some shit for this, but is unfortunately tied to that mess that is locales.
People don't want to touch that shit and usually end up decoding it themselves or using a library for it.

Yes I'm certain that hello world tutorial you finished in python was of much better quality, I'd like to buy lessons sir.

>learning clojure
feels good man. very comfy lang, enjoying it very much. the load times for the repl sucks though

Why can't you just admit that you have utterly failed and whatever it was you were trying didn't work at all?

>C# as low as HTML/CSS
noo wtf

Attached: 1497886870367.png (808x805, 236K)