/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1546427951145.jpg (475x603, 132K)

I got stuck on this book by chapter 2, too much math for a brainlet like me.

Attached: 1562880285468.jpg (1280x720, 356K)

It worked because &XXX was getting interpreted by the browser as a character code like   or similar.

Daily offer to prove that C++ is actually no really guys I'm serious capable of performing outstanding memory allocation optimisations:

>Then why don't you go ahead and run some C++ program with an overloaded malloc implementation that counts how many 64-Bytes-or-less allocations have been performed? And with a corresponding free overload you can see how long they survived. I also don't care about your synthetic benchmarks for a simple program, all right? I want real-world applications.

, and that's why it's better than C.

>inb4 the compiler cannot apply its optimisations
Most real-world applications link their shit dynamically. Dynamic linking means you can inject symbols via LD_PRELOAD on Linux (no idea about the interface on Windows however). Since the compiler has NOTHING to do with symbol resolving that should give you a proper idea of how much a C++ compiler is actually capable of optimisation.

>inb4 I'm too dumb to do that; gimme code/instructions!
Take the following code and put it into libcm.c:

/*$ gcc libcm.c -c -fPIC -o libcm.o -O3 -Wno-unused-result && gcc -shared -Wl,-soname,libcm.so.0 -o libcm.so.0.1 libcm.o
**$ LD_PRELOAD=./libcm.so.0.1 */

#include /*time*/
#include /*write*/
#include /*strlen*/
#include /*sprintf*/

/*No include file introduces the __libc_* symbols, but they're still present
**in libc.so - see:
**`readelf -s /lib/x86_64-linux-gnu/libc.so.6 | grep 'malloc` or whatever your
**glibc path is. As such we can simply introduce them here and then rely on
**the linker to resolve them for us.*/
extern void* __libc_malloc(size_t);
extern void* __libc_calloc(size_t,size_t);
extern void* __libc_realloc(void*,size_t);
extern void __libc_free(void*);

#define PRINT_SHIT
#define OUTPUT_LENGTH_MAX (128)
#define DO_PRINT write(STDERR_FILENO,output,output_length)

static size_t counters[4] = {0};

Oh that makes sense. Thanks again!

What exactly is a module? I just installed Eclipse after using a very simple IDE called TextPad. Upon creating a project I was prompted to make a module. I looked up what such a thing is in the context of java programming in this IDE, but I unfortunately still don't really understand what it is. As for now I'm going to just delete the file and create the classes I need.

__attribute__((destructor))
void cm_stats(void)
{
char output[OUTPUT_LENGTH_MAX];
int output_length;

output_length = sprintf
(
output,
"Mallocs: %lu\n"
"Callocs: %lu\n"
"Reallocs: %lu\n"
"Frees: %lu\n\n",
counters[0],
counters[1],
counters[2],
counters[3]
);
DO_PRINT;
}

/*Unfortunatey we cannot print the time in a proper fashion because calling
**localtime_r causes the program to lock up. Hard. I cannot even fathom what
**sort of lock it is that localtime_r and malloc are contesting for, and to be
**quite frank I don't fucking care either.*/
void*malloc(size_t size)
{
/*We cannot use printf/fprintf because those functions may request
**memory themselves. That's why we sprintf everything into our
**own buffer and write it directly to stderr.*/
#ifdef PRINT_SHIT
char output[OUTPUT_LENGTH_MAX];
int output_length; /*WHY THE FUCK IS THIS SIGNED?*/
time_t ut;
#endif
void*ptr;

ptr = __libc_malloc(size);
++counters[0];

#ifdef PRINT_SHIT
time(&ut);
output_length = sprintf(output,"[%lu]: Allocate %p|%lu\n",ut,ptr,size);
DO_PRINT;
#endif

return ptr;
}

void*calloc(size_t nmemb,size_t size)
{
#ifdef PRINT_SHIT
char output[OUTPUT_LENGTH_MAX];
int output_length;
time_t ut;
#endif
void*ptr;

ptr = __libc_calloc(nmemb,size);
++counters[1];

#ifdef PRINT_SHIT
time(&ut);
output_length = sprintf(output,"[%lu]: Callocate %p|%lu\n",ut,ptr,nmemb * size);
DO_PRINT;
#endif

return ptr;
}

void*realloc(void*ptr,size_t size)
{
#ifdef PRINT_SHIT
char output[OUTPUT_LENGTH_MAX];
int output_length;
time_t ut;
#endif
void*ptr_new;

ptr_new = __libc_realloc(ptr,size);
++counters[2];

#ifdef PRINT_SHIT
time(&ut);
output_length = sprintf(output,"[%lu]: Reallocate %p to %p|%lu\n",ut,ptr,ptr_new,size);
DO_PRINT;
#endif

return ptr_new;
}

void free(void*ptr)
{
#ifdef PRINT_SHIT
char output[OUTPUT_LENGTH_MAX];
int output_length;
time_t ut;
#endif

__libc_free(ptr);
++counters[3];

#ifdef PRINT_SHIT
time(&ut);
output_length = sprintf(output,"[%lu]: Free %p\n",ut,ptr);
DO_PRINT;
#endif
}


>inb4 cnile
>still no data
>still winning

¯\_(ツ)_/¯

You guys have been arguing about this for 3 days. This is like those threads on Canadian grocery prices.

Attached: mm.jpg (500x436, 52K)

There's barely any math in SICP. Try using the video lectures too, they're entertaining.
(it doesn't cost $10 anymore)

Attached: 1558638342292.png (640x974, 305K)

>__attribute__((destructor))
why do cniles continuously reinvent C++ features in disgusting nonportable manners?
It's almost as if their shitlang is defective.

Can anyone think of a good design pattern for this use case:
>Set of functions that can call each other, which may recurse:
f(a,b):
g(a+1,b/2);
h(a-1,b*2);
g(a,b):
f(a*3/2, b/5)
h(a,b*2)
etc.

Now,
How would you limit the max recursion depth across all functions?

Everything is bound statically, imagine C or C++

Attached: 1562857326127.png (666x855, 696K)

>why do cniles continuously reinvent C++ features
>not knowing this is a gcc extension
>not knowing this is executed when the lib is loaded
>still raging about clines knowing more than you

You must have enormous self-hatred.

Why does Jow Forums shill SICP? Does anyone on Earth even use Lisp?

>exercise 1.10: calculate these terms of ackermann's function
>ex. 1.15: do some shit with sine reduction
>ex. 1.19: reduce the steps to calculate fibonacci with successive squaring
It's math my dude.

Attached: 1562905693931.jpg (744x720, 98K)

The most straightforward way would be to make them take an additional parameter denoting the depth. Initially depth = 0. Throw error if depth > limit. Recursive calls pass depth + 1.

>>not knowing this is a gcc extension
that's exactly the point retard

"Elegant" I should add
The obvious one would be to add an incrementing variable (the top level-function could hide this and call the implementations f_(), g_(), or whatever) and add the check in every single function, but let's think beyond that

I was too slow but There will potentially be hundreds of functions

>good design pattern
>for a set of recursive functions
I recommend you the recursive functions pattern.

>that's exactly the point retard
You mixing up language features with compiler features? Does C++ have some mechanism with which a function is executed whenever a module is loaded/unloaded?

Oh, they rely on compiler extensions as well? Interesting ... for a Pajeet,

And of course you haven't tested the code yourself. Just how much do you want to discredit yourself?

>but let's think beyond that
what the fuck are you talking about
thats both the simplest and the only way to do it

how automatic does it need to be?
can you reset it by hand or do you want a fresh counter for every invocation?
do you have a specific language in mind?
most straightforward is passing depth along and checking it everytime.
If you have an object to hold the functions and a counter you could do it that way.
Or the functions could call a special function that increments a static counter and then calls the next function.

>1.10
They gave you the definition of the ackermann function, the code is already there. They're asking you to evaluate the function, just making sure you know how to run scheme code.
>1.15
Has absolutely nothing to do with math, They're asking how many times is recursively called, and how it grows. It's making sure you read the last section.
>1.19
They give you an explanation and ask you to plug in 2 expressions.

There's no way in hell you're too dumb to do this, it has nothing to do with math. Can't believe I had to dig out my dusty SICP for this shit.

yes they're called static constructors, what do you think your nonportable extension is imitating?

I think you could set a stack limit and handle the signal on stack overflow or some other similar hackery (like map some memory with no write access where you want the limit to be). But that would need the functions to have the same frame size for precise counting and actually have any frame size at all because they might be as well tail-call-optimized. Most likely you shouldn't and you don't need to do that. Otherwise the only other entity that could detect exceeded depth would be the functions themselves.

>There's no way in hell you're too dumb to do this
user, you vastly overestimate my intelligence. But thank you.

Attached: 1562847928605.jpg (750x925, 617K)

>what do you think your nonportable extension is imitating?
I dunno - something that can be injected into existing programs without much hassle? Oh wait ...

And of course you still havn't run it. At this point you have the code and the instructions; all you'd need to do is to compile and inject it. But of course you're not going to do that, because that would shatter your world view.

¯\_(ツ)_/¯

bash is actually fun

is python good for making gui programs and/or small video games?

That is absolutely not the only way to do it

e.g. using function objects you can use reference counting (ctor/dtor) to get the stack depth and determine whether the calls are to recurse further

Virtually hidden to the user, No ugly variable or repeated conditions

I don't care what the hell your code is trying to demonstrate I just find it hilarious that cniles think C++ is bad because it's bloated then reimplement its features with compiler extensions any way

If I want to create an AI that is capable of understanding relestste market where do I start?

learning to spell real estate would probably help

larger squid attack

Attached: 1540061326671.jpg (1280x720, 188K)

>literally no arguments left whatsoever
>still thinking he's above
It takes a certain amount of autism to be that far gone, but you, my clueless friend - you earned it.

>No ugly variable
oh you're one of those people
therei s a variable, you just can't see it

Which course/book(s)/topic cover stuff like Deterministic Finite Automatons and P = NP problem? I'm trying to make up for my lack of formal CS knowledge so I can stop being a fucking POO koder and work at real companies that do real software engineering. Someone told me algorithms but my CLRS doesn't cover it.

Attached: brainlet.png (621x702, 56K)

>P = NP problem
>real software engineering
pick one

It's JavaScript time! Woohoo!

Attached: dadcaac72f54ac813eec24b2f8cffd1c.jpg (600x900, 61K)

The question was on a "good design pattern" and an "elegant solution"

Having lots of duplicate code is neither

>work at real companies that do real software engineering
Like Oracle? Like Microsoft? Like Adobe? Like the entire snake oil industry?

Doesn't sound that glamorous all of a sudden, hm?

>>>/wdg/

these posts would be so much better without javascript

I know P = NP is irrelevant for the work you do but I just want to learn the theory and make sure I'm not missing out.

At least one of those companies does code review.

what the fuck does this mean

Attached: nigger.png (424x26, 2K)

Any programming book repository that isn't the gentoomen library?

what's the use case? to be able to catch a stack overflow before the program does? I usually use a global variable that gets incremented and decremented in the base function

>I just want to learn the theory and make sure I'm not missing out.
software engineer here, you aren't missing out, most "theory" is wank

you probably forgot to use parentheses on a call to the count method on a string object somewhere

it's the representation of a built-in method
did you forget the parentheses?

that's because "software engineer" "theory" is OOP design patterns methodology bandwagons etc (misc crap)

you printed the built-in method count of str object at 0x040EB8B8

>>> a
'faggot'
>>> a.count

>>> a.count('g')
2

Lets write Doom game without help

You can find mostly any book you want by title on libgen, a large collection of books is useless because you'll never read any of them.

go ahead
I won't help you I promise

that's only half true
OOP design patterns are poor practical theory, but at least it is practical theory unlike the useless shit they teach in CS

But without JavaScript you wouldn't have regular doll cuteposts cheering you on.

yeah i wont help you either, lets do this

Almost done with chapter 2. I've managed to power through it

>At least one of those companies does code review.
So? That doesn't mean anything at all! IIS runs in the fucking kernel because they couldn't make it faster!

This. Fucking this so much.

this is the dumbest post in the thread

I like large collections better, maybe I am stupid.

Example would be something like
MyFunctionObject:
static refCount = 0; // is a static variable that could be reset when not constructing using the copy constructor
constructor(functionToCall):
_refCount = 0
_functionToCall = functionToCall
copy_constructor():
refCount++
desctructor:
refCount--
operator(a,b):
if (ref < max_depth):
_functionToCall(a,b):


top-level where functions are called from:

f_obj = MyFunctionObject(&f);

f(a,b):
f_obj(a,b)

etc.

>So? That doesn't mean anything at all!
Means more than not doing code review and just pushing out what has surface functionality and operations. I just don't want to work with indians anymore man.

I'm not looking for practical theory. I know that 90% of your work is ETL and CRUD bullshit along with the usual "plug and play X into Y to make Z happen". I do the same thing dude. I just want to learn some real CS.

>I know that 90% of your work is ETL and CRUD bullshit
that's not engineering
CS isn't engineering either
the stuff they teach you in CS is mostly just useful for wanking off your other buddies in CS

new to programming i need help

Attached: im retarded.png (574x159, 5K)

Not stupid, just misguided. There's no use in having 1000 pdfs on your system, you won't read more than a tiny fraction of them. It's like the rich people who have a gigantic library of books they've never read.
Pick a good book, read the entire thing and it's worth more than a billion pdfs you've never looked at or only read the first chapter.

>Means more than not doing code review
It merely means that they've partially realised that their code is shit, and have been trying to fix it slowly over time - but they have so much more broken software out there that at the pace they're going I'm probably not going to see it happening.
>SQL Server literally re-defines what a Unicode codepoint is just so that they do not have to admit that their software engineers are fucking imbeciles who thought that UTF-16 character can only ever take up 2 bytes of memory

>I just don't want to work with indians anymore man.
>Satya Nadella is Indian

uhhh im retard too but I think it's len(text[18:27])

WHAT SHOULD I MAKE?!?!

Attached: silly negro.png (369x286, 159K)

Make install.

I USE NINJA IT'S FASTER!!!

what do you want to do?

make me a bf like kaworu

Attached: Eva24DC_Kaworu.jpg (365x273, 13K)

uber of jacking off

Alright, guess I'll control my autism and do this instead.

I CAN'T I DON'T KNOW WHERE ADAM IS
PLEASE EXPLAIN IN MORE DETAIL!!! LIKE, YOU ORDER SOMEONE TO COME JACK YOU OFF?

Script for remote webcam access through ssh
fun stuff

how do you fags feel that javascript kiddies earn 100k

In java you could just catch a StackOverflowException instead of counting... not recommending it though

You just seriously underestimate how terrible people are at math. The ackermann function exercise requires you to give a mathematical definition which is trivial if you didn't sleep through high school math, but that isn't rate at all.
The same also goes for the other exercises. You're saying "it's not math" and then literally go on to describe what a lot of mathlets struggle with.
There's not a single high school level math exercise that goes beyond plugging shit in and tons of people consider it a hard topic and are barely scraping by.

learning python
finnishing up a website in laravel

*ahem*

Attached: Webcam-Cover-Website-Images-Laptop.png (500x500, 150K)

what language do you use?

Pretty neat thing to 3D print if you have a printer

So like Ika said, there is actually something wrong with those people?

Attached: 1553685689312.jpg (686x720, 312K)

>printer
cunt, any cappable and normal human being should be able to make that using his hands and a knife

Yes and while it's a sad state of affairs how widespread this is, it's alright, they can still be taught to program, they just need resources designed for exceptional individuals. Something like HTDP is written so that it can literally be understood by children, so even mathlets shouldn't have too much trouble.

Does this seem a little challenging for CS101? This is the second assignment.

Attached: helk.jpg (1138x972, 178K)

It's amazing how far removed maths are removed from real-world applications. It's like the people who design these assignments have *no* idea how the fucking world works.

you should know how to do this from highschool maths

just find a matrix M that M^2 yields an idempotent matrix

Depends on whether they expect you to actually find a somewhat efficient algorithm or just bruteforce it.
If it's the latter, it's basically trivial.

since the matrix size is fixed at 3x3, you can just try all 3x3 binary matrices, shouldn't be that hard.

matrices actually have real world applications

>daily programming thread
>there are 2 each day
Intellectual checkmate. Any final words?

Attached: 1562956863545.jpg (1280x720, 87K)

computer programming isn't a real world application
programming is useless academic bullshit

what?

the /dpt/ creator only posts a day