/dpt/ - Daily Programming Thread

old thread: What are you working on, Sup Forums?

Other urls found in this thread:

cplusplus.com/doc/tutorial/namespaces/
fastformat.org/
en.wikipedia.org/wiki/Board_representation_(chess)
pastebin.com/hW9jvD3v
pastebin.com/df2Cct9H
pastebin.com/bE159agd
pastebin.com/BNKeBRcw
twitter.com/SFWRedditVideos

first for c#

w2c her programming garment

nth for Lua uma delicia

I tried VS code today and it's bretty good. It reads your include path and lets you look at definitions for functions. The built-in git integration also works well with GitHub. It also has a terminal window so you don't have to open a separate window to run your program with custom arguments.

Only thing is I disabled telemetry and crash reporting but I still don't Microsoft to respect my decisions.

Thought on vs code?

i want to POUND that anime

learning opengl with c++, doing pretty good

post more felix

I just use grep to find function definitions in codebases I'm not familiar with.
I don't mind opening a terminal window because I stay in one the entire time, exiting nano only to run make.

Is Go the perfect compromise between static and dynamic typing?

Go doesn't allow generics so it's dead in the water.
Even C lets you emulate generics with macros, and C11 has them natively built in to the preprocessor.

I guess grep works but I'm surprised you haven't gotten annoyed with nano yet

this is going to be next /tpg/ op image

There's nothing wrong with nano, it has just enough features to be useful.

Why ferris?

What the fuck do you do when you become an expert C++ programmer?
Does life stop making sense?

already used this one

I need to analyze the runtime of this function:

RecursiveMin(A, p, r){
if(p == r){
return A[p];
}else if(p < r){
q = floor((p + r)/2);

m1 = RecursiveMin(A, p, q);
m2 = RecursiveMin(A, q + 1, r);

if(m1 < m2)
return m1;
else
return m2;
}
}

I figure it's nlogn. It has to check every member of A to figure out the min, and the max depth of the tree is log(n)

pretty much, yeah

cplusplus.com/doc/tutorial/namespaces/

It looks like O(n) because the recursion tree has n leaves and each function call is O(1)

C++ question:
Why do I sometimes see people use

std::cout

Took my first C++ Exam today in class, so far c++ is easy, aside from a few minor hiccups like missing semicolons (which i figure out quickly) most of the stuff seems to come naturally.

Neither one is used in real code.
> stream are extreme security liabilities in C++ much like the deprecated gets() function in C.

Use the printf family functions instead.

Sorry I butchered my first post forgetting a /code tag

I use this fastformat.org/ but it's kind of a pain to get set up

namespaces help keep variable names from clashing with each other. In C, if you want to create a library with a set of function names that are unique, you'd normally append "library_" to each function name, like for a file that made ".qbd" files, you might have "libqbd_open". In C++, you can define a namespace called "qpd", and just have all functions under that called "qbd::open" or "qbd::close" or whatever, and it's understand that these functions are for libqbd.

However, if you put "using namespace qbd" at the top of your file, then you can ignore the namespace "qbd::" and instead write "open" and "close". The problem, of course, is that open and close are already standard library functions in C++.

Theyre omitting the namespace with a using namespace std; /code] somewhere above to make writing sepples slightly less painful.

it's a bad habit though, usings are shit and will make your codebase a nightmare to read through.

>last update in 2010
>hosted on SOURCEFORGE

ded project

...

>2017
>doesn't wear thigh-high striped stockings + school girl outfit while coding

You're not gonna make it

Report and ignore tranny threads

Alright, so the correct practice is to refrain from using a namespace at the start of your program and instead always reference the library like std::cout, and we do it this way so that:

1. Someone reading the code can instantly see what library your function name is referencing
2. So that you don't get conflicts between functions with the same names

>It's a tranny
bamboozled again

Or... you could just do it the C way.
It's worked great for the last 45 years.

hey man it's stable, does what I need
might fork it at some point though

Is it C++ convention to include an underscore after some variables names?

I'm reading some source code and some variables have an underscore after it but others don't, seemingly at random. The ones with an underscore after it appear to be unique with a single instance.

>tfw tinkering with your own project just for fun

>Spend hours debugging code
>Turns out I used < instead of

>spend hours debugging code
>sent panicked email to professor asking to meet tomorrow for help
>turns out forgot to cast an int to a double

>he doesn't like getting his ear teased by a qt girl (male)

Hey anons I was thinking of making a simple text chess game. Only thing is how would I know if the king is in check/checkmate?

Come on, chess logic/AI is the most rudimentary of all things.

How have you even lived this long?

>ctrl+f
>haskell
>ctrl+w

idk mostly because breathing is involuntary i guess. I was thinking something like every board position having an array of which pieces can be moved there. Does that sound about right?

perhaps only calculate which pieces can move to the position currently occupied by the king, and the positions adjacent to the king

All of Chess (and Go) can be defined in just a few lines of code. It's that simple.

Chess implementation are pretty interesting stuff. This is a good starting point

en.wikipedia.org/wiki/Board_representation_(chess)

that sounds like a good idea, user.

I have an async question:
Let's say I have thousands of links I need to download. What's better way to handle that:
>create one coroutine for each link
or
>create a queue with all links, and give that queue to a handful of coroutines, which will take links from the queue (i.e. basically like threads)

I just had the brilliant idea of attaching a runtime debugger to my dynamically-typed language to log the values actually used at each callsite and then generate possible type annotations

I assume by default this would be "dynamic analysis" in the same way that reading an AST would be static analysis but googling for the term only brings up stuff like valgrind. Is there a more smarter word for this kind of thing?

>have thousands of things running at once
or
>have a queue

coined the term yourself and sue everyone who use it

I think it depends on use-case and situation

What does a co-routine for every link do if there are more co-routines than links, or more links than co-routines?

By having a cache (your aforementioned 'queue') for the links to sit in and get pulled from, you basically answer that question and have something that's more adaptable, but probably less efficient.

t. I'm not even a programmer

there is only so much bandwith to play with. how about using a queue and focus on only a handful of thing at the same time.

Elaborate.
Creating thousands of coroutines isn't as bad as creating thousands of threads, which is why I asked the question.

Also, since it's async, there by definition won't be more than one thing running at one :^)

And thousands of coroutines squeeze all the possible bandwidth. At least that's how it seems in my brain.


I'll try implementing both of those solutions and see if any of them is better than the other.

>running at one :^)
I think you already know the answer, shit disturber.

It's all about context switches.

i'm eager to see the test result

>I think you already know the answer, shit disturber.
It's a friendly thread, pal, no need to call names.

And I don't know the answer. I know how async works, but not to the degree that allows me to see which of the solutions is clearly superior.
I'll write two test programs and post my results here.

You do that.
Please, let us all know which is faster: Doing one thing quickly and then moving onto the next, or constantly switching between once thing an another (many thousands or millions), a little bit at a time.

The idea is kinda similar to profile-based optimisation (though the objective is different)

What's the best way to profile my C program on Linux?
I'm trying to cut down on the CPU usage, and I need to know with good accuracy which functions are taking up the time.

Actually I'm a boy!

timestamps

sauceee

[Tonikaku] Josoko Hatten Kei

I'm profiling a program which has maybe 30K lines of code. I'm not going to do that.

treat it like a binsearch
keep bisecting your code down the perceptual middle and drill into the half that takes more time

oh damn I remember using that back before catalog was a thing

ty user

Just be intelligent about it. Label the timestamps then parse them using a script after running your program a few times to get an average

so you're a Sup Forumstard, then?

binary search best search

Imagine if C++ was good

imagine if lisp was popular

I'll be fucking damned.


Test setup: 575 wallpapers from Imgur, VPS in the Netherlands with 1Gbps connection.

Queues with 8, 16, or 32 downloader tasks: 16-18 seconds. (number of tasks doesn't change much)
Coroutines: 14-17 seconds, 700 MB of RAM eaten. It's actually faster, can't say I expected that after seeing it consume all my RAM.

perf output of both: pastebin.com/hW9jvD3v

Code with a queue: pastebin.com/df2Cct9H
Code with coroutines: pastebin.com/bE159agd
links.txt: pastebin.com/BNKeBRcw


Conclusion: use queues, unless you have more RAM than Google. And hey, the code without queues is much shorter :^)

well I was in like 2010

in general the more I/O limited your code is, the better returns parallelism gets you. though you often get diminishing returns after (2 * thread_count) + 1 threads

sorry, 2 * core count, not thread count

can someone write a program that will kill me

That would be really difficult and time-consuming. Also it would probably be murder even though you want to die.

I'm... not sure if the programmer would necessarily go to jail though. Especially if he just wrote it and you're the one who ran it on hardware. Was your intent to start a conversation on moral quandaries?

Sorry, but that's just too far out of the realm of possibility. I can't even begin to imagine it.

Writing a CUDA benchmark program for testing how well my distributed userspace NVMe driver works.

>C is the best programming language and used by smart people
>have never seen or heard of a non-cute C programmer
>Python and Java are the worst (popular) programming languages and used by idiots
>have never seen a non-brown Python and Java programmer
huh why is this?

You've got things the wrong way around. The printf family of functions are a common source of security bugs, particularly when non-literal strings are fed from untrusted input to any of them, or where %s is used anywhere in scanf.

By contrast, std::cin with the >> operator and std::string can read an arbitrary number of characters from stdin and never overflow memory. And std::cout avoids all of printf's problems by handling type deduction at compile time and not needing a format string in the first place. Furthermore, it can never write to arbitrary memory addresses, unlike %n.

Nobody uses scanf except for formatting buffers.

strtoul exists, you know.

>Thought on vs code?
I've already got 1 Chromium installed, why would I want a second Chromium?

After making a single session for all requests (and passing it as a parameter to the download function) the queue code finishes in 6-7 seconds, while the coroutine one takes 8-10 seconds.
I guess I was retarded after all.

Right. But don't pretend that C's format functions are secure, or even more secure than C++'s iostream functions. There are arguments that can be made against iostream: it's slightly slower, it increases program size, it looks ugly for some people... but strictly speaking, it is more secure.

>But don't pretend that C's format functions are secure
Explain to me how you believe strtoul is insecure.

>or even more secure than C++'s iostream functions
Explain to me how you believe iostream isn't using strtoul under the hood.

Does anyone here use a pirate version of IDA pro? does it work okay?

strtoul isn't a format function, idiot.

The C format functions include:

printf
fprintf
sprintf
snprintf
scanf
fscanf
sscanf

The _s variants of these are missing a few attack vectors and are preferable, however even more preferable is to not use % formatting at all.

>strtoul isn't a format function,
0 / 10 bait

I'm out, this shit is just stupid.

>Butthurt Ctard.

yeah, I got it from whatcd a few years back. works prefectly. I probably wouldn't trust something from a public tracker though

strtoul does not take a format string. Its parameters are as follows:

const char *str : A string representation of a number to be returned.
char **str_end : An optional location to place a pointer past the number string.
int base : The base of the number in str.

No % anything. It's not a format function. It may be called by the format functions, but that's kind of irrelevant.

>a formatting function must take a format string

guy with Turbo C++ book from last thread - forgot to mention the entire first half of the book covers C, not C++

just thought you might wanna know

Yes.
Even if you do have such a lose definition of a formatting function, strtoul still doesn't fit the description because it doesn't fucking format anything you retard.
It takes a string and converts it to an integer, you call that fucking formatting? that's PARSING.

>It takes a string and converts it to an integer, you call that fucking formatting? that's PARSING.
Says the guy who brought up scanf

I'm not that guy, I'm just pointing out your stupidity.

>I'm not that guy
Sure thing buddy.