/dpt/ - Daily Programming Thread

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

Attached: 1541483607240.jpg (1000x1100, 114K)

Other urls found in this thread:

chrisantonellis.com/files/gameboy/gb-programming-manual.pdf
cdecl.org/
rust-lang.org/en-US/community.html
effbot.org/tkinterbook/grid.htm
beta.rust-lang.org/community
twitter.com/SFWRedditGifs

SachiCOOL.

I get that I just don't know the syntax. How to declare them, how you can't, what kind of dumb things you can do.

Attached: 1445361568133.jpg (770x980, 396K)

Improvements for my life and yours

returntype (*funcpointer)(argtype, argtype, ...);

Attached: 1518799450077.jpg (1024x768, 190K)

My wife!

Is Elixir comfy?

Attached: steinsgate-03-mayuri.jpg (1280x720, 63K)

Somebody go ask hiromoot for /prog/ back.

Attached: prog.jpg (473x496, 105K)

This.

you can't post your waifu in a text only board

>someone was actually paid to make this

type (*name)(args) = value;
e.g.
int (*ptr)(const char *restrict , ...) = printf;
The type and args part works just the same as it does for any normal function declaration.
The "interesting" part is that it wraps around the variable, and due to types being recursive, you can create some abominations with it.
void *(*(*ptr)(void))(int);
ptr is a pointer to a function which takes no arguments and returns a pointer to a function which takes a pointer to a function which takes no arguments and returns an int which returns a pointer to void.
There is an algorithm for working out what the type is by starting in the middle (by the variable name) and work your way out, but it's honestly not that important. You never see this type of shit in real code.
If function pointers ever cause shit to be unreadable, people just use typedefs to clean it up.
typedef int (*int_fn)(void);
typedef void *(*voidptr_fn)(int_fn);
typedef voidptr_fn (*voidptrfn_fn)(void);

voidptrfn_fn ptr;

Make it an image board this time, we'll the retarded webdevs and /agdg/ if needed.

This is good. The only thing that's confusing me are the typedefs.

What are the pros and cons of C++ templates vs code generators?

>put calls to my longest function in a for loop in a try block
>except only does this
except:
print("An error occured")
pass

I should not code

I want to make up a fantasy 8-bit architecture and develop a virtual machine for it, as an emulator-like platform for making retro-style PC games.

If I were just going to have a single virtual processor and implement all I/O with instructions for that processor and memory mappings from/to device-like blackboxes that are really just multimedia frameworks -- a la Chip8 -- then the task before me would be trivially easy.

However, in the interest of some modicum of authenticity, I instead want to implement the framework frontends as actual virtual devices, that communicate via data buffers and interrupts. The virtual processor itself would, of course, be implemented as a virtual device in kind, with a data buffer and an interrupt table, and there would be 2-3 more virtual processors (at minimum an audio processor and a graphics processor) to drive all non-processor virtual devices.

Will this be hard?

Attached: 646a813e21076d69e27896f03ae7de07.png (900x469, 71K)

the daily programming thread is more like the every-2-hours-or-so programming thread, so yeah

what part of
int(**f(int[],int*))(int*[],int[],int(*f[])(int[],int(*f[])()));

do you not understand?

i use typedefs no matter what when it comes to function pointers
the syntax is retarded

>void *(*(*ptr)(void))(int);
there was a program that literally described what you entered, like
you described

chrisantonellis.com/files/gameboy/gb-programming-manual.pdf

Take care abour latencies from emulation.

8bits processor,non OS, begin way more simple.

ok it was this: cdecl.org/
but it gave a syntax error

>int(**f(int[],int*))(int*[],int[],int(*f[])(int[],int(*f[])()));

>int(*f[])(): array of pointers to functions that take varargs and return ints

>int(*f[])(int[],int(*f[])()): array of pointers to functions that each take an array of ints and an array of pointers to functions that take varargs and return ints and return ints

ok two steps into figuring out what this says i've already given up

That site seems to be extremely picky or flawed for some reason.
I did actually test if that expression was valid with a real C compiler before I posted it here.

ok for some reason ptr didn't work
void* (*(*s)(void))(int)
>declare s as pointer to function (void) returning pointer to function (int) returning pointer to void

>Erlang
>comfy

lol no

Generators are good and templates are bad

>rust drops irc for discord
Fuck this gimmick language.

yes maybe the cli one works better

too many toxic white males on irc

let's hope Jow Forums doesn't fuck up my spacing here, I'm using the capital V's to mark where I am in the type:
V
int( **f(int[],int*) )(int*[],int[],int(*f[])(int[],int(*f[])()));

f is a pointer to a pointer to a function. The function takes two arguments: an array of ints, and a pointer to int.
V
int(**f(int[],int*))(int*[],int[],int(*f[])(int[],int(*f[])()));

f's return type is another pointer to a function. That function returns an int, and it takes these arguments:
V-----------------------------------------V
int(**f(int[],int*)) (int*[],int[],int(*f[])(int[],int(*f[])()));

the first two are trivial: an array of pointers to ints, and an array of ints. the third argument is another function pointer, named f here but the name given here is discarded:
V--------------------------V
int(**f(int[],int*))(int*[],int[],int(*f[])(int[],int(*f[])()));

this is an array of pointers to functions that return int. Their arguments are: an array of ints, and an array of pointers to functions that return int and take no arguments.

declare f as function (array of int, pointer to int) returning pointer to pointer to function (array of pointer to int, array of int, array of pointer to function (array of int, array of pointer to function returning int) returning int) returning int

>I'm going to install something that allows people to show individuality at such a great extent
No

Odd. If you just replace ptr with 'name' it works
//incomprehensible gibberish
void *(*(*ptr)(void))(int);

//perfectly valid
void *(*(*name)(void))(int);


Maybe someone should bother to report the site admin.

I approve dropping IRC
but for discord?! really

if you don't like discord, why not just stay on the IRC? It's not like it's mandatory to use their discord or something.

What part of "dropped IRC" don't you understand?
They locked the rooms, klined all users and shut down the network it was on

rust-lang.org/en-US/community.html
They haven't updated this yet.
Maybe it's just an internal conflict that will resolve.

you got the pointer-to-a-pointer in the wrong spot. f isn't a function, it's a pointer to a pointer to a function. If you went on that cdecl site or whatever, don't trust it.

this
why does C need to use such ugly syntax

Attached: Ds9iiubVAAEp543.jpg (1200x821, 91K)

Code generators (specifically a type'd macro system, even multi-stage programming) are far more expressive, but code generators for the C family of languages sucked so fucking hard that by the mid 80's Stroustrup had invented the most salvageable alternative: templates.

>I approve dropping IRC
Why? IRC is perfectly fine and is the standard for the open-source community.
Changing to some shitty proprietary protocol which requires a proprietary client is just fucking pants-on-head retarded and is alienating people who potentially would've joined.

Spent most of the afternoon implementing a Bindable interface where you can have variables and lists which can be bound to and have (a) any like-typed Bindable object bind to it and have it so they're referencing the same thing (b) attach any amount of Observers to the Bindable object (where if the underlying value of the Binded object changes, all observers will be alerted, triggering whatever UI/business logic change is necessary) and, upon re-bind, have them be carried over and (c) allow for a contract where weak-referenced Observers will fall out of context and free up themselves despite being attached to the Bindable object (desireable because I don't particularly have control over the life-cycle of the UI components and the messaging to trigger Bind-removals would be a huge fucking pain)..

Ended up going through about 5 different iterations before I got it in a way that minimizes the confusion and maximizes the utility from the consumer's point of view. I already had an ad-hoc thing for single-variables that has been working for a while, but finally sat down and made something robust, that can work for Mutable Lists, and all sorts of other dynamic multi-variable objects. In case you're wondering the purpose of this is to define the updating of UI and other derived data based on the changes of particular model data in a way that you pretty much only ever have to define one place and then couple/decouple as you please

Now I think I'm going to work on some collision algorithms to cool off.

Who was this?

The core dev/head shill of Rust uses...Windows. And doesn't believe in trivial security practices, instead choosing to ignore them. So much for safety being important.

Attached: Screenshot_2018-11-29_18-55-58.png (780x154, 22K)

Templates are limited in scope when you consider what's readable.
A lot of things C++ programmers do in template metaprogramming should have been done through codegen.

But making some simple template function is obviously not a place to bring in code generators.

I don't really think there's a lot of drawbacks to either when thinking of proper use. With code-gen you could have better incremental recompile speed.

>why does C need to use such ugly syntax
you use typedefs to avoid them, never seen that kind of code in any C code (yet)

yeah, it is from cdecl, also it was giving error so I removed two "f"s

tfw u realize a neat thing

If there is a place to be concerned with security as a user it's Windows.
It seems odd that he'd disregard it so readily if he's a windows user. It's almost like he's looking to sneak in malicious code.

tfw u realise a NEET thing

Attached: 1529888535943.jpg (1920x1080, 290K)

Im working on a simple app that will pull data from an API, populate a contacts like list, let me launch VNC(local) files on that contact and keep notes.

I also want to be able to mass email them in which they can pick from a list to reserve a slot on a calendar(they have previously filled in with times suiting them, one time setup). That gets mirrored to my calendar without overlap. To avoid spam it contains 'delay this' by 3 and 6 months.

Problem is I barely know any code, I'm deep in some shitty tkinter gui tutorial and I can't even decide between grid or pack. Don't even know if the email/calender thing is even possible.

Should I give up

Attached: 45346246.png (1079x664, 27K)

I don't think I agree.
It's either too small to warrant a separate board or it'd just be a place every indian with an internet connection goes to to post their bugs.
A board also implies we'd get rid of the generality of /dpt/. We'd split into C programming general, Embedded general, esolang general, Flavor of the day web programming general, no programming general, etc.

here:
int( (**f)(int[],int*) )(int*[],int[],int((*)[])(int[],int((*)[])()));


declare f as pointer to pointer to function (array of int, pointer to int) returning function (array of pointer to int, array of int, pointer to array of function (array of int, pointer to array of function returning int) returning int) returning int

>no programming general
sign me up

>Should I give up
Programming isn't really hard. You seem to know a lot more than the average person when it comes to this kind of stuff and you seem to be able to look up tutorials on how to do things. You're better off than 90% of people doing the same thing.

He seems to be one of many "core" devs. Is there any reason to believe he's "the" core dev or has a particularly prominent role?

Employed Haskell programmer reporting in

Attached: 1463364999713.jpg (268x237, 52K)

Thankyou, I'll try and keep going. It may not seem that hard for you but I am brand new. This time I'm trying not to be lazy by just copy pasting others shit

Attached: 2005090216_1145444722.jpg (459x564, 95K)

give me your job

Attached: Dp2li8pWsAA0mVO.jpg (720x401, 29K)

But are you employed to program in Haskell?

>janitor

I think it should be perfectly doable.
>I'm deep in some shitty tkinter gui tutorial and I can't even decide between grid or pack.
Looking at your image it's almost certainly a grid layout you're looking for.
effbot.org/tkinterbook/grid.htm
>Don't even know if the email/calender thing is even possible.
You can email people automatically with just about any email software right now.
The calendar is more complicated because you've got a server-client relationship now, as i understand it. Alternatively you could just use the email API and have them send you emails in a structured format. I don't know how you're expecting your clients to interface here.

>This time I'm trying not to be lazy by just copy pasting others shit
You can still do that if you understand what you're copy pasting.

everyone get in here
it's time to take a stand against hiroshimoot

Attached: glenda_3.jpg (1910x2643, 271K)

He's the designated talking head on any given public forum.

Think about steps logically and break them down into smaller and smaller steps until you basically have a gigantic list of incredibly small steps. That's programming in a nutshell. A lot of programming languages allow you to be abstract (so you don't have to break things down into such tiny steps) but don't be fooled, in the end everything turns into a million simplistic steps.

I've got global variables defined outside my functions, but I'm still having to pass them to my functions as arguments and then return them from my functions so other functions can use and update them. I feel like I'm fucking up somewhere. Am I supposed to have lines that go like

iPay, gPay, totIPay, totGPay, totEmp, totIEmp, totGEmp = calc(totGPay, totIPay, totEmp, totGEmp, totIEmp)

This is Python, by the way.

>The calendar is more complicated because you've got a server-client relationship now, as i understand it. Alternatively you could just use the email API and have them send you emails in a structured format. I don't know how you're expecting your clients to interface here.

Before they get any email, they need to login to a calendar from which they choose times and days. This is a only done once.
Then they get an email and it contains a list of items to choose from, next to which is a reserve button.
If they click that, it has a unique ID on the url for their particular account(I think thats possible) which then slots it in to the previous available times for that user. Then *magic* all users reservations have populated in my calendar without overlapping(pushing ahead in time as needed).
I'm almost certain I'll need some LAMP on an EC2 but I don't suspect it needs to be too powerful, and deal with php/mysql and then the main program just handling the mass mailing.

Seems reasonable. I'm not clear on what you've already got going because it sounds like you've already got clients in a functioning system. But you'd probably be the best to judge on that.

Why the fuck can't I match the string __pycache__ in an if statement?

I'm manipulating some folders in a directory with a script and want to ignore it. If I change the name to something else it matches and filters.

Attached: why the fuck.png (250x250, 94K)

Yes I have a few, but the system they are on right now is fucking shit and doesn't let me do anything

Attached: 515a7222.jpg (800x623, 130K)

>countless args countless returns
If all the return variables are unrelated this could be the way to do it. More likely you're looking to group them in a tuple or a struct/class.
As for the args it's the same story.
>I've got global variables defined outside my functions but I'm still having to pass them to my functions
You could do the same thing there and just group them if it's onerous to type them out as arguments everywhere. I'm not sure why you're passing in your globals in the first place. Sounds like they shouldn't be globals then.

textboard.org/prog

Few people have been taught formal logic, but everyone can learn formal logic. With 100% of my being I believe that. It's a god damn-shame that they haven't and I could go into that, but point is the fundamentals of programming are mostly just formal logic. There's more on top of that these days, but if you get the fundamentals part then you're half-way to wherever you want to go.

We warned you bro

Lisp is the most powerful programming language.

Is there an easier way to do pic related? C++ won't let me use the string as a filename directly.

Attached: function.png (549x350, 25K)

you sound like a pinoy

Proof?

works on my machine

Attached: Capture.png (344x41, 1K)

ofstream outfile(name);

std::string::c_str

Can you post the exact error message? There are easier ways to convert an std::String to a char array and in this case a conversion shouldn't even be necessary.

The outfile.open shold compile, even checked it just now on my machine.

not in c++98

>c++98
why tho

Doesn't work.

I think I tried that too. I'll try again.

I did in the other thread.

USing the std::string directly probably really doesn't work because of the C++ standard you use. You have to use at least C++ 11, but c.str() should work with older standards.

Compare current vs new site:
rust-lang.org/en-US/community.html
beta.rust-lang.org/community

Okay, thank you. c.str() works as a replacement for the for loop.
Is there a faster way to do that whole block of code? As in, making a stringstream to accept the counter variable and make a filename out of it?

why is rust community so fuckdup

Run by hr, it's thoroughly modern after all.

>language's greatest strength isn't the language
trash

>Old Site
>Here are some IRC channels you can join on this server
>New Site
>WHAT'S UP GAMERS RUST HAPPENS ON DISCORD LOADING THE CAT VIDEOS LOADING THE MULTI-CORE RENDERING
oh no no no no

Attached: 1543227501314.png (536x536, 349K)

How do I read flags as well as multiple arguments? For example, ls. If you provide 2 directories, you get a list of both directories and the flags specified also work. How do I replicate this? I've tried looking at GNU ls, BSD ls, and BusyBox ls but I couldn't make heads or tails of anything.

fuck that looks horrible

You can pass the filename directly into the ofstream constructor, you would save the open call.

I would recommend using a more recent c++ standard btw, I think noonr uses c++98 anymore. If you use gcc from the commandline it's just one additional option that you have pass, if you use an IDE it is also not hard to do usually.

You want fstat bruh. You're talking about user permissions, right?

How do I use the new C++?

Reminder that OOP questions belong in

I'm trying to write a cli graphing program. Just to have something I can pipe into a text document. ie:
./graph -e foo bar
-e for export
foo is x
bar is y

Do you use the gcc compiler?
Something like this:
g++ -std=c++11 -o testcode1 code1.cpp

What is the least unacceptable paradigm?