/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: dec_pdp_11_by_pomorosso_d3fmh8w-pre.jpg (800x1000, 96K)

Other urls found in this thread:

arxiv.org/pdf/1706.01206.pdf
godbolt.org/z/83ZJTa
jsfiddle.net/sdfozptb/
twitter.com/SFWRedditVideos

Nothing.

Attached: 1537876820778.jpg (672x807, 87K)

Ah, I was waiting for you, Anone! Let us begin the JavaScript lesson. Please, come inside.

Attached: e86a2873e7584d434ff07abe9f8bd28b.jpg (736x1107, 210K)

oh god, I want to come inside her

1/3

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};

>Please, come inside.
That's lewd as hell.

2/3
__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;
}

3/3
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

¯\_(ツ)_/¯

>uninitialized variables
fucking vomit inducing.

How do I not fall for the polyglot meme, I feel I wanna learn too many languages. Send help.

Attached: on3gwklteuc11.jpg (236x230, 10K)

Where are they uninitialised?

get a job and stop being a NEET

paper on deep learning methods to combat online racism going pretty well

Attached: deep learning racism.png (721x875, 168K)

I hope a somalian refugee shanks you.

faggot haha

No degree, not many projects under my github. I am a fucking mess.

Attached: 1562707760857.png (200x186, 17K)

well i have two degrees but am still working on getting a job

>the first sentient ai will have twitter as a dataset instead of all the world's knowledge from digital libraries

Attached: 1562918877099.jpg (250x233, 5K)

arxiv.org/pdf/1706.01206.pdf
Mostly useless, NLP is too complex, people just will destroy filters in minutes.

...

At least link them together so people can hide it easily.

how will it not get bogged down under just how many different kinds of racism exist, or account for different sentiments about how far is "too far"?

I'm waiting, cuck.

No. I want people to be bothered by it to the point where they actually do it.

Oh now meme images for racism

Attached: 9ACC923A-C773-4067-B943-2841A981A4FF.jpg (824x1042, 98K)

That relies on the presumption they are interested in any other racism than that which emanates from whites.

You do realize some have filtered you already right?

no it doesn't

You do realise I don't care? As long as I'm proven wrong I'll keep posting this text. Only takes me three minutes, that's negligible.

Can I get a VERY quick rundown?

Why do britbongs hold grudges like this?

user spamming his extremely dumb and irrelevant shit for two or three threads now and jannies are masturbating instead

don't blame me for this incomprehensible garbage

See, that's why I do it. As long as there are people this butthurt over being wrong I'm doing God's work.

@71861337
>can't into basic logic101 to make correct arguments
>look at how butthurt everyone is for being wrong :^)

How the fuck do you hope to interpret this printout from a real world application?
What are you gonna compare it to? How are you gonna know how many allocations were optimized or not?

>he doesn't even understand the point of that post.
I suppose that's for the better.

>How the fuck do you hope to interpret this printout from a real world application?
You're missing the point here. *I* am not supposed to interpret the data; I've done that often enough. This data aren't for me; this for the people who claim that the C++ compiler can optimise away smaller allocations.

>How are you gonna know how many allocations were optimized or not?
It DOES show the sizes of each allocated block, doesn't it? If there's lots of allocations of smaller sizes you know there's something wrong.

if you were standing in front of me right now, i'd fucking batter you to death.

My personal favourite is thunderbird:
[1563038702]: Allocate 0x11899e0|704
[1563038702]: Free 0x11899e0
[1563038702]: Allocate 0x11899e0|704
[1563038702]: Free 0x11899e0
[1563038702]: Allocate 0x11899e0|704
[1563038702]: Free 0x11899e0
[1563038702]: Allocate 0x11899e0|704
[1563038702]: Free 0x11899e0
[1563038702]: Allocate 0x11899e0|704
[1563038702]: Free 0x11899e0
[1563038702]: Allocate 0x11899e0|704
[1563038702]: Free 0x11899e0
[1563038702]: Allocate 0x11899e0|704
[1563038702]: Allocate 0x11a05e0|596
[1563038702]: Free 0x11899e0
[1563038702]: Allocate 0x11899e0|704
[1563038702]: Free 0x11899e0
[1563038702]: Allocate 0x11899e0|704
[1563038702]: Free 0x11899e0
[1563038702]: Allocate 0x11899e0|704
[1563038702]: Free 0x11899e0
[1563038702]: Allocate 0x11899e0|704
[1563038702]: Free 0x11899e0
[1563038702]: Allocate 0x11899e0|704
[1563038702]: Free 0x11899e0
[1563038702]: Allocate 0x11899e0|704
[1563038702]: Free 0x11899e0
[1563038702]: Allocate 0x11899e0|704
[1563038702]: Free 0x11899e0
[1563038702]: Allocate 0x11899e0|704
[1563038702]: Free 0x11899e0

Sure thingy, keyboard warrior. *yawn*

>lying on the internet

Less whining, more programming. Here is a pretty function that sums all integers between and b.

(define (sum-integers a b)
(if (> a b)
0
(+ a (sum-integers (+ a 1) b))))

Attached: 9UPP38D.jpg (438x750, 76K)

>Here is a pretty function
pretty shit

>data is being posted
>"you're just lying"
>that much denial
C'mon, beef up your game.

if I don't have a degree how can I get foot in the door as a backend dev? nodejs/typescript or python/django would be enough to work in tech startups? I plan to learn really well a scripting language and a statically typed scalable language (probably java 8+) along with enough cs and software design and architecture
I finished a really good introductory course in programming and oop with java 8, also learned js/nodejs/express, jQuery and DOM fundamentals, now I'm reading K&R 2nd edition because every language points to C and I want to learn pointers and basics of how memory works

Make a solid website with solid backend and people will consider hiring you if it's any good.

Contribute to backend stuff on github.

That's it really.

Luck.
If you happen to run into someone willing to give you a chance you'll make it, otherwise not.

not really, you've claimed something much bolder that C++ compiler optimising away smaller allocations, you said that no memory management was possible at compile time and that your "data" was the only way to prove you wrong, so fuck off

Oh yeah, where were my variables uninitialised again? Or have you just been talking out of your arse, like 90% of the time?

Silly question of course. I already compiled my code with more warning flags, and no warnings were produced. Of COURSE you've been talking shit, like all sepples.

now make it tail recursive

>arse
filtered

kys cnile

>being so severely handicapped he can't read anymore
What I wrote was:
>Since the compiler has NOTHING to do with symbol resolving
, which means that at the point of symbol resolving all optimisations have already been done, and what you see is the """"""optimised"""" memory allocation.

It's not my fucking problem if you're dyslexic.

Gonna steal some github projects to add to my portfolio and act like I made them

Attached: serveimage.png (1000x1000, 478K)

FUCK OFF YOU LYING PIECE OF SHIT

>I'm talking about memory management, which is the one thing you can NOT do at compile time.
>but that's factually wrong, bro
>
>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.

TCO can't apply here because the call to + depends on the return value of the recursive call

They ask stuff about your projects to see if you understand your own code, and they check for plagiarism. I wouldn't advise it.

How do you plan/keep track of your work? I find myself spending a lot of time just figuring out what to work on, even though there’s stiĺl a shitton of stuff that needs to be done.

the return value of sprintf is signed because negative values are used to indicate errors
also calling time like that is not recommended

Man, twitter is salty today about
>you will never be a 10x engineer

someone at my uni got fired because he stole my code from github

Attached: 1553122118407.gif (340x340, 134K)

I use a whiteboard to note todo tasks. It's nicer than to do it on a computer imo.

so language/frameworks doesn't matter as much as building a website designed/architectured to scale with a good backend? also I thought learning c + go since language is backed by google and is gaining traction lately, what you say is it worth it?
I could also go for a degree but I would major in something like math or stats with a cs minor
thank you

I agree with you user but I'm pretty determined and I believe that luck favors those who work hard enough. thanks

>FUCK OFF YOU LYING PIECE OF SHIT
No.

>I'm talking about memory management, which is the one thing you can NOT do at compile time.
Alright, I'll explain it very, verrrrry slowly to you brainlet.

The compiler goes through the code and performs optimisations. However, when it comes to memory management, the compiler is almost completely powerless to optimise because all the compiler can do is compile-time optimisations, not run-time optimisations.

And that's exactly what my data shows, because *obviously* thunderbird - which I did post as an example - hasn't received any memory management optimisation. How else do you explain that a block of 704 bytes is allocated - and then freed - and then allocated - and then freed - and that for literally thousands of iterations?

Did I actually get through to you this time?

I don't care about your excuses, you lying piece of shit. go on, squirm squirm, it's so fitting for you cniles.

>the return value of sprintf is signed because negative values are used to indicate errors
Dude I know. I can read man pages. The point of me asking this is that sprintf should've written the bytes written into a separate variable, and the return value should've just indicated whether or not the call was a success.

>also calling time like that is not recommended
Pray explain why.

this doesn't prove whatsoever that compile-time memory management isn't possible.

>is explained where he's wrong
>LIAR LIAR PANTS ON FIRE
Lemme guess: you're one of those people who deny climate change because it's cold where you live right now.

It doesn't matter much, no. People like experience with certain backends sometimes (people are heavily looking for node.js experience) but if you're able to understand a framework then switching frameworks shouldn't be a problem, and that's probably what they're going to test you on (as in, if you understand what you're doing).

I would not recommend C unless you think you're going to have a use for it (for example toying with embedded stuff or deep Linux stuff). Go is an okay language. Your choice of language doesn't matter much actually as long as you don't pick something 100% dead, just get proefficient as some kind of technology even if a bit more fringe, and you should find a job eventually. Also don't be scared by all these jobs that require a degree, just send your application with your portfolio anyway, you have a shot at impressing people this way.

Do you need to learn PHP to set up a custom Vichan imageboard?

you didn't prove that compile time memory management was impossible, merely that C++ didn't do the optimizations you want it to d, lying piece of shit

>this doesn't prove whatsoever that compile-time memory management isn't possible.
Then why doesn't the C++ compiler do it? Allocating and then freeing the same block right after should be one of the *easiest* patterns to figure out.

I'd imagine using PHP/Javascript is pretty much necessary yes.

Make a program that automatically parse, shuffle and rename everything in an input folder!

now you're just proving you don't know basic logic, at least not enough to argue with people.

It says it doesn't use Javascript so I guess I'll just need to learn PHP

I don't understand dependency injection

Attached: 1532597501455.jpg (1680x1050, 1.02M)

kinda hard to parse that from your comment but fair enough
>Pray explain why
The tloc argument is obsolescent and should always be NULL in new code.
When tloc is NULL, the call cannot fail.
for more info check the man page for time

it's just partial function application

I wish instead of playing with computers for a decade I had made a family.

Attached: 1558489013777.jpg (573x781, 163K)

thank you for this post, I really appreciate it!

>Allocating and then freeing the same block right after should be one of the *easiest* patterns to figure out
I'm new to this discussion, but it does do that?
godbolt.org/z/83ZJTa
Compiles to single call to malloc

rather than using hard dependencies (e.g. concrete classes) you get them passed to you, usually in a constructor

instead of
class Foo
{
Bar bar;
Foo()
{
bar = new ConcreteBar();
}
}
you have
class Foo
{
Bar bar;
Foo(Bar bar)
{
this.bar = bar;
}
}

Attached: 1556834533921.png (500x326, 50K)

sounds easy. the why do I need frameworks like dagger2?

Well as long as I understand them
I can just change the name and the references to the author or his github to my own. Maybe the colors too

*then

In bash, how can I do something for each argument in a while loop?
for example

./test program a b c
while [ count -le $#]
do
echo $$count
count=$((count + 1))
done


desired output should be a b c
This is what i'm trying to do but $$count doesn't work as I want it to. whats the correct way of doing this?

./test_program *
not that it matters

Hey, here's a great idea. Why don't you do the same as I did - compile the code that I provided - and run it against some existing C++ applications, and just find me ONE example where the memory allocation isn't obviously trash and someone didn't do manual optimisations on the source-code level?

Now to be clear it's not *completely* impossible. But tracking pointers across several possible function calls and jumps is wildly complicated already. If people have been working on this for 30 years, and their software still produces code like I've shown, then you can assume it's rocket surgery.

(I'd also assume there's some aliasing bullshit going on, but at this point who knows. That's why I said: run it and show me the data, and if you find one not manually crafted example of proper memory utilisation I'll shut up. Hasn't happened so far - I have yet to see one such program).

More the equivalent of:
int *a,i;
for(i = 0;i < 10000;i++)
{
a = (int*)malloc(40 * sizeof(int));
free(a);
}

, but of course with less intentional stupidity.

DI frameworks generally involve using annotations so dependencies are automagically resolved rather than being explicitly provided by you in e.g. constructor calls.

for arg; do
echo "${arg}"
done

Lisp is the most powerful programming language.

It just says that:
>When tloc is NULL, the call cannot fail.
And that's not good enough for me. I already had to split the code into three postings.

this is why javascript is the most powerful language jsfiddle.net/sdfozptb/

i can make beautiful computer art and share it with the world instantly

#!/bin/sh
for a in "$@"
do
echo "$a"
done

or
#!/bin/sh
while [ "$#" -ne 0 ]
do
echo "$1"
shift
done

If you're stupid enough not to rename, reshuffle and possibly refactor everything (although that would constitute actual work) ya deserve it.

I don't think

ut = time(NULL);

is that much worse than
time(&ut);

besides you could just put up a pastebin link

Attached: 1558475700100.jpg (1240x699, 50K)